function getCompanyObject()
 {
     if (is_object($this->company_obj)) {
         return $this->company_obj;
     } else {
         $clf = new CompanyListFactory();
         $this->company_obj = $clf->getById($this->getCompany())->getCurrent();
         return $this->company_obj;
     }
 }
 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;
 }
Пример #3
0
 function generateData()
 {
     global $current_company, $current_user;
     TTDate::setTimeZone('PST8PDT');
     $current_epoch = time();
     $cf = new CompanyFactory();
     $cf->StartTransaction();
     $company_id = $this->createCompany();
     $clf = new CompanyListFactory();
     $clf->getById($company_id);
     $current_company = $clf->getCurrent();
     if ($company_id !== FALSE) {
         Debug::Text('Company Created Successfully!', __FILE__, __LINE__, __METHOD__, 10);
         $this->createPermissionGroups($company_id);
         //Create currency
         $currency_ids[] = $this->createCurrency($company_id, 10);
         //USD
         $currency_ids[] = $this->createCurrency($company_id, 20);
         //CAD
         //Create branch
         $branch_ids[] = $this->createBranch($company_id, 10);
         //NY
         $branch_ids[] = $this->createBranch($company_id, 20);
         //WA
         //Create departments
         $department_ids[] = $this->createDepartment($company_id, 10);
         $department_ids[] = $this->createDepartment($company_id, 20);
         //Create stations
         $station_id = $this->createStation($company_id);
         //Create pay stub accounts.
         $this->createPayStubAccount($company_id);
         //Link pay stub accounts.
         $this->createPayStubAccountLink($company_id);
         //Company Deductions
         $this->createCompanyDeduction($company_id);
         //Wage Groups
         $wage_group_ids[] = $this->createUserWageGroups($company_id);
         //User Groups
         $user_group_ids[] = $this->createUserGroup($company_id, 10, 0);
         $user_group_ids[] = $this->createUserGroup($company_id, 20, $user_group_ids[0]);
         $user_group_ids[] = $this->createUserGroup($company_id, 30, $user_group_ids[0]);
         $user_group_ids[] = $this->createUserGroup($company_id, 40, 0);
         $user_group_ids[] = $this->createUserGroup($company_id, 50, $user_group_ids[3]);
         //Users
         $user_ids[] = $this->createUser($company_id, 10, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 11, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 12, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 13, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 14, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 15, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 16, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 17, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 18, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[2]);
         $user_ids[] = $this->createUser($company_id, 19, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[2]);
         $user_ids[] = $this->createUser($company_id, 20, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[2]);
         $user_ids[] = $this->createUser($company_id, 21, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 22, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 23, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 24, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 25, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 26, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 27, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 28, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 29, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 30, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 40, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4]);
         $current_user_id = $user_ids[] = $this->createUser($company_id, 100, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[1]);
         //Create random users.
         for ($i = 0; $i <= $this->getMaxRandomUsers(); $i++) {
             $tmp_user_id = $this->createUser($company_id, 999, 0, $branch_ids[$i % 2], $department_ids[$i % 2], $currency_ids[0], $user_group_ids[$i % 5]);
             if ($tmp_user_id != FALSE) {
                 $user_ids[] = $tmp_user_id;
             }
         }
         Debug::Arr($user_ids, 'All User IDs:', __FILE__, __LINE__, __METHOD__, 10);
         $ulf = new UserListFactory();
         $ulf->getById($current_user_id);
         $current_user = $ulf->getCurrent();
         unset($current_user_id);
         //Create policies
         $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 10);
         //In
         $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 20);
         //Out
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 10);
         //Bank Time
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 20);
         //Vacaction
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 30);
         //Sick
         $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 10);
         $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 20, $policy_ids['accrual'][0]);
         $policy_ids['premium'][] = $this->createPremiumPolicy($company_id, 10);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 10, $policy_ids['accrual'][1]);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 20, $policy_ids['accrual'][0]);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 30, $policy_ids['accrual'][2]);
         $policy_ids['meal_1'] = $this->createMealPolicy($company_id);
         $policy_ids['schedule_1'] = $this->createSchedulePolicy($company_id, $policy_ids['meal_1']);
         $policy_ids['exception_1'] = $this->createExceptionPolicy($company_id);
         $hierarchy_user_ids = $user_ids;
         $root_user_id = array_pop($hierarchy_user_ids);
         unset($hierarchy_user_ids[0], $hierarchy_user_ids[1]);
         //Create authorization hierarchy
         $hierarchy_control_id = $this->createAuthorizationHierarchyControl($company_id, $hierarchy_user_ids);
         if ($root_user_id == FALSE) {
             Debug::Text('Administrator wasn\'t created! Duplicate username perhaps? Are we appending a random number?', __FILE__, __LINE__, __METHOD__, 10);
         }
         //Admin user at the top
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $root_user_id, 1);
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[0], 2);
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[1], 3);
         unset($hierarchy_user_ids, $root_user_id);
         //Pay Period Schedule
         $this->createPayPeriodSchedule($company_id, $user_ids);
         //Create Policy Group
         $this->createPolicyGroup($company_id, $policy_ids['meal_1'], $policy_ids['exception_1'], NULL, $policy_ids['overtime'], $policy_ids['premium'], $policy_ids['round'], $user_ids);
         if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL) {
             //Task Groups
             $task_group_ids[] = $this->createTaskGroup($company_id, 10, 0);
             $task_group_ids[] = $this->createTaskGroup($company_id, 20, $task_group_ids[0]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 30, $task_group_ids[0]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 40, 0);
             $task_group_ids[] = $this->createTaskGroup($company_id, 50, $task_group_ids[3]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 60, $task_group_ids[3]);
             //Job Tasks
             $default_task_id = $this->createTask($company_id, 10, $task_group_ids[2]);
             $task_ids[] = $this->createTask($company_id, 20, $task_group_ids[1]);
             $task_ids[] = $this->createTask($company_id, 30, $task_group_ids[1]);
             $task_ids[] = $this->createTask($company_id, 40, $task_group_ids[2]);
             $task_ids[] = $this->createTask($company_id, 50, $task_group_ids[4]);
             $task_ids[] = $this->createTask($company_id, 60, $task_group_ids[4]);
             $task_ids[] = $this->createTask($company_id, 70, $task_group_ids[5]);
             //Job Groups
             $job_group_ids[] = $this->createJobGroup($company_id, 10, 0);
             $job_group_ids[] = $this->createJobGroup($company_id, 20, $job_group_ids[0]);
             $job_group_ids[] = $this->createJobGroup($company_id, 30, $job_group_ids[0]);
             $job_group_ids[] = $this->createJobGroup($company_id, 40, 0);
             $job_group_ids[] = $this->createJobGroup($company_id, 50, $job_group_ids[3]);
             $job_group_ids[] = $this->createJobGroup($company_id, 60, $job_group_ids[3]);
             //Jobs
             $job_ids[] = $this->createJob($company_id, 10, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 11, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 12, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 13, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 14, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 15, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 16, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 17, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 18, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 19, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 20, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 21, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 22, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 23, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 24, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 25, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
         } else {
             $task_ids[] = 0;
             $job_ids[] = 0;
         }
         //Create Accrual balances
         foreach ($user_ids as $user_id) {
             foreach ($policy_ids['accrual'] as $accrual_policy_id) {
                 $this->createAccrualBalance($user_id, $accrual_policy_id);
             }
             unset($accrual_policy_id);
         }
         //Create recurring schedule templates
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 10, $policy_ids['schedule_1']);
         //Morning shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 20, $policy_ids['schedule_1']);
         //Afternoon shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 30, $policy_ids['schedule_1']);
         //Evening shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 40);
         //Split Shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 50, $policy_ids['schedule_1']);
         //Full rotation
         $recurring_schedule_start_date = TTDate::getBeginWeekEpoch($current_epoch + 86400 * 7.5);
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[0], $recurring_schedule_start_date, '', array($user_ids[0], $user_ids[1], $user_ids[2], $user_ids[3], $user_ids[4]));
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[1], $recurring_schedule_start_date, '', array($user_ids[5], $user_ids[6], $user_ids[7], $user_ids[8], $user_ids[9]));
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[2], $recurring_schedule_start_date, '', array($user_ids[10], $user_ids[11], $user_ids[12], $user_ids[13], $user_ids[14]));
         //Create schedule for each employee.
         foreach ($user_ids as $user_id) {
             //Create schedule starting 6 weeks ago, up to the end of the week.
             $schedule_options_arr = array('status_id' => 10, 'start_time' => '08:00AM', 'end_time' => '05:00PM', 'schedule_policy_id' => $policy_ids['schedule_1']);
             //$schedule_date = ($current_epoch-(86400*42));
             $schedule_date = $current_epoch - 86400 * 14;
             $schedule_end_date = TTDate::getEndWeekEpoch($current_epoch);
             //$schedule_date = ($current_epoch-(86400*14));
             //$schedule_end_date = ($current_epoch+(86400*28));
             while ($schedule_date <= $schedule_end_date) {
                 //Random departments/branches
                 $schedule_options_arr['branch_id'] = $branch_ids[rand(0, count($branch_ids) - 1)];
                 $schedule_options_arr['department_id'] = $department_ids[rand(0, count($department_ids) - 1)];
                 //Skip weekends.
                 if (date('w', $schedule_date) != 0 and date('w', $schedule_date) != 6) {
                     $this->createSchedule($user_id, $schedule_date, $schedule_options_arr);
                 }
                 $schedule_date += 86400;
             }
             //break;
             unset($schedule_options_arr, $schedule_date, $schedule_end_date, $user_id);
         }
         //Punch users in/out randomly.
         foreach ($user_ids as $user_id) {
             //Pick random jobs/tasks that are used for the entire date range.
             //So one employee isn't punching into 15 jobs.
             $user_random_job_ids = array_rand($job_ids, 2);
             $user_random_task_ids = array_rand($job_ids, 3);
             //Create punches starting 6 weeks ago, up to the end of the week.
             //$start_date = $punch_date = ($current_epoch-(86400*42));
             $start_date = $punch_date = $current_epoch - 86400 * 14;
             $end_date = TTDate::getEndWeekEpoch($current_epoch);
             //$start_date = $punch_date = ($current_epoch-(86400*14));
             //$end_date = ($current_epoch+(86400*28));
             $i = 0;
             while ($punch_date <= $end_date) {
                 $date_stamp = TTDate::getDate('DATE', $punch_date);
                 //$punch_full_time_stamp = strtotime($pc_data['date_stamp'].' '.$pc_data['time_stamp']);
                 $exception_cutoff_date = $current_epoch - 86400 * 14;
                 if (date('w', $punch_date) != 0 and date('w', $punch_date) != 6) {
                     if ($punch_date >= $exception_cutoff_date and $i % 4 == 0) {
                         $first_punch_in = rand(7, 8) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'AM';
                         $last_punch_out = strtotime($date_stamp . ' ' . rand(4, 5) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'PM');
                         if ($punch_date >= $exception_cutoff_date and rand(0, 20) == 0) {
                             //Create request
                             $this->createRequest(20, $user_id, $date_stamp);
                         }
                         if ($punch_date >= $exception_cutoff_date and rand(0, 16) == 0) {
                             //Create request
                             $this->createRequest(20, $user_id, $date_stamp);
                         }
                     } else {
                         $first_punch_in = '08:00AM';
                         if ($punch_date >= $exception_cutoff_date and $i % 10 == 0) {
                             //Don't punch out to generate exception.
                             $last_punch_out = NULL;
                             //Forgot to punch out request
                             $this->createRequest(30, $user_id, $date_stamp);
                         } else {
                             $last_punch_out = strtotime($date_stamp . ' 5:00PM');
                         }
                     }
                     //Weekdays
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' ' . $first_punch_in), strtotime($date_stamp . ' 11:00AM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 11:00AM'), strtotime($date_stamp . ' 1:00PM'), array('in_type_id' => 10, 'out_type_id' => 20, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                     //Calc total time on last punch pair only.
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 2:00PM'), $last_punch_out, array('in_type_id' => 20, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                 } elseif ($punch_date > $exception_cutoff_date and date('w', $punch_date) == 6 and $i % 10 == 0) {
                     //Sat.
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 10:00AM'), strtotime($date_stamp . ' 2:30PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                 }
                 //Recalculate entire day. Performance optimization.
                 //UserDateTotalFactory::reCalculateRange( $user_id, $start_date, $end_date );
                 $punch_date += 86400;
                 $i++;
             }
             unset($punch_options_arr, $punch_date, $user_id);
         }
         //Generate pay stubs for each pay period
         $pplf = new PayPeriodListFactory();
         $pplf->getByCompanyId($company_id);
         if ($pplf->getRecordCount() > 0) {
             foreach ($pplf as $pp_obj) {
                 foreach ($user_ids as $user_id) {
                     $cps = new CalculatePayStub();
                     $cps->setUser($user_id);
                     $cps->setPayPeriod($pp_obj->getId());
                     $cps->calculate();
                 }
             }
         }
         unset($pplf, $pp_obj, $user_id);
     }
     //$cf->FailTransaction();
     $cf->CommitTransaction();
     return FALSE;
 }
