示例#1
0
 function testMultiplePayStubAccruals()
 {
     //Test all parts of multiple pay stubs that span a year boundary.
     //Start 6 pay periods from the last one. Should be beginning/end of December,
     //Its the TRANSACTION date that counts
     $start_pay_period_id = count($this->pay_period_objs) - 8;
     Debug::text('Starting Pay Period: ' . TTDate::getDate('DATE+TIME', $this->pay_period_objs[$start_pay_period_id]->getStartDate()), __FILE__, __LINE__, __METHOD__, 10);
     //
     // First Pay Stub
     //
     //Test UnUsed YTD entries...
     $pay_stub = new PayStubFactory();
     $pay_stub->setUser($this->user_id);
     $pay_stub->setCurrency($pay_stub->getUserObject()->getCurrency());
     $pay_stub->setPayPeriod($this->pay_period_objs[$start_pay_period_id]->getId());
     $pay_stub->setStatus('NEW');
     $pay_stub->setDefaultDates();
     $pay_stub->loadPreviousPayStub();
     $pse_accounts = array('regular_time' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Regular Time'), 'over_time_1' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Over Time 1'), 'vacation_accrual_release' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Vacation Accrual Release'), 'federal_income_tax' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'Federal Income Tax'), 'state_income_tax' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'State Income Tax'), 'medicare' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 30, 'Medicare'), 'state_unemployment' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 30, 'State Unemployment Ins.'), 'vacation_accrual' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 50, 'Vacation Accrual'));
     $pay_stub->addEntry($pse_accounts['regular_time'], 100.01);
     $pay_stub->addEntry($pse_accounts['regular_time'], 10.01);
     $pay_stub->addEntry($pse_accounts['over_time_1'], 100.02);
     //Adjust YTD balance, emulating a YTD PS amendment
     $pay_stub->addEntry($pse_accounts['vacation_accrual'], -340.38, NULL, NULL, 'Vacation Accrual YTD adjustment', -1, 0, 0);
     $pay_stub->addEntry($pse_accounts['vacation_accrual_release'], 6.13);
     $pay_stub->addEntry($pse_accounts['federal_income_tax'], 50.01);
     $pay_stub->addEntry($pse_accounts['state_income_tax'], 25.04);
     $pay_stub->addEntry($pse_accounts['medicare'], 10.01);
     $pay_stub->addEntry($pse_accounts['state_unemployment'], 15.05);
     $pay_stub->addEntry($pse_accounts['vacation_accrual'], 60.03);
     $pay_stub->setEnableProcessEntries(TRUE);
     $pay_stub->processEntries();
     if ($pay_stub->isValid() == TRUE) {
         Debug::text('Pay Stub is valid, final save.', __FILE__, __LINE__, __METHOD__, 10);
         $pay_stub_id = $pay_stub->Save();
     }
     $pse_arr = $this->getPayStubEntryArray($pay_stub_id);
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][0]['amount'], '100.01');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][0]['ytd_amount'], '0.00');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][1]['amount'], '10.01');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][1]['ytd_amount'], '110.02');
     $this->assertEquals($pse_arr[$pse_accounts['over_time_1']][0]['amount'], '100.02');
     $this->assertEquals($pse_arr[$pse_accounts['over_time_1']][0]['ytd_amount'], '100.02');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual_release']][0]['amount'], '6.13');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual_release']][0]['ytd_amount'], '6.13');
     $this->assertEquals($pse_arr[$pse_accounts['federal_income_tax']][0]['amount'], '50.01');
     $this->assertEquals($pse_arr[$pse_accounts['federal_income_tax']][0]['ytd_amount'], '50.01');
     $this->assertEquals($pse_arr[$pse_accounts['state_income_tax']][0]['amount'], '25.04');
     $this->assertEquals($pse_arr[$pse_accounts['state_income_tax']][0]['ytd_amount'], '25.04');
     $this->assertEquals($pse_arr[$pse_accounts['medicare']][0]['amount'], '10.01');
     $this->assertEquals($pse_arr[$pse_accounts['medicare']][0]['ytd_amount'], '10.01');
     $this->assertEquals($pse_arr[$pse_accounts['state_unemployment']][0]['amount'], '15.05');
     $this->assertEquals($pse_arr[$pse_accounts['state_unemployment']][0]['ytd_amount'], '15.05');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][0]['amount'], '-340.38');
     //YTD adjustment
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][0]['ytd_amount'], '0.00');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][1]['amount'], '-6.13');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][1]['ytd_amount'], '0.00');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][2]['amount'], '60.03');
     //YTD adjustment
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][2]['ytd_amount'], '-286.48');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_gross']][0]['amount'], '216.17');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_gross']][0]['ytd_amount'], '216.17');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_deductions']][0]['amount'], '75.05');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_deductions']][0]['ytd_amount'], '75.05');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['net_pay']][0]['amount'], '141.12');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['net_pay']][0]['ytd_amount'], '141.12');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['employer_contribution']][0]['amount'], '25.06');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['employer_contribution']][0]['ytd_amount'], '25.06');
     unset($pse_arr, $pay_stub_id, $pay_stub);
     //
     //
     //
     //Second Pay Stub
     //
     //
     //
     $pay_stub = new PayStubFactory();
     $pay_stub->setUser($this->user_id);
     $pay_stub->setCurrency($pay_stub->getUserObject()->getCurrency());
     $pay_stub->setPayPeriod($this->pay_period_objs[$start_pay_period_id + 1]->getId());
     $pay_stub->setStatus('NEW');
     $pay_stub->setDefaultDates();
     $pay_stub->loadPreviousPayStub();
     $pse_accounts = array('regular_time' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Regular Time'), 'over_time_1' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Over Time 1'), 'vacation_accrual_release' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Vacation Accrual Release'), 'federal_income_tax' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'Federal Income Tax'), 'state_income_tax' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'State Income Tax'), 'medicare' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 30, 'Medicare'), 'state_unemployment' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 30, 'State Unemployment Ins.'), 'vacation_accrual' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 50, 'Vacation Accrual'));
     $pay_stub->addEntry($pse_accounts['regular_time'], 198.01);
     $pay_stub->addEntry($pse_accounts['regular_time'], 12.01);
     //$pay_stub->addEntry( $pse_accounts['over_time_1'], 111.02 );
     //$pay_stub->addEntry( $pse_accounts['vacation_accrual_release'], 1.03 );
     $pay_stub->addEntry($pse_accounts['federal_income_tax'], 53.01);
     $pay_stub->addEntry($pse_accounts['state_income_tax'], 27.04);
     $pay_stub->addEntry($pse_accounts['medicare'], 13.04);
     $pay_stub->addEntry($pse_accounts['state_unemployment'], 16.09);
     $pay_stub->addEntry($pse_accounts['vacation_accrual'], 240.01);
     $pay_stub->setEnableProcessEntries(TRUE);
     $pay_stub->processEntries();
     if ($pay_stub->isValid() == TRUE) {
         Debug::text('Pay Stub is valid, final save.', __FILE__, __LINE__, __METHOD__, 10);
         $pay_stub_id = $pay_stub->Save();
     }
     $pse_arr = $this->getPayStubEntryArray($pay_stub_id);
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][0]['amount'], '198.01');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][0]['ytd_amount'], '0.00');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][1]['amount'], '12.01');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][1]['ytd_amount'], '320.04');
     $this->assertEquals($pse_arr[$pse_accounts['over_time_1']][0]['amount'], '0.00');
     $this->assertEquals($pse_arr[$pse_accounts['over_time_1']][0]['ytd_amount'], '100.02');
     //$this->assertEquals( $pse_arr[$pse_accounts['vacation_accrual_release']][0]['amount'], '1.03' );
     //$this->assertEquals( $pse_arr[$pse_accounts['vacation_accrual_release']][0]['ytd_amount'], '2.03' );
     $this->assertEquals($pse_arr[$pse_accounts['federal_income_tax']][0]['amount'], '53.01');
     $this->assertEquals($pse_arr[$pse_accounts['federal_income_tax']][0]['ytd_amount'], '103.02');
     $this->assertEquals($pse_arr[$pse_accounts['state_income_tax']][0]['amount'], '27.04');
     $this->assertEquals($pse_arr[$pse_accounts['state_income_tax']][0]['ytd_amount'], '52.08');
     $this->assertEquals($pse_arr[$pse_accounts['medicare']][0]['amount'], '13.04');
     $this->assertEquals($pse_arr[$pse_accounts['medicare']][0]['ytd_amount'], '23.05');
     $this->assertEquals($pse_arr[$pse_accounts['state_unemployment']][0]['amount'], '16.09');
     $this->assertEquals($pse_arr[$pse_accounts['state_unemployment']][0]['ytd_amount'], '31.14');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][0]['amount'], '240.01');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][0]['ytd_amount'], '-46.47');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_gross']][0]['amount'], '210.02');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_gross']][0]['ytd_amount'], '426.19');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_deductions']][0]['amount'], '80.05');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_deductions']][0]['ytd_amount'], '155.10');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['net_pay']][0]['amount'], '129.97');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['net_pay']][0]['ytd_amount'], '271.09');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['employer_contribution']][0]['amount'], '29.13');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['employer_contribution']][0]['ytd_amount'], '54.19');
     unset($pse_arr, $pay_stub_id, $pay_stub);
     //
     // Third Pay Stub
     //
     //Test UnUsed YTD entries...
     $pay_stub = new PayStubFactory();
     $pay_stub->setUser($this->user_id);
     $pay_stub->setCurrency($pay_stub->getUserObject()->getCurrency());
     $pay_stub->setPayPeriod($this->pay_period_objs[$start_pay_period_id + 2]->getId());
     $pay_stub->setStatus('NEW');
     $pay_stub->setDefaultDates();
     $pay_stub->loadPreviousPayStub();
     $pse_accounts = array('regular_time' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Regular Time'), 'over_time_1' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Over Time 1'), 'vacation_accrual_release' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Vacation Accrual Release'), 'federal_income_tax' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'Federal Income Tax'), 'state_income_tax' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'State Income Tax'), 'medicare' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 30, 'Medicare'), 'state_unemployment' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 30, 'State Unemployment Ins.'), 'vacation_accrual' => CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 50, 'Vacation Accrual'));
     $pay_stub->addEntry($pse_accounts['regular_time'], 100.01);
     $pay_stub->addEntry($pse_accounts['regular_time'], 10.01);
     $pay_stub->addEntry($pse_accounts['over_time_1'], 100.02);
     $pay_stub->addEntry($pse_accounts['vacation_accrual_release'], 1.0);
     $pay_stub->addEntry($pse_accounts['federal_income_tax'], 50.01);
     $pay_stub->addEntry($pse_accounts['state_income_tax'], 25.04);
     $pay_stub->addEntry($pse_accounts['medicare'], 10.01);
     $pay_stub->addEntry($pse_accounts['state_unemployment'], 15.05);
     $pay_stub->addEntry($pse_accounts['vacation_accrual'], 65.01000000000001);
     $pay_stub->setEnableProcessEntries(TRUE);
     $pay_stub->processEntries();
     if ($pay_stub->isValid() == TRUE) {
         $pay_stub_id = $pay_stub->Save();
         Debug::text('Pay Stub is valid, final save, ID: ' . $pay_stub_id, __FILE__, __LINE__, __METHOD__, 10);
     }
     $pse_arr = $this->getPayStubEntryArray($pay_stub_id);
     //
     // IN NEW YEAR, YTD amounts are zero'd!
     //
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][0]['amount'], '100.01');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][0]['ytd_amount'], '0.00');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][1]['amount'], '10.01');
     $this->assertEquals($pse_arr[$pse_accounts['regular_time']][1]['ytd_amount'], '430.06');
     $this->assertEquals($pse_arr[$pse_accounts['over_time_1']][0]['amount'], '100.02');
     $this->assertEquals($pse_arr[$pse_accounts['over_time_1']][0]['ytd_amount'], '200.04');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual_release']][0]['amount'], '1.00');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual_release']][0]['ytd_amount'], '7.13');
     $this->assertEquals($pse_arr[$pse_accounts['federal_income_tax']][0]['amount'], '50.01');
     $this->assertEquals($pse_arr[$pse_accounts['federal_income_tax']][0]['ytd_amount'], '153.03');
     $this->assertEquals($pse_arr[$pse_accounts['state_income_tax']][0]['amount'], '25.04');
     $this->assertEquals($pse_arr[$pse_accounts['state_income_tax']][0]['ytd_amount'], '77.12');
     $this->assertEquals($pse_arr[$pse_accounts['medicare']][0]['amount'], '10.01');
     $this->assertEquals($pse_arr[$pse_accounts['medicare']][0]['ytd_amount'], '33.06');
     $this->assertEquals($pse_arr[$pse_accounts['state_unemployment']][0]['amount'], '15.05');
     $this->assertEquals($pse_arr[$pse_accounts['state_unemployment']][0]['ytd_amount'], '46.19');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][0]['amount'], '-1.00');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][0]['ytd_amount'], '0.00');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][1]['amount'], '65.01');
     $this->assertEquals($pse_arr[$pse_accounts['vacation_accrual']][1]['ytd_amount'], '17.54');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_gross']][0]['amount'], '211.04');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_gross']][0]['ytd_amount'], '637.23');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_deductions']][0]['amount'], '75.05');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['total_deductions']][0]['ytd_amount'], '230.15');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['net_pay']][0]['amount'], '135.99');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['net_pay']][0]['ytd_amount'], '407.08');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['employer_contribution']][0]['amount'], '25.06');
     $this->assertEquals($pse_arr[$this->pay_stub_account_link_arr['employer_contribution']][0]['ytd_amount'], '79.25');
     unset($pse_arr, $pay_stub_id, $pay_stub);
     return TRUE;
 }
 function calculate($epoch = NULL)
 {
     if ($this->getUserObject() == FALSE or $this->getUserObject()->getStatus() !== 10) {
         return FALSE;
     }
     $generic_queue_status_label = $this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Pay Stub');
     if ($epoch == NULL or $epoch == '') {
         $epoch = TTDate::getTime();
     }
     if ($this->getPayPeriodObject() == FALSE) {
         return FALSE;
     }
     Debug::text('bbUser Id: ' . $this->getUser() . ' Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $this->getPayPeriodObject()->getEndDate()), __FILE__, __LINE__, __METHOD__, 10);
     $pay_stub = new PayStubFactory();
     $pay_stub->StartTransaction();
     $old_pay_stub_id = NULL;
     if ($this->getEnableCorrection() == TRUE) {
         Debug::text('Correction Enabled!', __FILE__, __LINE__, __METHOD__, 10);
         $pay_stub->setTemp(TRUE);
         //Check for current pay stub ID so we can compare against it.
         $pslf = new PayStubListFactory();
         $pslf->getByUserIdAndPayPeriodId($this->getUser(), $this->getPayPeriod());
         if ($pslf->getRecordCount() > 0) {
             $old_pay_stub_id = $pslf->getCurrent()->getId();
             Debug::text('Comparing Against Pay Stub ID: ' . $old_pay_stub_id, __FILE__, __LINE__, __METHOD__, 10);
         }
     }
     $pay_stub->setUser($this->getUser());
     $pay_stub->setPayPeriod($this->getPayPeriod());
     $pay_stub->setCurrency($this->getUserObject()->getCurrency());
     $pay_stub->setStatus('NEW');
     //Use User Termination Date instead of ROE.
     if ($this->getUserObject()->getTerminationDate() != '' and $this->getUserObject()->getTerminationDate() >= $this->getPayPeriodObject()->getStartDate() and $this->getUserObject()->getTerminationDate() <= $this->getPayPeriodObject()->getEndDate()) {
         Debug::text('User has been terminated in this pay period!', __FILE__, __LINE__, __METHOD__, 10);
         $is_terminated = TRUE;
     } else {
         $is_terminated = FALSE;
     }
     if ($is_terminated == TRUE) {
         Debug::text('User is Terminated, assuming final pay, setting End Date to terminated date: ' . TTDate::getDate('DATE+TIME', $this->getUserObject()->getTerminationDate()), __FILE__, __LINE__, __METHOD__, 10);
         $pay_stub->setStartDate($pay_stub->getPayPeriodObject()->getStartDate());
         $pay_stub->setEndDate($this->getUserObject()->getTerminationDate());
         //Use the PS generation date instead of terminated date...
         //Unlikely they would pay someone before the pay stub is generated.
         //Perhaps still use the pay period transaction date for this too?
         //Anything we set won't be correct for everyone. Maybe a later date is better though?
         //Perhaps add to the user factory under Termination Date a: "Final Transaction Date" for this purpose?
         //Use the end of the current date for the transaction date, as if the employee is terminated
         //on the same day they are generating the pay stub, the transaction date could be before the end date
         //as the end date is at 11:59PM
         $pay_stub->setTransactionDate(TTDate::getEndDayEpoch(TTDate::getTime()));
     } else {
         Debug::text('User Termination Date is NOT set, assuming normal pay.', __FILE__, __LINE__, __METHOD__, 10);
         $pay_stub->setDefaultDates();
     }
     //This must go after setting advance
     if ($this->getEnableCorrection() == FALSE and $pay_stub->IsUniquePayStub() == FALSE) {
         Debug::text('Pay Stub already exists', __FILE__, __LINE__, __METHOD__, 10);
         $this->CommitTransaction();
         UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 20, TTi18n::gettext('Pay Stub for this employee already exists, skipping...'), NULL);
         return FALSE;
     }
     if ($pay_stub->isValid() == TRUE) {
         $pay_stub->Save(FALSE);
         $pay_stub->setStatus('Open');
     } else {
         Debug::text('Pay Stub isValid failed!', __FILE__, __LINE__, __METHOD__, 10);
         UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 10, $pay_stub->Validator->getTextErrors(), NULL);
         $this->FailTransaction();
         $this->CommitTransaction();
         return FALSE;
     }
     $pay_stub->loadPreviousPayStub();
     $user_date_total_arr = $this->getWageObject()->getUserDateTotalArray();
     if (isset($user_date_total_arr['entries']) and is_array($user_date_total_arr['entries'])) {
         foreach ($user_date_total_arr['entries'] as $udt_arr) {
             //Allow negative amounts so flat rate premium policies can reduce an employees wage if need be.
             if ($udt_arr['amount'] != 0) {
                 Debug::text('Adding Pay Stub Entry: ' . $udt_arr['pay_stub_entry'] . ' Amount: ' . $udt_arr['amount'], __FILE__, __LINE__, __METHOD__, 10);
                 $pay_stub->addEntry($udt_arr['pay_stub_entry'], $udt_arr['amount'], TTDate::getHours($udt_arr['total_time']), $udt_arr['rate']);
             } else {
                 Debug::text('NOT Adding ($0 amount) Pay Stub Entry: ' . $udt_arr['pay_stub_entry'] . ' Amount: ' . $udt_arr['amount'], __FILE__, __LINE__, __METHOD__, 10);
             }
         }
     } else {
         //No Earnings, CHECK FOR PS AMENDMENTS next for earnings.
         Debug::text('NO TimeSheet EARNINGS ON PAY STUB... Checking for PS amendments', __FILE__, __LINE__, __METHOD__, 10);
     }
     //Get all PS amendments and Tax / Deductions so we can determine the proper order to calculate them in.
     $psalf = new PayStubAmendmentListFactory();
     $psalf->getByUserIdAndAuthorizedAndStartDateAndEndDate($this->getUser(), TRUE, $this->getPayPeriodObject()->getStartDate(), $this->getPayPeriodObject()->getEndDate());
     $udlf = new UserDeductionListFactory();
     $udlf->getByCompanyIdAndUserId($this->getUserObject()->getCompany(), $this->getUserObject()->getId());
     $deduction_order_arr = $this->getOrderedDeductionAndPSAmendment($udlf, $psalf);
     if (is_array($deduction_order_arr) and count($deduction_order_arr) > 0) {
         foreach ($deduction_order_arr as $calculation_order => $data_arr) {
             Debug::text('Found PS Amendment/Deduction: Type: ' . $data_arr['type'] . ' Name: ' . $data_arr['name'] . ' Order: ' . $calculation_order, __FILE__, __LINE__, __METHOD__, 10);
             if (isset($data_arr['obj']) and is_object($data_arr['obj'])) {
                 if ($data_arr['type'] == 'UserDeductionListFactory') {
                     $ud_obj = $data_arr['obj'];
                     //Determine if this deduction is valid based on start/end dates.
                     //Determine if this deduction is valid based on min/max length of service.
                     if ($ud_obj->getCompanyDeductionObject()->isActiveDate($pay_stub->getPayPeriodObject()->getEndDate()) == TRUE and $ud_obj->getCompanyDeductionObject()->isActiveLengthOfService($this->getUserObject(), $pay_stub->getPayPeriodObject()->getEndDate()) == TRUE) {
                         $amount = $ud_obj->getDeductionAmount($this->getUserObject()->getId(), $pay_stub, $this->getPayPeriodObject());
                         Debug::text('User Deduction: ' . $ud_obj->getCompanyDeductionObject()->getName() . ' Amount: ' . $amount . ' Calculation Order: ' . $ud_obj->getCompanyDeductionObject()->getCalculationOrder(), __FILE__, __LINE__, __METHOD__, 10);
                         //Allow negative amounts, so they can reduce previously calculated deductions or something.
                         if (isset($amount) and $amount != 0) {
                             $pay_stub->addEntry($ud_obj->getCompanyDeductionObject()->getPayStubEntryAccount(), $amount);
                         } else {
                             Debug::text('Amount is 0, skipping...', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                     unset($amount, $ud_obj);
                 } elseif ($data_arr['type'] == 'PayStubAmendmentListFactory') {
                     $psa_obj = $data_arr['obj'];
                     Debug::text('Found Pay Stub Amendment: ID: ' . $psa_obj->getID() . ' Entry Name ID: ' . $psa_obj->getPayStubEntryNameId() . ' Type: ' . $psa_obj->getType(), __FILE__, __LINE__, __METHOD__, 10);
                     $amount = $psa_obj->getCalculatedAmount($pay_stub);
                     if (isset($amount) and $amount != 0) {
                         Debug::text('Pay Stub Amendment Amount: ' . $amount, __FILE__, __LINE__, __METHOD__, 10);
                         $pay_stub->addEntry($psa_obj->getPayStubEntryNameId(), $amount, $psa_obj->getUnits(), $psa_obj->getRate(), $psa_obj->getDescription(), $psa_obj->getID(), NULL, NULL, $psa_obj->getYTDAdjustment());
                         //Keep in mind this causes pay stubs to be re-generated every time, as this modifies the updated time
                         //to slightly more then the pay stub creation time.
                         $psa_obj->setStatus('IN USE');
                         $psa_obj->Save();
                     } else {
                         Debug::text('bPay Stub Amendment Amount is not set...', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     unset($amount, $psa_obj);
                 }
             }
         }
     }
     unset($deduction_order_arr, $calculation_order, $data_arr);
     $pay_stub_id = $pay_stub->getId();
     $pay_stub->setEnableProcessEntries(TRUE);
     $pay_stub->processEntries();
     if ($pay_stub->isValid() == TRUE) {
         Debug::text('Pay Stub is valid, final save.', __FILE__, __LINE__, __METHOD__, 10);
         $pay_stub->Save();
         if ($this->getEnableCorrection() == TRUE) {
             if (isset($old_pay_stub_id)) {
                 Debug::text('bCorrection Enabled - Doing Comparison here', __FILE__, __LINE__, __METHOD__, 10);
                 PayStubFactory::CalcDifferences($pay_stub_id, $old_pay_stub_id);
             }
             //Delete newly created temp paystub.
             //This used to be in the above IF block that depended on $old_pay_stub_id
             //being set, however in cases where the old pay stub didn't exist
             //TimeTrex wouldn't delete these temporary pay stubs.
             //Moving this code outside that IF statement so it only depends on EnableCorrection()
             //to be TRUE should fix that issue.
             $pslf = new PayStubListFactory();
             $pslf->getById($pay_stub_id);
             if ($pslf->getRecordCount() > 0) {
                 $tmp_ps_obj = $pslf->getCurrent();
                 $tmp_ps_obj->setDeleted(TRUE);
                 $tmp_ps_obj->Save();
                 unset($tmp_ps_obj);
             }
         }
         $pay_stub->CommitTransaction();
         UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 30, NULL, NULL);
         return TRUE;
     }
     Debug::text('Pay Stub is NOT valid returning FALSE', __FILE__, __LINE__, __METHOD__, 10);
     UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 10, $pay_stub->Validator->getTextErrors(), NULL);
     $pay_stub->FailTransaction();
     //Reduce transaction count by one.
     //$pay_stub->FailTransaction(); //Reduce transaction count by one.
     $pay_stub->CommitTransaction();
     return FALSE;
 }