function reCalculate()
 {
     //Re-generate final pay stub
     //get current pay period based off their last day of work
     $pplf = new PayPeriodListFactory();
     $pay_period_id = $pplf->getByUserIdAndEndDate($this->getUser(), $this->getLastDate())->getCurrent()->getId();
     Debug::Text('Pay Period ID: ' . $pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
     if (is_numeric($pay_period_id) == FALSE) {
         UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Pay Stub'), 10, TTi18n::gettext('Pay Period is invalid!'), NULL);
         return FALSE;
     }
     if ($this->getEnableGeneratePayStub() == TRUE) {
         //Find out if a pay stub is already generated for the pay period we are currently in.
         //If it is, delete it so we can start from fresh
         $pslf = new PayStubListFactory();
         $pslf->getByUserIdAndPayPeriodId($this->getUser(), $pay_period_id);
         foreach ($pslf as $pay_stub) {
             Debug::Text('Found Pay Stub ID: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10);
             //Do not delete PAID pay stubs!
             if ($pay_stub->getStatus() == 10) {
                 Debug::Text('Last Pay Stub Exists: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 $pay_stub->setDeleted(TRUE);
                 $pay_stub->Save();
             }
         }
         //FIXME: Make sure user isn't already in-active! Otherwise pay stub won't generate.
         //Check if pay stub is already generated as well, if it is, and marked paid, then
         //we can't re-generate it, we need to skip this step.
         Debug::Text('Calculating Pay Stub...', __FILE__, __LINE__, __METHOD__, 10);
         $cps = new CalculatePayStub();
         $cps->setUser($this->getUser());
         $cps->setPayPeriod($pay_period_id);
         $cps->calculate();
         Debug::Text('Done Calculating Pay Stub', __FILE__, __LINE__, __METHOD__, 10);
     } else {
         UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE), 20, TTi18n::gettext('Not generating final pay stub!'), NULL);
     }
     //FIXME: Alert the user if they don't have enough information in TimeTrex to get accurate values.
     //Get insurable hours, earnings, and vacation pay now that the final pay stub is generated
     $ugdlf = new UserGenericDataListFactory();
     $ugdlf->getByCompanyIdAndScriptAndDefault($this->getUserObject()->getCompany(), $this->getTable());
     if ($ugdlf->getRecordCount() > 0) {
         Debug::Text('Found Company Form Setup!', __FILE__, __LINE__, __METHOD__, 10);
         $ugd_obj = $ugdlf->getCurrent();
         $setup_data = $ugd_obj->getData();
     }
     unset($ugd_obj);
     if (isset($setup_data)) {
         //var_dump($setup_data);
         if (isset($setup_data['insurable_earnings_psea_ids'])) {
             $insurable_earnings_psea_ids = $setup_data['insurable_earnings_psea_ids'];
         } else {
             //Fall back to Total Gross.
             $insurable_earnings_psea_ids = $this->getPayStubEntryAccountLinkObject()->getTotalGross();
         }
     }
     //Find out the date of how far back we have to go to get insurable values.
     //Insurable Hours
     $insurable_hours_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableHoursReportPayPeriods());
     //Insurable hours dont include stats!Just get total signed in hours.
     //If someone has just a negative bank time balance, those are NOT insurable.
     $udtlf = new UserDateTotalListFactory();
     $worked_total_time = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($this->getUser(), $insurable_hours_start_date, $this->getLastDate());
     Debug::text('Worked Total Time: ' . $worked_total_time, __FILE__, __LINE__, __METHOD__, 10);
     $total_hours = Misc::MoneyFormat(TTDate::getHours($worked_total_time), FALSE);
     Debug::Text('Total Insurable Hours: ' . $total_hours, __FILE__, __LINE__, __METHOD__, 10);
     $insurable_earnings_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableEarningsReportPayPeriods());
     $pself = new PayStubEntryListFactory();
     $total_earnings = $this->getTotalInsurableEarnings();
     //$total_earnings = $pself->getAmountSumByUserIdAndEntryNameIdAndStartDateAndEndDate( $this->getUser(), $insurable_earnings_psea_ids, $insurable_earnings_start_date, $this->getLastDate(), 0 );
     //$total_earnings = $total_earnings['amount'];
     //Note, this includes the current pay stub we just generated
     Debug::Text('Total Insurable Earnings: ' . $total_earnings, __FILE__, __LINE__, __METHOD__, 10);
     UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Record of Employment'), 30, TTi18n::gettext('Insurable Hours:') . ' ' . $total_hours . ' ' . TTi18n::gettext('Insurable Earnings:') . ' ' . $total_earnings, NULL);
     //ReSave these
     if ($this->getId() != '') {
         $rlf = new ROEListFactory();
         $rlf->getById($this->getId());
         if ($rlf->getRecordCount() > 0) {
             $roe_obj = $rlf->getCurrent();
             $roe_obj->setInsurableHours($total_hours);
             $roe_obj->setInsurableEarnings($total_earnings);
             if ($roe_obj->isValid()) {
                 $roe_obj->Save();
             }
         }
     }
     return TRUE;
 }