Пример #4
0
                 $rows[$last_row][Misc::trimSortPrefix($static_column_key)] = NULL;
             }
             unset($static_column_key, $static_column_val);
         }
     }
 }
 foreach ($filter_data['column_ids'] as $column_key) {
     $filter_columns[Misc::trimSortPrefix($column_key)] = $columns[$column_key];
 }
 if ($action == 'display_t4s') {
     Debug::Text('Generating PDF: ', __FILE__, __LINE__, __METHOD__, 10);
     $last_row = count($rows) - 1;
     $total_row = $last_row + 1;
     //Get company information
     $clf = new CompanyListFactory();
     $company_obj = $clf->getById($current_company->getId())->getCurrent();
     //Debug::setVerbosity(11);
     $t4 = new T4();
     if (isset($filter_data['include_t4_back']) and $filter_data['include_t4_back'] == 1) {
         $t4->setShowInstructionPage(TRUE);
     }
     //$t4->setShowBackGround(FALSE);
     $t4->setShowBorder(FALSE);
     //$t4->setXOffset(10);
     //$t4->setYOffset(10);
     $t4->setType($filter_data['type']);
     $t4->setYear($filter_data['year']);
     $t4->setBusinessNumber($company_obj->getBusinessNumber());
     $t4->setCompanyName($company_obj->getName());
     $t4->setCompanyAddress1($company_obj->getAddress1());
     $t4->setCompanyAddress2($company_obj->getAddress2());
Пример #5
0
     $pp_transaction_date = $pay_period_obj->getAdvanceTransactionDate();
 } else {
     $pp_start_date = $pay_period_obj->getStartDate();
     $pp_end_date = $pay_period_obj->getEndDate();
     $pp_transaction_date = $pay_period_obj->getTransactionDate();
 }
 //Get pay period numbers
 $ppslf = new PayPeriodScheduleListFactory();
 $pay_period_schedule_obj = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
 $pay_period_data = array('advance' => $pay_stub_obj->getAdvance(), 'start_date' => TTDate::getDate('DATE', $pp_start_date), 'end_date' => TTDate::getDate('DATE', $pp_end_date), 'transaction_date' => TTDate::getDate('DATE', $pp_transaction_date), 'annual_pay_periods' => $pay_period_schedule_obj->getAnnualPayPeriods());
 //Get User information
 $ulf = new UserListFactory();
 $user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
 //Get company information
 $clf = new CompanyListFactory();
 $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
 //}
 //Figure out how much white space we need to fill the entire page.
 $max_rows = 29;
 //With borders you gotta drop this down to 28.
 $total_rows = floor($pself->getRecordCount() + $description_subscript_counter);
 if ($pay_stub_obj->getAdvance() === FALSE) {
     //$total_rows -= 1;
     $total_rows += 1;
 }
 if ($description_subscript_counter > 1) {
     $total_rows += 2;
 }
 $max_types = 6;
 $total_types = count($pay_stub['entries']);
 $spacer_rows = $max_rows - $total_rows + ($max_types - $total_types) * 2;
