function process_renewal($params)
 {
     $new_contract = $this->new_support_contracts[0];
     $new_contract->save();
     $old_contract = new SupportContract($new_contract->get('previous_contract_id'));
     $old_contract->set(array('status' => 'closed', 'end_date' => $new_contract->get('start_date'), 'replacement_contract_id' => $new_contract->id));
     $old_contract->save();
     $this->redirectTo(array('controller' => 'Company', 'action' => 'show', 'id' => $new_contract->get('company_id')));
 }
function productInstanceInfo($product_instance, $o = array())
{
    $r = getRenderer();
    $contract = new SupportContract($product_instance->getData('contract_id'));
    if (!$contract->hasData()) {
        $contract = false;
    }
    $company = new Company($product_instance->getData('company_id'));
    if (!$company->hasData()) {
        $company = false;
    }
    $list_items = array('Domain Name' => $product_instance->getData('domain_name'), 'Techonology' => $product_instance->getData('technology'), 'DNS Notes' => $product_instance->getData('dns_notes'), 'Other Domain Names' => $product_instance->getData('other_domain_names'), 'Server' => $product_instance->getData('server'), 'Subsites' => $product_instance->getData('subsites'), 'Server Account' => $product_instance->getData('server_account'), 'Apache File' => $product_instance->getData('apache_file'), 'Wordpress' => $product_instance->getData('wordpress') ? 'yes' : false, 'OS Commerce' => $product_instance->getData('oscom') ? 'yes' : false, 'Drupal' => $product_instance->getData('drupal') ? 'yes' : false, 'Secure HTTPS' => $product_instance->getData('secure_domain') ? 'yes' : false, 'China IP' => $product_instance->getData('china_ip') ? 'yes' : false, 'PHPlist' => $product_instance->getData('phplist') ? 'yes' : false, 'Contract' => $contract ? $contract->getName() : false, 'Company' => $company ? $company->getName() : false, 'Notes' => $product_instance->getData('notes'));
    $empty_list_keys = array_keys($list_items, false);
    foreach ($empty_list_keys as $key) {
        unset($list_items[$key]);
    }
    $product_instance_info = $r->view('basicList', $list_items);
    return $product_instance_info;
}
Beispiel #3
0
 function testDestroyAssociatedRecords()
 {
     $c = new Company();
     $c->set(array('name' => 'destroy_test'));
     $c->save();
     $p = new Project();
     $p->set(array('company_id' => $c->id, 'name' => 'destroy_project_test'));
     $p->save();
     $e = new Estimate();
     $e->set(array('project_id' => $p->id, 'name' => 'destroy_estimate_test'));
     $e->save();
     $h = new Hour();
     $h->set(array('estimate_id' => $e->id, 'name' => 'destroy_hour_test'));
     $h->save();
     $ch = new Charge();
     $ch->set(array('company_id' => $c->id, 'name' => 'destroy_charge_test'));
     $ch->save();
     $con = new SupportContract();
     $con->set(array('company_id' => $c->id, 'name' => 'destroy_contract_test'));
     $con->save();
     $sup_hr = new Hour();
     $sup_hr->set(array('support_contract_id' => $con->id, 'description' => 'destroy_support_hour_test'));
     $sup_hr->save();
     $pay = new Payment();
     $pay->set(array('company_id' => $c->id, 'name' => 'destroy_payment_test'));
     $pay->save();
     $deleted_items = array('company' => $c->id, 'project' => $p->id, 'estimate' => $e->id, 'hour' => $h->id, 'support_hour' => $sup_hr->id, 'charge' => $ch->id, 'support_contract' => $con->id, 'payment' => $pay->id);
     $c->destroyAssociatedRecords();
     $c->delete();
     $dbcon = AMP::getDb();
     foreach ($deleted_items as $table => $id) {
         if ($table == 'support_hour') {
             $table = 'hour';
         }
         $sql = 'SELECT * FROM ' . $table . ' WHERE id = ' . $id;
         if ($records = $dbcon->Execute($sql)) {
             $this->assertEqual($records->RecordCount(), 0, "{$table} not deleted correctly: %s");
         } else {
             trigger_error($dbcon->ErrorMsg());
         }
     }
 }
