Debug::Text(' Punch Control ID was passed: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10); //Get previous punch, and default timestamp to that. $plf = new PunchListFactory(); $plf->getPreviousPunchByPunchControlID($punch_control_id); if ($plf->getRecordCount() > 0) { $prev_punch_obj = $plf->getCurrent(); $time_stamp = $prev_punch_obj->getTimeStamp() + 3600; $date_stamp = $prev_punch_obj->getTimeStamp(); //Match date with previous punch as well, incase a new day hasnt been triggered yet. } else { $time_stamp = TTDate::getTime(); $date_stamp = NULL; } $pclf = new PunchControlListFactory(); $pclf->getById($punch_control_id); if ($pclf->getRecordCount() > 0) { $pc_obj = $pclf->getCurrent(); if ($date_stamp == NULL) { $date_stamp = $pc_obj->getUserDateObject()->getDateStamp(); } $pc_data = array('id' => $pc_obj->getId(), 'user_id' => $pc_obj->getUserDateObject()->getUser(), 'user_full_name' => $pc_obj->getUserDateObject()->getUserObject()->getFullName(), 'date_stamp' => $date_stamp, 'user_date_id' => $pc_obj->getUserDateObject()->getId(), 'time_stamp' => $time_stamp, 'branch_id' => $pc_obj->getBranch(), 'department_id' => $pc_obj->getDepartment(), 'job_id' => $pc_obj->getJob(), 'job_item_id' => $pc_obj->getJobItem(), 'quantity' => (double) $pc_obj->getQuantity(), 'bad_quantity' => (double) $pc_obj->getBadQuantity(), 'note' => $pc_obj->getNote(), 'other_id1' => $pc_obj->getOtherID1(), 'other_id2' => $pc_obj->getOtherID2(), 'other_id3' => $pc_obj->getOtherID3(), 'other_id4' => $pc_obj->getOtherID4(), 'other_id5' => $pc_obj->getOtherID5(), 'status_id' => $status_id); } } elseif ($user_id != '') { Debug::Text(' User ID was passed: ' . $user_id . ' Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10); //Don't guess too much. If they click a day to add a punch. Make sure that punch is on that day. if (isset($date_stamp) and $date_stamp != '') { $time_stamp = $date_stamp + 3600 * 12; //Noon } else { $time_stamp = TTDate::getBeginDayEpoch(TTDate::getTime()) + 3600 * 12; //Noon
function roundTimeStamp($epoch) { $original_epoch = $epoch; Debug::text(' Rounding Timestamp: ' . TTDate::getDate('DATE+TIME', $epoch) . ' Status ID: ' . $this->getStatus() . ' Type ID: ' . $this->getType(), __FILE__, __LINE__, __METHOD__, 10); /* //Punch control is no longer used for rounding. if ( !is_object( $this->getPunchControlObject() ) ) { return FALSE; } */ //Check for rounding policies. $riplf = new RoundIntervalPolicyListFactory(); $type_id = $riplf->getPunchTypeFromPunchStatusAndType($this->getStatus(), $this->getType()); Debug::text(' Round Interval Punch Type: ' . $type_id . ' User: '******' Found Rounding Policy: ' . $round_policy_obj->getId() . ' Punch Type: ' . $round_policy_obj->getPunchType(), __FILE__, __LINE__, __METHOD__, 10); //FIXME: It will only do proper total rounding if they edit the Lunch Out punch. //We need to account for cases when they edit just the Lunch In Punch. if ($round_policy_obj->getPunchType() == 100) { Debug::text('Lunch Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); //On Lunch Punch In (back from lunch) do the total rounding. if ($this->getStatus() == 10 and $this->getType() == 20) { Debug::text('bLunch Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); //If strict is set, round to scheduled lunch time? //Find Lunch Punch In. $plf = new PunchListFactory(); //$plf->getPreviousPunchByUserDateIdAndStatusAndTypeAndEpoch( $this->getPunchControlObject()->getUserDateID(), 20, 20, $epoch ); $plf->getPreviousPunchByUserIdAndStatusAndTypeAndEpoch($this->getUser(), 20, 20, $epoch); if ($plf->getRecordCount() == 1) { Debug::text('Found Lunch Punch Out: ' . TTDate::getDate('DATE+TIME', $plf->getCurrent()->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10); $total_lunch_time = $epoch - $plf->getCurrent()->getTimeStamp(); Debug::text('Total Lunch Time: ' . $total_lunch_time, __FILE__, __LINE__, __METHOD__, 10); //Set the ScheduleID $has_schedule = $this->setScheduleID($this->findScheduleID($epoch)); if ($has_schedule == TRUE and $round_policy_obj->getGrace() > 0 and is_object($this->getScheduleObject()->getSchedulePolicyObject()) and is_object($this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject())) { Debug::text(' Applying Grace Period: ', __FILE__, __LINE__, __METHOD__, 10); $total_lunch_time = TTDate::graceTime($total_lunch_time, $round_policy_obj->getGrace(), $this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject()->getAmount()); Debug::text('After Grace: ' . $total_lunch_time, __FILE__, __LINE__, __METHOD__, 10); } if ($round_policy_obj->getInterval() > 0) { Debug::Text(' Rounding to interval: ' . $round_policy_obj->getInterval(), __FILE__, __LINE__, __METHOD__, 10); $total_lunch_time = TTDate::roundTime($total_lunch_time, $round_policy_obj->getInterval(), $round_policy_obj->getRoundType(), $round_policy_obj->getGrace()); Debug::text('After Rounding: ' . $total_lunch_time, __FILE__, __LINE__, __METHOD__, 10); } if ($has_schedule == TRUE and $round_policy_obj->getStrict() == TRUE and is_object($this->getScheduleObject()->getSchedulePolicyObject()) and is_object($this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject())) { Debug::Text(' Snap Time: Round Type: ' . $round_policy_obj->getRoundType(), __FILE__, __LINE__, __METHOD__, 10); if ($round_policy_obj->getRoundType() == 10) { Debug::Text(' Snap Time DOWN ', __FILE__, __LINE__, __METHOD__, 10); $total_lunch_time = TTDate::snapTime($total_lunch_time, $this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject()->getAmount(), 'DOWN'); } elseif ($round_policy_obj->getRoundType() == 30) { Debug::Text(' Snap Time UP', __FILE__, __LINE__, __METHOD__, 10); $total_lunch_time = TTDate::snapTime($total_lunch_time, $this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject()->getAmount(), 'UP'); } else { Debug::Text(' Not Snaping Time', __FILE__, __LINE__, __METHOD__, 10); } } $epoch = $plf->getCurrent()->getTimeStamp() + $total_lunch_time; Debug::text('Epoch after total rounding is: ' . $epoch . ' - ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text('DID NOT Find Lunch Punch Out: ' . TTDate::getDate('DATE+TIME', $plf->getCurrent()->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Skipping Lunch Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); } } elseif ($round_policy_obj->getPunchType() == 110) { //Break Total Debug::text('break Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); //On break Punch In (back from break) do the total rounding. if ($this->getStatus() == 10 and $this->getType() == 30) { Debug::text('bbreak Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); //If strict is set, round to scheduled break time? //Find break Punch In. $plf = new PunchListFactory(); //$plf->getPreviousPunchByUserDateIdAndStatusAndTypeAndEpoch( $this->getPunchControlObject()->getUserDateID(), 20, 30, $epoch ); $plf->getPreviousPunchByUserIdAndStatusAndTypeAndEpoch($this->getUser(), 20, 30, $epoch); if ($plf->getRecordCount() == 1) { Debug::text('Found break Punch Out: ' . TTDate::getDate('DATE+TIME', $plf->getCurrent()->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10); $total_break_time = $epoch - $plf->getCurrent()->getTimeStamp(); Debug::text('Total break Time: ' . $total_break_time, __FILE__, __LINE__, __METHOD__, 10); //Set the ScheduleID $has_schedule = $this->setScheduleID($this->findScheduleID($epoch)); if ($has_schedule == TRUE and $round_policy_obj->getGrace() > 0 and is_object($this->getScheduleObject()->getSchedulePolicyObject()) and is_object($this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject())) { Debug::text(' Applying Grace Period: ', __FILE__, __LINE__, __METHOD__, 10); $total_break_time = TTDate::graceTime($total_break_time, $round_policy_obj->getGrace(), $this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject()->getAmount()); Debug::text('After Grace: ' . $total_break_time, __FILE__, __LINE__, __METHOD__, 10); } if ($round_policy_obj->getInterval() > 0) { Debug::Text(' Rounding to interval: ' . $round_policy_obj->getInterval(), __FILE__, __LINE__, __METHOD__, 10); $total_break_time = TTDate::roundTime($total_break_time, $round_policy_obj->getInterval(), $round_policy_obj->getRoundType(), $round_policy_obj->getGrace()); Debug::text('After Rounding: ' . $total_break_time, __FILE__, __LINE__, __METHOD__, 10); } if ($has_schedule == TRUE and $round_policy_obj->getStrict() == TRUE and is_object($this->getScheduleObject()->getSchedulePolicyObject()) and is_object($this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject())) { Debug::Text(' Snap Time: Round Type: ' . $round_policy_obj->getRoundType(), __FILE__, __LINE__, __METHOD__, 10); if ($round_policy_obj->getRoundType() == 10) { Debug::Text(' Snap Time DOWN ', __FILE__, __LINE__, __METHOD__, 10); $total_break_time = TTDate::snapTime($total_break_time, $this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject()->getAmount(), 'DOWN'); } elseif ($round_policy_obj->getRoundType() == 30) { Debug::Text(' Snap Time UP', __FILE__, __LINE__, __METHOD__, 10); $total_break_time = TTDate::snapTime($total_break_time, $this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject()->getAmount(), 'UP'); } else { Debug::Text(' Not Snaping Time', __FILE__, __LINE__, __METHOD__, 10); } } $epoch = $plf->getCurrent()->getTimeStamp() + $total_break_time; Debug::text('Epoch after total rounding is: ' . $epoch . ' - ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text('DID NOT Find break Punch Out: ' . TTDate::getDate('DATE+TIME', $plf->getCurrent()->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Skipping break Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); } } elseif ($round_policy_obj->getPunchType() == 120) { //Day Total Rounding Debug::text('Day Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); if ($this->getStatus() == 20 and $this->getType() == 10) { //Out, Type Normal Debug::text('bDay Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); //If strict is set, round to scheduled time? $plf = new PunchListFactory(); $plf->getPreviousPunchByUserIdAndEpochAndNotPunchIDAndMaximumShiftTime($this->getUser(), $epoch, $this->getId()); if ($plf->getRecordCount() == 1) { Debug::text('Found Previous Punch In: ' . TTDate::getDate('DATE+TIME', $plf->getCurrent()->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10); //Get day total time prior to this punch control. $pclf = new PunchControlListFactory(); $pclf->getByUserDateId($plf->getCurrent()->getPunchControlObject()->getUserDateID()); if ($pclf->getRecordCount() > 0) { $day_total_time = $epoch - $plf->getCurrent()->getTimeStamp(); Debug::text('aDay Total Time: ' . $day_total_time . ' Current Punch Control ID: ' . $this->getPunchControlID(), __FILE__, __LINE__, __METHOD__, 10); foreach ($pclf as $pc_obj) { if ($plf->getCurrent()->getPunchControlID() != $pc_obj->getID()) { Debug::text('Punch Control Total Time: ' . $pc_obj->getTotalTime() . ' ID: ' . $pc_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $day_total_time += $pc_obj->getTotalTime(); } } Debug::text('bDay Total Time: ' . $day_total_time, __FILE__, __LINE__, __METHOD__, 10); $original_day_total_time = $day_total_time; if ($day_total_time > 0) { //Set the ScheduleID $has_schedule = $this->setScheduleID($this->findScheduleID($epoch)); if ($has_schedule == TRUE and $round_policy_obj->getGrace() > 0 and is_object($this->getScheduleObject()->getSchedulePolicyObject()) and is_object($this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject())) { Debug::text(' Applying Grace Period: ', __FILE__, __LINE__, __METHOD__, 10); $day_total_time = TTDate::graceTime($day_total_time, $round_policy_obj->getGrace(), $this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject()->getAmount()); Debug::text('After Grace: ' . $day_total_time, __FILE__, __LINE__, __METHOD__, 10); } if ($round_policy_obj->getInterval() > 0) { Debug::Text(' Rounding to interval: ' . $round_policy_obj->getInterval(), __FILE__, __LINE__, __METHOD__, 10); $day_total_time = TTDate::roundTime($day_total_time, $round_policy_obj->getInterval(), $round_policy_obj->getRoundType(), $round_policy_obj->getGrace()); Debug::text('After Rounding: ' . $day_total_time, __FILE__, __LINE__, __METHOD__, 10); } if ($has_schedule == TRUE and $round_policy_obj->getStrict() == TRUE and is_object($this->getScheduleObject()->getSchedulePolicyObject()) and is_object($this->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject())) { Debug::Text(' Snap Time: Round Type: ' . $round_policy_obj->getRoundType(), __FILE__, __LINE__, __METHOD__, 10); if ($round_policy_obj->getRoundType() == 10) { Debug::Text(' Snap Time DOWN ', __FILE__, __LINE__, __METHOD__, 10); $day_total_time = TTDate::snapTime($day_total_time, $this->getScheduleObject()->getTotalTime(), 'DOWN'); } elseif ($round_policy_obj->getRoundType() == 30) { Debug::Text(' Snap Time UP', __FILE__, __LINE__, __METHOD__, 10); $day_total_time = TTDate::snapTime($day_total_time, $this->getScheduleObject()->getTotalTime(), 'UP'); } else { Debug::Text(' Not Snaping Time', __FILE__, __LINE__, __METHOD__, 10); } } Debug::text('cDay Total Time: ' . $day_total_time, __FILE__, __LINE__, __METHOD__, 10); $day_total_time_diff = $day_total_time - $original_day_total_time; Debug::text('Day Total Diff: ' . $day_total_time_diff, __FILE__, __LINE__, __METHOD__, 10); $epoch = $original_epoch + $day_total_time_diff; } } } else { Debug::text('DID NOT Find Normal Punch Out: ' . TTDate::getDate('DATE+TIME', $plf->getCurrent()->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Skipping Lunch Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('NOT Total Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); if ($this->inScheduleStartStopWindow($epoch) and $round_policy_obj->getGrace() > 0) { Debug::text(' Applying Grace Period: ', __FILE__, __LINE__, __METHOD__, 10); $epoch = TTDate::graceTime($epoch, $round_policy_obj->getGrace(), $this->getScheduleWindowTime()); Debug::text('After Grace: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); } $grace_time = $round_policy_obj->getGrace(); //If strict scheduling is enabled, handle grace times differently. //Only apply them above if we are near the schedule start/stop time. //This allows for grace time to apply if an employee punches in late, //but afterwards not apply at all. if ($round_policy_obj->getStrict() == TRUE) { $grace_time = 0; } if ($round_policy_obj->getInterval() > 0) { Debug::Text(' Rounding to interval: ' . $round_policy_obj->getInterval(), __FILE__, __LINE__, __METHOD__, 10); $epoch = TTDate::roundTime($epoch, $round_policy_obj->getInterval(), $round_policy_obj->getRoundType(), $grace_time); Debug::text('After Rounding: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); } //ONLY perform strict rounding on Normal punches, not break/lunch punches? //Modify the UI to restrict this as well perhaps? if ($round_policy_obj->getStrict() == TRUE and $this->getScheduleWindowTime() !== FALSE) { Debug::Text(' Snap Time: Round Type: ' . $round_policy_obj->getRoundType(), __FILE__, __LINE__, __METHOD__, 10); if ($round_policy_obj->getRoundType() == 10) { Debug::Text(' Snap Time DOWN ', __FILE__, __LINE__, __METHOD__, 10); $epoch = TTDate::snapTime($epoch, $this->getScheduleWindowTime(), 'DOWN'); } elseif ($round_policy_obj->getRoundType() == 30) { Debug::Text(' Snap Time UP', __FILE__, __LINE__, __METHOD__, 10); $epoch = TTDate::snapTime($epoch, $this->getScheduleWindowTime(), 'UP'); } else { //If its an In Punch, snap up, if its out punch, snap down? Debug::Text(' Average rounding type, automatically determining snap direction.', __FILE__, __LINE__, __METHOD__, 10); if ($this->getStatus() == 10) { Debug::Text(' Snap Time UP', __FILE__, __LINE__, __METHOD__, 10); $epoch = TTDate::snapTime($epoch, $this->getScheduleWindowTime(), 'UP'); } else { Debug::Text(' Snap Time DOWN ', __FILE__, __LINE__, __METHOD__, 10); $epoch = TTDate::snapTime($epoch, $this->getScheduleWindowTime(), 'DOWN'); } } } } } else { Debug::text(' NO Rounding Policy(s) Found', __FILE__, __LINE__, __METHOD__, 10); } Debug::text(' Rounded TimeStamp: ' . TTDate::getDate('DATE+TIME', $epoch) . ' Original TimeStamp: ' . TTDate::getDate('DATE+TIME', $original_epoch), __FILE__, __LINE__, __METHOD__, 10); return $epoch; }
function postSave() { $this->removeCache($this->getId()); Debug::Text('Post Save... Deleted: ' . (int) $this->getDeleted(), __FILE__, __LINE__, __METHOD__, 10); //Delete punch control/schedules assigned to this. if ($this->getDeleted() == TRUE) { //Delete schedules assigned to this user date. //Turn off any re-calc's $slf = new ScheduleListFactory(); $slf->getByUserDateID($this->getId()); if ($slf->getRecordCount() > 0) { foreach ($slf as $schedule_obj) { $schedule_obj->setDeleted(TRUE); $schedule_obj->Save(); } } $pclf = new PunchControlListFactory(); $pclf->getByUserDateID($this->getId()); if ($pclf->getRecordCount() > 0) { foreach ($pclf as $pc_obj) { $pc_obj->setDeleted(TRUE); $pc_obj->Save(); } } //Delete user_date_total rows too $udtlf = new UserDateTotalListFactory(); $udtlf->getByUserDateID($this->getId()); if ($udtlf->getRecordCount() > 0) { foreach ($udtlf as $udt_obj) { $udt_obj->setDeleted(TRUE); $udt_obj->Save(); } } } return TRUE; }
function calcUserDate() { if ($this->getEnableCalcUserDateID() == TRUE) { Debug::Text(' Calculating User Date ID...', __FILE__, __LINE__, __METHOD__, 10); $shift_data = $this->getShiftData(); if (is_array($shift_data)) { $user_date_id = $this->getUserDateID(); //preSave should already be called before running this function. if (isset($user_date_id) and $user_date_id > 0 and isset($shift_data['punch_control_ids']) and is_array($shift_data['punch_control_ids'])) { Debug::Text('Assigning all punch_control_ids to User Date ID: ' . $user_date_id, __FILE__, __LINE__, __METHOD__, 10); $this->old_user_date_ids[] = $user_date_id; $this->old_user_date_ids[] = $this->getOldUserDateID(); foreach ($shift_data['punch_control_ids'] as $punch_control_id) { $pclf = new PunchControlListFactory(); $pclf->getById($punch_control_id); if ($pclf->getRecordCount() == 1) { $pc_obj = $pclf->getCurrent(); if ($pc_obj->getUserDateID() != $user_date_id) { Debug::Text(' Saving Punch Control ID: ' . $punch_control_id . ' with new User Date Total ID: ' . $user_date_id, __FILE__, __LINE__, __METHOD__, 10); $this->old_user_date_ids[] = $pc_obj->getUserDateID(); $pc_obj->setUserDateID($user_date_id); $pc_obj->setEnableCalcUserDateTotal(TRUE); $pc_obj->Save(); } else { Debug::Text(' NOT Saving Punch Control ID, as User Date ID didnt change: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10); } } } Debug::Arr($this->old_user_date_ids, 'aOld User Date IDs: ', __FILE__, __LINE__, __METHOD__, 10); return TRUE; } } } return FALSE; }
function calcPremiumPolicyTotalTime($udt_meal_policy_adjustment_arr, $udt_break_policy_adjustment_arr, $daily_total_time = FALSE) { global $profiler; $profiler->startTimer("UserDateTotal::calcPremiumPolicyTotalTime() - Part 1"); if ($daily_total_time === FALSE) { $daily_total_time = $this->getDailyTotalTime(); } $pplf = new PremiumPolicyListFactory(); $pplf->getByPolicyGroupUserId($this->getUserDateObject()->getUser()); if ($pplf->getRecordCount() > 0) { Debug::text('Found Premium Policies to apply.', __FILE__, __LINE__, __METHOD__, 10); foreach ($pplf as $pp_obj) { Debug::text('Found Premium Policy: ID: ' . $pp_obj->getId() . ' Type: ' . $pp_obj->getType(), __FILE__, __LINE__, __METHOD__, 10); //FIXME: Support manually setting a premium policy through the Edit Hours page? //In those cases, just skip auto-calculating it and accept it? switch ($pp_obj->getType()) { case 10: //Date/Time Debug::text(' Date/Time Premium Policy...', __FILE__, __LINE__, __METHOD__, 10); //Make sure this is a valid day //Take into account shifts that span midnight though, where one half of the shift is eligilble for premium time. //ie: Premium Policy starts 7AM to 7PM on Sat/Sun. Punches in at 9PM Friday and out at 9AM Sat, we need to check if both days are valid. //FIXME: Handle shifts that are longer than 24hrs in length. if ($pp_obj->isActive($this->getUserDateObject()->getDateStamp() - 86400, $this->getUserDateObject()->getDateStamp() + 86400)) { Debug::text(' Premium Policy Is Active On OR Around This Day.', __FILE__, __LINE__, __METHOD__, 10); $total_daily_time_used = 0; $daily_trigger_time = 0; $udtlf = new UserDateTotalListFactory(); if ($pp_obj->isHourRestricted() == TRUE) { if ($pp_obj->getWeeklyTriggerTime() > 0) { //Get Pay Period Schedule info if (is_object($this->getUserDateObject()->getPayPeriodObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject())) { $start_week_day_id = $this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()->getStartWeekDay(); } else { $start_week_day_id = 0; } Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10); $weekly_total_time = $udtlf->getWeekRegularTimeSumByUserIDAndEpochAndStartWeekEpoch($this->getUserDateObject()->getUser(), $this->getUserDateObject()->getDateStamp(), TTDate::getBeginWeekEpoch($this->getUserDateObject()->getDateStamp(), $start_week_day_id)); if ($weekly_total_time > $pp_obj->getWeeklyTriggerTime()) { $daily_trigger_time = 0; } else { $daily_trigger_time = $pp_obj->getWeeklyTriggerTime() - $weekly_total_time; } Debug::text(' Weekly Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10); } if ($pp_obj->getDailyTriggerTime() > 0 and $pp_obj->getDailyTriggerTime() > $daily_trigger_time) { $daily_trigger_time = $pp_obj->getDailyTriggerTime(); } } Debug::text(' Daily Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10); //Loop through all worked (status: 20) UserDateTotalRows $udtlf->getByUserDateIdAndStatus($this->getUserDateID(), 20); $i = 1; if ($udtlf->getRecordCount() > 0) { Debug::text('Found Total Hours to attempt to apply premium policy... Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($udtlf as $udt_obj) { Debug::text('UserDateTotal ID: ' . $udt_obj->getID() . ' Total Time: ' . $udt_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10); //Ignore incomplete punches if ($udt_obj->getTotalTime() == 0) { continue; } //How do we handle actual shifts for premium time? //So if premium policy starts at 1PM for shifts, to not //include employees who return from lunch at 1:30PM. //Create a function that takes all punches for a day, and returns //the first in and last out time for a given shift when taking //into account minimum time between shifts, as well as the total time for that shift. //We can then use that time for ActiveTime on premium policies, and determine if a //punch falls within the active time, then we add it to the total. if ($pp_obj->isTimeRestricted() == TRUE and $udt_obj->getPunchControlID() != FALSE) { Debug::text('Time Restricted Premium Policy, lookup punches to get times.', __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getIncludePartialPunch() == FALSE) { $shift_data = $this->getShiftDataByUserDateID($this->getUserDateID()); } $plf = new PunchListFactory(); $plf->getByPunchControlId($udt_obj->getPunchControlID()); if ($plf->getRecordCount() > 0) { Debug::text('Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($plf as $punch_obj) { if ($pp_obj->getIncludePartialPunch() == TRUE) { //Debug::text('Including Partial Punches...', __FILE__, __LINE__, __METHOD__, 10); if ($punch_obj->getStatus() == 10) { $punch_times['in'] = $punch_obj->getTimeStamp(); } elseif ($punch_obj->getStatus() == 20) { $punch_times['out'] = $punch_obj->getTimeStamp(); } } else { if (isset($shift_data) and is_array($shift_data)) { foreach ($shift_data as $shift) { if ($punch_obj->getTimeStamp() >= $shift['first_in'] and $punch_obj->getTimeStamp() <= $shift['last_out']) { //Debug::Arr($shift,'Shift Data...', __FILE__, __LINE__, __METHOD__, 10); Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') inside shift time...', __FILE__, __LINE__, __METHOD__, 10); $punch_times['in'] = $shift['first_in']; $punch_times['out'] = $shift['last_out']; break; } else { Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') outside shift time...', __FILE__, __LINE__, __METHOD__, 10); } } } } } if (isset($punch_times) and count($punch_times) == 2 and $pp_obj->isActiveTime($punch_times['in'], $punch_times['out']) == TRUE) { //Debug::Arr($punch_times, 'Punch Times: ', __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = $pp_obj->getPartialPunchTotalTime($punch_times['in'], $punch_times['out'], $udt_obj->getTotalTime()); Debug::text('Valid Punch pair in active time, Partial Punch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text('InValid Punch Pair or outside Active Time...', __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = 0; } } } elseif ($pp_obj->isActive($udt_obj->getUserDateObject()->getDateStamp()) == TRUE) { $punch_total_time = $udt_obj->getTotalTime(); } else { $punch_total_time = 0; } Debug::text('aPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); //Apply meal policy adjustment as early as possible. if ($pp_obj->getIncludeMealPolicy() == TRUE and isset($udt_meal_policy_adjustment_arr[$udt_obj->getId()])) { Debug::text(' Meal Policy Adjustment Found: ' . $udt_meal_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = bcadd($punch_total_time, $udt_meal_policy_adjustment_arr[$udt_obj->getId()]); $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_meal_policy_adjustment_arr[$udt_obj->getId()]); } else { $tmp_punch_total_time = $udt_obj->getTotalTime(); } Debug::text('bPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); //Apply break policy adjustment as early as possible. if ($pp_obj->getIncludeBreakPolicy() == TRUE and isset($udt_break_policy_adjustment_arr[$udt_obj->getId()])) { Debug::text(' Break Policy Adjustment Found: ' . $udt_break_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = bcadd($punch_total_time, $udt_break_policy_adjustment_arr[$udt_obj->getId()]); $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_break_policy_adjustment_arr[$udt_obj->getId()]); } else { $tmp_punch_total_time = $udt_obj->getTotalTime(); } Debug::text('cPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); $total_daily_time_used += $tmp_punch_total_time; Debug::text('Daily Total Time Used: ' . $total_daily_time_used, __FILE__, __LINE__, __METHOD__, 10); //FIXME: Should the daily/weekly trigger time be >= instead of >. //That way if the policy is active after 7.5hrs, punch time of exactly 7.5hrs will still //activate the policy, rather then requiring 7.501hrs+ if ($punch_total_time > 0 and $total_daily_time_used > $daily_trigger_time) { Debug::text('Past Trigger Time!!', __FILE__, __LINE__, __METHOD__, 10); //Calculate how far past trigger time we are. $past_trigger_time = $total_daily_time_used - $daily_trigger_time; if ($punch_total_time > $past_trigger_time) { $punch_total_time = $past_trigger_time; Debug::text('Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text('NOT Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10); } $total_time = $punch_total_time; if ($pp_obj->getMinimumTime() > 0 or $pp_obj->getMaximumTime() > 0) { $premium_policy_daily_total_time = (int) $udtlf->getPremiumPolicySumByUserDateIDAndPremiumPolicyID($this->getUserDateID(), $pp_obj->getId()); Debug::text(' Premium Policy Daily Total Time: ' . $premium_policy_daily_total_time . ' Minimum Time: ' . $pp_obj->getMinimumTime() . ' Maximum Time: ' . $pp_obj->getMaximumTime() . ' Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getMinimumTime() > 0) { //FIXME: Split the minimum time up between all the punches somehow. //Apply the minimum time on the last punch, otherwise if there are two punch pairs of 15min each //and a 1hr minimum time, if the minimum time is applied to the first, it will be 1hr and 15min //for the day. If its applied to the last it will be just 1hr. //Min & Max time is based on the shift time, rather then per punch pair time. //FIXME: If there is a minimum time set to say 9hrs, and the punches go like this: // In: 7:00AM Out: 3:00:PM, Out: 3:30PM (missing 2nd In Punch), the minimum time won't be calculated due to the invalid punch pair. if ($i == $udtlf->getRecordCount() and bcadd($premium_policy_daily_total_time, $total_time) < $pp_obj->getMinimumTime()) { $total_time = bcsub($pp_obj->getMinimumTime(), $premium_policy_daily_total_time); } } Debug::text(' Total Time After Minimum is applied: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getMaximumTime() > 0) { //Min & Max time is based on the shift time, rather then per punch pair time. if (bcadd($premium_policy_daily_total_time, $total_time) > $pp_obj->getMaximumTime()) { Debug::text(' bMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10); $total_time = bcsub($total_time, bcsub(bcadd($premium_policy_daily_total_time, $total_time), $pp_obj->getMaximumTime())); } } } Debug::text(' Premium Punch Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); if ($total_time > 0) { Debug::text(' Applying Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); $udtf = new UserDateTotalFactory(); $udtf->setUserDateID($this->getUserDateID()); $udtf->setStatus(10); //System $udtf->setType(40); //Premium $udtf->setPremiumPolicyId($pp_obj->getId()); $udtf->setBranch($udt_obj->getBranch()); $udtf->setDepartment($udt_obj->getDepartment()); $udtf->setJob($udt_obj->getJob()); $udtf->setJobItem($udt_obj->getJobItem()); $udtf->setQuantity($udt_obj->getQuantity()); $udtf->setBadQuantity($udt_obj->getBadQuantity()); $udtf->setTotalTime($total_time); $udtf->setEnableCalcSystemTotalTime(FALSE); if ($udtf->isValid() == TRUE) { $udtf->Save(); } unset($udtf); } else { Debug::text(' Premium Punch Total Time is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Not Past Trigger Time Yet or Punch Time is 0...', __FILE__, __LINE__, __METHOD__, 10); } $i++; } } } break; case 20: //Differential Debug::text(' Differential Premium Policy...', __FILE__, __LINE__, __METHOD__, 10); //Loop through all worked (status: 20) UserDateTotalRows $udtlf = new UserDateTotalListFactory(); $udtlf->getByUserDateIdAndStatus($this->getUserDateID(), 20); if ($udtlf->getRecordCount() > 0) { Debug::text('Found Total Hours to attempt to apply premium policy... Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($udtlf as $udt_obj) { //Ignore incomplete punches if ($udt_obj->getTotalTime() == 0) { continue; } if ($pp_obj->getBranchSelectionType() == 10 and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 20 and in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 30 and !in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch())) { Debug::text(' Shift Differential... Meets Branch Criteria! Select Type: ' . $pp_obj->getBranchSelectionType() . ' Exclude Default Branch: ' . (int) $pp_obj->getExcludeDefaultBranch() . ' Default Branch: ' . $this->getUserDateObject()->getUserObject()->getDefaultBranch(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getDepartmentSelectionType() == 10 and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 20 and in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 30 and !in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment())) { Debug::text(' Shift Differential... Meets Department Criteria! Select Type: ' . $pp_obj->getDepartmentSelectionType() . ' Exclude Default Department: ' . (int) $pp_obj->getExcludeDefaultDepartment() . ' Default Department: ' . $this->getUserDateObject()->getUserObject()->getDefaultDepartment(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobGroupSelectionType() == 10 or $pp_obj->getJobGroupSelectionType() == 20 and (is_object($udt_obj->getJobObject()) and in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup())) or $pp_obj->getJobGroupSelectionType() == 30 and (is_object($udt_obj->getJobObject()) and !in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup()))) { Debug::text(' Shift Differential... Meets Job Group Criteria! Select Type: ' . $pp_obj->getJobGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobSelectionType() == 10 or $pp_obj->getJobSelectionType() == 20 and in_array($udt_obj->getJob(), (array) $pp_obj->getJob()) or $pp_obj->getJobSelectionType() == 30 and !in_array($udt_obj->getJob(), (array) $pp_obj->getJob())) { Debug::text(' Shift Differential... Meets Job Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobItemGroupSelectionType() == 10 or $pp_obj->getJobItemGroupSelectionType() == 20 and (is_object($udt_obj->getJobItemObject()) and in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup())) or $pp_obj->getJobItemGroupSelectionType() == 30 and (is_object($udt_obj->getJobItemObject()) and !in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup()))) { Debug::text(' Shift Differential... Meets Task Group Criteria! Select Type: ' . $pp_obj->getJobItemGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobItemSelectionType() == 10 or $pp_obj->getJobItemSelectionType() == 20 and in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem()) or $pp_obj->getJobItemSelectionType() == 30 and !in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem())) { Debug::text(' Shift Differential... Meets Task Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10); $premium_policy_daily_total_time = 0; $punch_total_time = $udt_obj->getTotalTime(); $total_time = 0; //Apply meal policy adjustment BEFORE min/max times if ($pp_obj->getIncludeMealPolicy() == TRUE and isset($udt_meal_policy_adjustment_arr[$udt_obj->getId()])) { Debug::text(' Meal Policy Adjustment Found: ' . $udt_meal_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = bcadd($punch_total_time, $udt_meal_policy_adjustment_arr[$udt_obj->getId()]); } if ($pp_obj->getIncludeBreakPolicy() == TRUE and isset($udt_break_policy_adjustment_arr[$udt_obj->getId()])) { Debug::text(' Break Policy Adjustment Found: ' . $udt_break_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = bcadd($punch_total_time, $udt_break_policy_adjustment_arr[$udt_obj->getId()]); } if ($pp_obj->getMinimumTime() > 0 or $pp_obj->getMaximumTime() > 0) { $premium_policy_daily_total_time = $udtlf->getPremiumPolicySumByUserDateIDAndPremiumPolicyID($this->getUserDateID(), $pp_obj->getId()); Debug::text(' Premium Policy Daily Total Time: ' . $premium_policy_daily_total_time . ' Minimum Time: ' . $pp_obj->getMinimumTime() . ' Maximum Time: ' . $pp_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getMinimumTime() > 0) { if ($daily_total_time < $pp_obj->getMinimumTime()) { //Split the minimum time up between all punches //We only get IN punches, so we don't need to divide $total_punches by 2. //This won't calculate the proper amount if punches aren't paired, but everything //is broken then anyways. $total_time = bcdiv($pp_obj->getMinimumTime(), $total_punches); Debug::text(' Daily Total Time is less the Minimum, using: ' . $total_time . ' Total Punches: ' . $total_punches, __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text(' Daily Total is more then minimum...', __FILE__, __LINE__, __METHOD__, 10); $total_time = $punch_total_time; } } else { $total_time = $punch_total_time; } Debug::text(' Total Time After Minimum is applied: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getMaximumTime() > 0) { if ($total_time > $pp_obj->getMaximumTime()) { Debug::text(' aMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10); $total_time = $pp_obj->getMaximumTime(); } elseif (bcadd($premium_policy_daily_total_time, $total_time) > $pp_obj->getMaximumTime()) { Debug::text(' bMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10); $total_time = bcsub(bcadd($premium_policy_daily_total_time, $total_time), $pp_obj->getMaximumTime()); } } } else { $total_time = $punch_total_time; } Debug::text(' Premium Punch Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); if ($total_time > 0) { Debug::text(' Applying Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); $udtf = new UserDateTotalFactory(); $udtf->setUserDateID($this->getUserDateID()); $udtf->setStatus(10); //System $udtf->setType(40); //Premium $udtf->setPremiumPolicyId($pp_obj->getId()); $udtf->setBranch($udt_obj->getBranch()); $udtf->setDepartment($udt_obj->getDepartment()); $udtf->setJob($udt_obj->getJob()); $udtf->setJobItem($udt_obj->getJobItem()); $udtf->setQuantity($udt_obj->getQuantity()); $udtf->setBadQuantity($udt_obj->getBadQuantity()); $udtf->setTotalTime($total_time); $udtf->setEnableCalcSystemTotalTime(FALSE); if ($udtf->isValid() == TRUE) { $udtf->Save(); } unset($udtf); } else { Debug::text(' Premium Punch Total Time is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Task Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Task Group Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Job Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Job Group Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Department Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Branch Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } } break; case 30: //Meal/Break Debug::text(' Meal/Break Premium Policy...', __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getDailyTriggerTime() == 0 or $pp_obj->getDailyTriggerTime() > 0 and $daily_total_time >= $pp_obj->getDailyTriggerTime()) { //Find maximum worked without a break. $plf = new PunchListFactory(); $plf->getByUserDateId($this->getUserDateID()); //Get all punches for the day. if ($plf->getRecordCount() > 0) { Debug::text('Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($plf as $p_obj) { Debug::text('TimeStamp: ' . $p_obj->getTimeStamp() . ' Status: ' . $p_obj->getStatus(), __FILE__, __LINE__, __METHOD__, 10); $punch_pairs[$p_obj->getPunchControlID()][] = array('status_id' => $p_obj->getStatus(), 'punch_control_id' => $p_obj->getPunchControlID(), 'time_stamp' => $p_obj->getTimeStamp()); } if (isset($punch_pairs)) { $prev_punch_timestamp = NULL; $maximum_time_worked_without_break = 0; foreach ($punch_pairs as $punch_pair) { if (count($punch_pair) > 1) { //Total Punch Time $total_punch_pair_time = $punch_pair[1]['time_stamp'] - $punch_pair[0]['time_stamp']; $maximum_time_worked_without_break += $total_punch_pair_time; Debug::text('Total Punch Pair Time: ' . $total_punch_pair_time . ' Maximum No Break Time: ' . $maximum_time_worked_without_break, __FILE__, __LINE__, __METHOD__, 10); if ($prev_punch_timestamp !== NULL) { $break_time = $punch_pair[0]['time_stamp'] - $prev_punch_timestamp; if ($break_time > $pp_obj->getMinimumBreakTime()) { Debug::text('Exceeded Minimum Break Time: ' . $break_time . ' Minimum: ' . $pp_obj->getMinimumBreakTime(), __FILE__, __LINE__, __METHOD__, 10); $maximum_time_worked_without_break = 0; } } if ($maximum_time_worked_without_break > $pp_obj->getMaximumNoBreakTime()) { Debug::text('Exceeded maximum no break time!', __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getMaximumTime() > $pp_obj->getMinimumTime()) { $total_time = $pp_obj->getMaximumTime(); } else { $total_time = $pp_obj->getMinimumTime(); } if ($total_time > 0) { Debug::text(' Applying Meal/Break Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); //Get Punch Control obj. $pclf = new PunchControlListFactory(); $pclf->getById($punch_pair[0]['punch_control_id']); if ($pclf->getRecordCount() > 0) { $pc_obj = $pclf->getCurrent(); } $udtf = new UserDateTotalFactory(); $udtf->setUserDateID($this->getUserDateID()); $udtf->setStatus(10); //System $udtf->setType(40); //Premium $udtf->setPremiumPolicyId($pp_obj->getId()); if (isset($pc_obj) and is_object($pc_obj)) { $udtf->setBranch($pc_obj->getBranch()); $udtf->setDepartment($pc_obj->getDepartment()); $udtf->setJob($pc_obj->getJob()); $udtf->setJobItem($pc_obj->getJobItem()); } $udtf->setTotalTime($total_time); $udtf->setEnableCalcSystemTotalTime(FALSE); if ($udtf->isValid() == TRUE) { $udtf->Save(); } unset($udtf); break; //Stop looping through punches. } } else { Debug::text('Did not exceed maximum no break time yet...', __FILE__, __LINE__, __METHOD__, 10); } $prev_punch_timestamp = $punch_pair[1]['time_stamp']; } else { Debug::text('Found UnPaired Punch, Ignorning...', __FILE__, __LINE__, __METHOD__, 10); } } unset($plf, $punch_pairs, $punch_pair, $prev_punch_timestamp, $maximum_time_worked_without_break, $total_time); } } } else { Debug::text(' Not within Daily Total Time: ' . $daily_total_time . ' Trigger Time: ' . $pp_obj->getDailyTriggerTime(), __FILE__, __LINE__, __METHOD__, 10); } break; case 100: //Advanced Debug::text(' Advanced Premium Policy...', __FILE__, __LINE__, __METHOD__, 10); //Make sure this is a valid day if ($pp_obj->isActive($this->getUserDateObject()->getDateStamp() - 86400, $this->getUserDateObject()->getDateStamp() + 86400)) { Debug::text(' Premium Policy Is Active On This Day.', __FILE__, __LINE__, __METHOD__, 10); $total_daily_time_used = 0; $daily_trigger_time = 0; $udtlf = new UserDateTotalListFactory(); if ($pp_obj->isHourRestricted() == TRUE) { if ($pp_obj->getWeeklyTriggerTime() > 0) { //Get Pay Period Schedule info if (is_object($this->getUserDateObject()->getPayPeriodObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject())) { $start_week_day_id = $this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()->getStartWeekDay(); } else { $start_week_day_id = 0; } Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10); $weekly_total_time = $udtlf->getWeekRegularTimeSumByUserIDAndEpochAndStartWeekEpoch($this->getUserDateObject()->getUser(), $this->getUserDateObject()->getDateStamp(), TTDate::getBeginWeekEpoch($this->getUserDateObject()->getDateStamp(), $start_week_day_id)); if ($weekly_total_time > $pp_obj->getWeeklyTriggerTime()) { $daily_trigger_time = 0; } else { $daily_trigger_time = $pp_obj->getWeeklyTriggerTime() - $weekly_total_time; } Debug::text(' Weekly Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10); } if ($pp_obj->getDailyTriggerTime() > 0 and $pp_obj->getDailyTriggerTime() > $daily_trigger_time) { $daily_trigger_time = $pp_obj->getDailyTriggerTime(); } } Debug::text(' Daily Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10); //Loop through all worked (status: 20) UserDateTotalRows $udtlf->getByUserDateIdAndStatus($this->getUserDateID(), 20); $i = 1; if ($udtlf->getRecordCount() > 0) { Debug::text('Found Total Hours to attempt to apply premium policy... Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($udtlf as $udt_obj) { //Ignore incomplete punches if ($udt_obj->getTotalTime() == 0) { continue; } //Check Shift Differential criteria before calculatating daily/weekly time which //is more resource intensive. if ($pp_obj->getBranchSelectionType() == 10 and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 20 and in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 30 and !in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch())) { Debug::text(' Shift Differential... Meets Branch Criteria! Select Type: ' . $pp_obj->getBranchSelectionType() . ' Exclude Default Branch: ' . (int) $pp_obj->getExcludeDefaultBranch() . ' Default Branch: ' . $this->getUserDateObject()->getUserObject()->getDefaultBranch(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getDepartmentSelectionType() == 10 and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 20 and in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 30 and !in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment())) { Debug::text(' Shift Differential... Meets Department Criteria! Select Type: ' . $pp_obj->getDepartmentSelectionType() . ' Exclude Default Department: ' . (int) $pp_obj->getExcludeDefaultDepartment() . ' Default Department: ' . $this->getUserDateObject()->getUserObject()->getDefaultDepartment(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobGroupSelectionType() == 10 or $pp_obj->getJobGroupSelectionType() == 20 and is_object($udt_obj->getJobObject()) and in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup()) or $pp_obj->getJobGroupSelectionType() == 30 and is_object($udt_obj->getJobObject()) and !in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup())) { Debug::text(' Shift Differential... Meets Job Group Criteria! Select Type: ' . $pp_obj->getJobGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobSelectionType() == 10 or $pp_obj->getJobSelectionType() == 20 and in_array($udt_obj->getJob(), (array) $pp_obj->getJob()) or $pp_obj->getJobSelectionType() == 30 and !in_array($udt_obj->getJob(), (array) $pp_obj->getJob())) { Debug::text(' Shift Differential... Meets Job Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobItemGroupSelectionType() == 10 or $pp_obj->getJobItemGroupSelectionType() == 20 and is_object($udt_obj->getJobItemObject()) and in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup()) or $pp_obj->getJobItemGroupSelectionType() == 30 and is_object($udt_obj->getJobItemObject()) and !in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup())) { Debug::text(' Shift Differential... Meets Task Group Criteria! Select Type: ' . $pp_obj->getJobItemGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getJobItemSelectionType() == 10 or $pp_obj->getJobItemSelectionType() == 20 and in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem()) or $pp_obj->getJobItemSelectionType() == 30 and !in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem())) { Debug::text(' Shift Differential... Meets Task Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->isTimeRestricted() == TRUE and $udt_obj->getPunchControlID() != FALSE) { Debug::text('Time Restricted Premium Policy, lookup punches to get times.', __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getIncludePartialPunch() == FALSE) { $shift_data = $this->getShiftDataByUserDateID($this->getUserDateID()); } $plf = new PunchListFactory(); $plf->getByPunchControlId($udt_obj->getPunchControlID()); if ($plf->getRecordCount() > 0) { Debug::text('Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($plf as $punch_obj) { if ($pp_obj->getIncludePartialPunch() == TRUE) { //Debug::text('Including Partial Punches...', __FILE__, __LINE__, __METHOD__, 10); if ($punch_obj->getStatus() == 10) { $punch_times['in'] = $punch_obj->getTimeStamp(); } elseif ($punch_obj->getStatus() == 20) { $punch_times['out'] = $punch_obj->getTimeStamp(); } } else { if (isset($shift_data) and is_array($shift_data)) { foreach ($shift_data as $shift) { if ($punch_obj->getTimeStamp() >= $shift['first_in'] and $punch_obj->getTimeStamp() <= $shift['last_out']) { //Debug::Arr($shift,'Shift Data...', __FILE__, __LINE__, __METHOD__, 10); Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') inside shift time...', __FILE__, __LINE__, __METHOD__, 10); $punch_times['in'] = $shift['first_in']; $punch_times['out'] = $shift['last_out']; break; } else { Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') outside shift time...', __FILE__, __LINE__, __METHOD__, 10); } } } } } if (isset($punch_times) and count($punch_times) == 2 and $pp_obj->isActiveTime($punch_times['in'], $punch_times['out']) == TRUE) { //Debug::Arr($punch_times, 'Punch Times: ', __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = $pp_obj->getPartialPunchTotalTime($punch_times['in'], $punch_times['out'], $udt_obj->getTotalTime()); Debug::text('Valid Punch pair in active time, Partial Punch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text('InValid Punch Pair or outside Active Time...', __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = 0; } } } elseif ($pp_obj->isActive($udt_obj->getUserDateObject()->getDateStamp()) == TRUE) { $punch_total_time = $udt_obj->getTotalTime(); } else { $punch_total_time = 0; } Debug::text('aPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); //Apply meal policy adjustment as early as possible. if ($pp_obj->getIncludeMealPolicy() == TRUE and isset($udt_meal_policy_adjustment_arr[$udt_obj->getId()])) { Debug::text(' Meal Policy Adjustment Found: ' . $udt_meal_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = bcadd($punch_total_time, $udt_meal_policy_adjustment_arr[$udt_obj->getId()]); $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_meal_policy_adjustment_arr[$udt_obj->getId()]); } else { $tmp_punch_total_time = $udt_obj->getTotalTime(); } Debug::text('bPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getIncludeBreakPolicy() == TRUE and isset($udt_break_policy_adjustment_arr[$udt_obj->getId()])) { Debug::text(' Break Policy Adjustment Found: ' . $udt_break_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10); $punch_total_time = bcadd($punch_total_time, $udt_break_policy_adjustment_arr[$udt_obj->getId()]); $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_break_policy_adjustment_arr[$udt_obj->getId()]); } else { $tmp_punch_total_time = $udt_obj->getTotalTime(); } Debug::text('cPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10); $total_daily_time_used += $tmp_punch_total_time; Debug::text('Daily Total Time Used: ' . $total_daily_time_used, __FILE__, __LINE__, __METHOD__, 10); if ($punch_total_time > 0 and $total_daily_time_used > $daily_trigger_time) { Debug::text('Past Trigger Time!!', __FILE__, __LINE__, __METHOD__, 10); //Calculate how far past trigger time we are. $past_trigger_time = $total_daily_time_used - $daily_trigger_time; if ($punch_total_time > $past_trigger_time) { $punch_total_time = $past_trigger_time; Debug::text('Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text('NOT Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10); } $total_time = $punch_total_time; if ($pp_obj->getMinimumTime() > 0 or $pp_obj->getMaximumTime() > 0) { $premium_policy_daily_total_time = (int) $udtlf->getPremiumPolicySumByUserDateIDAndPremiumPolicyID($this->getUserDateID(), $pp_obj->getId()); Debug::text(' Premium Policy Daily Total Time: ' . $premium_policy_daily_total_time . ' Minimum Time: ' . $pp_obj->getMinimumTime() . ' Maximum Time: ' . $pp_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getMinimumTime() > 0) { //FIXME: Split the minimum time up between all the punches somehow. if ($i == $udtlf->getRecordCount() and bcadd($premium_policy_daily_total_time, $total_time) < $pp_obj->getMinimumTime()) { $total_time = bcsub($pp_obj->getMinimumTime(), $premium_policy_daily_total_time); } } Debug::text(' Total Time After Minimum is applied: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); if ($pp_obj->getMaximumTime() > 0) { if ($total_time > $pp_obj->getMaximumTime()) { Debug::text(' aMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10); $total_time = $pp_obj->getMaximumTime(); } elseif (bcadd($premium_policy_daily_total_time, $total_time) > $pp_obj->getMaximumTime()) { Debug::text(' bMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10); //$total_time = bcsub( bcadd( $premium_policy_daily_total_time, $total_time ), $pp_obj->getMaximumTime() ); $total_time = bcsub($total_time, bcsub(bcadd($premium_policy_daily_total_time, $total_time), $pp_obj->getMaximumTime())); } } } Debug::text(' Premium Punch Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); if ($total_time > 0) { Debug::text(' Applying Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10); $udtf = new UserDateTotalFactory(); $udtf->setUserDateID($this->getUserDateID()); $udtf->setStatus(10); //System $udtf->setType(40); //Premium $udtf->setPremiumPolicyId($pp_obj->getId()); $udtf->setBranch($udt_obj->getBranch()); $udtf->setDepartment($udt_obj->getDepartment()); $udtf->setJob($udt_obj->getJob()); $udtf->setJobItem($udt_obj->getJobItem()); $udtf->setQuantity($udt_obj->getQuantity()); $udtf->setBadQuantity($udt_obj->getBadQuantity()); $udtf->setTotalTime($total_time); $udtf->setEnableCalcSystemTotalTime(FALSE); if ($udtf->isValid() == TRUE) { $udtf->Save(); } unset($udtf); } else { Debug::text(' Premium Punch Total Time is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Not Past Trigger Time Yet or Punch Time is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Task Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Task Group Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Job Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Job Group Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Department Criteria!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Shift Differential... DOES NOT Meet Branch Criteria!', __FILE__, __LINE__, __METHOD__, 10); } $i++; } } } break; } } } $profiler->stopTimer("UserDateTotal::calcPremiumPolicyTotalTime() - Part 1"); return TRUE; }