function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     $clf = new CompanyListFactory();
     $clf->StartTransaction();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             if ($c_obj->getStatus() == 10) {
                 $ulf = new UserListFactory();
                 $ulf->getHighestEmployeeNumberByCompanyId($c_obj->getId());
                 if ($ulf->getRecordCount() > 0) {
                     $next_available_employee_number = $ulf->getCurrent()->getEmployeeNumber() + 1;
                 } else {
                     $next_available_employee_number = 1;
                 }
                 $ulf->getByCompanyId($c_obj->getId(), NULL, NULL, NULL, array('hire_date' => 'asc'));
                 if ($ulf->getRecordCount() > 0) {
                     foreach ($ulf as $u_obj) {
                         if ($u_obj->getEmployeeNumber() == '') {
                             Debug::text('Setting Employee Number to: ' . $next_available_employee_number . ' for ' . $u_obj->getUserName(), __FILE__, __LINE__, __METHOD__, 9);
                             $u_obj->setEmployeeNumber($next_available_employee_number);
                             if ($u_obj->isValid()) {
                                 $u_obj->Save();
                                 $next_available_employee_number++;
                             }
                         } else {
                             Debug::text('NOT Setting Employee Number for ' . $u_obj->getUserName() . ' already set to: ' . $u_obj->getEmployeeNumber(), __FILE__, __LINE__, __METHOD__, 9);
                         }
                     }
                 }
             }
         }
     }
     //$clf->FailTransaction();
     $clf->CommitTransaction();
     return TRUE;
 }
 static function addPresets($company_id)
 {
     if ($company_id == '') {
         Debug::text('Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $clf = new CompanyListFactory();
     $clf->getById($company_id);
     if ($clf->getRecordCount() > 0) {
         $company_obj = $clf->getCurrent();
         $country = $company_obj->getCountry();
         $province = $company_obj->getProvince();
     } else {
         Debug::text('bCompany ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     //Get PayStub Link accounts
     $pseallf = new PayStubEntryAccountLinkListFactory();
     $pseallf->getByCompanyId($company_id);
     if ($pseallf->getRecordCount() > 0) {
         $psea_obj = $pseallf->getCurrent();
     } else {
         Debug::text('cCompany ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     $cdf = new CompanyDeductionFactory();
     $cdf->StartTransaction();
     /*
     								10 => 'Percent',
     								15 => 'Advanced Percent',
     								20 => 'Fixed Amount',
     
     								//Federal
     								100 => 'Federal Income Tax Formula',
     
     								//Province/State
     								200 => 'Province/State Income Tax Formula',
     								210 => 'Province/State UI Formula',
     */
     Debug::text('Country: ' . $country, __FILE__, __LINE__, __METHOD__, 10);
     switch (strtolower($country)) {
         case 'ca':
             $pd_obj = new PayrollDeduction($country, 'BC');
             //Pick default province for now.
             $pd_obj->setDate(time());
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Federal Income Tax');
             $cdf->setCalculation(100);
             $cdf->setCalculationOrder(100);
             $cdf->setCountry('CA');
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, '%Federal Income%'));
             $cdf->setUserValue1($pd_obj->getBasicFederalClaimCodeAmount());
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $exclude_ids = array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'Union'));
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 //var_dump($exclude_ids);
                 $cdf->setExcludePayStubEntryAccount($exclude_ids);
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Additional Income Tax');
             $cdf->setCalculation(20);
             $cdf->setCalculationOrder(105);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, '%Additional Income Tax%'));
             $cdf->setUserValue1(0);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('CPP - Employee');
             $cdf->setCalculation(90);
             // CPP Formula
             $cdf->setCalculationOrder(80);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'CPP'));
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('CPP - Employer');
             $cdf->setCalculation(10);
             $cdf->setCalculationOrder(85);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, '%CPP - Employer%'));
             $cdf->setUserValue1(100);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'CPP')));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('EI - Employee');
             $cdf->setCalculation(91);
             //EI Formula
             $cdf->setCalculationOrder(90);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'EI'));
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('EI - Employer');
             $cdf->setCalculation(10);
             $cdf->setCalculationOrder(95);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, '%EI - Employer%'));
             $cdf->setUserValue1(140);
             //2006
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'EI')));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('WCB - Employer');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(95);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, '%WCB%'));
             $cdf->setUserValue1(0.0);
             //Default
             $cdf->setUserValue2(0);
             //Annual Wage Base: WCB has this, but can differ between rates/classifications.
             $cdf->setUserValue3(0);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(20);
             //Deduction
             $cdf->setName('Vacation Accrual');
             $cdf->setCalculation(10);
             $cdf->setCalculationOrder(50);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 50, 'Vacation Accrual'));
             $cdf->setUserValue1(4);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 $exclude_ids = array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 10, 'Vacation Accrual Release'), self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 10, 'Vacation Time'));
                 $cdf->setExcludePayStubEntryAccount($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(20);
             //Deduction
             $cdf->setName('Vacation Release');
             $cdf->setCalculation(10);
             $cdf->setCalculationOrder(51);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 10, 'Vacation Accrual Release'));
             $cdf->setUserValue1(4);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 $exclude_ids = array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 10, 'Vacation Accrual Release'), self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 10, 'Vacation Time'));
                 $cdf->setExcludePayStubEntryAccount($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'us':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Federal Income Tax');
             $cdf->setCalculation(100);
             $cdf->setCalculationOrder(100);
             $cdf->setCountry('US');
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, '%Federal Income%'));
             $cdf->setUserValue1(10);
             //Single
             $cdf->setUserValue2(1);
             //0 Allowances
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Advance Earned Income Credit (EIC)');
             $cdf->setCalculation(80);
             $cdf->setCalculationOrder(105);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, '%Advance EIC%'));
             $cdf->setUserValue1(10);
             //Single
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Federal Unemployment Insurance - Employer');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(80);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'Fed. Unemployment Ins.'));
             $cdf->setUserValue1(0.8);
             //2009
             $cdf->setUserValue2(7000);
             $cdf->setUserValue3(0);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Social Security - Employee');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(80);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'Social Security (FICA)'));
             $cdf->setUserValue1(6.2);
             //2009
             $cdf->setUserValue2(106800);
             $cdf->setUserValue3(0);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Social Security - Employer');
             $cdf->setCalculation(10);
             $cdf->setCalculationOrder(85);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'Social Security%'));
             $cdf->setUserValue1(100);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'Social Security (FICA)')));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Medicare - Employee');
             $cdf->setCalculation(10);
             $cdf->setCalculationOrder(90);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'Medicare'));
             $cdf->setUserValue1(1.45);
             //2009
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName('Medicare - Employer');
             $cdf->setCalculation(10);
             $cdf->setCalculationOrder(95);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'Medicare'));
             $cdf->setUserValue1(100);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 //$cdf->setIncludePayStubEntryAccount( array( $psea_obj->getTotalGross() ));
                 $cdf->setIncludePayStubEntryAccount(array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'Medicare')));
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'cr':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(TTi18n::gettext('Income Tax'));
             $cdf->setCalculation(100);
             $cdf->setCalculationOrder(100);
             $cdf->setCountry('CR');
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, '%Federal Income%'));
             $cdf->setUserValue1(10);
             //Single
             $cdf->setUserValue2(0);
             //0 Allowances
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
     }
     $pd_obj = new PayrollDeduction($country, $province);
     $pd_obj->setDate(time());
     Debug::text('Province/State: ' . $province, __FILE__, __LINE__, __METHOD__, 10);
     switch (strtolower($province)) {
         //Canada
         case 'ab':
         case 'bc':
         case 'sk':
         case 'mb':
         case 'qc':
         case 'on':
         case 'nl':
         case 'nb':
         case 'ns':
         case 'pe':
         case 'nt':
         case 'yt':
         case 'nu':
             $provincial_claim_amount = $pd_obj->getBasicProvinceClaimCodeAmount();
             break;
             //US
         //US
         case 'al':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ak':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance - Employer');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(32700);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance - Employee');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(32700);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ar':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(10000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'az':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Job Training');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Employee Training'));
             $cdf->setUserValue1(0.1);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ca':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Disability Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(180);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'State Disability Ins.'));
             $cdf->setUserValue1(1.1);
             //2009
             $cdf->setUserValue2(90669);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Employee Training');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Employee Training'));
             $cdf->setUserValue1(0.1);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'co':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(10000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ct':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(15000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'dc':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(9000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'de':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(10500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'fl':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ga':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'hi':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(13000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ia':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(23700);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'id':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(33200);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'il':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins. - Employer'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(12300);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'in':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ks':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ky':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'la':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ma':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(14000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'md':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'me':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(12000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'mi':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(9000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'mn':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(26000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'mo':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(12500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ms':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'mt':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(25100);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'nc':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(19300);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'nd':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(23700);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'nh':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ne':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(9000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'nj':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(28900);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(28900);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'nm':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(20900);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'nv':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(26600);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ny':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0);
             //2009
             $cdf->setUserValue2(8500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Reemployment Service Fund');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Reemployment'));
             $cdf->setUserValue1(0.075);
             //2009
             $cdf->setUserValue2(8500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Disability Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(180);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'State Disability Ins.'));
             $cdf->setUserValue1(0.5);
             //2009
             $cdf->setUserValue2(0);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'oh':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(9000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ok':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(14200);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'or':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Insurance'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(31300);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'pa':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ri':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Employment Security');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(18000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'sc':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'sd':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(9500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'tn':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(7000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'tx':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0);
             //2009
             $cdf->setUserValue2(9000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Employee Training');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Employee Training'));
             $cdf->setUserValue1(0.0);
             //2006
             $cdf->setUserValue2(9000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'ut':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(27800);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'va':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'vt':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'wa':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(37500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'wi':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(12000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'wv':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(8000);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
         case 'wy':
             $cdf = new CompanyDeductionFactory();
             $cdf->setCompany($company_id);
             $cdf->setStatus(10);
             //Enabled
             $cdf->setType(10);
             //Tax
             $cdf->setName(strtoupper($province) . ' - Unemployment Insurance');
             $cdf->setCalculation(15);
             $cdf->setCalculationOrder(185);
             $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 30, 'State Unemployment Ins.'));
             $cdf->setUserValue1(0.0);
             //2009
             $cdf->setUserValue2(21500);
             if ($cdf->isValid()) {
                 $cdf->Save(FALSE);
                 $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
                 unset($exclude_ids);
                 if ($cdf->isValid()) {
                     $cdf->Save();
                 }
             }
             break;
     }
     if ($country == 'CA') {
         $cdf = new CompanyDeductionFactory();
         $cdf->setCompany($company_id);
         $cdf->setStatus(10);
         //Enabled
         $cdf->setType(10);
         //Tax
         $cdf->setName(strtoupper($province) . ' - Provincial Income Tax');
         $cdf->setCalculation(200);
         $cdf->setCalculationOrder(110);
         $cdf->setCountry('CA');
         $cdf->setProvince(strtoupper($province));
         $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, '%Provincial Income%'));
         $cdf->setUserValue1($provincial_claim_amount);
         if ($cdf->isValid()) {
             $cdf->Save(FALSE);
             $exclude_ids = array(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, 'Union'));
             $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
             $cdf->setExcludePayStubEntryAccount($exclude_ids);
             unset($exclude_ids);
             if ($cdf->isValid()) {
                 $cdf->Save();
             }
         }
     } elseif ($country = 'US') {
         $cdf = new CompanyDeductionFactory();
         $cdf->setCompany($company_id);
         $cdf->setStatus(10);
         //Enabled
         $cdf->setType(10);
         //Tax
         $cdf->setName('State Income Tax');
         $cdf->setCalculation(200);
         $cdf->setCalculationOrder(200);
         $cdf->setCountry('US');
         $cdf->setProvince(strtoupper($province));
         $cdf->setPayStubEntryAccount(self::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($company_id, 20, '%State Income%'));
         $cdf->setUserValue1(10);
         //Single
         $cdf->setUserValue2(1);
         //0 Allowances
         if ($cdf->isValid()) {
             $cdf->Save(FALSE);
             $cdf->setIncludePayStubEntryAccount(array($psea_obj->getTotalGross()));
             unset($exclude_ids);
             if ($cdf->isValid()) {
                 $cdf->Save();
             }
         }
     }
     $cdf->CommitTransaction();
     //$cdf->FailTransaction();
     return TRUE;
 }
