function getNextPayPeriod($end_date = NULL) { if (!$this->Validator->isValid()) { return FALSE; } //Manual Pay Period Schedule, skip repeating... if ($this->getType() == 5) { return FALSE; } $pplf = new PayPeriodListFactory(); //Debug::text('PP Schedule ID: '. $this->getId(), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('PP Schedule Name: '. $this->getName(), __FILE__, __LINE__, __METHOD__, 10); Debug::text('PP Schedule Type (' . $this->getType() . '): ' . Option::getByKey($this->getType(), $this->getOptions('type')), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('Anchor Date: '. $this->getAnchorDate() ." - ". TTDate::getDate('DATE+TIME', $this->getAnchorDate() ), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('Primary Date: '. $this->getPrimaryDate() ." - ". TTDate::getDate('DATE+TIME', $this->getPrimaryDate() ), __FILE__, __LINE__, __METHOD__, 10); //Debug::text('Secondary Date: '. $this->getSecondaryDate() ." - ". TTDate::getDate('DATE+TIME', $this->getPrimaryDate() ), __FILE__, __LINE__, __METHOD__, 10); $last_pay_period_is_new = FALSE; if ($end_date != '' and $end_date != 0) { Debug::text('End Date is set: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); $last_pay_period_end_date = $end_date; } else { Debug::text('Checking for Previous pay periods...', __FILE__, __LINE__, __METHOD__, 10); //Get the last pay period schedule in the database. $pplf->getByPayPeriodScheduleId($this->getId(), NULL, NULL, NULL, array('start_date' => 'desc')); $last_pay_period = $pplf->getCurrent(); if ($last_pay_period->isNew()) { $last_pay_period_is_new = TRUE; Debug::text('No Previous pay periods...', __FILE__, __LINE__, __METHOD__, 10); //Do this so a rollover doesn't happen while we're calculating. //$last_pay_period_end_date = TTDate::getTime(); //This causes the pay period schedule to jump ahead one month. So set this to be beginning of the month. $last_pay_period_end_date = TTDate::getBeginMonthEpoch(); } else { Debug::text('Previous pay periods found... ID: ' . $last_pay_period->getId(), __FILE__, __LINE__, __METHOD__, 10); $last_pay_period_end_date = $last_pay_period->getEndDate(); } unset($last_pay_period, $pplf); } Debug::text('aLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); //FIXME: This breaks having pay periods with different daily start times. //However, without it, I think DST breaks pay periods. //$last_pay_period_end_date = TTDate::getEndDayEpoch( $last_pay_period_end_date + 1 ) - 86400; $last_pay_period_end_date = TTDate::getEndDayEpoch($last_pay_period_end_date - 86400 / 2); Debug::text('bLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); if ($this->getDayStartTime() != 0) { Debug::text('Daily Start Time is set, adjusting Last Pay Period End Date by: ' . TTDate::getHours($this->getDayStartTime()), __FILE__, __LINE__, __METHOD__, 10); //Next adjust last_pay_period_end_date (which becomes the start date) to DayStartTime because then there could be a gap if they //change this mid-schedule. The End Date will take care of it after the first pay period. $last_pay_period_end_date = TTDate::getTimeLockedDate(TTDate::getBeginDayEpoch($last_pay_period_end_date) + $this->getDayStartTime(), $last_pay_period_end_date); Debug::text('cLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); } $insert_pay_period = 1; //deprecate primary pay periods. switch ($this->getType()) { case 10: //Weekly //Weekly case 20: //Bi-Weekly $last_pay_period_end_day_of_week = TTDate::getDayOfWeek($last_pay_period_end_date); Debug::text('Last Pay Period End Day Of Week: ' . $last_pay_period_end_day_of_week . ' Start Day Of Week: ' . $this->getStartDayOfWeek(), __LINE__, __METHOD__, 10); if ($last_pay_period_end_day_of_week != $this->getStartDayOfWeek()) { Debug::text('zTmp Pay Period End Date: ' . 'next ' . TTDate::getDayOfWeekByInt($this->getStartDayOfWeek()), __FILE__, __LINE__, __METHOD__, 10); //$tmp_pay_period_end_date = strtotime('next '. TTDate::getDayOfWeekByInt( $this->getStartDayOfWeek() ), $last_pay_period_end_date )-1; $tmp_pay_period_end_date = strtotime('next ' . TTDate::getDayOfWeekByInt($this->getStartDayOfWeek(), FALSE), $last_pay_period_end_date); //strtotime doesn't keep time when using "next", it resets it to midnight on the day, so we need to adjust for that. $tmp_pay_period_end_date = TTDate::getTimeLockedDate(TTDate::getBeginDayEpoch($tmp_pay_period_end_date) + $this->getDayStartTime(), $tmp_pay_period_end_date) - 1; } else { $tmp_pay_period_end_date = $last_pay_period_end_date; //This should fix a bug where if they are creating a new pay period schedule //starting on Monday with the anchor date of 01-Jul-08, it would start on 01-Jul-08 (Tue) //rather moving back to the Monday. if (TTDate::getDayOfMonth($tmp_pay_period_end_date) != TTDate::getDayOfMonth($tmp_pay_period_end_date + 1)) { Debug::text('Right on day boundary, minus an additional second to account for difference...', __FILE__, __LINE__, __METHOD__, 10); $tmp_pay_period_end_date--; } } Debug::text('aTmp Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $tmp_pay_period_end_date) . ' (' . $tmp_pay_period_end_date . ')', __FILE__, __LINE__, __METHOD__, 10); $start_date = $tmp_pay_period_end_date + 1; if ($this->getType() == 10) { //Weekly $tmp_pay_period_end_date = TTDate::getMiddleDayEpoch($start_date) + 86400 * 7; //Add one week } elseif ($this->getType() == 20) { //Bi-Weekly $tmp_pay_period_end_date = TTDate::getMiddleDayEpoch($start_date) + 86400 * 14; //Add two weeks } //Use Begin Day Epoch to nullify DST issues. $end_date = TTDate::getBeginDayEpoch($tmp_pay_period_end_date) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getMiddleDayEpoch($end_date) + $this->getTransactionDate() * 86400); break; case 30: //Semi-monthly $tmp_last_pay_period_end_day_of_month = TTDate::getDayOfMonth($last_pay_period_end_date + 1); Debug::text('bLast Pay Period End Day Of Month: ' . $tmp_last_pay_period_end_day_of_month, __FILE__, __LINE__, __METHOD__, 10); if ($tmp_last_pay_period_end_day_of_month == $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())) { $insert_pay_period = 1; $primary = TRUE; } elseif ($tmp_last_pay_period_end_day_of_month == $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth())) { $insert_pay_period = 2; $primary = FALSE; } else { Debug::text('Finding if Primary or Secondary is closest...', __FILE__, __LINE__, __METHOD__, 10); $primary_date_offset = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())) - $last_pay_period_end_date; $secondary_date_offset = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth())) - $last_pay_period_end_date; Debug::text('Primary Date Offset: ' . TTDate::getDays($primary_date_offset) . ' Secondary Date Offset: ' . TTDate::getDays($secondary_date_offset), __FILE__, __LINE__, __METHOD__, 10); if ($primary_date_offset <= $secondary_date_offset) { $insert_pay_period = 1; $primary = TRUE; $last_pay_period_end_date = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())); } else { $insert_pay_period = 2; $primary = FALSE; $last_pay_period_end_date = TTDate::getDateOfNextDayOfMonth($last_pay_period_end_date, NULL, $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth())); } $last_pay_period_end_date = TTDate::getBeginDayEpoch($last_pay_period_end_date); } unset($tmp_last_pay_period_end_day_of_month); Debug::text('cLast Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $last_pay_period_end_date) . ' (' . $last_pay_period_end_date . ') Primary: ' . (int) $primary, __FILE__, __LINE__, __METHOD__, 10); $start_date = $last_pay_period_end_date + 1; if ($primary == TRUE) { $end_date = TTDate::getBeginDayEpoch(TTDate::getDateOfNextDayOfMonth($start_date, NULL, $this->convertLastDayOfMonth($this->getSecondaryDayOfMonth()))) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getDateOfNextDayOfMonth(TTDate::getMiddleDayEpoch($end_date), NULL, $this->convertLastDayOfMonth($this->getPrimaryTransactionDayOfMonth()))); } else { $end_date = TTDate::getBeginDayEpoch(TTDate::getDateOfNextDayOfMonth($start_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth()))) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getDateOfNextDayOfMonth(TTDate::getMiddleDayEpoch($end_date), NULL, $this->convertLastDayOfMonth($this->getSecondaryTransactionDayOfMonth()))); } break; case 50: //Monthly $start_date = $last_pay_period_end_date + 1; $end_date = TTDate::getDateOfNextDayOfMonth($start_date + 86400, NULL, $this->convertLastDayOfMonth($this->getPrimaryDayOfMonth())); //Use Begin Day Epoch to nullify DST issues. $end_date = TTDate::getBeginDayEpoch(TTDate::getBeginMinuteEpoch($end_date)) - 1; $transaction_date = TTDate::getMiddleDayEpoch(TTDate::getDateOfNextDayOfMonth($end_date, NULL, $this->convertLastDayOfMonth($this->getPrimaryTransactionDayOfMonth()))); break; } if ($this->getDayStartTime() != 0) { Debug::text('Daily Start Time is set, adjusting End Date by: ' . TTDate::getHours($this->getDayStartTime()) . ' Start Date: ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 10); //We already account for DayStartTime in weekly/bi-weekly start_date cases above, so skip applying it again here. if ($this->getType() != 10 and $this->getType() != 20) { $start_date = $start_date + $this->getDayStartTime(); } $end_date = $end_date + $this->getDayStartTime(); //Need to do this, otherwise transaction date could be earlier then end date. $transaction_date = $transaction_date + $this->getDayStartTime(); } Debug::text('aStart Date(' . $start_date . '): ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('aEnd Date(' . $end_date . '): ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('aPay Date(' . $transaction_date . '): ' . TTDate::getDate('DATE+TIME', $transaction_date), __FILE__, __LINE__, __METHOD__, 10); //Handle last day of the month flag for primary and secondary dates here if ($this->getType() == 30 and ($insert_pay_period == 1 and ($this->getPrimaryDayOfMonth() == 31 or $this->getPrimaryDayOfMonth() == -1) or $insert_pay_period == 2 and ($this->getSecondaryDayOfMonth() == 31 or $this->getSecondaryDayOfMonth() == -1)) or $this->getType() == 50 and ($this->getPrimaryDayOfMonth() == 31 or $this->getPrimaryDayOfMonth() == -1)) { Debug::text('Last day of the month set for start date: ', __FILE__, __LINE__, __METHOD__, 10); if ($this->getDayStartTime() > 0) { //Minus one day, THEN add daily start time, otherwise it will go past the month boundary $end_date = TTDate::getEndMonthEpoch($end_date) - 86400 + $this->getDayStartTime(); //End month epoch is 23:59:59, so don't minus one. } else { $end_date = TTDate::getEndMonthEpoch($end_date) + $this->getDayStartTime(); //End month epoch is 23:59:59, so don't minus one. } } //Handle "last day of the month" for transaction dates. if ($this->getPrimaryDayOfMonth() == 31 or $this->getPrimaryDayOfMonth() == -1) { //Debug::text('LDOM set for Primary: ', __FILE__, __LINE__, __METHOD__, 10); $transaction_date = TTDate::getEndMonthEpoch($transaction_date); } //Handle "always business day" flag for transaction dates here. if ($this->getTransactionDateBusinessDay() == TRUE) { $transaction_date = $this->getTransactionBusinessDay($transaction_date); } if ($transaction_date < $end_date) { $transaction_date = $end_date; } Debug::text('Start Date: ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text('Pay Date: ' . TTDate::getDate('DATE+TIME', $transaction_date), __FILE__, __LINE__, __METHOD__, 10); Debug::text("<br><br>\n\n", __FILE__, __LINE__, __METHOD__, 10); $this->next_start_date = $start_date; $this->next_end_date = $end_date; $this->next_transaction_date = $transaction_date; //Its a primary pay period if ($insert_pay_period == 1) { $this->next_primary = TRUE; } else { $this->next_primary = FALSE; } return TRUE; }
function getByUserIdAndPayPeriodIdAndEndDate($user_id, $pay_period_id, $end_date = NULL) { if ($user_id == '') { return FALSE; } if ($pay_period_id == '') { return FALSE; } if ($end_date == NULL) { //Get pay period end date. $pplf = new PayPeriodListFactory(); $pplf->getById($pay_period_id); if ($pplf->getRecordCount() > 0) { $pp_obj = $pplf->getCurrent(); $end_date = $pp_obj->getEndDate(); } } $udf = new UserDateFactory(); $uwf = new UserWageFactory(); $otpf = new OverTimePolicyFactory(); $apf = new AbsencePolicyFactory(); $ppf = new PremiumPolicyFactory(); $ph = array('user_id' => $user_id, 'pay_period_id' => $pay_period_id, 'end_date' => $this->db->BindDate($end_date)); /* select a.status_id as status_id, a.type_id as type_id, a.over_time_policy_id as over_time_policy_id, a.absence_policy_id as absence_policy_id, a.premium_policy_id as premium_policy_id, z.id as user_wage_id, z.effective_date as user_wage_effective_date, sum(total_Time) as total_time from '. $this->getTable() .' as a LEFT JOIN '. $udf->getTable() .' as b ON a.user_date_id = b.id LEFT JOIN '. $uwf->getTable() .' as z ON z.id = (select z.id from '. $uwf->getTable() .' as z where z.user_id = b.user_id and z.effective_date <= b.date_stamp and z.deleted = 0 order by z.effective_date desc limit 1) where b.user_id = ? AND b.pay_period_id = ? AND b.date_stamp <= ? AND a.status_id in (10,30) AND ( a.deleted = 0 AND b.deleted = 0) group by user_wage_id, user_wage_effective_date, a.status_id, a.type_id, a.over_time_policy_id, a.absence_policy_id, a.premium_policy_id order by a.status_id desc, a.type_id asc, user_wage_effective_date desc */ //Order dock hours first, so it can be deducted from regular time. //Order newest wage changes first too. This is VERY important for calculating pro-rate amounts. $query = ' select a.status_id as status_id, a.type_id as type_id, a.over_time_policy_id as over_time_policy_id, n.id as over_time_policy_wage_id, n.effective_date as over_time_policy_wage_effective_date, a.absence_policy_id as absence_policy_id, p.id as absence_policy_wage_id, p.effective_date as absence_policy_wage_effective_date, a.premium_policy_id as premium_policy_id, r.id as premium_policy_wage_id, r.effective_date as premium_policy_wage_effective_date, z.id as user_wage_id, z.effective_date as user_wage_effective_date, sum(total_Time) as total_time from ' . $this->getTable() . ' as a LEFT JOIN ' . $udf->getTable() . ' as b ON a.user_date_id = b.id LEFT JOIN ' . $otpf->getTable() . ' as m ON a.over_time_policy_id = m.id LEFT JOIN ' . $uwf->getTable() . ' as n ON n.id = (select n.id from ' . $uwf->getTable() . ' as n where n.user_id = b.user_id and n.wage_group_id = m.wage_group_id and n.effective_date <= b.date_stamp and n.deleted = 0 order by n.effective_date desc limit 1) LEFT JOIN ' . $apf->getTable() . ' as o ON a.absence_policy_id = o.id LEFT JOIN ' . $uwf->getTable() . ' as p ON p.id = (select p.id from ' . $uwf->getTable() . ' as p where p.user_id = b.user_id and p.wage_group_id = o.wage_group_id and p.effective_date <= b.date_stamp and p.deleted = 0 order by p.effective_date desc limit 1) LEFT JOIN ' . $ppf->getTable() . ' as q ON a.premium_policy_id = q.id LEFT JOIN ' . $uwf->getTable() . ' as r ON r.id = (select r.id from ' . $uwf->getTable() . ' as r where r.user_id = b.user_id and r.wage_group_id = q.wage_group_id and r.effective_date <= b.date_stamp and r.deleted = 0 order by r.effective_date desc limit 1) LEFT JOIN ' . $uwf->getTable() . ' as z ON z.id = (select z.id from ' . $uwf->getTable() . ' as z where z.user_id = b.user_id and z.wage_group_id = 0 and z.effective_date <= b.date_stamp and z.deleted = 0 order by z.effective_date desc limit 1) where b.user_id = ? AND b.pay_period_id = ? AND b.date_stamp <= ? AND a.status_id in (10,30) AND ( a.deleted = 0 AND b.deleted = 0) group by user_wage_id, user_wage_effective_date, over_time_policy_wage_id, over_time_policy_wage_effective_date, absence_policy_wage_id, absence_policy_wage_effective_date, premium_policy_wage_id, premium_policy_wage_effective_date, a.status_id, a.type_id, a.over_time_policy_id, a.absence_policy_id, a.premium_policy_id order by a.status_id desc, a.type_id asc, user_wage_effective_date desc, over_time_policy_wage_effective_date desc, absence_policy_wage_effective_date desc, premium_policy_wage_effective_date desc '; $this->ExecuteSQL($query, $ph); return $this; }
static function CalcDifferences($pay_stub_id1, $pay_stub_id2, $ps_amendment_date = NULL) { //PayStub 1 is new. //PayStub 2 is old. if ($pay_stub_id1 == '') { return FALSE; } if ($pay_stub_id2 == '') { return FALSE; } if ($pay_stub_id1 == $pay_stub_id2) { return FALSE; } Debug::Text('Calculating the differences between Pay Stub: ' . $pay_stub_id1 . ' And: ' . $pay_stub_id2, __FILE__, __LINE__, __METHOD__, 10); $pslf = new PayStubListFactory(); $pslf->StartTransaction(); $pslf->getById($pay_stub_id1); if ($pslf->getRecordCount() > 0) { $pay_stub1_obj = $pslf->getCurrent(); } else { Debug::Text('Pay Stub1 does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $pslf->getById($pay_stub_id2); if ($pslf->getRecordCount() > 0) { $pay_stub2_obj = $pslf->getCurrent(); } else { Debug::Text('Pay Stub2 does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if ($pay_stub1_obj->getUser() != $pay_stub2_obj->getUser()) { Debug::Text('Pay Stubs are from different users!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if ($ps_amendment_date == NULL or $ps_amendment_date == '') { Debug::Text('PS Amendment Date not set, trying to figure it out!', __FILE__, __LINE__, __METHOD__, 10); //Take a guess at the end of the newest open pay period. $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getByUserId($pay_stub2_obj->getUser()); if ($ppslf->getRecordCount() > 0) { Debug::Text('Found Pay Period Schedule', __FILE__, __LINE__, __METHOD__, 10); $pplf = new PayPeriodListFactory(); $pplf->getByPayPeriodScheduleIdAndTransactionDate($ppslf->getCurrent()->getId(), time()); if ($pplf->getRecordCount() > 0) { Debug::Text('Using Pay Period End Date.', __FILE__, __LINE__, __METHOD__, 10); $ps_amendment_date = TTDate::getBeginDayEpoch($pplf->getCurrent()->getEndDate()); } } else { Debug::Text('Using Today.', __FILE__, __LINE__, __METHOD__, 10); $ps_amendment_date = time(); } } Debug::Text('Using Date: ' . TTDate::getDate('DATE+TIME', $ps_amendment_date), __FILE__, __LINE__, __METHOD__, 10); //Only do Earnings for now. //Get all earnings, EE/ER deduction PS entries. $pay_stub1_entry_ids = NULL; $pay_stub1_entries = new PayStubEntryListFactory(); $pay_stub1_entries->getByPayStubIdAndType($pay_stub1_obj->getId(), array(10, 20, 30)); if ($pay_stub1_entries->getRecordCount() > 0) { Debug::Text('Pay Stub1 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_stub1_entries as $pay_stub1_entry_obj) { $pay_stub1_entry_ids[] = $pay_stub1_entry_obj->getPayStubEntryNameId(); } } else { Debug::Text('Pay Stub1 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } Debug::Arr($pay_stub1_entry_ids, 'Pay Stub1 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10); //var_dump($pay_stub1_entry_ids); $pay_stub2_entry_ids = NULL; $pay_stub2_entries = new PayStubEntryListFactory(); $pay_stub2_entries->getByPayStubIdAndType($pay_stub2_obj->getId(), array(10, 20, 30)); if ($pay_stub2_entries->getRecordCount() > 0) { Debug::Text('Pay Stub2 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_stub2_entries as $pay_stub2_entry_obj) { $pay_stub2_entry_ids[] = $pay_stub2_entry_obj->getPayStubEntryNameId(); } } else { Debug::Text('Pay Stub2 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } Debug::Arr($pay_stub1_entry_ids, 'Pay Stub2 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10); $pay_stub_entry_ids = array_unique(array_merge($pay_stub1_entry_ids, $pay_stub2_entry_ids)); Debug::Arr($pay_stub_entry_ids, 'Pay Stub Entry Differences: ', __FILE__, __LINE__, __METHOD__, 10); //var_dump($pay_stub_entry_ids); $pself = new PayStubEntryListFactory(); if (count($pay_stub_entry_ids) > 0) { foreach ($pay_stub_entry_ids as $pay_stub_entry_id) { Debug::Text('Entry ID: ' . $pay_stub_entry_id, __FILE__, __LINE__, __METHOD__, 10); $pay_stub1_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub1_obj->getId(), $pay_stub_entry_id); $pay_stub2_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub2_obj->getId(), $pay_stub_entry_id); Debug::Text('Pay Stub1 Amount: ' . $pay_stub1_entry_arr['amount'] . ' Pay Stub2 Amount: ' . $pay_stub2_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10); if ($pay_stub1_entry_arr['amount'] != $pay_stub2_entry_arr['amount']) { $amount_diff = bcsub($pay_stub1_entry_arr['amount'], $pay_stub2_entry_arr['amount'], 2); $units_diff = abs(bcsub($pay_stub1_entry_arr['units'], $pay_stub2_entry_arr['units'], 2)); Debug::Text('FOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff, __FILE__, __LINE__, __METHOD__, 10); //Generate PS Amendment. $psaf = new PayStubAmendmentFactory(); $psaf->setUser($pay_stub1_obj->getUser()); $psaf->setStatus('ACTIVE'); $psaf->setType(10); $psaf->setPayStubEntryNameId($pay_stub_entry_id); if ($units_diff > 0) { //Re-calculate amount when units are involved, due to rounding issues. $unit_rate = Misc::MoneyFormat(bcdiv($amount_diff, $units_diff)); $amount_diff = Misc::MoneyFormat(bcmul($unit_rate, $units_diff)); Debug::Text('bFOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff . ' Unit Rate: ' . $unit_rate, __FILE__, __LINE__, __METHOD__, 10); $psaf->setRate($unit_rate); $psaf->setUnits($units_diff); $psaf->setAmount($amount_diff); } else { $psaf->setAmount($amount_diff); } $psaf->setDescription('Adjustment from Pay Period Ending: ' . TTDate::getDate('DATE', $pay_stub2_obj->getEndDate())); $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($ps_amendment_date)); if ($psaf->isValid()) { $psaf->Save(); } unset($amount_diff, $units_diff, $unit_rate); } else { Debug::Text('No DIFFERENCE!', __FILE__, __LINE__, __METHOD__, 10); } } } $pslf->CommitTransaction(); return TRUE; }
function getPayStubId() { //Find which pay period this effective date belongs too $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($this->getUser(), $this->getEffectiveDate()); if ($pplf->getRecordCount() > 0) { $pp_obj = $pplf->getCurrent(); Debug::text('Found Pay Period ID: ' . $pp_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //Percent PS amendments can't work on advances. $pslf = new PayStubListFactory(); $pslf->getByUserIdAndPayPeriodIdAndAdvance($this->getUser(), $pp_obj->getId(), FALSE); if ($pslf->getRecordCount() > 0) { $ps_obj = $pslf->getCurrent(); Debug::text('Found Pay Stub for this effective date: ' . $ps_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); return $ps_obj->getId(); } } return FALSE; }
function Validate() { //Make sure pay period isn't locked! if ($this->getPayPeriod() !== FALSE) { if ($this->getPayPeriodObject()->getIsLocked() == TRUE) { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Pay Period is Currently Locked')); } } //Make sure this is a UNIQUE user_date row. $this->Validator->isTRUE('date_stamp', $this->isUnique(), TTi18n::gettext('Employee can not have duplicate entries on the same day')); //Make sure the date isn't BEFORE the first pay period. $pplf = new PayPeriodListFactory(); $pplf->getByUserID($this->getUser(), NULL, NULL, NULL, array('a.start_date' => 'asc')); if ($pplf->getRecordCount() > 0) { $first_pp_obj = $pplf->getCurrent(); if ($this->getDateStamp() < $first_pp_obj->getStartDate()) { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Pay Period Missing') . '(b)'); } } else { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Pay Period Missing')); } return TRUE; }
$pdf->Ln(); $pdf->Cell(30, 4, TTi18n::gettext('Group:'), $border, 0, 'R'); $pdf->Cell(70, 4, $user_data['group'], $border, 0, 'L'); $pdf->Cell(40, 4, TTi18n::gettext('Department:'), $border, 0, 'R'); $pdf->Cell(60, 4, $user_data['default_department'], $border, 0, 'L'); $pdf->Ln(3); $pdf->SetFont('', '', 10); //Start displaying dates/times here. Start with header. $column_widths = array('line' => 5, 'date_stamp' => 20, 'dow' => 10, 'in_punch_time_stamp' => 20, 'out_punch_time_stamp' => 20, 'worked_time' => 15, 'paid_time' => 15, 'regular_time' => 15, 'over_time' => 37, 'absence_time' => 43); if (isset($user_data['data']) and is_array($user_data['data'])) { if (isset($filter_data['date_type']) and $filter_data['date_type'] == 'pay_period_ids') { //Fill in any missing days, only if they select by pay period. $pplf = new PayPeriodListFactory(); $pplf->getById($user_data['pay_period_id']); if ($pplf->getRecordCount() == 1) { $pp_obj = $pplf->getCurrent(); for ($d = TTDate::getBeginDayEpoch($pp_obj->getStartDate()); $d <= $pp_obj->getEndDate(); $d += 86400) { if (Misc::inArrayByKeyAndValue($user_data['data'], 'date_stamp', TTDate::getBeginDayEpoch($d)) == FALSE) { $user_data['data'][] = array('date_stamp' => TTDate::getBeginDayEpoch($d), 'in_punch_time' => NULL, 'out_punch_time' => NULL, 'worked_time' => NULL, 'regular_time' => NULL, 'over_time' => NULL, 'paid_time' => NULL, 'absence_time' => NULL); } } } } $user_data['data'] = Sort::Multisort($user_data['data'], 'date_stamp', NULL, 'ASC'); $week_totals = Misc::preSetArrayValues(NULL, array('worked_time', 'paid_time', 'absence_time', 'regular_time', 'over_time'), 0); $totals = array(); $totals = Misc::preSetArrayValues($totals, array('worked_time', 'paid_time', 'absence_time', 'regular_time', 'over_time'), 0); $i = 1; $x = 1; $y = 1; $max_i = count($user_data['data']);
function getPayPeriodObject() { if (is_object($this->pay_period_obj)) { return $this->pay_period_obj; } else { $pplf = new PayPeriodListFactory(); $pplf->getById($this->getPayPeriod()); if ($pplf->getRecordCount() > 0) { $this->pay_period_obj = $pplf->getCurrent(); return $this->pay_period_obj; } return FALSE; } }
/* Get TimeSheet verification */ if (isset($pay_period_obj) and is_object($pay_period_obj)) { $pptsvlf = new PayPeriodTimeSheetVerifyListFactory(); $pptsvlf->getByPayPeriodIdAndUserId($pay_period_obj->getId(), $user_id); if ($pptsvlf->getRecordCount() > 0) { $pptsv_obj = $pptsvlf->getCurrent(); $time_sheet_verify = array('id' => $pptsv_obj->getId(), 'status_id' => $pptsv_obj->getStatus(), 'status' => Option::getByKey($pptsv_obj->getStatus(), $pptsv_obj->getOptions('status')), 'pay_period_id' => $pptsv_obj->getPayPeriod(), 'user_id' => $pptsv_obj->getUser(), 'created_date' => $pptsv_obj->getCreatedDate(), 'created_by' => $pptsv_obj->getCreatedBy(), 'updated_date' => $pptsv_obj->getUpdatedDate(), 'updated_by' => $pptsv_obj->getUpdatedBy(), 'deleted_date' => $pptsv_obj->getDeletedDate(), 'deleted_by' => $pptsv_obj->getDeletedBy()); } //Check if previous pay period was verified or not $is_previous_time_sheet_verified = FALSE; $pplf = new PayPeriodListFactory(); $pplf->getPreviousPayPeriodById($pay_period_obj->getId()); if ($pplf->getRecordCount() > 0) { $previous_pay_period_obj = $pplf->getCurrent(); if ($previous_pay_period_obj->getStatus() == 20) { $is_previous_time_sheet_verified = TRUE; } else { $pptsvlf = new PayPeriodTimeSheetVerifyListFactory(); $pptsvlf->getByPayPeriodIdAndUserId($previous_pay_period_obj->getId(), $user_id); if ($pptsvlf->getRecordCount() > 0) { $pptsv_obj = $pptsvlf->getCurrent(); if ($pptsv_obj->getAuthorized() == TRUE) { $is_previous_time_sheet_verified = TRUE; } } } } else { $is_previous_time_sheet_verified = TRUE; //There is no previous pay period
$data = array('id' => $s_obj->getId(), 'user_date_id' => $s_obj->getUserDateId(), 'user_id' => $s_obj->getUserDateObject()->getUser(), 'user_full_name' => $s_obj->getUserDateObject()->getUserObject()->getFullName(), 'date_stamp' => $s_obj->getUserDateObject()->getDateStamp(), 'status_id' => $s_obj->getStatus(), 'start_time' => $s_obj->getStartTime(), 'parsed_start_time' => $s_obj->getStartTime(), 'end_time' => $s_obj->getEndTime(), 'parsed_end_time' => $s_obj->getEndTime(), 'total_time' => $s_obj->getTotalTime(), 'schedule_policy_id' => $s_obj->getSchedulePolicyID(), 'absence_policy_id' => $s_obj->getAbsencePolicyID(), 'branch_id' => $s_obj->getBranch(), 'department_id' => $s_obj->getDepartment(), 'job_id' => $s_obj->getJob(), 'job_item_id' => $s_obj->getJobItem(), 'pay_period_is_locked' => $s_obj->getUserDateObject()->getPayPeriodObject()->getIsLocked(), 'created_date' => $s_obj->getCreatedDate(), 'created_by' => $s_obj->getCreatedBy(), 'updated_date' => $s_obj->getUpdatedDate(), 'updated_by' => $s_obj->getUpdatedBy(), 'deleted_date' => $s_obj->getDeletedDate(), 'deleted_by' => $s_obj->getDeletedBy(), 'is_owner' => $permission->isOwner($s_obj->getUserDateObject()->getUserObject()->getCreatedBy(), $s_obj->getUserDateObject()->getUserObject()->getId()), 'is_child' => $permission->isChild($s_obj->getUserDateObject()->getUserObject()->getId(), $permission_children_ids)); } } elseif ($action != 'submit') { Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //Get user full name if ($user_id != '') { $ulf = new UserListFactory(); $user_obj = $ulf->getById($user_id)->getCurrent(); $user_full_name = $user_obj->getFullName(); $user_default_branch = $user_obj->getDefaultBranch(); $user_default_department = $user_obj->getDefaultDepartment(); $user_date_id = UserDateFactory::getUserDateID($user_id, $date_stamp); $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($user_id, $date_stamp); if ($pplf->getRecordCount() > 0) { $pay_period_is_locked = $pplf->getCurrent()->getIsLocked(); } else { $pay_period_is_locked = FALSE; } } else { $user_id = NULL; $user_date_id = NULL; $user_full_name = NULL; $user_default_branch = NULL; $user_default_department = NULL; $pay_period_is_locked = FALSE; } if (!is_numeric($start_time)) { $start_time = strtotime('08:00 AM'); $parsed_start_time = $start_time; }