Пример #6
0
 //Import all data
 $import_arr = Misc::parseCSV($import_csv_file, TRUE, FALSE, ",", 9216, 0);
 if (!is_array($import_arr)) {
     echo "Parsing CSV file failed!\n";
 } else {
     echo "Importing Users...\n";
     $uf = new UserFactory();
     $uf->StartTransaction();
     $commit_trans = TRUE;
     $i = 1;
     $e = 0;
     foreach ($import_arr as $tmp_import_arr) {
         $mapped_row = Misc::importApplyColumnMap($filtered_import_map, $tmp_import_arr);
         if ($i == 1 and $mapped_row['company_id'] > 0) {
             $clf = new CompanyListFactory();
             $clf->getById($mapped_row['company_id']);
             if ($clf->getRecordCount() > 0) {
                 echo 'Company: ' . $clf->getCurrent()->getName() . "\n";
                 ob_flush();
                 flush();
                 sleep(2);
             }
             unset($clf);
         }
         $uf = new UserFactory();
         //Start with user default values.
         $udlf = new UserDefaultListFactory();
         $udlf->getByCompanyId($mapped_row['company_id']);
         if ($udlf->getRecordCount() > 0) {
             Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10);
             $udf_obj = $udlf->getCurrent();
 function getPayStub($pslf = NULL, $hide_employer_rows = TRUE)
 {
     if (!is_object($pslf) and $this->getId() != '') {
         $pslf = new PayStubListFactory();
         $pslf->getById($this->getId());
     }
     if (get_class($pslf) !== 'PayStubListFactory') {
         return FALSE;
     }
     $border = 0;
     if ($pslf->getRecordCount() > 0) {
         $pdf = new TTPDF('P', 'mm', 'Letter');
         $pdf->setMargins(0, 0);
         //$pdf->SetAutoPageBreak(TRUE, 30);
         $pdf->SetAutoPageBreak(FALSE);
         $pdf->SetFont('freeserif', '', 10);
         //$pdf->SetFont('FreeSans','',10);
         $i = 0;
         foreach ($pslf as $pay_stub_obj) {
             $psealf = new PayStubEntryAccountListFactory();
             Debug::text($i . '. Pay Stub Transaction Date: ' . $pay_stub_obj->getTransactionDate(), __FILE__, __LINE__, __METHOD__, 10);
             //Get Pay Period information
             $pplf = new PayPeriodListFactory();
             $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
             //Use Pay Stub dates, not Pay Period dates.
             $pp_start_date = $pay_stub_obj->getStartDate();
             $pp_end_date = $pay_stub_obj->getEndDate();
             $pp_transaction_date = $pay_stub_obj->getTransactionDate();
             //Get pay period numbers
             $ppslf = new PayPeriodScheduleListFactory();
             $pay_period_schedule_obj = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
             //Get User information
             $ulf = new UserListFactory();
             $user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
             //Get company information
             $clf = new CompanyListFactory();
             $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
             //Change locale to users own locale.
             TTi18n::setCountry($user_obj->getCountry());
             TTi18n::setLanguage($user_obj->getUserPreferenceObject()->getLanguage());
             TTi18n::setLocale();
             //
             // Pay Stub Header
             //
             $pdf->AddPage();
             $adjust_x = 20;
             $adjust_y = 10;
             //Logo
             $pdf->Image($company_obj->getLogoFileName(), Misc::AdjustXY(0, $adjust_x + 0), Misc::AdjustXY(1, $adjust_y + 0), 50, 12, '', '', '', FALSE, 300, '', FALSE, FALSE, 0, TRUE);
             //Company name/address
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getName(), $border, 0, 'C');
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getAddress1() . ' ' . $company_obj->getAddress2(), $border, 0, 'C');
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getCity() . ', ' . $company_obj->getProvince() . ' ' . strtoupper($company_obj->getPostalCode()), $border, 0, 'C');
             //Pay Period info
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Pay Start Date:') . ' ', $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Pay End Date:') . ' ', $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Payment Date:') . ' ', $border, 0, 'R');
             $pdf->SetFont('', 'B', 10);
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_start_date), $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_end_date), $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_transaction_date), $border, 0, 'R');
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(17, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY(17, $adjust_y));
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(19, $adjust_y));
             $pdf->Cell(175, 5, TTi18n::gettext('STATEMENT OF EARNINGS AND DEDUCTIONS'), $border, 0, 'C', 0);
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(27, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY(27, $adjust_y));
             $pdf->setLineWidth(0.25);
             //Get pay stub entries.
             $pself = new PayStubEntryListFactory();
             $pself->getByPayStubId($pay_stub_obj->getId());
             Debug::text('Pay Stub Entries: ' . $pself->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             $prev_type = NULL;
             $description_subscript_counter = 1;
             foreach ($pself as $pay_stub_entry) {
                 Debug::text('Pay Stub Entry Account ID: ' . $pay_stub_entry->getPayStubEntryNameId(), __FILE__, __LINE__, __METHOD__, 10);
                 $description_subscript = NULL;
                 $pay_stub_entry_name_obj = $psealf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
                 //Use this to put the total for each type at the end of the array.
                 if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                     $type = $pay_stub_entry_name_obj->getType();
                 }
                 //Debug::text('Pay Stub Entry Name ID: '. $pay_stub_entry_name_obj->getId() .' Type ID: '. $pay_stub_entry_name_obj->getType() .' Type: '. $type, __FILE__, __LINE__, __METHOD__,10);
                 if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE and strlen($pay_stub_entry->getDescription()) > 0) {
                     $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                     $description_subscript = $description_subscript_counter;
                     $description_subscript_counter++;
                 }
                 //If type if 40 (a total) and the amount is 0, skip it.
                 //This if the employee has no deductions at all, it won't be displayed
                 //on the pay stub.
                 if ($type != 40 or $type == 40 and $pay_stub_entry->getAmount() != 0) {
                     $pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getName(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
                 }
                 $prev_type = $pay_stub_entry_name_obj->getType();
             }
             //There should always be pay stub entries for a pay stub.
             if (!isset($pay_stub_entries)) {
                 continue;
             }
             //Debug::Arr($pay_stub_entries, 'Pay Stub Entries...', __FILE__, __LINE__, __METHOD__,10);
             //$pay_period_number = $pay_period_schedule_obj->getCurrentPayPeriodNumber( $pay_period_obj->getTransactionDate(), $pay_period_obj->getEndDate() );
             $block_adjust_y = 30;
             //
             //Earnings
             //
             if (isset($pay_stub_entries[10])) {
                 //Earnings Header
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(90, 5, TTi18n::gettext('Earnings'), $border, 0, 'L');
                 $pdf->Cell(17, 5, TTi18n::gettext('Rate'), $border, 0, 'R');
                 $pdf->Cell(23, 5, TTi18n::gettext('Hrs/Units'), $border, 0, 'R');
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($pay_stub_entries[10] as $pay_stub_entry) {
                     if ($pay_stub_entry['type'] == 10) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(88, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         $pdf->Cell(17, 5, TTi18n::formatNumber($pay_stub_entry['rate'], TRUE), $border, 0, 'R');
                         $pdf->Cell(23, 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(110, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(131, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(90, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(17, 5, '', $border, 0, 'R');
                         $pdf->Cell(23, 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             // Deductions
             //
             if (isset($pay_stub_entries[20])) {
                 $max_deductions = count($pay_stub_entries[20]);
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                     $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                     $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                 } else {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(130, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                 }
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $tmp_block_adjust_y = $top_block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 $x = 0;
                 $max_block_adjust_y = 0;
                 foreach ($pay_stub_entries[20] as $pay_stub_entry) {
                     //Start with the right side.
                     if ($x < floor($max_deductions / 2)) {
                         $tmp_adjust_x = 90;
                     } else {
                         if ($tmp_block_adjust_y != 0) {
                             $block_adjust_y = $tmp_block_adjust_y;
                             $tmp_block_adjust_y = 0;
                         }
                         $tmp_adjust_x = 0;
                     }
                     if ($pay_stub_entry['type'] == 20) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         if ($max_deductions > 2) {
                             $pdf->setXY(Misc::AdjustXY(2, $tmp_adjust_x + $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         }
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(130, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                     if ($block_adjust_y > $max_block_adjust_y) {
                         $max_block_adjust_y = $block_adjust_y;
                     }
                     $x++;
                 }
                 //Draw line to separate the two columns
                 if ($max_deductions > 2) {
                     $pdf->Line(Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($top_block_adjust_y - 5, $adjust_y), Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($max_block_adjust_y - 5, $adjust_y));
                 }
                 unset($x, $max_deductions, $tmp_adjust_x, $max_block_adjust_y, $tmp_block_adjust_y, $top_block_adjust_y);
             }
             if (isset($pay_stub_entries[40][0])) {
                 $block_adjust_y = $block_adjust_y + 5;
                 //Net Pay entry
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(130, 5, $pay_stub_entries[40][0]['name'], $border, 0, 'L');
                 $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entries[40][0]['amount']), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entries[40][0]['ytd_amount']), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
             }
             //
             //Employer Contributions
             //
             //echo "Employee Ded: <br>\n";
             if (isset($pay_stub_entries[30]) and $hide_employer_rows != TRUE) {
                 $max_deductions = count($pay_stub_entries[30]);
                 //echo "Max Employee Ded: ". $max_deductions ."<br>\n";
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                     $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                     $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                 } else {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(130, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                 }
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $tmp_block_adjust_y = $top_block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 $x = 0;
                 $max_block_adjust_y = 0;
                 foreach ($pay_stub_entries[30] as $pay_stub_entry) {
                     //Start with the right side.
                     if ($x < floor($max_deductions / 2)) {
                         $tmp_adjust_x = 90;
                     } else {
                         if ($tmp_block_adjust_y != 0) {
                             $block_adjust_y = $tmp_block_adjust_y;
                             $tmp_block_adjust_y = 0;
                         }
                         $tmp_adjust_x = 0;
                     }
                     if ($pay_stub_entry['type'] == 30) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         if ($max_deductions > 2) {
                             $pdf->setXY(Misc::AdjustXY(2, $tmp_adjust_x + $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         }
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(130, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                     if ($block_adjust_y > $max_block_adjust_y) {
                         $max_block_adjust_y = $block_adjust_y;
                     }
                     $x++;
                 }
                 //Draw line to separate the two columns
                 if ($max_deductions > 2) {
                     $pdf->Line(Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($top_block_adjust_y - 5, $adjust_y), Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($max_block_adjust_y - 5, $adjust_y));
                 }
                 unset($x, $max_deductions, $tmp_adjust_x, $max_block_adjust_y, $tmp_block_adjust_y, $top_block_adjust_y);
             }
             //
             //Accruals PS accounts
             //
             if (isset($pay_stub_entries[50])) {
                 //Accrual Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(130, 5, TTi18n::gettext('Accruals'), $border, 0, 'L');
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('Balance'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($pay_stub_entries[50] as $pay_stub_entry) {
                     if ($pay_stub_entry['type'] == 50) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             //Accrual Policy Balances
             //
             $ablf = new AccrualBalanceListFactory();
             $ablf->getByUserIdAndCompanyIdAndEnablePayStubBalanceDisplay($user_obj->getId(), $user_obj->getCompany(), TRUE);
             if ($ablf->getRecordCount() > 0) {
                 //Accrual Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(40, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $accrual_time_header_start_x = $pdf->getX();
                 $accrual_time_header_start_y = $pdf->getY();
                 $pdf->Cell(70, 5, TTi18n::gettext('Accrual Time Balances as of ') . TTDate::getDate('DATE', time()), $border, 0, 'L');
                 $pdf->Cell(25, 5, TTi18n::gettext('Balance (hrs)'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $box_height = 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($ablf as $ab_obj) {
                     $balance = $ab_obj->getBalance();
                     if (!is_numeric($balance)) {
                         $balance = 0;
                     }
                     $pdf->setXY(Misc::AdjustXY(40, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(70, 5, $ab_obj->getColumn('name'), $border, 0, 'L');
                     $pdf->Cell(25, 5, TTi18n::formatNumber(TTDate::getHours($balance)), $border, 0, 'R');
                     $block_adjust_y = $block_adjust_y + 5;
                     $box_height = $box_height + 5;
                     unset($balance);
                 }
                 $pdf->Rect($accrual_time_header_start_x, $accrual_time_header_start_y, 95, $box_height);
                 unset($accrual_time_header_start_x, $accrual_time_header_start_y, $box_height);
             }
             //
             //Descriptions
             //
             if (isset($pay_stub_entry_descriptions) and count($pay_stub_entry_descriptions) > 0) {
                 //Description Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(175, 5, TTi18n::gettext('Notes'), $border, 0, 'L');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 8);
                 $x = 0;
                 foreach ($pay_stub_entry_descriptions as $pay_stub_entry_description) {
                     if ($x % 2 == 0) {
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     } else {
                         $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     }
                     //$pdf->Cell(173,5, '['.$pay_stub_entry_description['subscript'].'] '.$pay_stub_entry_description['description'], $border, 0, 'L');
                     $pdf->Cell(85, 5, '[' . $pay_stub_entry_description['subscript'] . '] ' . $pay_stub_entry_description['description'], $border, 0, 'L');
                     if ($x % 2 != 0) {
                         $block_adjust_y = $block_adjust_y + 5;
                     }
                     $x++;
                 }
             }
             unset($x, $pay_stub_entry_descriptions, $pay_stub_entry_description);
             //
             // Pay Stub Footer
             //
             $block_adjust_y = 215;
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY($block_adjust_y, $adjust_y));
             //Non Negotiable
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 3, $adjust_y));
             $pdf->Cell(175, 5, TTi18n::gettext('NON NEGOTIABLE'), $border, 0, 'C', 0);
             //Employee Address
             $pdf->SetFont('', 'B', 12);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 9, $adjust_y));
             $pdf->Cell(60, 5, TTi18n::gettext('CONFIDENTIAL'), $border, 0, 'C', 0);
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 14, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getFullName(), $border, 0, 'C', 0);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 19, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getAddress1(), $border, 0, 'C', 0);
             $address2_adjust_y = 0;
             if ($user_obj->getAddress2() != '') {
                 $address2_adjust_y = 5;
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 24, $adjust_y));
                 $pdf->Cell(60, 5, $user_obj->getAddress2(), $border, 0, 'C', 0);
             }
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 24 + $address2_adjust_y, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 1, 'C', 0);
             //Pay Period - Balance - ID
             $net_pay_amount = 0;
             if (isset($pay_stub_entries[40][0])) {
                 $net_pay_amount = $pay_stub_entries[40][0]['amount'];
             }
             if (isset($pay_stub_entries[65]) and count($pay_stub_entries[65]) > 0) {
                 $net_pay_label = TTi18n::gettext('Balance');
             } else {
                 $net_pay_label = TTi18n::gettext('Net Pay');
             }
             /*
             if ( $pay_period_schedule_obj->getType() != 5 AND $pay_period_number > 0 AND $pay_period_schedule_obj->getAnnualPayPeriods() > 0 ) {
             	$pdf->setXY( Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y+10, $adjust_y) );
             	$pdf->Cell(50, 5, TTi18n::gettext('Pay Period').' '. $pay_period_number .' '. TTi18n::gettext('of') .' '. $pay_period_schedule_obj->getAnnualPayPeriods(), $border, 1, 'L', 0);
             }
             */
             $pdf->SetFont('', 'B', 12);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y + 17, $adjust_y));
             $pdf->Cell(50, 5, $net_pay_label . ': ' . $pay_stub_obj->getCurrencyObject()->getSymbol() . $net_pay_amount . ' ' . $pay_stub_obj->getCurrencyObject()->getISOCode(), $border, 1, 'L', 0);
             if ($pay_stub_obj->getTainted() == TRUE) {
                 $tainted_flag = 'T';
             } else {
                 $tainted_flag = '';
             }
             $pdf->SetFont('', '', 8);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y + 30, $adjust_y));
             $pdf->Cell(50, 5, TTi18n::gettext('Identification #:') . ' ' . str_pad($pay_stub_obj->getId(), 12, 0, STR_PAD_LEFT) . $tainted_flag, $border, 1, 'L', 0);
             unset($net_pay_amount, $tainted_flag);
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 35, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY($block_adjust_y + 35, $adjust_y));
             $pdf->SetFont('', '', 6);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 38, $adjust_y));
             $pdf->Cell(175, 1, TTi18n::gettext('Pay Stub Generated by') . ' ' . APPLICATION_NAME, $border, 0, 'C', 0);
             unset($pay_period_schedule_obj, $pay_stub_entries, $pay_period_number);
             $i++;
         }
         $output = $pdf->Output('', 'S');
     }
     TTi18n::setMasterLocale();
     if (isset($output)) {
         return $output;
     }
     return FALSE;
 }