Exemplo n.º 3
0
 * $Date: 2013-01-20 09:21:15 -0800 (Sun, 20 Jan 2013) $
 */
/*
 * Calculate Exceptions for the previous day. This helps especially for
 * the "Unscheuled Absence" exception.
 *
 * Run this once a day. AFTER AddUserDate
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php';
//Debug::setVerbosity(5);
$execution_time = time();
$clf = new CompanyListFactory();
$clf->getAll();
$x = 0;
if ($clf->getRecordCount() > 0) {
    foreach ($clf as $c_obj) {
        if ($c_obj->getStatus() != 30) {
            $company_start_time = microtime(TRUE);
            Debug::text('Company: ' . $c_obj->getName() . '(' . $c_obj->getId() . ')', __FILE__, __LINE__, __METHOD__, 5);
            //Recalculate at least the last two days.
            $start_date = TTDate::getMiddleDayEpoch($execution_time) - 86400 * 2;
            $end_date = TTDate::getMiddleDayEpoch(time()) - 86400;
            //Get the last time cron ran this script.
            $cjlf = new CronJobListFactory();
            $cjlf->getByName('calcExceptions');
            if ($cjlf->getRecordCount() > 0) {
                foreach ($cjlf as $cj_obj) {
                    $tmp_start_date = $cj_obj->getLastRunDate();
                    if ($tmp_start_date < $start_date) {
                        $start_date = $tmp_start_date;
 function sendEmail($to, $headers, $body)
 {
     global $config_vars;
     if (!isset($config_vars['other']['primary_company_id'])) {
         $config_vars['other']['primary_company_id'] = 1;
     }
     $clf = new CompanyListFactory();
     $clf->getById($config_vars['other']['primary_company_id']);
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             $company_data = array('system_version' => APPLICATION_VERSION, 'registration_key' => $this->getLocalRegistrationKey(), 'product_edition_id' => $c_obj->getProductEdition(), 'product_edition_available' => getTTProductEdition(), 'name' => $c_obj->getName(), 'short_name' => $c_obj->getShortName(), 'work_phone' => $c_obj->getWorkPhone(), 'city' => $c_obj->getCity(), 'country' => $c_obj->getCountry(), 'province' => $c_obj->getProvince(), 'postal_code' => $c_obj->getPostalCode());
         }
     }
     if (isset($company_data) and $to != '' and $body != '') {
         return $this->getSoapObject()->sendEmail($to, $headers, $body, $company_data);
     }
     return FALSE;
 }
 function postInstall()
 {
     global $cache;
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Configure currencies for Standard Edition.
     if ($this->getIsUpgrade() == TRUE) {
         $clf = new CompanyListFactory();
         $clf->StartTransaction();
         $clf->getAll();
         if ($clf->getRecordCount() > 0) {
             foreach ($clf as $c_obj) {
                 if ($c_obj->getStatus() == 10) {
                     //Converting to new Accrual Policy table.
                     Debug::text('Converting to new Accrual Policy Table: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9);
                     $pglf = new PolicyGroupListFactory();
                     $pglf->getByCompanyId($c_obj->getId());
                     if ($pglf->getRecordCount() > 0) {
                         foreach ($pglf as $pg_obj) {
                             Debug::text('Accrual Policy ID: ' . $pg_obj->getColumn('accrual_policy_id'), __FILE__, __LINE__, __METHOD__, 9);
                             if ($pg_obj->getColumn('accrual_policy_id') != '' and $pg_obj->getColumn('accrual_policy_id') != 0) {
                                 $pg_obj->setAccrualPolicy(array($pg_obj->getColumn('accrual_policy_id')));
                                 if ($pg_obj->isValid()) {
                                     $pg_obj->Save();
                                 }
                             }
                         }
                     }
                     Debug::text('Adding Currency Information to Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9);
                     $crlf = new CurrencyListFactory();
                     $crlf->getByCompanyId($c_obj->getId());
                     if ($crlf->getRecordCount() == 0) {
                         $cf = new CurrencyFactory();
                         $country_to_currency_map_arr = $cf->getOptions('country_currency');
                         if (isset($country_to_currency_map_arr[$c_obj->getCountry()])) {
                             $base_currency = $country_to_currency_map_arr[$c_obj->getCountry()];
                             Debug::text('Found Base Currency For Country: ' . $c_obj->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9);
                         } else {
                             Debug::text('DID NOT Find Base Currency For Country: ' . $c_obj->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9);
                             $base_currency = 'USD';
                         }
                         $cf->setCompany($c_obj->getId());
                         $cf->setStatus(10);
                         $cf->setName($base_currency);
                         $cf->setISOCode($base_currency);
                         $cf->setConversionRate('1.000000000');
                         $cf->setAutoUpdate(FALSE);
                         $cf->setBase(TRUE);
                         $cf->setDefault(TRUE);
                         if ($cf->isValid()) {
                             $base_currency_id = $cf->Save();
                             Debug::text('Base Currency ID: ' . $base_currency_id, __FILE__, __LINE__, __METHOD__, 10);
                             //Set Employee Hire Defaults.
                             $udlf = new UserDefaultListFactory();
                             $udlf->getByCompanyId($c_obj->getId());
                             if ($udlf->getRecordCount() > 0) {
                                 $ud_obj = $udlf->getCurrent();
                                 $ud_obj->setCurrency($base_currency_id);
                                 $ud_obj->setLanguage('en');
                                 if ($ud_obj->isValid()) {
                                     $ud_obj->Save();
                                 }
                             }
                             unset($udlf, $ud_obj);
                             if (is_numeric($base_currency_id)) {
                                 $ulf = new UserListFactory();
                                 $ulf->getByCompanyId($c_obj->getId());
                                 if ($ulf->getRecordCount() > 0) {
                                     foreach ($ulf as $u_obj) {
                                         $user_id = $u_obj->getID();
                                         Debug::text('Setting Base Currency For User: '******' ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                         $u_obj->setCurrency($base_currency_id);
                                         if ($u_obj->isValid()) {
                                             if ($u_obj->Save() == TRUE) {
                                                 //Set User Default Language
                                                 $uplf = new UserPreferenceListFactory();
                                                 $uplf->getByUserIDAndCompanyID($user_id, $c_obj->getId());
                                                 if ($uplf->getRecordCount() > 0) {
                                                     $up_obj = $uplf->getCurrent();
                                                     $up_obj->setLanguage('en');
                                                     //Englist
                                                     if ($up_obj->isValid()) {
                                                         $up_obj->Save();
                                                     }
                                                 }
                                                 unset($uplf, $up_obj);
                                                 Debug::text('  Setting Base Currency for Pay Stubs, User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                                 //Change all pay stubs for this user to the base currency.
                                                 //Do this in a single query for speed purposes.
                                                 $ph = array('currency_id' => $base_currency_id, 'currency_rate' => '1.000000000', 'user_id' => $user_id);
                                                 $query = 'update pay_stub set currency_id = ?, currency_rate = ? where user_id = ?';
                                                 Debug::text('  Pay Stub Currency Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10);
                                                 $u_obj->db->Execute($query, $ph);
                                                 /*
                                                 $pslf = new PayStubListFactory();
                                                 $pslf->getByUserIdAndCompanyId( $user_id, $c_obj->getId() );
                                                 if ( $pslf->getRecordCount() > 0 ) {
                                                 	foreach( $pslf as $ps_obj ) {
                                                 		//Debug::text('    Setting Base Currency for Pay Stub ID: '. $ps_obj->getId(), __FILE__, __LINE__, __METHOD__,10);
                                                 		
                                                 		$ps_obj->setCurrency( $base_currency_id );
                                                 		if ( $ps_obj->isValid() ) {
                                                 			
                                                 			$ps_obj->setEnableLinkedAccruals( FALSE );												
                                                 			$ps_obj->setEnableCalcYTD( FALSE );
                                                 			$ps_obj->setEnableProcessEntries( FALSE );
                                                 			
                                                 			$ps_obj->Save();
                                                 		}
                                                 		
                                                 		unset($ps_obj);
                                                 	}
                                                 }
                                                 unset($pslf);
                                                 */
                                             } else {
                                                 Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                         } else {
                                             Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                         unset($u_obj, $user_id);
                                     }
                                 }
                                 unset($ulf);
                             }
                         }
                         unset($cf);
                     }
                 } else {
                     Debug::text('Company is not active! ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 }
                 unset($c_obj, $base_currency, $base_currency_id, $crlf);
             }
         }
         //$clf->FailTransaction();
         $clf->CommitTransaction();
     }
     //Add currency updating to cron.
     $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR;
     if (PHP_OS == 'WINNT') {
         $cron_job_base_command = 'php-win.exe ' . $maint_base_path;
     } else {
         $cron_job_base_command = 'php ' . $maint_base_path;
     }
     Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9);
     $cjf = new CronJobFactory();
     $cjf->setName('UpdateCurrencyRates');
     $cjf->setMinute(45);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('*');
     $cjf->setCommand($cron_job_base_command . 'UpdateCurrencyRates.php');
     $cjf->Save();
     return TRUE;
 }
 function checkCompanyStatus($user_name)
 {
     $ulf = new UserListFactory();
     $ulf->getByUserName(strtolower($user_name));
     if ($ulf->getRecordCount() == 1) {
         $u_obj = $ulf->getCurrent();
         if (is_object($u_obj)) {
             $clf = new CompanyListFactory();
             $clf->getById($u_obj->getCompany());
             if ($clf->getRecordCount() == 1) {
                 if ($clf->getCurrent()->getStatus() == 10) {
                     return TRUE;
                 }
             }
         }
     }
     return FALSE;
 }