Beispiel #2
0
     $roelf->getById($id);
     foreach ($roelf as $roe) {
         //Debug::Arr($department,'Department', __FILE__, __LINE__, __METHOD__,10);
         $roe_data = array('id' => $roe->getId(), 'user_id' => $roe->getUser(), 'pay_period_type_id' => $roe->getPayPeriodType(), 'code_id' => $roe->getCode(), 'first_date' => $roe->getFirstDate(), 'last_date' => $roe->getLastDate(), 'pay_period_end_date' => $roe->getPayPeriodEndDate(), 'recall_date' => $roe->getRecallDate(), 'insurable_hours' => $roe->getInsurableHours(), 'insurable_earnings' => $roe->getInsurableEarnings(), 'vacation_pay' => $roe->getVacationPay(), 'serial' => $roe->getSerial(), 'comments' => $roe->getComments(), 'created_date' => $roe->getCreatedDate(), 'created_by' => $roe->getCreatedBy(), 'updated_date' => $roe->getUpdatedDate(), 'updated_by' => $roe->getUpdatedBy(), 'deleted_date' => $roe->getDeletedDate(), 'deleted_by' => $roe->getDeletedBy());
     }
 } elseif (!isset($action)) {
     //Get all the data we should need for this ROE in regards to pay period and such
     //Guess for end dates...
     //get User data for hire date
     $ulf = new UserListFactory();
     $user_obj = $ulf->getById($user_id)->getCurrent();
     $plf = new PunchListFactory();
     //Is there a previous ROE? If so, find first shift back since ROE was issued.
     $rlf = new ROEListFactory();
     $rlf->getLastROEByUserId($user_id);
     if ($rlf->getRecordCount() > 0) {
         $roe_obj = $rlf->getCurrent();
         Debug::Text('Previous ROE Last Date: ' . TTDate::getDate('DATE+TIME', $roe_obj->getLastDate()), __FILE__, __LINE__, __METHOD__, 10);
         //$plf->getFirstPunchByUserIDAndEpoch( $user_id, $roe_obj->getLastDate() );
         $plf->getNextPunchByUserIdAndEpoch($user_id, $roe_obj->getLastDate());
         if ($plf->getRecordCount() > 0) {
             $first_date = $plf->getCurrent()->getTimeStamp();
         }
     }
     if (!isset($first_date) or $first_date == '') {
         $first_date = $user_obj->getHireDate();
     }
     Debug::Text('First Date: ' . TTDate::getDate('DATE+TIME', $first_date), __FILE__, __LINE__, __METHOD__, 10);
     //Get last shift worked (not scheduled)
     $plf->getLastPunchByUserId($user_id);
     if ($plf->getRecordCount() > 0) {