Beispiel #4
0
 function testCalculateBalanceWithDateRange()
 {
     #Company
     $cp = new Company();
     $cp->set(array('name' => 'Test Company', 'status' => 'active'));
     $cp->save();
     $pb = new CompanyPreviousBalance();
     $pb->set(array('company_id' => $cp->id, 'amount' => 600.25, 'date' => '2010-01-30'));
     $pb->save();
     $this->assertWithinMargin($pb->getAmount(), '600.25', '.01');
     ######### Support
     $sc = new SupportContract();
     $sc->set(array('company_id' => $cp->id, 'domain_name' => 'Test', 'start_date' => '2010-01-01', 'end_date' => '2010-04-30', 'hourly_rate' => '120', 'support_hours' => '.5', 'monthly_rate' => '50'));
     $sc->save();
     # add support hours
     # before previous balance
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-01-20', 'hours' => '2.5'));
     $h->save();
     # in range
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-02-20', 'hours' => '2.5'));
     $h->save();
     # in range
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-03-20', 'hours' => '2.5'));
     $h->save();
     # out of range
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-05-20', 'hours' => '2'));
     $h->save();
     ### Support Totals = in range is 2 months x 50 = 100, 4 @ 120 = 480 = 580
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $total = $cp->calculateSupportTotal($date_range);
     $this->assertEqual($total, 580);
     ###### Project
     $pj = new Project();
     $pj->set(array('name' => 'Test Project', 'company_id' => $cp->id, 'hourly_rate' => '120'));
     $pj->save();
     # Add an Estimate item #1
     $es1 = new Estimate();
     $es1->set(array('project_id' => $pj->id, 'name' => 'Test Estimate 1', 'high_hours' => '10', 'low_hours' => '5'));
     $es1->save();
     # Add an Estimate item #2
     $es2 = new Estimate();
     $es2->set(array('project_id' => $pj->id, 'name' => 'Test Estimate 2', 'high_hours' => '10', 'low_hours' => '5'));
     $es2->save();
     # Add some before previous balance hours for #1 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es1->id, 'description' => 'Test Hours for Estimate 1', 'date' => '2010-01-15', 'hours' => '5'));
     $hr->save();
     # Add some in range hours for #1 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es1->id, 'description' => 'Test Hours for Estimate 1', 'date' => '2010-02-15', 'hours' => '5'));
     $hr->save();
     # Add some in range hours for #2 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es2->id, 'description' => 'Test Hours for Estimate 2', 'date' => '2010-02-15', 'hours' => '5'));
     $hr->save();
     # Add some out of range hours for #2 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es2->id, 'description' => 'Test Hours for Estimate 2', 'date' => '2010-05-15', 'hours' => '5'));
     $hr->save();
     ## Project Totals = In range 1200, out of range 1800
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $total = $cp->calculateProjectsTotal($date_range);
     $this->assertEqual($total, 1200);
     #Charge
     # before previous balance
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-01-10', 'amount' => '20.50'));
     $cr->save();
     # in date range
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-03-14', 'amount' => '50.25'));
     $cr->save();
     # in date range
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-03-20', 'amount' => '50'));
     $cr->save();
     # out of date range
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-05-15', 'amount' => '50'));
     $cr->save();
     # Total Charges = in range 100.25, out of range 150.25
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $charge_total = $cp->calculateChargesTotal($date_range);
     $this->assertEqual($charge_total, 100.25);
     ## Test Total Costs
     # Charges 100.25 + project 1200 + support 580
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $total = $cp->calculateCosts($date_range);
     $this->assertEqual($total, 1880.25);
     ## Payments
     # add payment before previous balance date
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-01-22', 'amount' => '20.50'));
     $py->save();
     # add payment in range
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-02-10', 'amount' => '20.00'));
     $py->save();
     # add payment in range
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-03-01', 'amount' => '120.00'));
     $py->save();
     # add payment out of range
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-04-01', 'amount' => '20.25'));
     $py->save();
     # Total Payments are 20 + 120 = 140 in range and after previous balance
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $payment_total = $cp->calculatePaymentsTotal($date_range);
     $this->assertEqual($payment_total, 140);
     #### fails because the previous balance isn't getting included FIX ME!!
     # Total Balance Costs 1880.25 - Payments 140 + Previous balance 600.25 = 2340.5
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $balance = $cp->calculateBalance($date_range);
     $this->assertWithinMargin($balance, 2340.5, 0.001);
     ## clean up
     $cp->destroyAssociatedRecords();
     $cp->delete();
 }
