case 'search_form_clear': case 'search_form_search': Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10); $saved_search_id = UserGenericDataFactory::searchFormDataHandler($action, $filter_data, URLBuilder::getURL(NULL, 'PunchList.php')); default: BreadCrumb::setCrumb($title); extract(UserGenericDataFactory::getSearchFormData($saved_search_id, $sort_column)); Debug::Text('Sort Column: ' . $sort_column, __FILE__, __LINE__, __METHOD__, 10); Debug::Text('Saved Search ID: ' . $saved_search_id, __FILE__, __LINE__, __METHOD__, 10); $sort_array = NULL; if ($sort_column != '') { $sort_array = array(Misc::trimSortPrefix($sort_column) => $sort_order); } URLBuilder::setURL($_SERVER['SCRIPT_NAME'], array('sort_column' => Misc::trimSortPrefix($sort_column), 'sort_order' => $sort_order, 'saved_search_id' => $saved_search_id, 'page' => $page)); $ulf = new UserListFactory(); $plf = new PunchListFactory(); $hlf = new HierarchyListFactory(); $permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($current_company->getId(), $current_user->getId()); //Debug::Arr($permission_children_ids,'Permission Children Ids:', __FILE__, __LINE__, __METHOD__,10); if ($permission->Check('punch', 'view') == FALSE) { if ($permission->Check('punch', 'view_child')) { $filter_data['permission_children_ids'] = $permission_children_ids; } if ($permission->Check('punch', 'view_own')) { $filter_data['permission_children_ids'][] = $current_user->getId(); } } $pplf = new PayPeriodListFactory(); $pplf->getByCompanyId($current_company->getId()); $pay_period_options = $pplf->getArrayByListFactory($pplf, FALSE, FALSE); $pay_period_ids = array_keys((array) $pay_period_options);
function postSave() { if ($this->getDeleted() == TRUE) { $plf = new PunchListFactory(); $plf->getByPunchControlId($this->getPunchControlID()); if ($plf->getRecordCount() == 0) { //Check to see if any other punches are assigned to this punch_control_id Debug::text(' Deleted Last Punch for Punch Control Object.', __FILE__, __LINE__, __METHOD__, 10); $this->getPunchControlObject()->setDeleted(TRUE); } //Make sure we recalculate system time. $this->getPunchControlObject()->setPunchObject($this); //$this->getPunchControlObject()->setEnableCalcUserDateID( $this->getEnableCalcUserDateID() ); $this->getPunchControlObject()->setEnableCalcUserDateID(TRUE); $this->getPunchControlObject()->setEnableCalcSystemTotalTime($this->getEnableCalcSystemTotalTime()); $this->getPunchControlObject()->setEnableCalcWeeklySystemTotalTime($this->getEnableCalcWeeklySystemTotalTime()); $this->getPunchControlObject()->setEnableCalcException($this->getEnableCalcException()); $this->getPunchControlObject()->setEnablePreMatureException($this->getEnablePreMatureException()); $this->getPunchControlObject()->setEnableCalcUserDateTotal($this->getEnableCalcUserDateTotal()); $this->getPunchControlObject()->setEnableCalcTotalTime($this->getEnableCalcTotalTime()); $this->getPunchControlObject()->Save(); } return TRUE; }
function getShiftData($user_date_id = NULL, $user_id = NULL, $epoch = NULL, $filter = NULL, $tmp_punch_control_obj = NULL) { global $profiler; $profiler->startTimer('PayPeriodScheduleFactory::getShiftData()'); if (is_numeric($user_date_id) and $user_date_id > 0) { $user_id = $epoch = NULL; } if ($user_date_id == '' and $user_id == '' and $epoch == '') { return FALSE; } //Debug::text('User Date ID: '. $user_date_id .' User ID: '. $user_id .' TimeStamp: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); $new_shift_trigger_time = $this->getNewDayTriggerTime(); $plf = new PunchListFactory(); if ($user_date_id != '') { $plf->getByUserDateId($user_date_id); } else { //Get punches by time stamp. $punch_control_id = 0; if (is_object($tmp_punch_control_obj)) { $punch_control_id = $tmp_punch_control_obj->getId(); } $plf->getShiftPunchesByUserIDAndEpoch($user_id, $epoch, $punch_control_id, $this->getMaximumShiftTime()); unset($punch_control_id); } Debug::text('Punch Rows: ' . $plf->getRecordCount() . ' UserID: ' . $user_id . ' Date: ' . TTDate::getDate('DATE+TIME', $epoch) . '(' . $epoch . ') MaximumShiftTime: ' . $this->getMaximumShiftTime(), __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($punches, ' Punches: ', __FILE__, __LINE__, __METHOD__, 10); if ($plf->getRecordCount() > 0) { $shift = 0; $i = 0; $nearest_shift_id = 0; $nearest_punch_difference = FALSE; $prev_punch_obj = FALSE; foreach ($plf as $p_obj) { //Debug::text('Shift: '. $shift .' Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); //If we're editing a punch, we need to use the object passed to this function instead of the one //from the database. if ($epoch == NULL) { //If user_date_id is passed without epoch, set epoch to the first punch we find. $epoch = $p_obj->getTimeStamp(); } if (isset($prev_punch_arr) and $p_obj->getTimeStamp() > $prev_punch_arr['time_stamp']) { $shift_data[$shift]['previous_punch_key'] = $i - 1; if ($shift_data[$shift]['previous_punch_key'] < 0) { $shift_data[$shift]['previous_punch_key'] = NULL; } } //Determine if a non-saved PunchControl object was passed, and if so, match the IDs to use that instead. if (is_object($tmp_punch_control_obj) and $p_obj->getPunchControlID() == $tmp_punch_control_obj->getId()) { Debug::text('Passed non-saved punch control object that matches, using that instead... Using ID: ' . (int) $tmp_punch_control_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $punch_control_obj = $tmp_punch_control_obj; } else { $punch_control_obj = $p_obj->getPunchControlObject(); } //Can't use PunchControl object total_time because the record may not be saved yet when editing //an already existing punch. //When editing, simply pass the existing PunchControl object to this function so we can //use it instead of the one in the database perhaps? $total_time = $punch_control_obj->getTotalTime(); /* //We can't skip records with total_time == 0, because then when deleting one of the two //punches in a pair, the remaining punch is ignored and causing punches to jump around between days in some cases. if ( $total_time == 0 ) { Debug::text('Total time is 0, skipping this punch control object...', __FILE__, __LINE__, __METHOD__, 10); //continue; } */ if ($i > 0 and isset($shift_data[$shift]['last_out']) and ($p_obj->getStatus() == 10 or $p_obj->getStatus() == $prev_punch_arr['status_id'])) { Debug::text('Checking for new shift...', __FILE__, __LINE__, __METHOD__, 10); if ($p_obj->getTimeStamp() - $shift_data[$shift]['last_out']['time_stamp'] > $new_shift_trigger_time) { $shift++; } } if (!isset($shift_data[$shift]['total_time'])) { $shift_data[$shift]['total_time'] = 0; } $punch_day_epoch = TTDate::getBeginDayEpoch($p_obj->getTimeStamp()); if (!isset($shift_data[$shift]['total_time_per_day'][$punch_day_epoch])) { $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] = 0; } //Determine which shift is closest to the given epoch. $punch_difference_from_epoch = abs($epoch - $p_obj->getTimeStamp()); if ($nearest_punch_difference === FALSE or $punch_difference_from_epoch < $nearest_punch_difference) { Debug::text('Nearest Shift Determined to be: ' . $shift . ' Nearest Punch Diff: ' . (int) $nearest_punch_difference . ' Punch Diff: ' . $punch_difference_from_epoch, __FILE__, __LINE__, __METHOD__, 10); $nearest_shift_id = $shift; $nearest_punch_difference = $punch_difference_from_epoch; } $punch_arr = array('id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_date_id' => $punch_control_obj->getUserDateID(), 'time_stamp' => $p_obj->getTimeStamp(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType()); $shift_data[$shift]['punches'][] = $punch_arr; $shift_data[$shift]['punch_control_ids'][] = $p_obj->getPunchControlId(); if ($punch_control_obj->getUserDateID() != FALSE) { $shift_data[$shift]['user_date_ids'][] = $punch_control_obj->getUserDateID(); } $shift_data[$shift]['span_midnight'] = FALSE; if (!isset($shift_data[$shift]['first_in']) and $p_obj->getStatus() == 10) { //Debug::text('First In -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['first_in'] = $punch_arr; } elseif ($p_obj->getStatus() == 20) { //Debug::text('Last Out -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['last_out'] = $punch_arr; //Debug::text('Total Time: '. $total_time, __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['total_time'] += $total_time; //Check to see if the previous punch was on a different day then the current punch. if (isset($prev_punch_arr) and is_array($prev_punch_arr) and ($p_obj->getStatus() == 20 and $prev_punch_arr['status_id'] != 20) and TTDate::doesRangeSpanMidnight($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()) == TRUE) { Debug::text('Punch pair DOES span midnight', __FILE__, __LINE__, __METHOD__, 10); $shift_data[$shift]['span_midnight'] = TRUE; $total_time_for_each_day_arr = TTDate::calculateTimeOnEachDayBetweenRange($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()); if (is_array($total_time_for_each_day_arr)) { foreach ($total_time_for_each_day_arr as $begin_day_epoch => $day_total_time) { if (!isset($shift_data[$shift]['total_time_per_day'][$begin_day_epoch])) { $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] = 0; } $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] += $day_total_time; } } unset($total_time_for_each_day_arr, $begin_day_epoch, $day_total_time, $prev_day_total_time); } else { $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] += $total_time; } } $prev_punch_arr = $punch_arr; $i++; } //Debug::Arr($shift_data, 'aShift Data:', __FILE__, __LINE__, __METHOD__, 10); if (isset($shift_data)) { //Loop through each shift to determine the day with the most time. foreach ($shift_data as $tmp_shift_key => $tmp_shift_data) { krsort($shift_data[$tmp_shift_key]['total_time_per_day']); //Sort by day first arsort($shift_data[$tmp_shift_key]['total_time_per_day']); //Sort by total time per day. reset($shift_data[$tmp_shift_key]['total_time_per_day']); $shift_data[$tmp_shift_key]['day_with_most_time'] = key($shift_data[$tmp_shift_key]['total_time_per_day']); $shift_data[$tmp_shift_key]['punch_control_ids'] = array_unique($shift_data[$tmp_shift_key]['punch_control_ids']); if (isset($shift_data[$tmp_shift_key]['user_date_ids'])) { $shift_data[$tmp_shift_key]['user_date_ids'] = array_unique($shift_data[$tmp_shift_key]['user_date_ids']); } } unset($tmp_shift_key, $tmp_shift_data); if ($filter == 'first_shift') { //Only return first shift. $shift_data = $shift_data[0]; } elseif ($filter == 'last_shift') { //Only return last shift. $shift_data = $shift_data[$shift]; } elseif ($filter == 'nearest_shift') { $shift_data = $shift_data[$nearest_shift_id]; //Check to make sure the nearest shift is within the new shift trigger time of EPOCH. if (isset($shift_data['first_in']['time_stamp'])) { $first_in = $shift_data['first_in']['time_stamp']; } elseif (isset($shift_data['last_out']['time_stamp'])) { $first_in = $shift_data['last_out']['time_stamp']; } if (isset($shift_data['last_out']['time_stamp'])) { $last_out = $shift_data['last_out']['time_stamp']; } elseif (isset($shift_data['first_in']['time_stamp'])) { $last_out = $shift_data['first_in']['time_stamp']; } if (TTDate::isTimeOverLap($epoch, $epoch, $first_in - $new_shift_trigger_time, $last_out + $new_shift_trigger_time) == FALSE) { Debug::Text('Nearest shift is outside the new shift trigger time... Epoch: ' . $epoch . ' First In: ' . $first_in . ' Last Out: ' . $last_out . ' New Shift Trigger: ' . $new_shift_trigger_time, __FILE__, __LINE__, __METHOD__, 10); return FALSE; } unset($first_in, $last_out); } $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()'); //Debug::Arr($shift_data, 'bShift Data:', __FILE__, __LINE__, __METHOD__, 10); return $shift_data; } } $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()'); return FALSE; }
function changePreviousPunchType() { Debug::text(' Previous Punch to Lunch/Break...', __FILE__, __LINE__, __METHOD__, 10); if (is_object($this->getPunchObject())) { if ($this->getPunchObject()->getType() == 20 and $this->getPunchObject()->getStatus() == 10) { Debug::text(' bbPrevious Punch to Lunch...', __FILE__, __LINE__, __METHOD__, 10); $shift_data = $this->getShiftData(); if (isset($shift_data['previous_punch_key']) and isset($shift_data['punches'][$shift_data['previous_punch_key']]) and $shift_data['punches'][$shift_data['previous_punch_key']]['type_id'] != 20) { $previous_punch_arr = $shift_data['punches'][$shift_data['previous_punch_key']]; Debug::text(' Previous Punch ID: ' . $previous_punch_arr['id'], __FILE__, __LINE__, __METHOD__, 10); if ($this->getPunchObject()->inMealPolicyWindow($this->getPunchObject()->getTimeStamp(), $previous_punch_arr['time_stamp']) == TRUE) { Debug::text(' Previous Punch needs to change to Lunch...', __FILE__, __LINE__, __METHOD__, 10); $plf = new PunchListFactory(); $plf->getById($previous_punch_arr['id']); if ($plf->getRecordCount() == 1) { Debug::text(' Modifying previous punch...', __FILE__, __LINE__, __METHOD__, 10); $pf = $plf->getCurrent(); $pf->setType(20); //Lunch //If we start re-rounding this punch we have to recalculate the total for the previous punch_control too. //$p_obj->setTimeStamp( $p_obj->getTimeStamp() ); //Re-round timestamp now that its a lunch punch. if ($pf->Save(FALSE) == TRUE) { Debug::text(' Returning TRUE!', __FILE__, __LINE__, __METHOD__, 10); return TRUE; } } } } } elseif ($this->getPunchObject()->getType() == 30 and $this->getPunchObject()->getStatus() == 10) { Debug::text(' bbPrevious Punch to Break...', __FILE__, __LINE__, __METHOD__, 10); $shift_data = $this->getShiftData(); if (isset($shift_data['previous_punch_key']) and isset($shift_data['punches'][$shift_data['previous_punch_key']]) and $shift_data['punches'][$shift_data['previous_punch_key']]['type_id'] != 30) { $previous_punch_arr = $shift_data['punches'][$shift_data['previous_punch_key']]; Debug::text(' Previous Punch ID: ' . $previous_punch_arr['id'], __FILE__, __LINE__, __METHOD__, 10); if ($this->getPunchObject()->inBreakPolicyWindow($this->getPunchObject()->getTimeStamp(), $previous_punch_arr['time_stamp']) == TRUE) { Debug::text(' Previous Punch needs to change to Break...', __FILE__, __LINE__, __METHOD__, 10); $plf = new PunchListFactory(); $plf->getById($previous_punch_arr['id']); if ($plf->getRecordCount() == 1) { Debug::text(' Modifying previous punch...', __FILE__, __LINE__, __METHOD__, 10); $pf = $plf->getCurrent(); $pf->setType(30); //Break //If we start re-rounding this punch we have to recalculate the total for the previous punch_control too. //$p_obj->setTimeStamp( $p_obj->getTimeStamp() ); //Re-round timestamp now that its a lunch punch. if ($pf->Save(FALSE) == TRUE) { Debug::text(' Returning TRUE!', __FILE__, __LINE__, __METHOD__, 10); return TRUE; } } } } } } Debug::text(' Returning false!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
function getPunchDataArray($start_date, $end_date) { $plf = new PunchListFactory(); $plf->getByCompanyIDAndUserIdAndStartDateAndEndDate($this->company_id, $this->user_id, $start_date, $end_date); if ($plf->getRecordCount() > 0) { //Only return punch_control data for now $i = 0; $prev_punch_control_id = NULL; foreach ($plf as $p_obj) { if ($prev_punch_control_id == NULL or $prev_punch_control_id != $p_obj->getPunchControlID()) { $date_stamp = $p_obj->getPunchControlObject()->getUserDateObject()->getDateStamp(); $p_obj->setUser($this->user_id); $p_obj->getPunchControlObject()->setPunchObject($p_obj); $retarr[$date_stamp][$i] = array('id' => $p_obj->getPunchControlObject()->getID(), 'date_stamp' => $date_stamp, 'user_date_id' => $p_obj->getPunchControlObject()->getUserDateID(), 'shift_data' => $p_obj->getPunchControlObject()->getShiftData()); $prev_punch_control_id = $p_obj->getPunchControlID(); $i++; } } if (isset($retarr)) { return $retarr; } } return FALSE; }
if ($p_obj->getStation() != FALSE) { $slf->getById($p_obj->getStation()); if ($slf->getRecordCount() > 0) { $s_obj = $slf->getCurrent(); $station_data = array('id' => $s_obj->getId(), 'type_id' => $s_obj->getType(), 'type' => Option::getByKey($s_obj->getType(), $s_obj->getOptions('type')), 'station_id' => $s_obj->getStation(), 'source' => $s_obj->getSource(), 'description' => Misc::TruncateString($s_obj->getDescription(), 20)); } } $pc_data = array('id' => $pc_obj->getId(), 'user_date_id' => $pc_obj->getUserDateId(), 'user_id' => $pc_obj->getUserDateObject()->getUser(), 'user_full_name' => $pc_obj->getUserDateObject()->getUserObject()->getFullName(), 'pay_period_id' => $pc_obj->getUserDateObject()->getPayPeriod(), '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(), 'punch_id' => $p_obj->getId(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType(), 'station_id' => $p_obj->getStation(), 'station_data' => $station_data, 'time_stamp' => $p_obj->getTimeStamp(), 'date_stamp' => $p_obj->getTimeStamp(), 'original_time_stamp' => $p_obj->getOriginalTimeStamp(), 'actual_time_stamp' => $p_obj->getActualTimeStamp(), 'longitude' => $p_obj->getLongitude(), 'latitude' => $p_obj->getLatitude(), 'created_date' => $p_obj->getCreatedDate(), 'created_by' => $p_obj->getCreatedBy(), 'created_by_name' => (string) $ulf->getFullNameById($p_obj->getCreatedBy()), 'updated_date' => $p_obj->getUpdatedDate(), 'updated_by' => $p_obj->getUpdatedBy(), 'updated_by_name' => (string) $ulf->getFullNameById($p_obj->getUpdatedBy()), 'deleted_date' => $p_obj->getDeletedDate(), 'deleted_by' => $p_obj->getDeletedBy()); } } elseif ($action != 'submit') { Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //UserID has to be set at minimum if ($punch_control_id != '') { 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) {
function calcExceptions($user_date_id, $enable_premature_exceptions = FALSE, $enable_future_exceptions = TRUE) { global $profiler; $profiler->startTimer("ExceptionPolicy::calcExceptions()"); if ($user_date_id == '') { return FALSE; } Debug::text(' User Date ID: ' . $user_date_id . ' PreMature: ' . (int) $enable_premature_exceptions, __FILE__, __LINE__, __METHOD__, 10); //Get user date info $udlf = new UserDateListFactory(); $udlf->getById($user_date_id); if ($udlf->getRecordCount() > 0) { $user_date_obj = $udlf->getCurrent(); if ($enable_future_exceptions == FALSE and $user_date_obj->getDateStamp() > TTDate::getEndDayEpoch()) { return FALSE; } } else { return FALSE; } //Since we are not usng demerits yet, just always delete exceptions and re-calculate them $elf = new ExceptionListFactory(); $elf->getByUserDateID($user_date_id); if ($elf->getRecordCount() > 0) { foreach ($elf as $e_obj) { Debug::text(' Deleting Exception: ' . $e_obj->getID(), __FILE__, __LINE__, __METHOD__, 10); $e_obj->Delete(); } } //Get all Punches on this date for this user. $plf = new PunchListFactory(); $plf->getByUserDateId($user_date_id); if ($plf->getRecordCount() > 0) { Debug::text(' Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); } $slf = new ScheduleListFactory(); $slf->getByUserDateIdAndStatusId($user_date_id, 10); if ($slf->getRecordCount() > 0) { Debug::text(' Found Schedule: ' . $slf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); } $schedule_id_cache = NULL; //Cache schedule IDs so we don't need to do a lookup for every exception. //Get all active exceptions. $eplf = new ExceptionPolicyListFactory(); $eplf->getByPolicyGroupUserIdAndActive($user_date_obj->getUser(), TRUE); if ($eplf->getRecordCount() > 0) { Debug::text(' Found Active Exceptions: ' . $eplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($eplf as $ep_obj) { //Debug::text(' Found Exception Type: '. $ep_obj->getType() .' ID: '. $ep_obj->getID() .' Control ID: '. $ep_obj->getExceptionPolicyControl(), __FILE__, __LINE__, __METHOD__,10); if ($enable_premature_exceptions == TRUE and self::isPreMature($ep_obj->getType()) == TRUE) { //Debug::text(' Premature Exception: '. $ep_obj->getType() , __FILE__, __LINE__, __METHOD__,10); $type_id = 5; //Pre-Mature } else { //Debug::text(' NOT Premature Exception: '. $ep_obj->getType() , __FILE__, __LINE__, __METHOD__,10); $type_id = 50; //Active } switch (strtolower($ep_obj->getType())) { case 's1': //Unscheduled Absence... Anytime they are scheduled and have not punched in. //Ignore these exceptions if the schedule is after today (not including today), //so if a supervisors schedules an employee two days in advance they don't get a unscheduled //absence appearing right away. if ($plf->getRecordCount() == 0) { if ($slf->getRecordCount() > 0) { foreach ($slf as $s_obj) { if ($s_obj->getStatus() == 10 and TTDate::getBeginDayEpoch($s_obj->getStartTime()) - TTDate::getBeginDayEpoch(TTDate::getTime()) <= 0) { $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } } else { Debug::text(' NOT Scheduled', __FILE__, __LINE__, __METHOD__, 10); } } break; case 's2': //Not Scheduled $schedule_total_time = 0; if ($slf->getRecordCount() == 0) { if ($plf->getRecordCount() > 0) { Debug::text(' Worked when wasnt scheduled', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } else { Debug::text(' IS Scheduled', __FILE__, __LINE__, __METHOD__, 10); } break; case 's3': //In Early if ($plf->getRecordCount() > 0) { //Loop through each punch, find out if they are scheduled, and if they are in early foreach ($plf as $p_obj) { if ($p_obj->getType() == 10 and $p_obj->getStatus() == 10) { //Normal In if (!isset($scheduled_id_cache[$p_obj->getID()])) { $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser()); } if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) { if ($p_obj->getTimeStamp() < $p_obj->getScheduleObject()->getStartTime()) { if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getGrace()) == TRUE) { Debug::text(' Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getWatchWindow()) == TRUE) { Debug::text(' NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setPunchID($p_obj->getID()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } } else { Debug::text(' NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10); } } } } break; case 's4': //In Late if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { if ($p_obj->getType() == 10 and $p_obj->getStatus() == 10) { //Normal In if (!isset($scheduled_id_cache[$p_obj->getID()])) { $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser()); } if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) { if ($p_obj->getTimeStamp() > $p_obj->getScheduleObject()->getStartTime()) { if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getGrace()) == TRUE) { Debug::text(' Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getWatchWindow()) == TRUE) { Debug::text(' NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setPunchID($p_obj->getID()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } } else { Debug::text(' NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10); } } } } break; case 's5': //Out Early if ($plf->getRecordCount() > 0) { //Loop through each punch, find out if they are scheduled, and if they are in early foreach ($plf as $p_obj) { if ($p_obj->getType() == 10 and $p_obj->getStatus() == 20) { //Normal Out if (!isset($scheduled_id_cache[$p_obj->getID()])) { $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser()); } if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) { if ($p_obj->getTimeStamp() < $p_obj->getScheduleObject()->getEndTime()) { if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getGrace()) == TRUE) { Debug::text(' Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getWatchWindow()) == TRUE) { Debug::text(' NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setPunchID($p_obj->getID()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } } else { Debug::text(' NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10); } } } } break; case 's6': //Out Late if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { if ($p_obj->getType() == 10 and $p_obj->getStatus() == 20) { //Normal Out if (!isset($scheduled_id_cache[$p_obj->getID()])) { $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser()); } if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) { if ($p_obj->getTimeStamp() > $p_obj->getScheduleObject()->getEndTime()) { if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getGrace()) == TRUE) { Debug::text(' Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getWatchWindow()) == TRUE) { Debug::text(' NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setPunchID($p_obj->getID()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } } else { Debug::text(' NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10); } } } } break; case 'm1': //Missing In Punch if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { //Debug::text(' Punch: Status: '. $p_obj->getStatus() .' Punch Control ID: '. $p_obj->getPunchControlID() .' Punch ID: '. $p_obj->getId() .' TimeStamp: '. $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__,10); if ($type_id == 5 and $p_obj->getTimeStamp() < time() - self::$premature_delay) { $type_id = 50; } $punch_pairs[$p_obj->getPunchControlID()][] = array('status_id' => $p_obj->getStatus(), 'punch_control_id' => $p_obj->getPunchControlID(), 'punch_id' => $p_obj->getId()); } if (isset($punch_pairs)) { foreach ($punch_pairs as $punch_control_id => $punch_pair) { //Debug::Arr($punch_pair, 'Punch Pair for Control ID:'. $punch_control_id, __FILE__, __LINE__, __METHOD__,10); if (count($punch_pair) != 2) { Debug::text('aFound Missing Punch: ', __FILE__, __LINE__, __METHOD__, 10); if ($punch_pair[0]['status_id'] == 20) { //Missing In Punch Debug::text('bFound Missing In Punch: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setPunchControlID($punch_pair[0]['punch_control_id']); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } else { Debug::text('No Missing Punches...', __FILE__, __LINE__, __METHOD__, 10); } } } unset($punch_pairs, $punch_pair); } break; case 'm2': //Missing Out Punch if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { Debug::text(' Punch: Status: ' . $p_obj->getStatus() . ' Punch Control ID: ' . $p_obj->getPunchControlID() . ' Punch ID: ' . $p_obj->getId() . ' TimeStamp: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10); if ($type_id == 5 and $p_obj->getTimeStamp() < time() - self::$premature_delay) { $type_id = 50; } $punch_pairs[$p_obj->getPunchControlID()][] = array('status_id' => $p_obj->getStatus(), 'punch_control_id' => $p_obj->getPunchControlID()); } if (isset($punch_pairs)) { foreach ($punch_pairs as $punch_control_id => $punch_pair) { if (count($punch_pair) != 2) { Debug::text('aFound Missing Punch: ', __FILE__, __LINE__, __METHOD__, 10); if ($punch_pair[0]['status_id'] == 10) { //Missing Out Punch Debug::text('bFound Missing Out Punch: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setPunchControlID($punch_pair[0]['punch_control_id']); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } else { Debug::text('No Missing Punches...', __FILE__, __LINE__, __METHOD__, 10); } } } unset($punch_pairs, $punch_pair); } break; case 'm3': //Missing Lunch In/Out punch if ($plf->getRecordCount() > 0) { //We need to account for cases where they may punch IN from lunch first, then Out. //As well as just a Lunch In punch and nothing else. foreach ($plf as $p_obj) { if ($type_id == 5 and $p_obj->getTimeStamp() < time() - self::$premature_delay) { $type_id = 50; } $punches[] = $p_obj; } if (isset($punches) and is_array($punches)) { foreach ($punches as $key => $p_obj) { if ($p_obj->getType() == 20) { //Lunch Debug::text(' Punch: Status: ' . $p_obj->getStatus() . ' Punch Control ID: ' . $p_obj->getPunchControlID() . ' TimeStamp: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10); if ($p_obj->getStatus() == 10) { //Make sure previous punch is Lunch/Out if (!isset($punches[$key - 1]) or isset($punches[$key - 1]) and is_object($punches[$key - 1]) and ($punches[$key - 1]->getType() != 20 or $punches[$key - 1]->getStatus() != 20)) { //Invalid punch $invalid_punches[] = array('punch_id' => $p_obj->getId()); } } else { //Make sure next punch is Lunch/In if (!isset($punches[$key + 1]) or isset($punches[$key + 1]) and is_object($punches[$key + 1]) and ($punches[$key + 1]->getType() != 20 or $punches[$key + 1]->getStatus() != 10)) { //Invalid punch $invalid_punches[] = array('punch_id' => $p_obj->getId()); } } } } unset($punches, $key, $p_obj); if (isset($invalid_punches) and count($invalid_punches) > 0) { foreach ($invalid_punches as $invalid_punch_arr) { Debug::text('Found Missing Lunch In/Out Punch: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); //$ef->setPunchControlID( $invalid_punch_arr['punch_id'] ); $ef->setPunchID($invalid_punch_arr['punch_id']); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } unset($invalid_punch_arr); } else { Debug::text('Lunch Punches match up.', __FILE__, __LINE__, __METHOD__, 10); } unset($invalid_punches); } } break; case 'm4': //Missing Break In/Out punch if ($plf->getRecordCount() > 0) { //We need to account for cases where they may punch IN from break first, then Out. //As well as just a break In punch and nothing else. foreach ($plf as $p_obj) { if ($type_id == 5 and $p_obj->getTimeStamp() < time() - self::$premature_delay) { $type_id = 50; } $punches[] = $p_obj; } if (isset($punches) and is_array($punches)) { foreach ($punches as $key => $p_obj) { if ($p_obj->getType() == 30) { //Break Debug::text(' Punch: Status: ' . $p_obj->getStatus() . ' Type: ' . $p_obj->getType() . ' Punch Control ID: ' . $p_obj->getPunchControlID() . ' TimeStamp: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10); if ($p_obj->getStatus() == 10) { //Make sure previous punch is Break/Out if (!isset($punches[$key - 1]) or isset($punches[$key - 1]) and is_object($punches[$key - 1]) and ($punches[$key - 1]->getType() != 30 or $punches[$key - 1]->getStatus() != 20)) { //Invalid punch $invalid_punches[] = array('punch_id' => $p_obj->getId()); } } else { //Make sure next punch is Break/In if (!isset($punches[$key + 1]) or isset($punches[$key + 1]) and is_object($punches[$key + 1]) and ($punches[$key + 1]->getType() != 30 or $punches[$key + 1]->getStatus() != 10)) { //Invalid punch $invalid_punches[] = array('punch_id' => $p_obj->getId()); } } } } unset($punches, $key, $p_obj); if (isset($invalid_punches) and count($invalid_punches) > 0) { foreach ($invalid_punches as $invalid_punch_arr) { Debug::text('Found Missing Break In/Out Punch: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); //$ef->setPunchControlID( $invalid_punch_arr['punch_id'] ); $ef->setPunchID($invalid_punch_arr['punch_id']); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } unset($invalid_punch_arr); } else { Debug::text('Lunch Punches match up.', __FILE__, __LINE__, __METHOD__, 10); } unset($invalid_punches); } } break; case 's7': //Over Scheduled Hours if ($plf->getRecordCount() > 0) { //This ONLY takes in to account WORKED hours, not paid absence hours. $schedule_total_time = 0; if ($slf->getRecordCount() > 0) { //Check for schedule policy foreach ($slf as $s_obj) { Debug::text(' Schedule Total Time: ' . $s_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10); $schedule_total_time += $s_obj->getTotalTime(); } $daily_total_time = 0; if ($schedule_total_time > 0) { //Get daily total time. $udtlf = new UserDateTotalListFactory(); //Take into account auto-deduct/add meal policies //$udtlf->getByUserDateIdAndStatus( $user_date_id, 20 ); $udtlf->getByUserDateIdAndStatusAndType($user_date_id, 10, 10); if ($udtlf->getRecordCount() > 0) { foreach ($udtlf as $udt_obj) { $daily_total_time += $udt_obj->getTotalTime(); } } Debug::text(' Daily Total Time: ' . $daily_total_time . ' Schedule Total Time: ' . $schedule_total_time, __FILE__, __LINE__, __METHOD__, 10); if ($daily_total_time > 0 and $daily_total_time > $schedule_total_time + $ep_obj->getGrace()) { Debug::text(' Worked Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text(' DID NOT Work Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text(' Not Scheduled', __FILE__, __LINE__, __METHOD__, 10); } } break; case 's8': //Under Scheduled Hours if ($plf->getRecordCount() > 0) { //This ONLY takes in to account WORKED hours, not paid absence hours. $schedule_total_time = 0; if ($slf->getRecordCount() > 0) { //Check for schedule policy foreach ($slf as $s_obj) { Debug::text(' Schedule Total Time: ' . $s_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10); $schedule_total_time += $s_obj->getTotalTime(); } $daily_total_time = 0; if ($schedule_total_time > 0) { //Get daily total time. $udtlf = new UserDateTotalListFactory(); //Take into account auto-deduct/add meal policies //$udtlf->getByUserDateIdAndStatus( $user_date_id, 20 ); $udtlf->getByUserDateIdAndStatusAndType($user_date_id, 10, 10); if ($udtlf->getRecordCount() > 0) { foreach ($udtlf as $udt_obj) { $daily_total_time += $udt_obj->getTotalTime(); } } Debug::text(' Daily Total Time: ' . $daily_total_time . ' Schedule Total Time: ' . $schedule_total_time, __FILE__, __LINE__, __METHOD__, 10); if ($daily_total_time < $schedule_total_time - $ep_obj->getGrace()) { Debug::text(' Worked Under Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10); if ($type_id == 5 and $user_date_obj->getDateStamp() < TTDate::getBeginDayEpoch(time() - self::$premature_delay)) { $type_id = 50; } $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text(' DID NOT Work Under Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text(' Not Scheduled', __FILE__, __LINE__, __METHOD__, 10); } } break; case 'o1': //Over Daily Time. if ($plf->getRecordCount() > 0) { //This ONLY takes in to account WORKED hours, not paid absence hours. $daily_total_time = 0; //Get daily total time. $udtlf = new UserDateTotalListFactory(); //Take into account auto-deduct/add meal policies $udtlf->getByUserDateIdAndStatusAndType($user_date_id, 10, 10); if ($udtlf->getRecordCount() > 0) { foreach ($udtlf as $udt_obj) { $daily_total_time += $udt_obj->getTotalTime(); } } Debug::text(' Daily Total Time: ' . $daily_total_time . ' Watch Window: ' . $ep_obj->getWatchWindow() . ' User Date ID: ' . $user_date_id, __FILE__, __LINE__, __METHOD__, 10); if ($daily_total_time > 0 and $daily_total_time > $ep_obj->getWatchWindow()) { Debug::text(' Worked Over Daily Hours', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text(' DID NOT Work Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10); } } break; case 'o2': //Over Weekly Time. //Over Weekly Time. case 's9': //Over Weekly Scheduled Time. if ($plf->getRecordCount() > 0) { //Get Pay Period Schedule info if (is_object($user_date_obj->getPayPeriodObject()) and is_object($user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject())) { $start_week_day_id = $user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject()->getStartWeekDay(); } else { $start_week_day_id = 0; } Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10); $weekly_scheduled_total_time = 0; if (strtolower($ep_obj->getType()) == 's9') { $tmp_slf = new ScheduleListFactory(); $tmp_slf->getByUserIdAndStartDateAndEndDate($user_date_obj->getUser(), TTDate::getBeginWeekEpoch($user_date_obj->getDateStamp(), $start_week_day_id), $user_date_obj->getDateStamp()); if ($tmp_slf->getRecordCount() > 0) { foreach ($tmp_slf as $s_obj) { $weekly_scheduled_total_time += $s_obj->getTotalTime(); } } unset($tmp_slf, $s_obj); } //This ONLY takes in to account WORKED hours, not paid absence hours. $weekly_total_time = 0; //Get daily total time. $udtlf = new UserDateTotalListFactory(); $weekly_total_time = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($user_date_obj->getUser(), TTDate::getBeginWeekEpoch($user_date_obj->getDateStamp(), $start_week_day_id), $user_date_obj->getDateStamp()); Debug::text(' Weekly Total Time: ' . $weekly_total_time . ' Weekly Scheduled Total Time: ' . $weekly_scheduled_total_time . ' Watch Window: ' . $ep_obj->getWatchWindow() . ' Grace: ' . $ep_obj->getGrace() . ' User Date ID: ' . $user_date_id, __FILE__, __LINE__, __METHOD__, 10); if (strtolower($ep_obj->getType()) == 'o2' and $weekly_total_time > 0 and $weekly_total_time > $ep_obj->getWatchWindow() or strtolower($ep_obj->getType()) == 's9' and $weekly_total_time > 0 and $weekly_total_time > $weekly_scheduled_total_time + $ep_obj->getGrace()) { Debug::text(' Worked Over Weekly Hours', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text(' DID NOT Work Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10); } } break; case 'l1': //Long Lunch //Long Lunch case 'l2': //Short Lunch if ($plf->getRecordCount() > 0) { //Get all lunch punches. $pair = 0; $x = 0; $out_for_lunch = FALSE; foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 20 and $p_obj->getType() == 20) { $lunch_out_timestamp = $p_obj->getTimeStamp(); $lunch_punch_arr[$pair]['punch_id'] = $p_obj->getId(); $out_for_lunch = TRUE; } elseif ($out_for_lunch == TRUE and $p_obj->getStatus() == 10 and $p_obj->getType() == 20) { $lunch_punch_arr[$pair][20] = $lunch_out_timestamp; $lunch_punch_arr[$pair][10] = $p_obj->getTimeStamp(); $out_for_lunch = FALSE; $pair++; unset($lunch_out_timestamp); } else { $out_for_lunch = FALSE; } } if (isset($lunch_punch_arr)) { Debug::Arr($lunch_punch_arr, 'Lunch Punch Array: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($lunch_punch_arr as $pair => $time_stamp_arr) { if (isset($time_stamp_arr[10]) and isset($time_stamp_arr[20])) { $lunch_total_time = bcsub($time_stamp_arr[10], $time_stamp_arr[20]); Debug::text(' Lunch Total Time: ' . $lunch_total_time, __FILE__, __LINE__, __METHOD__, 10); if (!isset($scheduled_id_cache[$p_obj->getID()])) { $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser()); } //Check to see if they have a schedule policy if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE and is_object($p_obj->getScheduleObject()) == TRUE and is_object($p_obj->getScheduleObject()->getSchedulePolicyObject()) == TRUE) { $mp_obj = $p_obj->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject(); } else { $mplf = new MealPolicyListFactory(); $mplf->getByPolicyGroupUserId($user_date_obj->getUserObject()->getId()); if ($mplf->getRecordCount() > 0) { Debug::text('Found Meal Policy to apply.', __FILE__, __LINE__, __METHOD__, 10); $mp_obj = $mplf->getCurrent(); } } if (isset($mp_obj) and is_object($mp_obj)) { $meal_policy_lunch_time = $mp_obj->getAmount(); Debug::text('Meal Policy Time: ' . $meal_policy_lunch_time, __FILE__, __LINE__, __METHOD__, 10); $add_exception = FALSE; if (strtolower($ep_obj->getType()) == 'l1' and $meal_policy_lunch_time > 0 and $lunch_total_time > 0 and $lunch_total_time > $meal_policy_lunch_time + $ep_obj->getGrace()) { $add_exception = TRUE; } elseif (strtolower($ep_obj->getType()) == 'l2' and $meal_policy_lunch_time > 0 and $lunch_total_time > 0 and $lunch_total_time < $meal_policy_lunch_time - $ep_obj->getGrace()) { $add_exception = TRUE; } if ($add_exception == TRUE) { Debug::text('Adding Exception!', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); if (isset($time_stamp_arr['punch_id'])) { $ef->setPunchID($time_stamp_arr['punch_id']); } $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text('Not Adding Exception!', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text(' Lunch Punches not paired... Skipping!', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text(' No Lunch Punches found, or none are paired.', __FILE__, __LINE__, __METHOD__, 10); } } break; case 'l3': //No Lunch if ($plf->getRecordCount() > 0) { //If they are scheduled or not, we can check for a meal policy and base our //decision off that. We don't want a No Lunch exception on a 3hr shift though. //Also ignore this exception if the lunch is auto-deduct. $daily_total_time = 0; $udtlf = new UserDateTotalListFactory(); $udtlf->getByUserDateIdAndStatus($user_date_id, 20); if ($udtlf->getRecordCount() > 0) { foreach ($udtlf as $udt_obj) { $daily_total_time += $udt_obj->getTotalTime(); } } Debug::text('Day Total Time: ' . $daily_total_time, __FILE__, __LINE__, __METHOD__, 10); if ($daily_total_time > 0) { //Check for lunch punch. $lunch_punch = FALSE; foreach ($plf as $p_obj) { if ($p_obj->getType() == 20) { Debug::text('Found Lunch Punch: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10); $lunch_punch = TRUE; break; } } if ($lunch_punch == FALSE) { Debug::text('DID NOT Find Lunch Punch... Checking meal policies. ', __FILE__, __LINE__, __METHOD__, 10); //Use scheduled meal policy first. if ($slf->getRecordCount() > 0) { Debug::text('Schedule Found...', __FILE__, __LINE__, __METHOD__, 10); foreach ($slf as $s_obj) { if ($s_obj->getSchedulePolicyObject() !== FALSE and $s_obj->getSchedulePolicyObject()->getMealPolicyObject() !== FALSE and $s_obj->getSchedulePolicyObject()->getMealPolicyObject()->getType() != 10) { Debug::text('Found Schedule Meal Policy... Trigger Time: ' . $s_obj->getSchedulePolicyObject()->getMealPolicyObject()->getTriggerTime(), __FILE__, __LINE__, __METHOD__, 10); if ($daily_total_time > $s_obj->getSchedulePolicyObject()->getMealPolicyObject()->getTriggerTime()) { Debug::text('Daily Total Time is After Schedule Meal Policy Trigger Time: ', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } else { Debug::text('Schedule Meal Policy does not exist, or is auto-deduct?', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text('No Schedule Found...', __FILE__, __LINE__, __METHOD__, 10); //Check if they have a meal policy, with no schedule. $mplf = new MealPolicyListFactory(); $mplf->getByPolicyGroupUserId($user_date_obj->getUser()); if ($mplf->getRecordCount() > 0) { Debug::text('Found UnScheduled Meal Policy...', __FILE__, __LINE__, __METHOD__, 10); $m_obj = $mplf->getCurrent(); if ($daily_total_time > $m_obj->getTriggerTime() and $m_obj->getType() == 20) { Debug::text('Daily Total Time is After Schedule Meal Policy Trigger Time: ' . $m_obj->getTriggerTime(), __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text('Auto-deduct meal policy, ignorning this exception.', __FILE__, __LINE__, __METHOD__, 10); } } else { //There is no meal policy or schedule policy with a meal policy assigned to it //With out this we could still apply No Lunch exceptions, but they will happen even on //a 2minute shift. Debug::text('No meal policy, applying No Lunch exception.', __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } } else { Debug::text('Found Lunch Punch... Ignoring this exception. ', __FILE__, __LINE__, __METHOD__, 10); } } } break; case 'b1': //Long Break //Long Break case 'b2': //Short Break if ($plf->getRecordCount() > 0) { //Get all break punches. $pair = 0; $x = 0; $out_for_break = FALSE; foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 20 and $p_obj->getType() == 30) { $break_out_timestamp = $p_obj->getTimeStamp(); $break_punch_arr[$pair]['punch_id'] = $p_obj->getId(); $out_for_break = TRUE; } elseif ($out_for_break == TRUE and $p_obj->getStatus() == 10 and $p_obj->getType() == 30) { $break_punch_arr[$pair][20] = $break_out_timestamp; $break_punch_arr[$pair][10] = $p_obj->getTimeStamp(); $out_for_break = FALSE; $pair++; unset($break_out_timestamp); } else { $out_for_break = FALSE; } } unset($pair); if (isset($break_punch_arr)) { Debug::Arr($break_punch_arr, 'Break Punch Array: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($break_punch_arr as $pair => $time_stamp_arr) { if (isset($time_stamp_arr[10]) and isset($time_stamp_arr[20])) { $break_total_time = bcsub($time_stamp_arr[10], $time_stamp_arr[20]); Debug::text(' Break Total Time: ' . $break_total_time, __FILE__, __LINE__, __METHOD__, 10); if (!isset($scheduled_id_cache[$p_obj->getID()])) { $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser()); } //Check to see if they have a schedule policy $bplf = new BreakPolicyListFactory(); if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE and is_object($p_obj->getScheduleObject()) == TRUE and is_object($p_obj->getScheduleObject()->getSchedulePolicyObject()) == TRUE) { $break_policy_ids = $p_obj->getScheduleObject()->getSchedulePolicyObject()->getBreakPolicyObject(); $bplf->getByIdAndCompanyId($break_policy_ids, $user_date_obj->getUserObject()->getCompany()); } else { $bplf->getByPolicyGroupUserId($user_date_obj->getUser()); } unset($break_policy_ids); if ($bplf->getRecordCount() > 0) { Debug::text('Found Break Policy(ies) to apply: ' . $bplf->getRecordCount() . ' Pair: ' . $pair, __FILE__, __LINE__, __METHOD__, 10); foreach ($bplf as $bp_obj) { $bp_objs[] = $bp_obj; } unset($bplf, $bp_obj); if (isset($bp_objs[$pair]) and is_object($bp_objs[$pair])) { $bp_obj = $bp_objs[$pair]; $break_policy_break_time = $bp_obj->getAmount(); Debug::text('Break Policy Time: ' . $break_policy_break_time . ' ID: ' . $bp_obj->getID(), __FILE__, __LINE__, __METHOD__, 10); $add_exception = FALSE; if (strtolower($ep_obj->getType()) == 'b1' and $break_policy_break_time > 0 and $break_total_time > 0 and $break_total_time > $break_policy_break_time + $ep_obj->getGrace()) { $add_exception = TRUE; } elseif (strtolower($ep_obj->getType()) == 'b2' and $break_policy_break_time > 0 and $break_total_time > 0 and $break_total_time < $break_policy_break_time - $ep_obj->getGrace()) { $add_exception = TRUE; } if ($add_exception == TRUE) { Debug::text('Adding Exception! ' . $ep_obj->getType(), __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); if (isset($time_stamp_arr['punch_id'])) { $ef->setPunchID($time_stamp_arr['punch_id']); } $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text('Not Adding Exception!', __FILE__, __LINE__, __METHOD__, 10); } unset($bp_obj); } unset($bp_objs); } } else { Debug::text(' Break Punches not paired... Skipping!', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text(' No Break Punches found, or none are paired.', __FILE__, __LINE__, __METHOD__, 10); } } break; case 'b3': //Too Many Breaks //Too Many Breaks case 'b4': //Too Few Breaks if ($plf->getRecordCount() > 0) { //Get all break punches. $pair = 0; $x = 0; $out_for_break = FALSE; foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 20 and $p_obj->getType() == 30) { $break_out_timestamp = $p_obj->getTimeStamp(); $break_punch_arr[$pair]['punch_id'] = $p_obj->getId(); $out_for_break = TRUE; } elseif ($out_for_break == TRUE and $p_obj->getStatus() == 10 and $p_obj->getType() == 30) { $break_punch_arr[$pair][20] = $break_out_timestamp; $break_punch_arr[$pair][10] = $p_obj->getTimeStamp(); $out_for_break = FALSE; $pair++; unset($break_out_timestamp); } else { $out_for_break = FALSE; } } unset($pair); if (isset($break_punch_arr)) { $total_breaks = count($break_punch_arr); Debug::Arr($break_punch_arr, 'Break Punch Array: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($break_punch_arr as $pair => $time_stamp_arr) { if (isset($time_stamp_arr[10]) and isset($time_stamp_arr[20])) { $break_total_time = bcsub($time_stamp_arr[10], $time_stamp_arr[20]); Debug::text(' Break Total Time: ' . $break_total_time, __FILE__, __LINE__, __METHOD__, 10); if (!isset($scheduled_id_cache[$p_obj->getID()])) { $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser()); } //Check to see if they have a schedule policy $bplf = new BreakPolicyListFactory(); if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE and is_object($p_obj->getScheduleObject()) == TRUE and is_object($p_obj->getScheduleObject()->getSchedulePolicyObject()) == TRUE) { $break_policy_ids = $p_obj->getScheduleObject()->getSchedulePolicyObject()->getBreakPolicyObject(); $bplf->getByIdAndCompanyId($break_policy_ids, $user_date_obj->getUserObject()->getCompany()); } else { $bplf->getByPolicyGroupUserId($user_date_obj->getUser()); } unset($break_policy_ids); $allowed_breaks = $bplf->getRecordCount(); $add_exception = FALSE; if (strtolower($ep_obj->getType()) == 'b3' and $total_breaks > $allowed_breaks) { Debug::text(' Too many breaks taken...', __FILE__, __LINE__, __METHOD__, 10); $add_exception = TRUE; } elseif (strtolower($ep_obj->getType()) == 'b4' and $total_breaks < $allowed_breaks) { Debug::text(' Too few breaks taken...', __FILE__, __LINE__, __METHOD__, 10); $add_exception = TRUE; } else { Debug::text(' Proper number of breaks taken...', __FILE__, __LINE__, __METHOD__, 10); } if ($add_exception == TRUE and (strtolower($ep_obj->getType()) == 'b4' or strtolower($ep_obj->getType()) == 'b3' and $pair > $allowed_breaks - 1)) { Debug::text('Adding Exception! ' . $ep_obj->getType(), __FILE__, __LINE__, __METHOD__, 10); $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); if (isset($time_stamp_arr['punch_id']) and strtolower($ep_obj->getType()) == 'b3') { $ef->setPunchID($time_stamp_arr['punch_id']); } $ef->setType($type_id); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text('Not Adding Exception!', __FILE__, __LINE__, __METHOD__, 10); } } } } } break; case 'j1': //Not Allowed on Job if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 10) { //In punches if (is_object($p_obj->getPunchControlObject()) and $p_obj->getPunchControlObject()->getJob() > 0) { //Found job punch, check job settings. $jlf = new JobListFactory(); $jlf->getById($p_obj->getPunchControlObject()->getJob()); if ($jlf->getRecordCount() > 0) { $j_obj = $jlf->getCurrent(); if ($j_obj->isAllowedUser($user_date_obj->getUser()) == FALSE) { $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setPunchControlId($p_obj->getPunchControlId()); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text(' User allowed on Job!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Job not found!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Not a Job Punch...', __FILE__, __LINE__, __METHOD__, 10); } } } unset($j_obj); } break; case 'j2': //Not Allowed on Task if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 10) { //In punches if (is_object($p_obj->getPunchControlObject()) and $p_obj->getPunchControlObject()->getJob() > 0 and $p_obj->getPunchControlObject()->getJobItem() > 0) { //Found job punch, check job settings. $jlf = new JobListFactory(); $jlf->getById($p_obj->getPunchControlObject()->getJob()); if ($jlf->getRecordCount() > 0) { $j_obj = $jlf->getCurrent(); if ($j_obj->isAllowedItem($p_obj->getPunchControlObject()->getJobItem()) == FALSE) { $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setPunchControlId($p_obj->getPunchControlId()); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text(' Job item allowed on job!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Job not found!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Not a Job Punch...', __FILE__, __LINE__, __METHOD__, 10); } } } unset($j_obj); } break; case 'j3': //Job already completed if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 10) { //In punches if (is_object($p_obj->getPunchControlObject()) and $p_obj->getPunchControlObject()->getJob() > 0) { //Found job punch, check job settings. $jlf = new JobListFactory(); $jlf->getById($p_obj->getPunchControlObject()->getJob()); if ($jlf->getRecordCount() > 0) { $j_obj = $jlf->getCurrent(); //Status is completed and the User Date Stamp is greater then the job end date. //If no end date is set, ignore this. if ($j_obj->getStatus() == 30 and $j_obj->getEndDate() != FALSE and $user_date_obj->getDateStamp() > $j_obj->getEndDate()) { $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setPunchControlId($p_obj->getPunchControlId()); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } else { Debug::text(' Job Not Completed!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Job not found!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Not a Job Punch...', __FILE__, __LINE__, __METHOD__, 10); } } } unset($j_obj); } break; case 'j4': //No Job or Task if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { //In punches only if ($p_obj->getStatus() == 10 and is_object($p_obj->getPunchControlObject()) and ($p_obj->getPunchControlObject()->getJob() == '' or $p_obj->getPunchControlObject()->getJob() == 0 or $p_obj->getPunchControlObject()->getJob() == FALSE or $p_obj->getPunchControlObject()->getJobItem() == '' or $p_obj->getPunchControlObject()->getJobItem() == 0 or $p_obj->getPunchControlObject()->getJobItem() == FALSE)) { $ef = new ExceptionFactory(); $ef->setUserDateID($user_date_id); $ef->setExceptionPolicyID($ep_obj->getId()); $ef->setType($type_id); $ef->setPunchControlId($p_obj->getPunchControlId()); $ef->setPunchId($p_obj->getId()); $ef->setEnableDemerits(TRUE); if ($ef->isValid()) { if ($enable_premature_exceptions == TRUE) { $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, $ep_obj); } $ef->Save(); } } } } break; default: Debug::text('BAD, should never get here: ', __FILE__, __LINE__, __METHOD__, 10); break; } } } $profiler->stopTimer("ExceptionPolicy::calcExceptions()"); return TRUE; }
function setPunchID($id) { $id = trim($id); if ($id == '' or empty($id)) { $id = NULL; } $plf = new PunchListFactory(); if ($id == NULL or $this->Validator->isResultSetWithRows('punch', $plf->getByID($id), TTi18n::gettext('Invalid Punch ID'))) { $this->data['punch_id'] = $id; return TRUE; } return FALSE; }
function getInCompletePunchControlIdByUserIdAndEpoch($user_id, $epoch, $status_id) { Debug::text(' Epoch: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10); if ($user_id == '') { return FALSE; } if ($epoch == '') { return FALSE; } $plf = new PunchListFactory(); $plf->getShiftPunchesByUserIDAndEpoch($user_id, $epoch); if ($plf->getRecordCount() > 0) { //Check for gaps. $prev_time_stamp = 0; foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 10) { $punch_arr[$p_obj->getPunchControlId()]['in'] = $p_obj->getTimeStamp(); } else { $punch_arr[$p_obj->getPunchControlId()]['out'] = $p_obj->getTimeStamp(); } if ($prev_time_stamp != 0) { $prev_punch_arr[$p_obj->getTimeStamp()] = $prev_time_stamp; } $prev_time_stamp = $p_obj->getTimeStamp(); } unset($prev_time_stamp); if (isset($prev_punch_arr)) { $next_punch_arr = array_flip($prev_punch_arr); } //Debug::Arr( $punch_arr, ' Punch Array: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr( $next_punch_arr, ' Next Punch Array: ', __FILE__, __LINE__, __METHOD__,10); if (isset($punch_arr)) { $i = 0; foreach ($punch_arr as $punch_control_id => $data) { $found_gap = FALSE; Debug::text(' Iteration: ' . $i, __FILE__, __LINE__, __METHOD__, 10); //Skip complete punch control rows. if (isset($data['in']) and isset($data['out'])) { Debug::text(' Punch Control ID is Complete: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10); } else { //Make sure we don't assign a In punch that comes AFTER an Out punch to the same pair. //As well the opposite, an Out punch that comes BEFORE an In punch to the same pair. if ($status_id == 10 and !isset($data['in']) and (isset($data['out']) and $epoch <= $data['out'])) { Debug::text(' aFound Valid Gap...', __FILE__, __LINE__, __METHOD__, 10); $found_gap = TRUE; } elseif ($status_id == 20 and !isset($data['out']) and (isset($data['in']) and $epoch >= $data['in'])) { Debug::text(' bFound Valid Gap...', __FILE__, __LINE__, __METHOD__, 10); $found_gap = TRUE; } else { Debug::text(' No Valid Gap Found...', __FILE__, __LINE__, __METHOD__, 10); } } if ($found_gap == TRUE) { if ($status_id == 10) { //In Gap Debug::text(' In Gap...', __FILE__, __LINE__, __METHOD__, 10); if (isset($prev_punch_arr[$data['out']])) { Debug::text(' Punch Before In Gap... Range Start: ' . TTDate::getDate('DATE+TIME', $prev_punch_arr[$data['out']]) . ' End: ' . TTDate::getDate('DATE+TIME', $data['out']), __FILE__, __LINE__, __METHOD__, 10); if ($prev_punch_arr[$data['out']] == $data['out'] or TTDate::isTimeOverLap($epoch, $epoch, $prev_punch_arr[$data['out']], $data['out'])) { Debug::text(' Epoch OverLaps, THIS IS GOOD!', __FILE__, __LINE__, __METHOD__, 10); Debug::text(' aReturning Punch Control ID: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10); $retval = $punch_control_id; break; //Without this adding mass punches fails in some basic circumstances because it loops and attaches to a later punch control } else { Debug::text(' Epoch does not OverLaps, Cant attached to this punch_control!', __FILE__, __LINE__, __METHOD__, 10); } } else { //No Punch After Debug::text(' NO Punch Before In Gap...', __FILE__, __LINE__, __METHOD__, 10); $retval = $punch_control_id; break; } } else { //Out Gap Debug::text(' Out Gap...', __FILE__, __LINE__, __METHOD__, 10); //Start: $data['in'] //End: $data['in'] if (isset($next_punch_arr[$data['in']])) { Debug::text(' Punch After Out Gap... Range Start: ' . TTDate::getDate('DATE+TIME', $data['in']) . ' End: ' . TTDate::getDate('DATE+TIME', $next_punch_arr[$data['in']]), __FILE__, __LINE__, __METHOD__, 10); if ($data['in'] == $next_punch_arr[$data['in']] or TTDate::isTimeOverLap($epoch, $epoch, $data['in'], $next_punch_arr[$data['in']])) { Debug::text(' Epoch OverLaps, THIS IS GOOD!', __FILE__, __LINE__, __METHOD__, 10); Debug::text(' bReturning Punch Control ID: ' . $punch_control_id, __FILE__, __LINE__, __METHOD__, 10); $retval = $punch_control_id; break; //Without this adding mass punches fails in some basic circumstances because it loops and attaches to a later punch control } else { Debug::text(' Epoch does not OverLaps, Cant attached to this punch_control!', __FILE__, __LINE__, __METHOD__, 10); } } else { //No Punch After Debug::text(' NO Punch After Out Gap...', __FILE__, __LINE__, __METHOD__, 10); $retval = $punch_control_id; break; } } } $i++; } } } if (isset($retval)) { Debug::text(' Returning Punch Control ID: ' . $retval, __FILE__, __LINE__, __METHOD__, 10); return $retval; } Debug::text(' Returning FALSE No Valid Gaps Found...', __FILE__, __LINE__, __METHOD__, 10); //FALSE means no gaps in punch control rows found. return FALSE; }
} else { unset($filter_data['pay_period_ids']); } foreach ($ulf as $u_obj) { $filter_data['include_user_ids'][] = $u_obj->getId(); } if (isset($filter_data['pay_period_ids'])) { //Trim sort prefix from selected pay periods. $tmp_filter_pay_period_ids = $filter_data['pay_period_ids']; $filter_data['pay_period_ids'] = array(); foreach ($tmp_filter_pay_period_ids as $key => $filter_pay_period_id) { $filter_data['pay_period_ids'][] = Misc::trimSortPrefix($filter_pay_period_id); } unset($key, $tmp_filter_pay_period_ids, $filter_pay_period_id); } $plf = new PunchListFactory(); if ($current_company->getProductEdition() == 20) { if (!isset($filter_data['job_item_ids'])) { $filter_data['job_item_ids'] = array(); } $jlf = new JobListFactory(); $jlf->getSearchByCompanyIdAndStatusIdAndBranchIdAndDepartmentIdAndGroupIdAndClientIdAndIncludeIdAndExcludeId($current_company->getId(), NULL, NULL, NULL, Misc::trimSortPrefix($filter_data['job_group_ids'], TRUE), NULL, $filter_data['include_job_ids'], $filter_data['exclude_job_ids']); $filter_data['job_ids'] = array(); if ($jlf->getRecordCount() > 0) { foreach ($jlf as $j_obj) { $filter_data['job_ids'][] = $j_obj->getId(); } } } else { $filter_data['job_ids'] = array(-1); $filter_data['job_item_ids'] = array(-1);
if ($e_obj->getColumn('severity_id') == 20) { $exceptions['med'] = $e_obj->getColumn('count'); } if ($e_obj->getColumn('severity_id') == 30) { $exceptions['high'] = $e_obj->getColumn('count'); } } } else { Debug::Text(' No Exceptions!', __FILE__, __LINE__, __METHOD__, 10); } //Get all pending requests $pending_requests = 0; $rlf = new RequestListFactory(); $rlf->getSumByPayPeriodIdAndStatus($pay_period_obj->getId(), 30); if ($rlf->getRecordCount() > 0) { $pending_requests = $rlf->getCurrent()->getColumn('total'); } $pay_period_data['pending_requests'] = $pending_requests; //Count how many punches are in this pay period. $plf = new PunchListFactory(); $pay_period_data['total_punches'] = $plf->getByPayPeriodId($pay_period_id)->getRecordCount(); Debug::Text(' Total Punches: ' . $pay_period_data['total_punches'], __FILE__, __LINE__, __METHOD__, 10); } //var_dump($pay_period_data); $smarty->assign_by_ref('exceptions', $exceptions); $smarty->assign_by_ref('pay_period_data', $pay_period_data); $smarty->assign_by_ref('current_epoch', TTDate::getTime()); break; } $smarty->assign_by_ref('ppf', $ppf); $smarty->display('payperiod/ViewPayPeriod.tpl');
break; case 'recalculate employee': Debug::Text('Recalculating employee timesheet!', __FILE__, __LINE__, __METHOD__, 10); Redirect::Page(URLBuilder::getURL(array('action' => 'recalculate_employee', 'pay_period_ids' => $pay_period_id, 'filter_user_id' => $filter_data['user_id'], 'next_page' => urlencode(URLBuilder::getURL(NULL, '../timesheet/ViewUserTimeSheet.php'))), '../progress_bar/ProgressBarControl.php'), FALSE); break; case 'submit': default: BreadCrumb::setCrumb($title); Debug::Text('Default Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10); $start_date = TTDate::getBeginWeekEpoch($filter_data['date'], $current_user_prefs->getStartWeekDay()); $end_date = TTDate::getEndWeekEpoch($filter_data['date'], $current_user_prefs->getStartWeekDay()); Debug::Text('Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); $calendar_array = TTDate::getCalendarArray($start_date, $end_date, $current_user_prefs->getStartWeekDay()); //var_dump($calendar_array); //Get all punches, put in array by date epoch. $plf = new PunchListFactory(); $plf->getByCompanyIDAndUserIdAndStartDateAndEndDate($current_company->getId(), $user_id, $start_date, $end_date); if ($plf->getRecordCount() > 0) { foreach ($plf as $punch_obj) { $user_date_stamp = TTDate::strtotime($punch_obj->getColumn('user_date_stamp')); if ($punch_obj->getColumn('note') != '') { $has_note = TRUE; } else { $has_note = FALSE; } $punches[$user_date_stamp][] = array('date_stamp' => $punch_obj->getColumn('user_date_stamp'), 'id' => $punch_obj->getId(), 'punch_control_id' => $punch_obj->getPunchControlId(), 'time_stamp' => $punch_obj->getTimeStamp(), 'status_id' => $punch_obj->getStatus(), 'type_id' => $punch_obj->getType(), 'type_code' => $punch_obj->getTypeCode(), 'has_note' => $has_note); //Total up meal and break total time for each day. if ($punch_obj->getType() != 10) { if ($punch_obj->getStatus() == 20) { $tmp_date_break_totals[$user_date_stamp][$punch_obj->getType()]['prev'] = $punch_obj->getTimeStamp(); } elseif (isset($tmp_date_break_totals[$user_date_stamp][$punch_obj->getType()]['prev'])) {
if ($pcf->Save(TRUE, TRUE) == TRUE) { //Force isNew() lookup. //$pf->FailTransaction(); $pf->CommitTransaction(); Redirect::Page(URLBuilder::getURL(NULL, '../CloseWindow.php')); break; } } } } $pf->FailTransaction(); default: $epoch = TTDate::getTime(); $slf = new ScheduleListFactory(); //Get last punch for this day, for this user. $plf = new PunchListFactory(); if ($action != 'submit') { $plf->getPreviousPunchByUserIDAndEpoch($current_user->getId(), $epoch); if ($plf->getRecordCount() > 0) { $prev_punch_obj = $plf->getCurrent(); Debug::Text(' Found Previous Punch within Continuous Time from now: ' . TTDate::getDate('DATe+TIME', $prev_punch_obj->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10); $branch_id = $prev_punch_obj->getPunchControlObject()->getBranch(); $department_id = $prev_punch_obj->getPunchControlObject()->getDepartment(); $job_id = $prev_punch_obj->getPunchControlObject()->getJob(); $job_item_id = $prev_punch_obj->getPunchControlObject()->getJobItem(); //Don't enable transfer by default if the previous punch was any OUT punch. //Transfer does the OUT punch for them, so if the previous punch is an OUT punch //we don't gain anything anyways. if ($permission->Check('punch', 'default_transfer') and $prev_punch_obj->getStatus() == 10) { $transfer = TRUE; } else {
function calcBreakPolicyTotalTime($break_policy_ids = NULL) { //Debug::arr($meal_policy_obj, 'MealPolicyObject param:', __FILE__, __LINE__, __METHOD__, 10); //Get total worked time for the day. $udtlf = new UserDateTotalListFactory(); $daily_total_time = $udtlf->getWorkedTimeSumByUserDateID($this->getUserDateID()); Debug::text('Daily Total Time: ' . $daily_total_time, __FILE__, __LINE__, __METHOD__, 10); $bplf = new BreakPolicyListFactory(); if (is_array($break_policy_ids)) { $bplf->getByIdAndCompanyId($break_policy_ids, $this->getUserDateObject()->getUserObject()->getCompany()); } else { //Lookup break policy $bplf->getByPolicyGroupUserIdAndDayTotalTime($this->getUserDateObject()->getUser(), $daily_total_time); } $break_policy_total_time = 0; if ($bplf->getRecordCount() > 0) { Debug::text('Found Break Policy(ies) to apply: ' . $bplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); $break_total_time = array(); $break_overall_total_time = 0; $plf = new PunchListFactory(); $plf->getByUserDateIdAndTypeId($this->getUserDateId(), 30); //Only Break punches if ($plf->getRecordCount() > 0) { $pair = 0; $x = 0; $out_for_break = FALSE; foreach ($plf as $p_obj) { if ($p_obj->getStatus() == 20 and $p_obj->getType() == 30) { $break_out_timestamp = $p_obj->getTimeStamp(); $out_for_break = TRUE; } elseif ($out_for_break == TRUE and $p_obj->getStatus() == 10 and $p_obj->getType() == 30) { $break_punch_arr[$pair][20] = $break_out_timestamp; $break_punch_arr[$pair][10] = $p_obj->getTimeStamp(); $out_for_break = FALSE; $pair++; unset($break_out_timestamp); } else { $out_for_break = FALSE; } $x++; } if (isset($break_punch_arr)) { foreach ($break_punch_arr as $punch_control_id => $time_stamp_arr) { if (isset($time_stamp_arr[10]) and isset($time_stamp_arr[20])) { $break_overall_total_time = bcadd($break_overall_total_time, bcsub($time_stamp_arr[10], $time_stamp_arr[20])); $break_total_time[] = bcsub($time_stamp_arr[10], $time_stamp_arr[20]); } else { Debug::text(' Break Punches not paired... Skipping!', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::text(' No Break Punches found, or none are paired.', __FILE__, __LINE__, __METHOD__, 10); } } //Debug::Arr($break_punch_arr, ' Break Punch Arr: ', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($break_total_time, ' Break Total Time Arr: ', __FILE__, __LINE__, __METHOD__, 10); Debug::text(' Break Overall Total Time: ' . $break_overall_total_time, __FILE__, __LINE__, __METHOD__, 10); $i = 0; foreach ($bplf as $break_policy_obj) { Debug::text('Break Policy ID: ' . $break_policy_obj->getId() . ' Type ID: ' . $break_policy_obj->getType() . ' Amount: ' . $break_policy_obj->getAmount() . ' Daily Total Time: ' . $daily_total_time, __FILE__, __LINE__, __METHOD__, 10); /* //If we skip this, then we can't force a break auto-deduct even when the employee doesn't punch in/out for breaks. //However the opposite is true if we want to auto-add break time only when the employee does take a break, this will always add it. if ( !isset( $break_total_time[$i] ) ) { Debug::text(' No Break Total Time for this break policy...Skipping...: ', __FILE__, __LINE__, __METHOD__, 10); continue; } */ $break_policy_time = 0; switch ($break_policy_obj->getType()) { case 10: //Auto-Deduct Debug::text(' Break AutoDeduct.', __FILE__, __LINE__, __METHOD__, 10); if ($break_policy_obj->getIncludeBreakPunchTime() == TRUE) { $break_policy_time = bcsub($break_policy_obj->getAmount(), $break_total_time[$i]) * -1; //If they take more then their alloted break, zero it out so time isn't added. if ($break_policy_time > 0) { $break_policy_time = 0; } } else { $break_policy_time = $break_policy_obj->getAmount() * -1; } break; case 15: //Auto-Include Debug::text(' Break AutoInclude... Break Total Time: ' . $break_total_time[$i] . ' Break Policy Amount: ' . $break_policy_obj->getAmount(), __FILE__, __LINE__, __METHOD__, 10); if ($break_policy_obj->getIncludeBreakPunchTime() == TRUE) { if ($break_total_time[$i] > $break_policy_obj->getAmount()) { $break_policy_time = $break_policy_obj->getAmount(); } else { $break_policy_time = $break_total_time[$i]; } } else { $break_policy_time = $break_policy_obj->getAmount(); } break; } Debug::text(' Break Policy Total Time: ' . $break_policy_time . ' Break Policy ID: ' . $break_policy_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); if ($break_policy_time != 0) { $break_policy_total_time = bcadd($break_policy_total_time, $break_policy_time); $udtf = new UserDateTotalFactory(); $udtf->setUserDateID($this->getUserDateID()); $udtf->setStatus(10); //System $udtf->setType(110); //Break $udtf->setBreakPolicyId($break_policy_obj->getId()); $udtf->setBranch($this->getUserDateObject()->getUserObject()->getDefaultBranch()); $udtf->setDepartment($this->getUserDateObject()->getUserObject()->getDefaultDepartment()); $udtf->setTotalTime($break_policy_time); $udtf->setEnableCalcSystemTotalTime(FALSE); if ($udtf->isValid() == TRUE) { $udtf->Save(); } unset($udtf); } $i++; } } else { Debug::text(' No Break Policy found, or not after break policy trigger time yet...', __FILE__, __LINE__, __METHOD__, 10); } Debug::text(' Final Break Policy Total Time: ' . $break_policy_total_time, __FILE__, __LINE__, __METHOD__, 10); return $break_policy_total_time; }
$action = Misc::findSubmitButton(); Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10); switch ($action) { case 'export': case 'display_report': //Debug::setVerbosity(11); Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($filter_data, 'Filter Data', __FILE__, __LINE__, __METHOD__,10); $filter_data['job_group_ids'] = Misc::trimSortPrefix($filter_data['job_group_ids'], TRUE); $ulf = new UserListFactory(); $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { $filter_data['user_ids'][] = $u_obj->getId(); } $plf = new PunchListFactory(); if ($current_company->getProductEdition() == 20) { if (!isset($filter_data['job_item_ids'])) { $filter_data['job_item_ids'] = array(); } $jlf = new JobListFactory(); $jlf->getSearchByCompanyIdAndStatusIdAndBranchIdAndDepartmentIdAndGroupIdAndClientIdAndIncludeIdAndExcludeId($current_company->getId(), NULL, NULL, NULL, Misc::trimSortPrefix($filter_data['job_group_ids'], TRUE), NULL, $filter_data['include_job_ids'], $filter_data['exclude_job_ids']); $filter_data['job_ids'] = array(); if ($jlf->getRecordCount() > 0) { foreach ($jlf as $j_obj) { $filter_data['job_ids'][] = $j_obj->getId(); } } } else { $filter_data['job_ids'] = array(-1); $filter_data['job_item_ids'] = array(-1);
if (isset($schedule_rows[$pay_period_id][$user_id][$date_stamp]['working'])) { $tmp_rows[$pay_period_id][$user_id][$date_stamp]['schedule_working'] = $schedule_rows[$pay_period_id][$user_id][$date_stamp]['working']; } else { $tmp_rows[$pay_period_id][$user_id][$date_stamp]['schedule_working'] = NULL; } if (isset($schedule_rows[$pay_period_id][$user_id][$date_stamp]['absence'])) { $tmp_rows[$pay_period_id][$user_id][$date_stamp]['schedule_absence'] = $schedule_rows[$pay_period_id][$user_id][$date_stamp]['absence']; } else { $tmp_rows[$pay_period_id][$user_id][$date_stamp]['schedule_absence'] = NULL; } $tmp_rows[$pay_period_id][$user_id][$date_stamp]['min_punch_time_stamp'] = TTDate::strtotime($udt_obj->getColumn('min_punch_time_stamp')); $tmp_rows[$pay_period_id][$user_id][$date_stamp]['max_punch_time_stamp'] = TTDate::strtotime($udt_obj->getColumn('max_punch_time_stamp')); } //Get all punches if ($action == 'display_detailed_timesheet') { $plf = new PunchListFactory(); $plf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data); if ($plf->getRecordCount() > 0) { foreach ($plf as $p_obj) { $punch_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][TTDate::strtotime($p_obj->getColumn('date_stamp'))][$p_obj->getPunchControlID()][$p_obj->getStatus()] = array('status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType(), 'type_code' => $p_obj->getTypeCode(), 'time_stamp' => $p_obj->getTimeStamp()); } } unset($plf, $p_obj); } $ulf = new UserListFactory(); $utlf = new UserTitleListFactory(); $title_options = $utlf->getByCompanyIdArray($current_company->getId()); $blf = new BranchListFactory(); $branch_options = $blf->getByCompanyIdArray($current_company->getId()); $dlf = new DepartmentListFactory(); $department_options = $dlf->getByCompanyIdArray($current_company->getId());
function editPunch($id, $data = NULL) { if ($id == '') { return FALSE; } //Edit out punch so its on the next day. $plf = new PunchListFactory(); $plf->getById($id); if ($plf->getRecordCount() == 1) { //var_dump($data); $p_obj = $plf->getCurrent(); //$p_obj->setUser( $this->user_id ); if (isset($data['type_id'])) { $p_obj->setType($data['type_id']); } if (isset($data['status_id'])) { $p_obj->setStatus($data['status_id']); } if (isset($data['time_stamp'])) { $p_obj->setTimeStamp($data['time_stamp']); } if ($p_obj->isValid() == TRUE) { $p_obj->Save(FALSE); $p_obj->getPunchControlObject()->setPunchObject($p_obj); $p_obj->getPunchControlObject()->setEnableCalcUserDateID(TRUE); $p_obj->getPunchControlObject()->setEnableCalcSystemTotalTime(TRUE); $p_obj->getPunchControlObject()->setEnableCalcWeeklySystemTotalTime(TRUE); $p_obj->getPunchControlObject()->setEnableCalcException(TRUE); $p_obj->getPunchControlObject()->setEnablePreMatureException(TRUE); $p_obj->getPunchControlObject()->setEnableCalcUserDateTotal(TRUE); $p_obj->getPunchControlObject()->setEnableCalcTotalTime(TRUE); if ($p_obj->getPunchControlObject()->isValid() == TRUE) { $p_obj->getPunchControlObject()->Save(); return TRUE; } } } return FALSE; }
function getPunchData() { if ($this->StationCheckAllowed() !== TRUE) { Debug::text('Station NOT allowed: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $epoch = TTDate::getTime(); $slf = new ScheduleListFactory(); //Get last punch for this day, for this user. $plf = new PunchListFactory(); $plf->getPreviousPunchByUserIDAndEpoch($this->getUserObject()->getId(), $epoch); if ($plf->getRecordCount() > 0) { $prev_punch_obj = $plf->getCurrent(); Debug::Text(' Found Previous Punch within Continuous Time from now, ID: ' . $prev_punch_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $branch_id = $prev_punch_obj->getPunchControlObject()->getBranch(); $department_id = $prev_punch_obj->getPunchControlObject()->getDepartment(); $job_id = $prev_punch_obj->getPunchControlObject()->getJob(); $job_item_id = $prev_punch_obj->getPunchControlObject()->getJobItem(); //Don't enable transfer by default if the previous punch was any OUT punch. //Transfer does the OUT punch for them, so if the previous punch is an OUT punch //we don't gain anything anyways. if ($this->getPermissionObject()->Check('punch', 'default_transfer') and $prev_punch_obj->getStatus() == 10) { $transfer = TRUE; } else { $transfer = FALSE; } if ($branch_id == '' or empty($branch_id) or $department_id == '' or empty($department_id) or $job_id == '' or empty($job_id) or $job_item_id == '' or empty($job_item_id)) { Debug::Text(' Branch or department are null. ', __FILE__, __LINE__, __METHOD__, 10); $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($this->getUserObject()->getId(), $epoch); if (is_object($s_obj)) { Debug::Text(' Found Schedule!: ', __FILE__, __LINE__, __METHOD__, 10); if ($branch_id == '' or empty($branch_id)) { Debug::Text(' overrriding branch: ' . $s_obj->getBranch(), __FILE__, __LINE__, __METHOD__, 10); $branch_id = $s_obj->getBranch(); } if ($department_id == '' or empty($department_id)) { Debug::Text(' overrriding department: ' . $s_obj->getDepartment(), __FILE__, __LINE__, __METHOD__, 10); $department_id = $s_obj->getDepartment(); } if ($job_id == '' or empty($job_id)) { Debug::Text(' overrriding job: ' . $s_obj->getJob(), __FILE__, __LINE__, __METHOD__, 10); $job_id = $s_obj->getJob(); } if ($job_item_id == '' or empty($job_item_id)) { Debug::Text(' overrriding job item: ' . $s_obj->getJobItem(), __FILE__, __LINE__, __METHOD__, 10); $job_item_id = $s_obj->getJobItem(); } } } $next_type = $prev_punch_obj->getNextType(); //Check for break policy window. if ($next_type != 30 and ($prev_punch_obj->getStatus() != 30 and $prev_punch_obj->getType() != 30)) { $prev_punch_obj->setUser($this->getUserObject()->getId()); $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($epoch)); if ($prev_punch_obj->inBreakPolicyWindow($epoch, $prev_punch_obj->getTimeStamp()) == TRUE) { Debug::Text(' Setting Type to Break: ', __FILE__, __LINE__, __METHOD__, 10); $next_type = 30; } } //Check for meal policy window. if ($next_type != 20 and ($prev_punch_obj->getStatus() != 20 and $prev_punch_obj->getType() != 20)) { $prev_punch_obj->setUser($this->getUserObject()->getId()); $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($epoch)); if ($prev_punch_obj->inMealPolicyWindow($epoch, $prev_punch_obj->getTimeStamp()) == TRUE) { Debug::Text(' Setting Type to Lunch: ', __FILE__, __LINE__, __METHOD__, 10); $next_type = 20; } } Debug::Text(' cJob Item ID: ' . $job_item_id, __FILE__, __LINE__, __METHOD__, 10); $note = ''; if ((int) $prev_punch_obj->getNextStatus() == 20) { $note = $prev_punch_obj->getPunchControlObject()->getNote(); } $data = array('user_id' => (int) $this->getUserObject()->getId(), 'user_full_name' => $this->getUserObject()->getFullName(), 'time_stamp' => TTDate::getDate('TIME', $epoch), 'date_stamp' => TTDate::getDate('DATE', $epoch), 'full_time_stamp' => $epoch, 'iso_time_stamp' => TTDate::getDBTimeStamp($epoch, FALSE), 'transfer' => $transfer, 'branch_id' => (int) $branch_id, 'department_id' => (int) $department_id, 'job_id' => $job_id, 'job_item_id' => $job_item_id, 'quantity' => $prev_punch_obj->getPunchControlObject()->getQuantity(), 'bad_quantity' => $prev_punch_obj->getPunchControlObject()->getBadQuantity(), 'note' => (string) $note, 'other_id1' => $prev_punch_obj->getPunchControlObject()->getOtherID1(), 'other_id2' => $prev_punch_obj->getPunchControlObject()->getOtherID2(), 'other_id3' => $prev_punch_obj->getPunchControlObject()->getOtherID3(), 'other_id4' => $prev_punch_obj->getPunchControlObject()->getOtherID4(), 'other_id5' => $prev_punch_obj->getPunchControlObject()->getOtherID5(), 'status_id' => (int) $prev_punch_obj->getNextStatus(), 'type_id' => (int) $next_type, 'punch_control_id' => (int) $prev_punch_obj->getNextPunchControlID()); unset($note); } else { Debug::Text(' DID NOT Find Previous Punch within Continuous Time from now: ', __FILE__, __LINE__, __METHOD__, 10); //These used to be NULLs, but as of TT v3.0 they cause deserilizer errors with a Java client. $branch_id = ''; $department_id = ''; $job_id = ''; $job_item_id = ''; $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($this->getUserObject()->getId(), $epoch); if (is_object($s_obj)) { Debug::Text(' Found Schedule! ID:' . $s_obj->getID() . ' Job ID: ' . $s_obj->getJob(), __FILE__, __LINE__, __METHOD__, 10); $branch_id = $s_obj->getBranch(); $department_id = $s_obj->getDepartment(); $job_id = $s_obj->getJob(); $job_item_id = $s_obj->getJobItem(); } else { //Check for defaults $branch_id = $this->getUserObject()->getDefaultBranch(); $department_id = $this->getUserObject()->getDefaultDepartment(); //Check station for default/forced settings. if (is_object($this->getStationObject())) { if ($this->getStationObject()->getDefaultBranch() !== FALSE and $this->getStationObject()->getDefaultBranch() != 0) { $branch_id = $this->getStationObject()->getDefaultBranch(); } if ($this->getStationObject()->getDefaultDepartment() !== FALSE and $this->getStationObject()->getDefaultDepartment() != 0) { $department_id = $this->getStationObject()->getDefaultDepartment(); } if ($this->getStationObject()->getDefaultJob() !== FALSE and $this->getStationObject()->getDefaultJob() != 0) { $job_id = $this->getStationObject()->getDefaultJob(); } if ($this->getStationObject()->getDefaultJobItem() !== FALSE and $this->getStationObject()->getDefaultJobItem() != 0) { $job_item_id = $this->getStationObject()->getDefaultJobItem(); } } } $data = array('user_id' => (int) $this->getUserObject()->getId(), 'user_full_name' => $this->getUserObject()->getFullName(), 'time_stamp' => TTDate::getDate('TIME', $epoch), 'date_stamp' => TTDate::getDate('DATE', $epoch), 'full_time_stamp' => $epoch, 'iso_time_stamp' => TTDate::getDBTimeStamp($epoch, FALSE), 'transfer' => FALSE, 'branch_id' => (int) $branch_id, 'department_id' => (int) $department_id, 'job_id' => $job_id, 'job_item_id' => $job_item_id, 'status_id' => 10, 'type_id' => 10); } //Get options. $blf = new BranchListFactory(); $blf->getByCompanyId($this->getCompanyObject()->getId()); $branch_options = $blf->getArrayByListFactory($blf, TRUE, FALSE); $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($this->getCompanyObject()->getId()); $department_options = $dlf->getArrayByListFactory($dlf, TRUE, FALSE); $job_options = array(); $job_item_options = array(); if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL) { $jlf = new JobListFactory(); $job_options = $jlf->getByCompanyIdAndUserIdAndStatusArray($this->getCompanyObject()->getId(), $this->getUserObject()->getId(), array(10), TRUE); $jilf = new JobItemListFactory(); $job_item_options = $jilf->getByCompanyIdArray($this->getCompanyObject()->getId(), TRUE); } $pf = new PunchFactory(); //Select box options; $data['status_options'] = $pf->getOptions('status'); $data['type_options'] = $pf->getOptions('type'); $data['branch_options'] = $branch_options; $data['department_options'] = $department_options; $data['job_options'] = $job_options; $data['job_item_options'] = $job_item_options; //Hack for PHP v5.0.4 shotty SOAP. //If it can cast the first array key to a INT, it rekeys the entire array. //02-Nov-09: Using NULL values causes the Java client to throw a deserlizer error. Using '' causes blank entries. /* $data['status_options'] = Misc::prependArray( array('_' => FALSE ), $data['status_options'] ); $data['type_options'] = Misc::prependArray( array('_' => FALSE ), $data['type_options'] ); $data['branch_options'] = Misc::prependArray( array('_' => FALSE ), $data['branch_options'] ); $data['department_options'] = Misc::prependArray( array('_' => FALSE ), $data['department_options'] ); $data['job_options'] = Misc::prependArray( array('_' => FALSE ), $data['job_options'] ); $data['job_item_options'] = Misc::prependArray( array('_' => FALSE ), $data['job_item_options'] ); */ $data['timeout'] = 5; $data['date_format_example'] = (string) $this->getUserObject()->getUserPreferenceObject()->getDateFormatExample(); $data['time_format_example'] = (string) $this->getUserObject()->getUserPreferenceObject()->getTimeFormatExample(); //Debug::Arr($data, 'punchDataArray', __FILE__, __LINE__, __METHOD__,10); if (!$this->getPermissionObject()->Check('job', 'enabled')) { unset($data['job_options']); unset($data['job_item_options']); } //Debug::Arr($data, 'Return Data: ', __FILE__, __LINE__, __METHOD__,10); return $data; }
function setOfflinePunch($data) { Debug::Text('Setting Offline Punches... Rows: ' . count($data), __FILE__, __LINE__, __METHOD__, 10); // //WHen in Offline mode, default Type/Status to "AUTO"... //That way once I get the punches, I can determine what they should be on my end. // if (!is_array($data) or count($data) == 0) { return FALSE; } ksort($data); //Debug::Arr($data, 'offlinePunchDataArr', __FILE__, __LINE__, __METHOD__,10); /* //Original $data[] = array( 'user_id' => 1, 'time_stamp' => '12:00 PM', 'date_stamp' => '03-Dec-05', 'branch_id' => 1, 'department_id' => NULL, 'status_id' => 20, 'type_id' => 20, 'punch_control_id' => 0, 'station_id' => '7D00000023352A81' ); */ /* unset($data); $data[] = array( 'user_id' => 1001, 'time_stamp' => '08:00 AM', 'date_stamp' => '05-Dec-05', 'branch_id' => 5, 'department_id' => 3, 'status_id' => 0, 'type_id' => 0, 'punch_control_id' => 0, 'station_id' => '7D00000023352A81' ); $data[] = array( 'user_id' => 1001, 'time_stamp' => '12:00 PM', 'date_stamp' => '05-Dec-05', 'branch_id' => 0, 'department_id' => 3, 'status_id' => 20, 'type_id' => 0, 'punch_control_id' => 0, 'station_id' => '7D00000023352A81' ); */ /* $data[] = array( 'user_id' => 1001, 'time_stamp' => '1:00 PM', 'date_stamp' => '05-Dec-05', 'branch_id' => 6, 'department_id' => 0, 'status_id' => 0, 'type_id' => 20, 'punch_control_id' => 0, 'station_id' => '7D00000023352A81' ); */ /* $data[] = array( 'user_id' => 1001, 'time_stamp' => '5:00 PM', 'date_stamp' => '05-Dec-05', 'branch_id' => 0, 'department_id' => 0, 'status_id' => 0, 'type_id' => 0, 'punch_control_id' => 0, 'station_id' => '7D00000023352A81' ); */ //Debug::Arr($data, 'offlinePunchDataArr', __FILE__, __LINE__, __METHOD__,10); //One punch per row foreach ($data as $row_key => $punch_row) { Debug::Text('--------------------------========================---------------------------', __FILE__, __LINE__, __METHOD__, 10); Debug::Text('--------------------------========================---------------------------', __FILE__, __LINE__, __METHOD__, 10); Debug::Text('Row Key: ' . $row_key . ' Date: ' . $punch_row['date_stamp'] . ' Time: ' . $punch_row['time_stamp'] . ' Station ID: ' . $punch_row['station_id'], __FILE__, __LINE__, __METHOD__, 10); if (isset($punch_row['station_id'])) { $slf = new StationListFactory(); $slf->getByStationId($punch_row['station_id']); if ($slf->getRecordCount() > 0) { Debug::Text('Found Station Data...', __FILE__, __LINE__, __METHOD__, 10); $current_station = $slf->getCurrent(); } else { Debug::Text('DID NOT Find Station Data...', __FILE__, __LINE__, __METHOD__, 10); continue; } unset($slf); } if (isset($punch_row['user_id']) and $punch_row['user_id'] != '') { $ulf = new UserListFactory(); $ulf->getById($punch_row['user_id']); if ($ulf->getRecordCount() > 0) { $current_user = $ulf->getCurrent(); Debug::Text('Valid User ID: ' . $punch_row['user_id'] . ' User Name: ' . $current_user->getFullName(), __FILE__, __LINE__, __METHOD__, 10); //Need to handle timezone somehow. The station should send us the system's timezone //so we can calculate based on that. //Or just use the employees date preference. $current_user->getUserPreferenceObject()->setDateTimePreferences(); } else { Debug::Text('aInValid User ID: ' . $punch_row['user_id'], __FILE__, __LINE__, __METHOD__, 10); continue; } } else { Debug::Text('bInValid User ID: ' . $punch_row['user_id'], __FILE__, __LINE__, __METHOD__, 10); continue; } //Check to make sure the station is allowed. if (is_object($current_station) and is_object($current_user) and $current_station->checkAllowed($current_user->getId(), $current_station->getStation(), $current_station->getType()) == FALSE) { Debug::text('Station NOT allowed: Station ID: ' . $current_station->getId() . ' User: '******'date_stamp'] . ' ' . $punch_row['time_stamp']); //Make sure time stamp converts properly, otherwise skip this punch. if (!is_int($punch_full_time_stamp)) { Debug::Text('Failed TimeStamp: ' . $punch_full_time_stamp, __FILE__, __LINE__, __METHOD__, 10); continue; } Debug::Text('Punch Date/Time: ' . $punch_full_time_stamp . ' Offset that was already applied: ' . $punch_row['offset'], __FILE__, __LINE__, __METHOD__, 10); $fail_transaction = FALSE; $pf = new PunchFactory(); $pf->StartTransaction(); $slf = new ScheduleListFactory(); //Auto Punch if (isset($punch_row['status_id']) and $punch_row['status_id'] == 0 or isset($punch_row['type_id']) and $punch_row['type_id'] == 0 or isset($punch_row['branch_id']) and $punch_row['branch_id'] == 0 or isset($punch_row['department_id']) and $punch_row['department_id'] == 0 or isset($punch_row['job_id']) and $punch_row['job_id'] == 0 or isset($punch_row['job_item_id']) and $punch_row['job_item_id'] == 0) { $plf = new PunchListFactory(); $plf->getPreviousPunchByUserIDAndEpoch($punch_row['user_id'], $punch_full_time_stamp); if ($plf->getRecordCount() > 0) { Debug::Text(' Found Previous Punch within Continuous Time from now: ', __FILE__, __LINE__, __METHOD__, 10); $prev_punch_obj = $plf->getCurrent(); $branch_id = $prev_punch_obj->getPunchControlObject()->getBranch(); $department_id = $prev_punch_obj->getPunchControlObject()->getDepartment(); $job_id = $prev_punch_obj->getPunchControlObject()->getJob(); $job_item_id = $prev_punch_obj->getPunchControlObject()->getJobItem(); $quantity = $prev_punch_obj->getPunchControlObject()->getQuantity(); $bad_quantity = $prev_punch_obj->getPunchControlObject()->getBadQuantity(); if ($branch_id == '' or empty($branch_id) or $department_id == '' or empty($department_id)) { Debug::Text(' Branch or department are null. ', __FILE__, __LINE__, __METHOD__, 10); $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($punch_row['user_id'], $punch_full_time_stamp); if (is_object($s_obj)) { Debug::Text(' Found Schedule!: ', __FILE__, __LINE__, __METHOD__, 10); if ($branch_id == '' or empty($branch_id)) { Debug::Text(' overrriding branch: ' . $s_obj->getBranch(), __FILE__, __LINE__, __METHOD__, 10); $branch_id = $s_obj->getBranch(); } if ($department_id == '' or empty($department_id)) { Debug::Text(' overrriding department: ' . $s_obj->getDepartment(), __FILE__, __LINE__, __METHOD__, 10); $department_id = $s_obj->getDepartment(); } } } $type_id = $prev_punch_obj->getNextType(); $status_id = $prev_punch_obj->getNextStatus(); $next_type = $prev_punch_obj->getNextType(); //Check for break policy window. if ($next_type != 30 and ($prev_punch_obj->getStatus() != 30 and $prev_punch_obj->getType() != 30)) { $prev_punch_obj->setUser($current_user->getId()); $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($punch_full_time_stamp)); if ($prev_punch_obj->inBreakPolicyWindow($punch_full_time_stamp, $prev_punch_obj->getTimeStamp()) == TRUE) { Debug::Text(' Setting Type to Break: ', __FILE__, __LINE__, __METHOD__, 10); $next_type = 30; } } //Check for meal policy window. if ($next_type != 20 and ($prev_punch_obj->getStatus() != 20 and $prev_punch_obj->getType() != 20)) { $prev_punch_obj->setUser($current_user->getId()); $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($punch_full_time_stamp)); if ($prev_punch_obj->inMealPolicyWindow($punch_full_time_stamp, $prev_punch_obj->getTimeStamp()) == TRUE) { Debug::Text(' Setting Type to Lunch: ', __FILE__, __LINE__, __METHOD__, 10); $next_type = 20; } } } else { Debug::Text(' DID NOT Find Previous Punch within Continuous Time from now: ', __FILE__, __LINE__, __METHOD__, 10); $branch_id = NULL; $department_id = NULL; $job_id = NULL; $job_item_id = NULL; $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($punch_row['user_id'], $punch_full_time_stamp); if (is_object($s_obj)) { Debug::Text(' Found Schedule!: ', __FILE__, __LINE__, __METHOD__, 10); $branch_id = $s_obj->getBranch(); $department_id = $s_obj->getDepartment(); } else { $branch_id = $current_user->getDefaultBranch(); $department_id = $current_user->getDefaultDepartment(); //Check station for default/forced settings. if (is_object($current_station)) { if ($current_station->getDefaultBranch() !== FALSE and $current_station->getDefaultBranch() != 0) { $branch_id = $current_station->getDefaultBranch(); } if ($current_station->getDefaultDepartment() !== FALSE and $current_station->getDefaultDepartment() != 0) { $department_id = $current_station->getDefaultDepartment(); } if ($current_station->getDefaultJob() !== FALSE and $current_station->getDefaultJob() != 0) { $job_id = $current_station->getDefaultJob(); } if ($current_station->getDefaultJobItem() !== FALSE and $current_station->getDefaultJobItem() != 0) { $job_item_id = $current_station->getDefaultJobItem(); } } } $status_id = 10; //In $type_id = 10; //Normal } if (isset($punch_row['status_id']) and $punch_row['status_id'] != 0) { Debug::Text(' Status ID is NOT AUTO: ' . $punch_row['status_id'], __FILE__, __LINE__, __METHOD__, 10); $status_id = $punch_row['status_id']; } if (isset($punch_row['type_id']) and $punch_row['type_id'] != 0) { Debug::Text(' Type ID is NOT AUTO: ' . $punch_row['type_id'], __FILE__, __LINE__, __METHOD__, 10); $type_id = $punch_row['type_id']; } if (isset($punch_row['branch_id']) and $punch_row['branch_id'] != 0) { Debug::Text(' Branch ID is NOT AUTO: ' . $punch_row['branch_id'], __FILE__, __LINE__, __METHOD__, 10); $branch_id = $punch_row['branch_id']; } if (isset($punch_row['department_id']) and $punch_row['department_id'] != 0) { Debug::Text(' Department ID is NOT AUTO: ' . $punch_row['department_id'], __FILE__, __LINE__, __METHOD__, 10); $department_id = $punch_row['department_id']; } if (isset($punch_row['job_id']) and $punch_row['job_id'] != 0) { Debug::Text(' Job ID is NOT AUTO: ' . $punch_row['job_id'], __FILE__, __LINE__, __METHOD__, 10); $job_id = $punch_row['job_id']; } if (isset($punch_row['job_item_id']) and $punch_row['job_item_id'] != 0) { Debug::Text(' Job Item ID is NOT AUTO: ' . $punch_row['job_item_id'], __FILE__, __LINE__, __METHOD__, 10); $job_item_id = $punch_row['job_item_id']; } if (isset($punch_row['quantity'])) { Debug::Text(' Quantity is NOT AUTO: ' . $punch_row['quantity'], __FILE__, __LINE__, __METHOD__, 10); $quantity = $punch_row['quantity']; } if (isset($punch_row['bad_quantity'])) { Debug::Text(' Bad Quantity is NOT AUTO: ' . $punch_row['bad_quantity'], __FILE__, __LINE__, __METHOD__, 10); $bad_quantity = $punch_row['bad_quantity']; } } else { $status_id = $punch_row['status_id']; $type_id = $punch_row['type_id']; $branch_id = $punch_row['branch_id']; $department_id = $punch_row['department_id']; $job_id = $punch_row['job_id']; $job_item_id = $punch_row['job_item_id']; $quantity = $punch_row['quantity']; $bad_quantity = $punch_row['bad_quantity']; } //Set User before setTimeStamp so rounding can be done properly. $pf->setUser($punch_row['user_id']); if (isset($punch_row['transfer']) and $punch_row['transfer'] == 1) { Debug::Text(' Enabling Transfer!: ', __FILE__, __LINE__, __METHOD__, 10); $type_id = 10; $status_id = 10; $pf->setTransfer(TRUE); } $pf->setType($type_id); $pf->setStatus($status_id); $pf->setTimeStamp($punch_full_time_stamp, TRUE); //Make sure we round here. if (isset($status_id) and $status_id == 20 and isset($punch_row['punch_control_id']) and $punch_row['punch_control_id'] != '' and $punch_row['punch_control_id'] != 0) { $pf->setPunchControlID($punch_row['punch_control_id']); } else { $pf->setPunchControlID($pf->findPunchControlID()); } $pf->setStation($current_station->getId()); if ($pf->isNew()) { $pf->setActualTimeStamp($punch_full_time_stamp); $pf->setOriginalTimeStamp($pf->getTimeStamp()); } if ($pf->isValid() == TRUE) { if ($pf->Save(FALSE) == TRUE) { $pcf = new PunchControlFactory(); $pcf->setId($pf->getPunchControlID()); $pcf->setPunchObject($pf); if (isset($branch_id) and $branch_id != '') { $pcf->setBranch($branch_id); } if (isset($department_id) and $department_id != '') { $pcf->setDepartment($department_id); } if (isset($job_id) and $job_id != '') { $pcf->setJob($job_id); } if (isset($job_item_id) and $job_item_id != '') { $pcf->setJobItem($job_item_id); } if (isset($quantity) and $quantity != '') { $pcf->setQuantity($quantity); } if (isset($bad_quantity) and $bad_quantity != '') { $pcf->setBadQuantity($bad_quantity); } if (isset($punch_row['note']) and $punch_row['note'] != '') { $pcf->setNote($punch_row['note']); } if (isset($punch_row['other_id1']) and $punch_row['other_id1'] != '') { $pcf->setOtherID1($punch_row['other_id1']); } if (isset($punch_row['other_id2']) and $punch_row['other_id2'] != '') { $pcf->setOtherID2($punch_row['other_id2']); } if (isset($punch_row['other_id3']) and $punch_row['other_id3'] != '') { $pcf->setOtherID3($punch_row['other_id3']); } if (isset($punch_row['other_id4']) and $punch_row['other_id4'] != '') { $pcf->setOtherID4($punch_row['other_id4']); } if (isset($punch_row['other_id5']) and $punch_row['other_id5'] != '') { $pcf->setOtherID5($punch_row['other_id5']); } $pcf->setEnableStrictJobValidation(TRUE); $pcf->setEnableCalcUserDateID(TRUE); $pcf->setEnableCalcTotalTime(TRUE); $pcf->setEnableCalcSystemTotalTime(TRUE); $pcf->setEnableCalcUserDateTotal(TRUE); $pcf->setEnableCalcException(TRUE); $pcf->setEnablePreMatureException(TRUE); //Enable pre-mature exceptions at this point. if ($pcf->isValid() == TRUE) { Debug::Text(' Punch Control is valid, saving...: ', __FILE__, __LINE__, __METHOD__, 10); if ($pcf->Save(TRUE, TRUE) == TRUE) { //Force isNew() lookup. Debug::text('Saved Punch!', __FILE__, __LINE__, __METHOD__, 10); } else { Debug::text('PCF Save failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10); $fail_transaction = TRUE; } } else { Debug::text('PCF Validate failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10); $fail_transaction = TRUE; } } else { Debug::text('PF Save failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10); $fail_transaction = TRUE; } } else { Debug::text('PF Validate failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10); $fail_transaction = TRUE; } if ($fail_transaction == FALSE) { $pf->CommitTransaction(); } else { $pf->FailTransaction(); } unset($punch_full_time_stamp, $current_station, $current_user); //End Foreach } return TRUE; }
unset($ugd_obj); if (isset($id)) { BreadCrumb::setCrumb($title); $roelf = new ROEListFactory(); $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(); }