Exemplo n.º 7
0
/*
 * $Revision: 1396 $
 * $Id: CheckForUpdate.php 1396 2007-11-07 16:49:35Z ipso $
 * $Date: 2007-11-07 08:49:35 -0800 (Wed, 07 Nov 2007) $
 */
/*
 * Checks for any version updates...
 *
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php';
$ttsc = new TimeTrexSoapClient();
if ($ttsc->isUpdateNotifyEnabled() == TRUE) {
    $clf = new CompanyListFactory();
    $clf->getAll();
    if ($clf->getRecordCount() > 0) {
        $i = 0;
        foreach ($clf as $c_obj) {
            if ($ttsc->getLocalRegistrationKey() == FALSE or $ttsc->getLocalRegistrationKey() == '') {
                $ttsc->saveRegistrationKey();
            }
            //We must ensure that the data is up to date
            //Otherwise version check will fail.
            $ttsc->sendCompanyData($c_obj->getId());
            $ttsc->sendCompanyUserLocationData($c_obj->getId());
            $ttsc->sendCompanyUserCountData($c_obj->getId());
            $ttsc->sendCompanyVersionData($c_obj->getId());
            //Only need to call this on the last company
            if ($i == $clf->getRecordCount() - 1) {
                $latest_version = $ttsc->isLatestVersion($c_obj->getId());
                $latest_tax_engine_version = $ttsc->isLatestTaxEngineVersion($c_obj->getId());
 static function addPresets($company_id)
 {
     if ($company_id == '') {
         return FALSE;
     }
     $clf = new CompanyListFactory();
     $clf->getById($company_id);
     if ($clf->getRecordCount() > 0) {
         $company_obj = $clf->getCurrent();
         $country = $company_obj->getCountry();
         $province = $company_obj->getProvince();
     } else {
         return FALSE;
     }
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->StartTransaction();
     /*
     								10 => 'Earning',
     								20 => 'Employee Deduction',
     								30 => 'Employer Deduction',
     								40 => 'Total',
     								50 => 'Accrual',
     								60 => 'Advance Earning',
     								65 => 'Advance Deduction',
     */
     //See if accounts are already linked
     $pseallf = new PayStubEntryAccountLinkListFactory();
     $pseallf->getByCompanyId($company_id);
     if ($pseallf->getRecordCount() > 0) {
         $psealf = $pseallf->getCurrent();
     } else {
         $psealf = new PayStubEntryAccountLinkFactory();
         $psealf->setCompany($company_id);
     }
     Debug::text('Country: ' . $country, __FILE__, __LINE__, __METHOD__, 10);
     switch (strtolower($country)) {
         case 'ca':
             Debug::text('Saving.... Federal Taxes', __FILE__, __LINE__, __METHOD__, 10);
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Federal Income Tax');
             $pseaf->setOrder(210);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Provincial Income Tax');
             $pseaf->setOrder(220);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Additional Income Tax');
             $pseaf->setOrder(230);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('CPP');
             $pseaf->setOrder(240);
             if ($pseaf->isValid()) {
                 $psea_id = $pseaf->Save();
                 $psealf->setEmployeeCPP($psea_id);
                 unset($psea_id);
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('EI');
             $pseaf->setOrder(250);
             if ($pseaf->isValid()) {
                 $psea_id = $pseaf->Save();
                 $psealf->setEmployeeEI($psea_id);
                 unset($psea_id);
             }
             //Employer Contributions
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('CPP - Employer');
             $pseaf->setOrder(300);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('EI - Employer');
             $pseaf->setOrder(310);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('WCB - Employer');
             $pseaf->setOrder(320);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             Debug::text('Saving.... Vacation Accrual', __FILE__, __LINE__, __METHOD__, 10);
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(50);
             $pseaf->setName('Vacation Accrual');
             $pseaf->setOrder(400);
             if ($pseaf->isValid()) {
                 $vacation_accrual_id = $pseaf->Save();
                 Debug::text('Saving.... Earnings - Vacation Accrual Release', __FILE__, __LINE__, __METHOD__, 10);
                 $pseaf = new PayStubEntryAccountFactory();
                 $pseaf->setCompany($company_id);
                 $pseaf->setStatus(10);
                 $pseaf->setType(10);
                 $pseaf->setName('Vacation Accrual Release');
                 $pseaf->setOrder(180);
                 $pseaf->setAccrual($vacation_accrual_id);
                 if ($pseaf->isValid()) {
                     $pseaf->Save();
                 }
                 unset($vaction_accrual_id);
             }
             break;
         case 'us':
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Federal Income Tax');
             $pseaf->setOrder(210);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Advance EIC');
             $pseaf->setOrder(215);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('State Income Tax');
             $pseaf->setOrder(220);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('District Income Tax');
             $pseaf->setOrder(225);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Federal Add. Income Tax');
             $pseaf->setOrder(230);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('State Add. Income Tax');
             $pseaf->setOrder(235);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Social Security (FICA)');
             $pseaf->setOrder(240);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('Social Security (FICA)');
             $pseaf->setOrder(340);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('Fed. Unemployment Ins.');
             $pseaf->setOrder(342);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('State Unemployment Ins.');
             $pseaf->setOrder(240);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('Medicare');
             $pseaf->setOrder(245);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('Medicare');
             $pseaf->setOrder(346);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(20);
             $pseaf->setName('State Disability Ins.');
             $pseaf->setOrder(250);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('State Unemployment Ins.');
             $pseaf->setOrder(350);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('State Employee Training');
             $pseaf->setOrder(352);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             break;
     }
     Debug::text('Province: ' . $province, __FILE__, __LINE__, __METHOD__, 10);
     switch (strtolower($province)) {
         case 'ny':
             $pseaf = new PayStubEntryAccountFactory();
             $pseaf->setCompany($company_id);
             $pseaf->setStatus(10);
             $pseaf->setType(30);
             $pseaf->setName('State Reemployment');
             $pseaf->setOrder(354);
             if ($pseaf->isValid()) {
                 $pseaf->Save();
             }
             break;
     }
     Debug::text('Saving.... Earnings - Regular Time', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(10);
     $pseaf->setName('Regular Time');
     $pseaf->setOrder(100);
     if ($pseaf->isValid()) {
         $psea_id = $pseaf->Save();
         $psealf->setRegularTime($psea_id);
         unset($psea_id);
     }
     Debug::text('Saving.... Earnings - Over Time 1', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(10);
     $pseaf->setName('Over Time 1');
     $pseaf->setOrder(150);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Earnings - Over Time 2', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(10);
     $pseaf->setName('Over Time 2');
     $pseaf->setOrder(151);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Earnings - Premium Time 1', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(10);
     $pseaf->setName('Premium 1');
     $pseaf->setOrder(170);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Earnings - Premium Time 2', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(10);
     $pseaf->setName('Premium 2');
     $pseaf->setOrder(171);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Earnings - Bonus', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(10);
     $pseaf->setName('Bonus');
     $pseaf->setOrder(185);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Earnings - Other', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(10);
     $pseaf->setName('Other');
     $pseaf->setOrder(189);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Union Dues', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(20);
     $pseaf->setName('Union Dues');
     $pseaf->setOrder(285);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Employee Benefits Plan', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(20);
     $pseaf->setName('Benefits Plan');
     $pseaf->setOrder(225);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Employer Benefits Plan', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(30);
     $pseaf->setName('Benefits Plan');
     $pseaf->setOrder(330);
     if ($pseaf->isValid()) {
         $pseaf->Save();
     }
     Debug::text('Saving.... Total Earnings', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(40);
     $pseaf->setName('Total Gross');
     $pseaf->setOrder(199);
     if ($pseaf->isValid()) {
         $psea_id = $pseaf->Save();
         $psealf->setTotalGross($psea_id);
         unset($psea_id);
     }
     Debug::text('Saving.... Total Deductions', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(40);
     $pseaf->setName('Total Deductions');
     $pseaf->setOrder(298);
     if ($pseaf->isValid()) {
         $psea_id = $pseaf->Save();
         $psealf->setTotalEmployeeDeduction($psea_id);
         unset($psea_id);
     }
     Debug::text('Saving.... Net Pay', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(40);
     $pseaf->setName('Net Pay');
     $pseaf->setOrder(299);
     if ($pseaf->isValid()) {
         $psea_id = $pseaf->Save();
         $psealf->setTotalNetPay($psea_id);
         unset($psea_id);
     }
     Debug::text('Saving.... Employer Total Cont', __FILE__, __LINE__, __METHOD__, 10);
     $pseaf = new PayStubEntryAccountFactory();
     $pseaf->setCompany($company_id);
     $pseaf->setStatus(10);
     $pseaf->setType(40);
     $pseaf->setName('Employer Total Contributions');
     $pseaf->setOrder(399);
     if ($pseaf->isValid()) {
         $psea_id = $pseaf->Save();
         $psealf->setTotalEmployerDeduction($psea_id);
         unset($psea_id);
     }
     if ($psealf->isValid() == TRUE) {
         Debug::text('Saving.... PSA Linking', __FILE__, __LINE__, __METHOD__, 10);
         $psealf->Save();
     } else {
         Debug::text('Saving.... PSA Linking FAILED!', __FILE__, __LINE__, __METHOD__, 10);
     }
     $pseaf->CommitTransaction();
     //$pseaf->FailTransaction();
     return TRUE;
 }
 function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Go through all pay period schedules and update the annual pay period column
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             $pps_obj->setAnnualPayPeriods($pps_obj->calcAnnualPayPeriods());
             if ($pps_obj->isValid()) {
                 $pps_obj->Save();
             }
         }
     }
     //Go through all employee wages and update HourlyRate to the accurate annual hourly rate.
     //**Handle this in 1034A postInstall() instead, as it needs to handle incorrect effective_dates properly.
     /*
     $uwlf = new UserWageListFactory();
     $uwlf->getAll();
     if ( $uwlf->getRecordCount() > 0 ) {
     	foreach( $uwlf as $uw_obj ) {
     		$uw_obj->setHourlyRate( $uw_obj->calcHourlyRate( time(), TRUE ) );
     		if ( $uw_obj->isValid() ) {
     			$uw_obj->Save();
     		}
     	}
     }
     */
     //Upgrade to new hierarchy format.
     $clf = new CompanyListFactory();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             if ($c_obj->getStatus() != 30) {
                 /*
                 					if ( !($c_obj->getId() == 1052) ) { //$c_obj->getId() == 1009 OR $c_obj->getId() == 1087 OR
                 						continue;
                 					}
                 */
                 $company_id = $c_obj->getId();
                 Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                 $hclf = new HierarchyControlListFactory();
                 $hclf->StartTransaction();
                 $hclf->getByCompanyId($company_id);
                 if ($hclf->getRecordCount() > 0) {
                     foreach ($hclf as $hc_obj) {
                         $paths_to_root = array();
                         $hierarchy_id = $hc_obj->getId();
                         $hlf = new HierarchyListFactory();
                         $hierarchy_users = $hlf->getByCompanyIdAndHierarchyControlId($company_id, $hierarchy_id);
                         if (is_array($hierarchy_users) and count($hierarchy_users) > 0) {
                             $hotlf = new HierarchyObjectTypeListFactory();
                             $hotlf->getByHierarchyControlId($hierarchy_id);
                             if ($hotlf->getRecordCount() > 0) {
                                 foreach ($hotlf as $hot_obj) {
                                     $object_types[$hierarchy_id][] = $hot_obj->getObjectType();
                                 }
                             }
                             foreach ($hierarchy_users as $hierarchy_user_arr) {
                                 Debug::Text(' Checking User ID: ' . $hierarchy_user_arr['id'], __FILE__, __LINE__, __METHOD__, 10);
                                 $id = $hierarchy_user_arr['id'];
                                 $tmp_id = $id;
                                 $i = 0;
                                 do {
                                     Debug::Text(' Iteration...', __FILE__, __LINE__, __METHOD__, 10);
                                     $hlf_b = new HierarchyListFactory();
                                     $parents = $hlf_b->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $tmp_id);
                                     sort($parents);
                                     $level = $hlf_b->getFastTreeObject()->getLevel($tmp_id) - 1;
                                     if (is_array($parents) and count($parents) > 0) {
                                         $parent_users = array();
                                         foreach ($parents as $user_id) {
                                             $parent_users[] = $user_id;
                                             unset($user);
                                         }
                                         $parent_groups[$level] = $parent_users;
                                         unset($parent_users);
                                     }
                                     if (isset($parents[0])) {
                                         $tmp_id = $parents[0];
                                     }
                                     $i++;
                                 } while (is_array($parents) and count($parents) > 0 and $i < 100);
                                 if (isset($parent_groups)) {
                                     $serialized_path = serialize($parent_groups);
                                     $paths_to_root[$serialized_path][] = $id;
                                     unset($serialized_path);
                                 }
                                 unset($parent_groups, $parents);
                             }
                         }
                         Debug::Arr($paths_to_root, ' Paths To Root: ', __FILE__, __LINE__, __METHOD__, 10);
                         //Decode path_to_root array
                         if (isset($paths_to_root) and count($paths_to_root) > 0) {
                             foreach ($paths_to_root as $serialized_path => $children) {
                                 $path_arr = unserialize($serialized_path);
                                 $decoded_paths[] = array('hierarchy_control_id' => $hierarchy_id, 'path' => $path_arr, 'children' => $children);
                             }
                             unset($path_arr, $children);
                             Debug::Arr($decoded_paths, ' Decoded Paths: ', __FILE__, __LINE__, __METHOD__, 10);
                             if (isset($decoded_paths) and is_array($decoded_paths)) {
                                 foreach ($decoded_paths as $decoded_path) {
                                     Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                                     //Create new hierarchy_control
                                     $hcf = new HierarchyControlFactory();
                                     $hcf->setCompany($company_id);
                                     $hcf->setObjectType($object_types[$decoded_path['hierarchy_control_id']]);
                                     //Generate meaningful name
                                     $name = FALSE;
                                     if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                         ksort($decoded_path['path']);
                                         //Sort by level.
                                         foreach ($decoded_path['path'] as $level => $superior_ids) {
                                             foreach ($superior_ids as $superior_id) {
                                                 $ulf = new UserListFactory();
                                                 $ulf->getById($superior_id);
                                                 if ($ulf->getRecordCount() > 0) {
                                                     $name[] = $level . '. ' . $ulf->getCurrent()->getFullName();
                                                 }
                                             }
                                         }
                                         unset($level, $superior_ids, $superior_id);
                                     }
                                     if (isset($name)) {
                                         $name = $hc_obj->getName() . ' ' . implode(', ', $name) . ' (#' . rand(1000, 9999) . ')';
                                     } else {
                                         $name = $hc_obj->getName() . ' (#' . rand(1000, 9999) . ')';
                                     }
                                     $hcf->setName(substr($name, 0, 249));
                                     $hcf->setDescription(TTi18n::getText('Automatically created by TimeTrex'));
                                     if ($hcf->isValid()) {
                                         $hc_id = $hcf->Save(FALSE);
                                         Debug::Text('Hierarchy Control ID: ' . $hc_id, __FILE__, __LINE__, __METHOD__, 10);
                                         $hcf->setUser($decoded_path['children']);
                                         if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                             foreach ($decoded_path['path'] as $level => $superior_ids) {
                                                 foreach ($superior_ids as $superior_id) {
                                                     $hlf = new HierarchyLevelFactory();
                                                     $hlf->setHierarchyControl($hc_id);
                                                     $hlf->setLevel($level);
                                                     $hlf->setUser($superior_id);
                                                     if ($hlf->isValid()) {
                                                         $hlf->Save();
                                                         Debug::Text('Saving Level Row ID... User ID: ' . $superior_id, __FILE__, __LINE__, __METHOD__, 10);
                                                     }
                                                 }
                                             }
                                             unset($level, $superior_ids, $superior_id);
                                         }
                                     }
                                 }
                             }
                             unset($decoded_paths);
                         }
                         //Delete existing hierarchy control.
                         $hc_obj->setDeleted(TRUE);
                         if ($hc_obj->isValid() == TRUE) {
                             $hc_obj->Save();
                         }
                     }
                 }
                 //$hclf->FailTransaction();
                 $hclf->CommitTransaction();
             }
         }
     }
     //Go through each permission group, and enable break policies for anyone who can see meal policies
     $clf = new CompanyListFactory();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             Debug::text('Company: ' . $c_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
             if ($c_obj->getStatus() != 30) {
                 $pclf = new PermissionControlListFactory();
                 $pclf->getByCompanyId($c_obj->getId());
                 if ($pclf->getRecordCount() > 0) {
                     foreach ($pclf as $pc_obj) {
                         Debug::text('Permission Group: ' . $pc_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
                         $plf = new PermissionListFactory();
                         $plf->getByCompanyIdAndPermissionControlIdAndSectionAndName($c_obj->getId(), $pc_obj->getId(), 'meal_policy', 'enabled');
                         if ($plf->getRecordCount() > 0) {
                             Debug::text('Found permission group with meal policy enabled: ' . $plf->getCurrent()->getValue(), __FILE__, __LINE__, __METHOD__, 9);
                             $pc_obj->setPermission(array('break_policy' => array('enabled' => TRUE, 'view' => TRUE, 'add' => TRUE, 'edit' => TRUE, 'delete' => TRUE)));
                         } else {
                             Debug::text('Permission group does NOT have meal policy enabled...', __FILE__, __LINE__, __METHOD__, 9);
                         }
                     }
                 }
             }
         }
     }
     //Add MiscDaily cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscDaily');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('*');
     $cjf->setCommand('MiscDaily.php');
     $cjf->Save();
     //Add MiscWeekly cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscWeekly');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('0');
     //Sunday morning.
     $cjf->setCommand('MiscWeekly.php');
     $cjf->Save();
     return TRUE;
 }