Beispiel #5
0
 function makeCriteriaCompany($value)
 {
     $sql = array();
     $projects = Project::getMany(array('company_id' => $value));
     if ($projects) {
         $project_ids = array();
         $sql[] = $this->makeCriteriaProject(array_map(function ($item) {
             return $item->id;
         }, $projects));
     }
     $support_contracts = SupportContract::getMany(array('company_id' => $value));
     if ($support_contracts) {
         $sql[] = $this->makeCriteriaSupportContract(array_map(function ($item) {
             return $item->id;
         }, $support_contracts));
     }
     return '(' . implode(' or ', $sql) . ') ';
 }
        $status = 'active';
    }
    $company_data = array('name' => $rows->Fields('Company'), 'notes' => $rows->Fields('custom9'), 'street' => $rows->Fields('Street'), 'street_2' => $rows->Fields('Street_2'), 'city' => $rows->Fields('City'), 'state' => $rows->Fields('State'), 'zip' => $rows->Fields('Zip'), 'preamp_id' => $rows->Fields('custom1'), 'status' => $status, 'bay_area' => $rows->Fields('custom11'), 'date_started' => $rows->Fields('custom8'));
    $c = new Company();
    $c->set($company_data);
    $c->save();
    $billing_name = explode(' ', $rows->Fields('custom18'), 2);
    $billing_first = !empty($billing_name[0]) ? $billing_name[0] : '';
    $billing_last = !empty($billing_name[1]) ? $billing_name[1] : '';
    $billing_data = array('first_name' => $billing_first, 'last_name' => $billing_last, 'company_id' => $c->id, 'email' => $rows->Fields('custom2'), 'phone' => $rows->Fields('Cell_Phone'), 'is_billing_contact' => true, 'preamp_id' => $rows->Fields('custom1'));
    $billing_contact = new Contact();
    $billing_contact->set($billing_data);
    $billing_contact->save();
    $primary_name = explode(' ', $rows->Fields('custom17'), 2);
    $primary_first = !empty($primary_name[0]) ? $primary_name[0] : '';
    $primary_last = !empty($primary_name[1]) ? $primary_name[1] : '';
    $primary_data = array('first_name' => $primary_first, 'last_name' => $primary_last, 'company_id' => $c->id, 'email' => $rows->Fields('custom3'), 'phone' => $rows->Fields('Phone'), 'is_primary_contact' => true, 'preamp_id' => $rows->Fields('custom1'));
    $primary_contact = new Contact();
    $primary_contact->set($primary_data);
    $primary_contact->save();
    $balance_data = array('company_id' => $c->id, 'date' => '2009-12-31', 'amount' => $rows->Fields('custom12'));
    $balance = new CompanyPreviousBalance();
    $balance->set($balance_data);
    $balance->save();
    $c->getData('status') == 'closed' ? $contract_status = 'cancelled' : ($contract_status = 'active');
    $contract_data = array('domain_name' => 'Old Preamp Contract', 'company_id' => $c->id, 'status' => $contract_status, 'monthly_rate' => $rows->Fields('custom5'), 'support_hours' => $rows->Fields('custom7'), 'hourly_rate' => $rows->Fields('custom6'), 'start_date' => '2009-12-25');
    $contract = new SupportContract();
    $contract->set($contract_data);
    $contract->save();
    $rows->MoveNext();
}