Пример #8
0
 function getROE($rlf = NULL, $show_background = TRUE)
 {
     if (!is_object($rlf) and $this->getId() != '') {
         $rlf = new ROEListFactory();
         $rlf->getById($this->getId());
     }
     if (get_class($rlf) !== 'ROEListFactory') {
         return FALSE;
     }
     $border = 0;
     if ($rlf->getRecordCount() > 0) {
         $ppsf = new PayPeriodScheduleListFactory();
         $pay_period_type_options = $ppsf->getOptions('type');
         $pdf = new TTPDF();
         $pdf->setMargins(0, 0, 0, 0);
         $pdf->SetAutoPageBreak(FALSE);
         foreach ($rlf as $r_obj) {
             $pdf->SetFont('freesans', '', 12);
             //Get User information
             $ulf = new UserListFactory();
             $user_obj = $ulf->getById($r_obj->getUser())->getCurrent();
             $ulf = new UserListFactory();
             $created_user_obj = $ulf->getById($r_obj->getCreatedBy())->getCurrent();
             //Get company information
             $clf = new CompanyListFactory();
             $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
             $pdf->AddPage();
             if ($show_background == TRUE) {
                 $pdf->Image(Environment::getImagesPath() . 'roe-template.jpg', 0, 0, 210, 300);
             }
             //Serial
             $pdf->setXY(10, 17);
             $pdf->Cell(55, 10, $r_obj->getSerial(), $border, 0, 'L');
             //Employer Info
             $pdf->setXY(10, 30);
             $pdf->Cell(120, 10, $company_obj->getName(), $border, 0, 'L');
             $pdf->setXY(10, 40);
             $pdf->Cell(120, 10, $company_obj->getAddress1() . ' ' . $company_obj->getAddress2(), $border, 0, 'L');
             $pdf->setXY(10, 50);
             $pdf->Cell(90, 10, $company_obj->getCity() . ', ' . $company_obj->getProvince(), $border, 0, 'L');
             $postal_code_a = substr($company_obj->getPostalCode(), 0, 3);
             $postal_code_b = substr($company_obj->getPostalCode(), 3, 6);
             $pdf->setXY(110, 50);
             $pdf->Cell(10, 10, $postal_code_a, $border, 0, 'L');
             $pdf->setXY(122, 50);
             $pdf->Cell(10, 10, $postal_code_b, $border, 0, 'L');
             //Business Number
             $pdf->setXY(138, 28);
             $pdf->Cell(120, 10, $company_obj->getBusinessNumber(), $border, 0, 'L');
             //Pay Period Type
             $pdf->setXY(138, 40);
             $pdf->Cell(50, 10, $pay_period_type_options[$r_obj->getPayPeriodType()], $border, 0, 'L');
             //SIN
             $pdf->setXY(138, 50);
             $pdf->Cell(50, 10, $user_obj->getSIN(), $border, 0, 'L');
             //Employee info
             $pdf->SetFontSize(10);
             $pdf->setXY(10, 75);
             $pdf->Cell(90, 5, $user_obj->getFullName(), $border, 0, 'L');
             $pdf->setXY(10, 80);
             $pdf->Cell(90, 5, $user_obj->getAddress1() . ' ' . $user_obj->getAddress2(), $border, 0, 'L');
             $pdf->setXY(10, 85);
             $pdf->Cell(90, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 0, 'L');
             $pdf->SetFontSize(12);
             //Employee Title
             if (is_object($user_obj->getTitleObject())) {
                 $title = $user_obj->getTitleObject()->getName();
             } else {
                 $title = NULL;
             }
             $pdf->setXY(10, 100);
             $pdf->Cell(90, 10, $title, $border, 0, 'L');
             //First Day Worked
             $pdf->SetFontSize(10);
             $first_date = getdate($r_obj->getFirstDate());
             $pdf->setXY(175, 64);
             $pdf->Cell(8, 10, $first_date['mday'], $border, 0, 'C');
             $pdf->setXY(185, 64);
             $pdf->Cell(8, 10, $first_date['mon'], $border, 0, 'C');
             $pdf->setXY(196, 64);
             $pdf->Cell(10, 10, $first_date['year'], $border, 0, 'C');
             //Last day paid
             $last_date = getdate($r_obj->getLastDate());
             $pdf->setXY(175, 75);
             $pdf->Cell(8, 10, $last_date['mday'], $border, 0, 'C');
             $pdf->setXY(185, 75);
             $pdf->Cell(8, 10, $last_date['mon'], $border, 0, 'C');
             $pdf->setXY(196, 75);
             $pdf->Cell(10, 10, $last_date['year'], $border, 0, 'C');
             //Pay Period End Date
             $pay_period_end_date = getdate($r_obj->getPayPeriodEndDate());
             $pdf->setXY(175, 86);
             $pdf->Cell(8, 10, $pay_period_end_date['mday'], $border, 0, 'C');
             $pdf->setXY(185, 86);
             $pdf->Cell(8, 10, $pay_period_end_date['mon'], $border, 0, 'C');
             $pdf->setXY(196, 86);
             $pdf->Cell(10, 10, $pay_period_end_date['year'], $border, 0, 'C');
             //Insurable Hours
             $pdf->SetFontSize(10);
             $pdf->setXY(75, 113);
             $pdf->Cell(25, 10, Misc::getBeforeDecimal($r_obj->getInsurableHours()), $border, 0, 'R');
             $pdf->setXY(101, 113);
             $pdf->Cell(10, 10, Misc::getAfterDecimal(Misc::MoneyFormat($r_obj->getInsurableHours(), FALSE)), $border, 0, 'L');
             //Enter Code
             $pdf->setXY(185, 113);
             $pdf->Cell(10, 10, $r_obj->getCode(), $border, 0, 'C');
             //Further Information Contact Name
             $pdf->setXY(130, 126);
             $pdf->Cell(75, 5, $created_user_obj->getFullName(), $border, 0, 'R');
             $pdf->setXY(130, 132);
             $pdf->Cell(75, 10, $created_user_obj->getWorkPhone(), $border, 0, 'R');
             //Insurable Earnings
             $pdf->setXY(75, 131);
             $pdf->Cell(25, 10, Misc::getBeforeDecimal($r_obj->getInsurableEarnings()), $border, 0, 'R');
             $pdf->setXY(101, 131);
             $pdf->Cell(10, 10, Misc::getAfterDecimal(Misc::MoneyFormat($r_obj->getInsurableEarnings(), FALSE)), $border, 0, 'L');
             //Check to see if a pay period didn't have earnings.
             if ($r_obj->isPayPeriodWithNoEarnings() == TRUE) {
                 $pay_period_earnings = $r_obj->getInsurableEarningsByPayPeriod();
                 if (is_array($pay_period_earnings)) {
                     //Add additional entries for testing alignment purposes.
                     /*
                     for( $y=0; $y < 14; $y++ ) {
                     	$pay_period_earnings[] = array('amount' => rand(1,10) );
                     }
                     */
                     $top_left_x = $x = Misc::AdjustXY(30, 0);
                     $top_left_y = $y = Misc::AdjustXY(157, 0);
                     $col = 1;
                     $i = 1;
                     foreach ($pay_period_earnings as $pay_period_earning) {
                         Debug::Text('I: ' . $i . ' X: ' . $x . ' Y: ' . $y . ' Col: ' . $col . ' Amount: ' . (double) $pay_period_earning['amount'], __FILE__, __LINE__, __METHOD__, 10);
                         $pdf->setXY($x, $y);
                         $pdf->Cell(6, 6, Misc::MoneyFormat((double) $pay_period_earning['amount'], FALSE), $border, 0, 'R');
                         if ($i > 0 and $i % 3 == 0) {
                             $x = $top_left_x;
                             $y += 7;
                         } else {
                             $x += 35;
                         }
                         $i++;
                     }
                 }
             }
             //Box 17A, Vacation pay in last pay period.
             $vacation_pay = $r_obj->getLastPayPeriodVacationEarnings();
             if ($vacation_pay > 0) {
                 $pdf->setXY(132, 155);
                 $pdf->Cell(10, 10, Misc::getBeforeDecimal(Misc::MoneyFormat($vacation_pay, FALSE)), $border, 0, 'R');
                 $pdf->Cell(10, 10, Misc::getAfterDecimal(Misc::MoneyFormat($vacation_pay, FALSE)), $border, 0, 'L');
             }
             //Comments
             $pdf->setXY(115, 212);
             $pdf->MultiCell(85, 5, $r_obj->getComments(), $border, 'L');
             //English
             $pdf->setXY(8.5, 256.5);
             $pdf->Cell(10, 10, 'X', $border, 0, 'L');
             //ROE creator phone number
             $pdf->setXY(75, 258);
             $pdf->Cell(25, 10, $created_user_obj->getWorkPhone(), $border, 0, 'L');
             //ROE create name.
             $pdf->SetFontSize(12);
             $pdf->setXY(87, 273);
             $pdf->Cell(75, 10, $created_user_obj->getFullName(), $border, 0, 'C');
             //Create Date
             $created_date = getdate($r_obj->getCreatedDate());
             $pdf->SetFontSize(10);
             $pdf->setXY(175, 273);
             $pdf->Cell(8, 10, $created_date['mday'], $border, 0, 'C');
             $pdf->setXY(185, 273);
             $pdf->Cell(8, 10, $created_date['mon'], $border, 0, 'C');
             $pdf->setXY(195, 273);
             $pdf->Cell(10, 10, $created_date['year'], $border, 0, 'C');
         }
         $output = $pdf->Output('', 'S');
     }
     if (isset($output)) {
         return $output;
     }
     return FALSE;
 }
 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;
 }