Exemplo n.º 10
0
 /**
  * Get about data .
  *
  */
 function getAboutData($ytd = 0, $all_companies = FALSE)
 {
     global $config_vars;
     $clf = new CompanyListFactory();
     $sslf = new SystemSettingListFactory();
     $system_settings = $sslf->getAllArray();
     $clf->getByID(PRIMARY_COMPANY_ID);
     if ($clf->getRecordCount() == 1) {
         $primary_company = $clf->getCurrent();
     }
     $current_user = $this->getCurrentUserObject();
     if (isset($primary_company) and PRIMARY_COMPANY_ID == $current_user->getCompany()) {
         $current_company = $primary_company;
     } else {
         $current_company = $clf->getByID($current_user->getCompany())->getCurrent();
     }
     //$current_user_prefs = $current_user->getUserPreferenceObject();
     $data = $system_settings;
     if (isset($data['new_version']) and $data['new_version'] == TRUE) {
         $data['new_version'] = TRUE;
     } else {
         $data['new_version'] = FALSE;
     }
     $data['product_edition'] = Option::getByKey(DEPLOYMENT_ON_DEMAND == TRUE ? $current_company->getProductEdition() : getTTProductEdition(), $current_company->getOptions('product_edition'));
     $data['application_name'] = APPLICATION_NAME;
     $data['organization_url'] = ORGANIZATION_URL;
     //Get Employee counts for this month, and last month
     $month_of_year_arr = TTDate::getMonthOfYearArray();
     //This month
     if (isset($ytd) and $ytd == 1) {
         $begin_month_epoch = strtotime('-2 years');
     } else {
         $begin_month_epoch = TTDate::getBeginMonthEpoch(TTDate::getBeginMonthEpoch(time()) - 86400);
     }
     $cuclf = TTnew('CompanyUserCountListFactory');
     if (isset($config_vars['other']['primary_company_id']) and $current_company->getId() == $config_vars['other']['primary_company_id'] and $all_companies == TRUE) {
         $cuclf->getTotalMonthlyMinAvgMaxByCompanyStatusAndStartDateAndEndDate(10, $begin_month_epoch, TTDate::getEndMonthEpoch(time()), NULL, NULL, NULL, array('date_stamp' => 'desc'));
     } else {
         $cuclf->getMonthlyMinAvgMaxByCompanyIdAndStartDateAndEndDate($current_company->getId(), $begin_month_epoch, TTDate::getEndMonthEpoch(time()), NULL, NULL, NULL, array('date_stamp' => 'desc'));
     }
     Debug::Text('Company User Count Rows: ' . $cuclf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($cuclf->getRecordCount() > 0) {
         foreach ($cuclf as $cuc_obj) {
             $data['user_counts'][] = array('label' => $month_of_year_arr[TTDate::getMonth(TTDate::strtotime($cuc_obj->getColumn('date_stamp')))] . ' ' . TTDate::getYear(TTDate::strtotime($cuc_obj->getColumn('date_stamp'))), 'max_active_users' => $cuc_obj->getColumn('max_active_users'), 'max_inactive_users' => $cuc_obj->getColumn('max_inactive_users'), 'max_deleted_users' => $cuc_obj->getColumn('max_deleted_users'));
         }
     }
     if (isset($data['user_counts']) == FALSE) {
         $data['user_counts'] = array();
     }
     $cjlf = TTnew('CronJobListFactory');
     $cjlf->getMostRecentlyRun();
     if ($cjlf->getRecordCount() > 0) {
         $cj_obj = $cjlf->getCurrent();
         $data['cron'] = array('last_run_date' => $cj_obj->getLastRunDate() == FALSE ? TTi18n::getText('Never') : TTDate::getDate('DATE+TIME', $cj_obj->getLastRunDate()));
     }
     $data['show_license_data'] = FALSE;
     if ((DEPLOYMENT_ON_DEMAND == FALSE and $current_company->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $current_company->getId() == $config_vars['other']['primary_company_id']) and getTTProductEdition() > 10) {
         if (!isset($system_settings['license'])) {
             $system_settings['license'] = NULL;
         }
         $data['show_license_data'] = TRUE;
         //Set this so the license upload area at least shows up regardles of edition.
         $data['license_data'] = array();
         $license = new TTLicense();
         $retval = $license->validateLicense($system_settings['license']);
         if ($retval == TRUE) {
             $data['license_data'] = array('organization_name' => $license->getOrganizationName(), 'major_version' => $license->getMajorVersion(), 'minor_version' => $license->getMinorVersion(), 'product_name' => $license->getProductName(), 'active_employee_licenses' => $license->getActiveEmployeeLicenses(), 'issue_date' => TTDate::getDate('DATE', $license->getIssueDate()), 'expire_date' => $license->getExpireDate(), 'expire_date_display' => TTDate::getDate('DATE', $license->getExpireDate()), 'registration_key' => $license->getRegistrationKey(), 'message' => $license->getFullErrorMessage($retval), 'retval' => $retval);
         }
     }
     //Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__,10);
     return $this->returnHandler($data);
 }
Exemplo n.º 11
0
}
//Do not overwrite a previously sent content-type header, this breaks WAP.
if (!isset($enable_wap)) {
    header('Content-Type: text/html; charset=UTF-8');
}
//Skip this step if disable_database_connection is enabled or the user is going through the installer still
$clf = new CompanyListFactory();
if ((!isset($disable_database_connection) or isset($disable_database_connection) and $disable_database_connection != TRUE) and (!isset($config_vars['other']['installer_enabled']) or isset($config_vars['other']['installer_enabled']) and $config_vars['other']['installer_enabled'] != TRUE)) {
    //Get all system settings, so they can be used even if the user isn't logged in, such as the login page.
    try {
        $sslf = new SystemSettingListFactory();
        $system_settings = $sslf->getAllArray();
        unset($sslf);
        //Get primary company data needs to be used when user isn't logged in as well.
        $clf->getByID(PRIMARY_COMPANY_ID);
        if ($clf->getRecordCount() == 1) {
            $primary_company = $clf->getCurrent();
        }
    } catch (Exception $e) {
        //Database not initialized, or some error, redirect to Install page.
        throw new DBError($e, 'DBInitialize');
    }
}
$permission = new Permission();
$authentication = new Authentication();
if (isset($authenticate) and $authenticate === FALSE) {
    Debug::text('Bypassing Authentication', __FILE__, __LINE__, __METHOD__, 10);
    TTi18n::chooseBestLocale();
} else {
    //Increase timeout on WAP devices, so they don't have to login as often.
    if (isset($enable_wap) and $enable_wap == TRUE) {