$dlf->getByCompanyId($current_company->getId()); $department_options = Misc::prependArray($all_array_option, $dlf->getArrayByListFactory($dlf, FALSE, TRUE)); $filter_data['src_department_options'] = Misc::arrayDiffByKey((array) $filter_data['department_ids'], $department_options); $filter_data['selected_department_options'] = Misc::arrayIntersectByKey((array) $filter_data['department_ids'], $department_options); $filter_data['src_punch_branch_options'] = Misc::arrayDiffByKey((array) $filter_data['punch_branch_ids'], $branch_options); $filter_data['selected_punch_branch_options'] = Misc::arrayIntersectByKey((array) $filter_data['punch_branch_ids'], $branch_options); $filter_data['src_punch_department_options'] = Misc::arrayDiffByKey((array) $filter_data['punch_department_ids'], $department_options); $filter_data['selected_punch_department_options'] = Misc::arrayIntersectByKey((array) $filter_data['punch_department_ids'], $department_options); //Get employee titles $utlf = new UserTitleListFactory(); $utlf->getByCompanyId($current_company->getId()); $user_title_options = Misc::prependArray($all_array_option, $utlf->getArrayByListFactory($utlf, FALSE, TRUE)); $filter_data['src_user_title_options'] = Misc::arrayDiffByKey((array) $filter_data['user_title_ids'], $user_title_options); $filter_data['selected_user_title_options'] = Misc::arrayIntersectByKey((array) $filter_data['user_title_ids'], $user_title_options); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); //Get include job list. $jlf->getByCompanyId($current_company->getId()); $job_options = Misc::prependArray(array('0' => TTi18n::gettext('- No Job -')), $jlf->getArrayByListFactory($jlf, FALSE, TRUE)); $filter_data['job_manual_id_options'] = $jlf->getManualIDArrayByListFactory($jlf, TRUE); $filter_data['src_include_job_options'] = Misc::arrayDiffByKey((array) $filter_data['include_job_ids'], $job_options); $filter_data['selected_include_job_options'] = Misc::arrayIntersectByKey((array) $filter_data['include_job_ids'], $job_options); //Get exclude job list $exclude_job_options = Misc::prependArray($all_array_option, $jlf->getArrayByListFactory($jlf, FALSE, TRUE)); $filter_data['src_exclude_job_options'] = Misc::arrayDiffByKey((array) $filter_data['exclude_job_ids'], $job_options); $filter_data['selected_exclude_job_options'] = Misc::arrayIntersectByKey((array) $filter_data['exclude_job_ids'], $job_options); //Get Job Groups $jglf = new JobGroupListFactory(); $nodes = FastTree::FormatArray($jglf->getByCompanyIdArray($current_company->getId()), 'TEXT', TRUE); $job_group_options = Misc::prependArray($all_array_option, $jglf->getArrayByNodes($nodes, FALSE, TRUE)); $filter_data['src_job_group_options'] = Misc::arrayDiffByKey((array) $filter_data['job_group_ids'], $job_group_options);
$branch_options = $blf->getByCompanyIdArray($current_company->getId()); $dlf = new DepartmentListFactory(); $department_options = $dlf->getByCompanyIdArray($current_company->getId()); //Absence policies $otplf = new AbsencePolicyListFactory(); $absence_policy_options = $otplf->getByCompanyIDArray($current_company->getId(), TRUE); //Overtime policies $otplf = new OverTimePolicyListFactory(); $over_time_policy_options = $otplf->getByCompanyIDArray($current_company->getId(), TRUE); //Premium policies $pplf = new PremiumPolicyListFactory(); $premium_policy_options = $pplf->getByCompanyIDArray($current_company->getId(), TRUE); $job_options = array(); $job_item_options = array(); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $job_options = $jlf->getByCompanyIdArray($current_company->getId(), FALSE); $jilf = new JobItemListFactory(); $job_item_options = $jilf->getByCompanyIdArray($current_company->getId(), TRUE); } $day_total_time = array('total_time' => 0, 'worked_time' => 0, 'difference' => 0); foreach ($udtlf as $udt_obj) { if ($udt_obj->getStatus() == 20) { $day_total_time['worked_time'] += $udt_obj->getTotalTime(); } elseif ($udt_obj->getStatus() == 10 and $udt_obj->getType() == 10) { $day_total_time['total_time'] += $udt_obj->getTotalTime(); } if ($filter_system_time != 1 and $udt_obj->getStatus() == 10) { continue; } if ($udt_obj->getJob() != FALSE) {
$src_user_options = UserListFactory::getArrayByListFactory($ulf, FALSE, FALSE); $user_options = Misc::arrayDiffByKey((array) $filter_user_id, $src_user_options); $filter_user_options = Misc::arrayIntersectByKey((array) $filter_user_id, $src_user_options); $prepend_array_option = array(0 => '--', -1 => TTi18n::gettext('-- Default --')); $splf = new SchedulePolicyListFactory(); $schedule_policy_options = $splf->getByCompanyIdArray($current_company->getId()); $aplf = new AbsencePolicyListFactory(); $absence_policy_options = $aplf->getByCompanyIdArray($current_company->getId()); $blf = new BranchListFactory(); $blf->getByCompanyId($current_company->getId()); $branch_options = Misc::prependArray($prepend_array_option, $blf->getArrayByListFactory($blf, FALSE, TRUE)); $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($current_company->getId()); $department_options = Misc::prependArray($prepend_array_option, $dlf->getArrayByListFactory($dlf, FALSE, TRUE)); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $jlf->getByStatusIdAndCompanyId(array(10, 20, 30, 40), $current_company->getId()); //$jlf->getByCompanyIdAndUserIdAndStatus( $current_company->getId(), $data['user_id'], array(10,20,30,40) ); $data['job_options'] = $jlf->getArrayByListFactory($jlf, TRUE, TRUE); $data['job_manual_id_options'] = $jlf->getManualIDArrayByListFactory($jlf, TRUE); $jilf = new JobItemListFactory(); $jilf->getByCompanyId($current_company->getId()); $data['job_item_options'] = $jilf->getArrayByListFactory($jilf, TRUE); $data['job_item_manual_id_options'] = $jilf->getManualIdArrayByListFactory($jilf, TRUE); } //Select box options; $smarty->assign_by_ref('user_options', $user_options); $smarty->assign_by_ref('filter_user_options', $filter_user_options); $data['status_options'] = $sf->getOptions('status'); $data['schedule_policy_options'] = $schedule_policy_options; $data['absence_policy_options'] = $absence_policy_options;
function setJob($id) { $id = trim($id); if ($id == FALSE or $id == 0 or $id == '') { $id = 0; } if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL) { $jlf = new JobListFactory(); } if ($id == 0 or $this->Validator->isResultSetWithRows('job', $jlf->getByID($id), TTi18n::gettext('Job does not exist'))) { $this->data['job_id'] = $id; return TRUE; } return FALSE; }
function Validate() { Debug::text('Validating...', __FILE__, __LINE__, __METHOD__, 10); //Call this here so getShiftData can get the correct total time, before we call findUserDate. if ($this->getEnableCalcTotalTime() == TRUE) { $this->calcTotalTime(); } if (is_object($this->getPunchObject())) { $this->findUserDate(); } Debug::text('User Date Id: ' . $this->getUserDateID(), __FILE__, __LINE__, __METHOD__, 10); if ($this->getUserDateObject() == FALSE or $this->getUserDateObject()->getPayPeriodObject() == FALSE) { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Date/Time is incorrect, or pay period does not exist for this date. Please create a pay period schedule if you have not done so already')); } elseif ($this->getUserDateObject() == FALSE or $this->getUserDateObject()->getPayPeriodObject()->getIsLocked() == TRUE) { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Pay Period is Currently Locked')); } $plf = $this->getPLFByPunchControlID(); if ($plf !== NULL and ($this->isNew() and $plf->getRecordCount() == 2 or $plf->getRecordCount() > 2)) { //TTi18n::gettext('Punch Control can not have more than two punches. Please use the Add Punch button instead') //They might be trying to insert a punch inbetween two others? $this->Validator->isTRUE('punch_control', FALSE, TTi18n::gettext('Time conflicts with another punch on this day (c)')); } //Skip these checks if they are deleting a punch. if (is_object($this->getPunchObject()) and $this->getPunchObject()->getDeleted() == FALSE) { $shift_data = $this->getShiftData(); if (is_array($shift_data)) { foreach ($shift_data['punches'] as $punch_data) { //Make sure there aren't two In punches, or two Out punches in the same pair. //This fixes the bug where if you have an In punch, then click the blank cell below it //to add a new punch, but change the status from Out to In instead. if (isset($punches[$punch_data['punch_control_id']][$punch_data['status_id']])) { if ($punch_data['status_id'] == 10) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('In punches cannot occur twice in the same punch pair, you may want to make this an out punch instead')); } else { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('Out punches cannot occur twice in the same punch pair, you may want to make this an in punch instead')); } } Debug::text(' Current Punch Object: ID: ' . $this->getPunchObject()->getId() . ' TimeStamp: ' . $this->getPunchObject()->getTimeStamp() . ' Status: ' . $this->getPunchObject()->getStatus(), __FILE__, __LINE__, __METHOD__, 10); Debug::text(' Looping Punch Object: ID: ' . $punch_data['id'] . ' TimeStamp: ' . $punch_data['time_stamp'] . ' Status: ' . $punch_data['status_id'], __FILE__, __LINE__, __METHOD__, 10); //Check for another punch that matches the timestamp and status. if ($this->getPunchObject()->getID() != $punch_data['id']) { if ($this->getPunchObject()->getTimeStamp() == $punch_data['time_stamp'] and $this->getPunchObject()->getStatus() == $punch_data['status_id']) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('Time and status match that of another punch, this could be due to rounding (a)')); } } //Check for another punch that matches the timestamp and NOT status in the SAME punch pair. if ($this->getPunchObject()->getID() != $punch_data['id'] and $this->getID() == $punch_data['punch_control_id']) { if ($this->getPunchObject()->getTimeStamp() == $punch_data['time_stamp'] and $this->getPunchObject()->getStatus() != $punch_data['status_id']) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('Time matches another punch in the same punch pair, this could be due to rounding (b)')); } } $punches[$punch_data['punch_control_id']][$punch_data['status_id']] = $punch_data; } unset($punch_data); if (isset($punches[$this->getID()])) { Debug::text('Current Punch ID Id: ' . $this->getPunchObject()->getId() . ' Punch Control ID: ' . $this->getID() . ' Status: ' . $this->getPunchObject()->getStatus(), __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($punches, 'Punches Arr: ', __FILE__, __LINE__, __METHOD__,10); if ($this->getPunchObject()->getStatus() == 10 and isset($punches[$this->getID()][20]) and $this->getPunchObject()->getTimeStamp() > $punches[$this->getID()][20]['time_stamp']) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('In punches cannot occur after an out punch, in the same punch pair')); } elseif ($this->getPunchObject()->getStatus() == 20 and isset($punches[$this->getID()][10]) and $this->getPunchObject()->getTimeStamp() < $punches[$this->getID()][10]['time_stamp']) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('Out punches cannot occur before an in punch, in the same punch pair')); } else { Debug::text('bPunch does not match any other punch pair.', __FILE__, __LINE__, __METHOD__, 10); $punch_neighbors = Misc::getArrayNeighbors($punches, $this->getID(), 'both'); //Debug::Arr($punch_neighbors, ' Punch Neighbors: ', __FILE__, __LINE__, __METHOD__,10); if (isset($punch_neighbors['next']) and isset($punches[$punch_neighbors['next']])) { Debug::text('Found Next Punch...', __FILE__, __LINE__, __METHOD__, 10); if (isset($punches[$punch_neighbors['next']][10]) and $this->getPunchObject()->getTimeStamp() > $punches[$punch_neighbors['next']][10]['time_stamp'] or isset($punches[$punch_neighbors['next']][20]) and $this->getPunchObject()->getTimeStamp() > $punches[$punch_neighbors['next']][20]['time_stamp']) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('Time conflicts with another punch on this day') . ' (a)'); } } if (isset($punch_neighbors['prev']) and isset($punches[$punch_neighbors['prev']])) { Debug::text('Found prev Punch...', __FILE__, __LINE__, __METHOD__, 10); if (isset($punches[$punch_neighbors['prev']][10]) and $this->getPunchObject()->getTimeStamp() < $punches[$punch_neighbors['prev']][10]['time_stamp'] or isset($punches[$punch_neighbors['prev']][20]) and $this->getPunchObject()->getTimeStamp() < $punches[$punch_neighbors['prev']][20]['time_stamp']) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('Time conflicts with another punch on this day') . ' (b)'); } } } //Check to make sure punches don't exceed maximum shift time. $maximum_shift_time = $plf->getPayPeriodMaximumShiftTime($this->getPunchObject()->getUser()); Debug::text('aaaMaximum shift time: ' . $maximum_shift_time, __FILE__, __LINE__, __METHOD__, 10); if ($shift_data['total_time'] > $maximum_shift_time) { $this->Validator->isTRUE('time_stamp', FALSE, TTi18n::gettext('Punch exceeds maximum shift time of') . ' ' . TTDate::getTimeUnit($maximum_shift_time) . ' ' . TTi18n::getText('hrs set for this pay period schedule')); } } unset($punches); } } if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL and $this->getEnableStrictJobValidation() == TRUE) { if ($this->getJob() > 0) { $jlf = new JobListFactory(); $jlf->getById($this->getJob()); if ($jlf->getRecordCount() > 0) { $j_obj = $jlf->getCurrent(); if (is_object($this->getUserDateObject()) and $j_obj->isAllowedUser($this->getUserDateObject()->getUser()) == FALSE) { $this->Validator->isTRUE('job', FALSE, TTi18n::gettext('Employee is not assigned to this job')); } if ($j_obj->isAllowedItem($this->getJobItem()) == FALSE) { $this->Validator->isTRUE('job_item', FALSE, TTi18n::gettext('Task is not assigned to this job')); } } } } return TRUE; }
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 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; }
//Get all branches $blf = new BranchListFactory(); $blf->getByCompanyId($u_obj->getCompany()); $branch_options = $blf->getArrayByListFactory($blf, FALSE, TRUE); unset($blf); } if (!isset($department_options)) { //Get departments $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($u_obj->getCompany()); $department_options = $dlf->getArrayByListFactory($dlf, FALSE, TRUE); unset($dlf); } if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL and !isset($job_options)) { //Get jobs $jlf = new JobListFactory(); $jlf->getByCompanyId($u_obj->getCompany()); $job_options = $jlf->getArrayByListFactory($jlf, FALSE, TRUE); unset($jlf); } if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL and !isset($job_item_options)) { //Get tasks $jilf = new JobItemListFactory(); $jilf->getByCompanyId($u_obj->getCompany()); $job_item_options = $jilf->getArrayByListFactory($jilf, FALSE, TRUE); unset($jilf); } if (isset($mapped_row['time_stamp']) and $mapped_row['time_stamp'] != '') { $time_stamp_epoch = Misc::importCallInputParseFunction('time_stamp', $mapped_row['time_stamp'], $filtered_import_map['time_stamp']['default_value'], $filtered_import_map['time_stamp']['parse_hint']); } else { if (isset($mapped_row['start_time_stamp']) and $mapped_row['start_time_stamp'] != '') {
$dlf = new DepartmentListFactory(); $department_options = $dlf->getByCompanyIdArray($current_company->getId()); //Absence policies $otplf = new AbsencePolicyListFactory(); $absence_policy_options = $otplf->getByCompanyIDArray($current_company->getId(), TRUE); //Overtime policies $otplf = new OverTimePolicyListFactory(); $over_time_policy_options = $otplf->getByCompanyIDArray($current_company->getId(), TRUE); //Premium policies $pplf = new PremiumPolicyListFactory(); $premium_policy_options = $pplf->getByCompanyIDArray($current_company->getId(), TRUE); //Meal policies $mplf = new MealPolicyListFactory(); $meal_policy_options = $mplf->getByCompanyIDArray($current_company->getId(), TRUE); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $udt_data['job_options'] = $jlf->getByCompanyIdAndUserIdAndStatusArray($current_company->getId(), $udt_data['user_id'], array(10, 20, 30, 40), TRUE); $jilf = new JobItemListFactory(); $udt_data['job_item_options'] = $jilf->getByCompanyIdArray($current_company->getId(), TRUE); } //Select box options; $udt_data['status_options'] = $udtf->getOptions('status'); $udt_data['type_options'] = $udtf->getOptions('type'); $udt_data['branch_options'] = $branch_options; $udt_data['department_options'] = $department_options; $udt_data['absence_policy_options'] = $absence_policy_options; $udt_data['over_time_policy_options'] = $over_time_policy_options; $udt_data['premium_policy_options'] = $premium_policy_options; $udt_data['meal_policy_options'] = $meal_policy_options; //var_dump($pc_data); $smarty->assign_by_ref('udt_data', $udt_data);
} else { $data['user_id'] = $current_user->getId(); $data['user_full_name'] = $current_user->getFullName(); $data['time_stamp'] = $epoch; $data['date_stamp'] = $epoch; } $blf = new BranchListFactory(); $blf->getByCompanyId($current_company->getId()); $branch_options = $blf->getArrayByListFactory($blf, TRUE, FALSE); //$branch_options = $blf->getByCompanyIdArray( $current_company->getId() ); $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($current_company->getId()); $department_options = $dlf->getArrayByListFactory($dlf, TRUE, FALSE); //$department_options = $dlf->getByCompanyIdArray( $current_company->getId() ); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $jlf->getByCompanyIdAndUserIdAndStatus($current_company->getId(), $current_user->getId(), array(10)); $data['job_options'] = $jlf->getArrayByListFactory($jlf, TRUE, TRUE); $data['job_manual_id_options'] = $jlf->getManualIDArrayByListFactory($jlf, TRUE); $jilf = new JobItemListFactory(); $jilf->getByCompanyIdAndStatus($current_company->getId(), 10); $data['job_item_options'] = $jilf->getArrayByListFactory($jilf, TRUE, FALSE); $data['job_item_manual_id_options'] = $jilf->getManualIdArrayByListFactory($jilf, FALSE); } //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; //Get other field names $oflf = new OtherFieldListFactory();
function getJobOptions($user_id) { global $current_company; if (!is_object($current_company)) { return FALSE; } Debug::text('User ID: ' . $user_id . ' Company ID: ' . $current_company->getId(), __FILE__, __LINE__, __METHOD__, 10); $jlf = new JobListFactory(); return $jlf->getByCompanyIdAndUserIdAndStatusArray($current_company->getId(), $user_id, array(10, 20, 30, 40), TRUE); }
} $week_rows[$next_blank_id] = array('id' => $next_blank_id, 'week' => $last_week + 1, 'start_time' => $week_rows[$lowest_id]['start_time'], 'end_time' => $week_rows[$lowest_id]['end_time'], 'total_time' => $next_total_time, 'schedule_policy_id' => $week_rows[$lowest_id]['schedule_policy_id'], 'branch_id' => $week_rows[$lowest_id]['branch_id'], 'department_id' => $week_rows[$lowest_id]['department_id'], 'mon' => @$week_rows[$lowest_id]['mon'], 'tue' => @$week_rows[$lowest_id]['tue'], 'wed' => @$week_rows[$lowest_id]['wed'], 'thu' => @$week_rows[$lowest_id]['thu'], 'fri' => @$week_rows[$lowest_id]['fri'], 'sat' => @$week_rows[$lowest_id]['sat'], 'sun' => @$week_rows[$lowest_id]['sun']); } elseif ($action != 'submit' and $action != 'delete') { $week_rows[-1] = array('id' => -1, 'week' => 1, 'mon' => TRUE, 'tue' => TRUE, 'wed' => TRUE, 'thu' => TRUE, 'fri' => TRUE, 'start_time' => strtotime('08:00'), 'end_time' => strtotime('17:00'), 'total_time' => 9 * 3600, 'branch_id' => -1, 'department_id' => -1, 'schedule_policy_id' => 0); } $prepend_array_option = array(0 => '--', -1 => TTi18n::gettext('-- Default --')); //Select box options; $splf = new SchedulePolicyListFactory(); $data['schedule_options'] = $splf->getByCompanyIdArray($current_company->getId()); $blf = new BranchListFactory(); $blf->getByCompanyId($current_company->getId()); $data['branch_options'] = Misc::prependArray($prepend_array_option, $blf->getArrayByListFactory($blf, FALSE, TRUE)); //$data['branch_options'] = Misc::prependArray( array( -1 => '-- Default --' ), $blf->getByCompanyIdArray( $current_company->getId(), FALSE, FALSE ) ); $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($current_company->getId()); $data['department_options'] = Misc::prependArray($prepend_array_option, $dlf->getArrayByListFactory($dlf, FALSE, TRUE)); //$data['department_options'] = $dlf->getByCompanyIdArray( $current_company->getId() ); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $data['job_options'] = $jlf->getByCompanyIdAndStatusArray($current_company->getId(), array(10, 20, 30, 40), TRUE); $jilf = new JobItemListFactory(); $data['job_item_options'] = $jilf->getByCompanyIdArray($current_company->getId(), TRUE); } //var_dump($week_rows); $smarty->assign_by_ref('data', $data); $smarty->assign_by_ref('week_rows', $week_rows); break; } $smarty->assign_by_ref('rstcf', $rstcf); $smarty->assign_by_ref('rstf', $rstf); $smarty->display('schedule/EditRecurringScheduleTemplate.tpl');
//Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10); $data = array('id' => $s_obj->getId(), 'status' => $s_obj->getStatus(), 'type' => $s_obj->getType(), 'station' => $s_obj->getStation(), 'source' => $s_obj->getSource(), 'description' => $s_obj->getDescription(), 'port' => $s_obj->getPort(), 'user_name' => $s_obj->getUserName(), 'password' => $s_obj->getPassword(), 'poll_frequency' => $s_obj->getPollFrequency(), 'push_frequency' => $s_obj->getPushFrequency(), 'partial_push_frequency' => $s_obj->getPartialPushFrequency(), 'enable_auto_punch_status' => $s_obj->getEnableAutoPunchStatus(), 'mode_flag' => $s_obj->getModeFlag(), 'last_punch_time_stamp' => $s_obj->getLastPunchTimeStamp(), 'last_poll_date' => $s_obj->getLastPollDate(), 'last_push_date' => $s_obj->getLastPushDate(), 'last_partial_push_date' => $s_obj->getLastPartialPushDate(), 'branch_id' => $s_obj->getDefaultBranch(), 'department_id' => $s_obj->getDefaultDepartment(), 'job_id' => $s_obj->getDefaultJob(), 'job_item_id' => $s_obj->getDefaultJobItem(), 'time_zone_id' => $s_obj->getTimeZone(), 'group_selection_type_id' => $s_obj->getGroupSelectionType(), 'group_ids' => $s_obj->getGroup(), 'branch_selection_type_id' => $s_obj->getBranchSelectionType(), 'branch_ids' => $s_obj->getBranch(), 'department_selection_type_id' => $s_obj->getDepartmentSelectionType(), 'department_ids' => $s_obj->getDepartment(), 'include_user_ids' => $s_obj->getIncludeUser(), 'exclude_user_ids' => $s_obj->getExcludeUser(), 'created_date' => $s_obj->getCreatedDate(), 'created_by' => $s_obj->getCreatedBy(), 'updated_date' => $s_obj->getUpdatedDate(), 'updated_by' => $s_obj->getUpdatedBy(), 'deleted_date' => $s_obj->getDeletedDate(), 'deleted_by' => $s_obj->getDeletedBy()); } } elseif ($action != 'submit' and $action != 'time_clock_command') { $data = array('status' => 20, 'port' => 80, 'password' => 0, 'poll_frequency' => 600, 'push_frequency' => 86400, 'partial_push_frequency' => 3600); } $data = Misc::preSetArrayValues($data, array('branch_ids', 'department_ids', 'group_ids', 'include_user_ids', 'exclude_user_ids'), NULL); //Select box options; $data['status_options'] = $sf->getOptions('status'); $data['type_options'] = $sf->getOptions('type'); $data['poll_frequency_options'] = $sf->getOptions('poll_frequency'); $data['push_frequency_options'] = $sf->getOptions('push_frequency'); $data['time_clock_command_options'] = $sf->getOptions('time_clock_command'); $data['mode_flag_options'] = $sf->getOptions('mode_flag'); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $jlf->getByCompanyId($current_company->getId()); $data['job_options'] = Misc::prependArray(array(0 => '-- None --'), $jlf->getArrayByListFactory($jlf, FALSE, TRUE)); $jilf = new JobItemListFactory(); $jilf->getByCompanyIdAndStatus($current_company->getId(), 10); $data['job_item_options'] = Misc::prependArray(array(0 => '-- None --'), $jilf->getArrayByListFactory($jilf, TRUE, FALSE)); } //Get branches $blf = new BranchListFactory(); $blf->getByCompanyId($current_company->getId()); $branch_options = $blf->getArrayByListFactory($blf, FALSE, TRUE); $data['src_branch_options'] = Misc::arrayDiffByKey((array) $data['branch_ids'], $branch_options); $data['selected_branch_options'] = Misc::arrayIntersectByKey((array) $data['branch_ids'], $branch_options); //Get departments $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($current_company->getId());
$data['selected_branch_options'] = Misc::arrayIntersectByKey((array) $data['branch_ids'], $branch_options); //Get departments $dlf = new DepartmentListFactory(); $dlf->getByCompanyId($current_company->getId()); $department_options = $dlf->getArrayByListFactory($dlf, FALSE, TRUE); $data['src_department_options'] = Misc::arrayDiffByKey((array) $data['department_ids'], $department_options); $data['selected_department_options'] = Misc::arrayIntersectByKey((array) $data['department_ids'], $department_options); if ($current_company->getProductEdition() == 20) { //Get Job Groups $jglf = new JobGroupListFactory(); $nodes = FastTree::FormatArray($jglf->getByCompanyIdArray($current_company->getId()), 'TEXT', TRUE); $job_group_options = $jglf->getArrayByNodes($nodes, FALSE, FALSE); $data['src_job_group_options'] = Misc::arrayDiffByKey((array) $data['job_group_ids'], $job_group_options); $data['selected_job_group_options'] = Misc::arrayIntersectByKey((array) $data['job_group_ids'], $job_group_options); //Get Jobs $jlf = new JobListFactory(); $jlf->getByCompanyId($current_company->getId()); $job_options = $jlf->getArrayByListFactory($jlf, FALSE, TRUE); $data['src_job_options'] = Misc::arrayDiffByKey((array) $data['job_ids'], $job_options); $data['selected_job_options'] = Misc::arrayIntersectByKey((array) $data['job_ids'], $job_options); //Get Job Item Groups $jiglf = new JobItemGroupListFactory(); $nodes = FastTree::FormatArray($jiglf->getByCompanyIdArray($current_company->getId()), 'TEXT', TRUE); $job_item_group_options = $jiglf->getArrayByNodes($nodes, FALSE, FALSE); $data['src_job_item_group_options'] = Misc::arrayDiffByKey((array) $data['job_item_group_ids'], $job_item_group_options); $data['selected_job_item_group_options'] = Misc::arrayIntersectByKey((array) $data['job_item_group_ids'], $job_item_group_options); //Get Job Items $jilf = new JobItemListFactory(); $jilf->getByCompanyId($current_company->getId()); $job_item_options = $jilf->getArrayByListFactory($jilf, FALSE, TRUE); $data['src_job_item_options'] = Misc::arrayDiffByKey((array) $data['job_item_ids'], $job_item_options);
*/ $ulf = new UserListFactory(); $ulf->getByIdAndCompanyId($user_id, $current_company->getId()); if ($ulf->getRecordCount() > 0) { $user_obj = $ulf->getCurrent(); $pc_data = array('user_id' => $user_obj->getId(), 'user_full_name' => $user_obj->getFullName(), 'date_stamp' => $date_stamp, 'time_stamp' => $time_stamp, 'status_id' => $status_id, 'branch_id' => $user_obj->getDefaultBranch(), 'department_id' => $user_obj->getDefaultDepartment(), 'quantity' => 0, 'bad_quantity' => 0); } unset($time_stamp, $plf); } } $blf = new BranchListFactory(); $branch_options = $blf->getByCompanyIdArray($current_company->getId()); $dlf = new DepartmentListFactory(); $department_options = $dlf->getByCompanyIdArray($current_company->getId()); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $jlf->getByCompanyIdAndUserIdAndStatus($current_company->getId(), $pc_data['user_id'], array(10, 20, 30, 40)); $pc_data['job_options'] = $jlf->getArrayByListFactory($jlf, TRUE, TRUE); $pc_data['job_manual_id_options'] = $jlf->getManualIDArrayByListFactory($jlf, TRUE); $jilf = new JobItemListFactory(); $jilf->getByCompanyId($current_company->getId()); $pc_data['job_item_options'] = $jilf->getArrayByListFactory($jilf, TRUE, TRUE); $pc_data['job_item_manual_id_options'] = $jilf->getManualIdArrayByListFactory($jilf, TRUE); } //Select box options; $pc_data['status_options'] = $pf->getOptions('status'); $pc_data['type_options'] = $pf->getOptions('type'); $pc_data['branch_options'] = $branch_options; $pc_data['department_options'] = $department_options; //Get other field names $oflf = new OtherFieldListFactory();
function setJob($ids) { if (getTTProductEdition() != TT_PRODUCT_PROFESSIONAL) { return FALSE; } Debug::text('Setting IDs...', __FILE__, __LINE__, __METHOD__, 10); if (is_array($ids)) { $tmp_ids = array(); if (!$this->isNew()) { //If needed, delete mappings first. $lf_a = new PremiumPolicyJobListFactory(); $lf_a->getByPremiumPolicyId($this->getId()); foreach ($lf_a as $obj) { $id = $obj->getjob(); Debug::text('job ID: ' . $obj->getJob() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //Delete users that are not selected. if (!in_array($id, $ids)) { Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10); $obj->Delete(); } else { //Save ID's that need to be updated. Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10); $tmp_ids[] = $id; } } unset($id, $obj); } //Insert new mappings. $lf_b = new JobListFactory(); foreach ($ids as $id) { if (isset($ids) and $id > 0 and !in_array($id, $tmp_ids)) { $f = new PremiumPolicyJobFactory(); $f->setPremiumPolicy($this->getId()); $f->setJob($id); $obj = $lf_b->getById($id)->getCurrent(); if ($this->Validator->isTrue('job', $f->Validator->isValid(), TTi18n::gettext('Selected Job is invalid') . ' (' . $obj->getName() . ')')) { $f->save(); } } } return TRUE; } Debug::text('No IDs to set.', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
function getJobtoUserMap($station_id) { //If the user is not in the list, that means they are allowed to ALL jobs. Debug::Text('Getting JobToUser Map for Station ID: ' . $station_id, __FILE__, __LINE__, __METHOD__, 10); if ($station_id == '') { return FALSE; } if (getTTProductEdition() != TT_PRODUCT_PROFESSIONAL) { return FALSE; } $slf = new StationListFactory(); $slf->getByStationID($station_id); if ($slf->getRecordCount() > 0) { $s_obj = $slf->getCurrent(); $company_id = $s_obj->getCompany(); Debug::Text('Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10); if ($company_id != FALSE) { //Gets all users allowed to punch in/out from this station $jlf = new JobListFactory(); $job_to_user_map = $jlf->getJobToUserMapByCompanyIdAndStatus($company_id, 10); if (is_array($job_to_user_map)) { foreach ($job_to_user_map as $key => $arr) { $list["'{$key}'"] = array('job_id' => (int) $arr['job_id'], 'user_id' => (int) $arr['user_id']); } if (isset($list)) { return $list; } } /* $jualf = new JobUserAllowListFactory(); $jualf->getByCompanyIdAndStatus( $company_id, 10); if ( $jualf->getRecordCount() > 0 ) { $x=0; foreach( $jualf as $jua_obj) { $list["'$x'"] = array( 'job_id' => (int)$jua_obj->getJob(), 'user_id' => (int)$jua_obj->getUser(), ); $x++; } if ( isset($list) ) { return $list; } } */ } } Debug::Text('Returning FALSE!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
function setDefaultJob($id) { $id = trim($id); if ($id == FALSE or $id == 0 or $id == '') { $id = 0; } Debug::Text('Job ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10); if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL) { $jlf = new JobListFactory(); } if ($id == 0 or $this->Validator->isResultSetWithRows('job_id', $jlf->getByID($id), TTi18n::gettext('Invalid Job'))) { $this->data['job_id'] = $id; return TRUE; } return FALSE; }