Пример #10
0
            $country = $current_company->getCountry();
        } else {
            $permission->Redirect(FALSE);
        }
        if (!isset($action)) {
            BreadCrumb::setCrumb($title);
            foreach ($balf as $bank_account) {
                //Debug::Arr($department,'Department', __FILE__, __LINE__, __METHOD__,10);
                $bank_data = array('id' => $bank_account->getId(), 'country' => strtolower($country), 'institution' => $bank_account->getInstitution(), 'transit' => $bank_account->getTransit(), 'account' => $bank_account->getAccount(), 'created_date' => $bank_account->getCreatedDate(), 'created_by' => $bank_account->getCreatedBy(), 'updated_date' => $bank_account->getUpdatedDate(), 'updated_by' => $bank_account->getUpdatedBy(), 'deleted_date' => $bank_account->getDeletedDate(), 'deleted_by' => $bank_account->getDeletedBy());
            }
        }
        if (isset($user_id) and $company_id == '') {
            //$user_id = $current_user->getId();
            $ulf = new UserListFactory();
            $full_name = $ulf->getById($user_id)->getCurrent()->getFullName();
        } elseif ($company_id != '') {
            $clf = new CompanyListFactory();
            $full_name = $clf->getById($company_id)->getCurrent()->getName();
        }
        $bank_data['full_name'] = $full_name;
        $bank_data['country'] = strtolower($country);
        $bank_data['user_id'] = $user_id;
        $bank_data['company_id'] = $company_id;
        //var_dump($bank_data);
        $smarty->assign_by_ref('bank_data', $bank_data);
        $smarty->assign_by_ref('data_saved', $data_saved);
        break;
}
$smarty->assign_by_ref('baf', $baf);
//$smarty->assign_by_ref('current_time', TTDate::getDate('TIME') );
$smarty->display('bank_account/EditBankAccount.tpl');
 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;
 }
Пример #12
0
 if ($parse_license_retval === TRUE) {
     $sslf = new SystemSettingListFactory();
     $sslf->getByName('license');
     if ($sslf->getRecordCount() == 1) {
         $obj = $sslf->getCurrent();
     } else {
         $obj = new SystemSettingListFactory();
     }
     $obj->setName('license');
     $obj->setValue($license_data);
     if ($obj->isValid()) {
         Debug::text('Setting License Data...', __FILE__, __LINE__, __METHOD__, 9);
         $obj->Save();
         //Save company name from license file.
         $clf = new CompanyListFactory();
         $clf->getById($license->getPrimaryCompanyID());
         if ($clf->getRecordCount() > 0) {
             $c_obj = $clf->getCurrent();
         } else {
             $c_obj = $current_company;
         }
         $c_obj->setName($license->getOrganizationName(), TRUE);
         if ($c_obj->isValid()) {
             $c_obj->Save();
         }
         //Save registration key
         $sslf = new SystemSettingListFactory();
         $sslf->getByName('registration_key');
         if ($sslf->getRecordCount() == 1) {
             $obj = $sslf->getCurrent();
         } else {
Пример #13
0
 function getData()
 {
     $psenlf = new PayStubEntryNameListFactory();
     $pslf = new PayStubListFactory();
     //$pslf->getByIdAndUserId($id, $current_user->getId(), $current_user_prefs->getItemsPerPage(), $page, NULL, array($sort_column => $sort_order) );
     $pslf->getById($this->pay_stub_id);
     $pager = new Pager($pslf);
     foreach ($pslf as $pay_stub_obj) {
         //Get pay stub entries.
         $pself = new PayStubEntryListFactory();
         $pself->getByPayStubId($pay_stub_obj->getId());
         $prev_type = NULL;
         $description_subscript_counter = 1;
         foreach ($pself as $pay_stub_entry) {
             $description_subscript = NULL;
             $pay_stub_entry_name_obj = $psenlf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
             if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                 $type = $pay_stub_entry_name_obj->getType();
             }
             if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE) {
                 $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                 $description_subscript = $description_subscript_counter;
                 $description_subscript_counter++;
             }
             $this->pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getDescription(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
             $prev_type = $pay_stub_entry_name_obj->getType();
         }
         //'entries' => $pay_stub_entries,
         $this->pay_stub = array('id' => $pay_stub_obj->getId(), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'advance' => $pay_stub_obj->getAdvance(), 'status' => $pay_stub_obj->getStatus(), 'created_date' => $pay_stub_obj->getCreatedDate(), 'created_by' => $pay_stub_obj->getCreatedBy(), 'updated_date' => $pay_stub_obj->getUpdatedDate(), 'updated_by' => $pay_stub_obj->getUpdatedBy(), 'deleted_date' => $pay_stub_obj->getDeletedDate(), 'deleted_by' => $pay_stub_obj->getDeletedBy());
         //Get Pay Period information
         $pplf = new PayPeriodListFactory();
         $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
         if ($pay_stub_obj->getAdvance() == TRUE) {
             $pp_start_date = $pay_period_obj->getStartDate();
             $pp_end_date = $pay_period_obj->getAdvanceEndDate();
             $pp_transaction_date = $pay_period_obj->getAdvanceTransactionDate();
         } else {
             $pp_start_date = $pay_period_obj->getStartDate();
             $pp_end_date = $pay_period_obj->getEndDate();
             $pp_transaction_date = $pay_period_obj->getTransactionDate();
         }
         $this->pay_period = array('start_date' => TTDate::getDate('DATE', $pp_start_date), 'end_date' => TTDate::getDate('DATE', $pp_end_date), 'transaction_date' => TTDate::getDate('DATE', $pp_transaction_date));
         //Get User information
         $ulf = new UserListFactory();
         $this->user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
         //Get company information
         $clf = new CompanyListFactory();
         $this->company_obj = $clf->getById($this->user_obj->getCompany())->getCurrent();
     }
 }
 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;
 }