$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) { $date_stamp = $pc_obj->getUserDateObject()->getDateStamp(); } $pc_data = array('id' => $pc_obj->getId(), 'user_id' => $pc_obj->getUserDateObject()->getUser(), 'user_full_name' => $pc_obj->getUserDateObject()->getUserObject()->getFullName(), 'date_stamp' => $date_stamp, 'user_date_id' => $pc_obj->getUserDateObject()->getId(), 'time_stamp' => $time_stamp, 'branch_id' => $pc_obj->getBranch(), 'department_id' => $pc_obj->getDepartment(), 'job_id' => $pc_obj->getJob(), 'job_item_id' => $pc_obj->getJobItem(), 'quantity' => (double) $pc_obj->getQuantity(), 'bad_quantity' => (double) $pc_obj->getBadQuantity(), 'note' => $pc_obj->getNote(), 'other_id1' => $pc_obj->getOtherID1(), 'other_id2' => $pc_obj->getOtherID2(), 'other_id3' => $pc_obj->getOtherID3(), 'other_id4' => $pc_obj->getOtherID4(), 'other_id5' => $pc_obj->getOtherID5(), 'status_id' => $status_id);
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; }
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 preSave() { if ($this->isNew()) { //Debug::text(' Setting Original TimeStamp: '. $this->getTimeStamp(), __FILE__, __LINE__, __METHOD__,10); $this->setOriginalTimeStamp($this->getTimeStamp()); } if ($this->getDeleted() == FALSE) { if ($this->getTransfer() == TRUE and $this->getEnableAutoTransfer() == TRUE) { Debug::text(' Transfer is Enabled, automatic punch out of last punch pair: ', __FILE__, __LINE__, __METHOD__, 10); //Check to make sure there is an open punch pair. $plf = new PunchListFactory(); $plf->getPreviousPunchByUserIdAndEpoch($this->getUser(), $this->getTimeStamp()); if ($plf->getRecordCount() > 0) { $p_obj = $plf->getCurrent(); Debug::text(' Found Last Punch: ', __FILE__, __LINE__, __METHOD__, 10); if ($p_obj->getStatus() == 10) { Debug::text(' Last Punch was in. Auto Punch Out now: ', __FILE__, __LINE__, __METHOD__, 10); //Make sure the current punch status is IN $this->setStatus(10); //In $this->setType(10); //Normal (can't transfer in/out of lunches?) $pf = new PunchFactory(); $pf->setUser($this->getUser()); $pf->setEnableAutoTransfer(FALSE); $pf->setPunchControlID($p_obj->getPunchControlID()); $pf->setTransfer(TRUE); $pf->setType($p_obj->getNextType()); $pf->setStatus(20); //Out $pf->setTimeStamp($this->getTimeStamp(), FALSE); //Disable rounding. $pf->setActualTimeStamp($this->getTimeStamp()); $pf->setOriginalTimeStamp($this->getTimeStamp()); if ($pf->isValid()) { if ($pf->Save(FALSE) == TRUE) { $p_obj->getPunchControlObject()->setEnableCalcTotalTime(TRUE); $p_obj->getPunchControlObject()->setEnableCalcSystemTotalTime(TRUE); $p_obj->getPunchControlObject()->setEnableCalcUserDateTotal(TRUE); $p_obj->getPunchControlObject()->setEnableCalcException(TRUE); $p_obj->getPunchControlObject()->setEnablePreMatureException(TRUE); if ($p_obj->getPunchControlObject()->isValid()) { $p_obj->getPunchControlObject()->Save(); } else { Debug::text(' aError saving auto out punch...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' bError saving auto out punch...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' cError saving auto out punch...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text(' Last Punch was out. No Auto Punch ', __FILE__, __LINE__, __METHOD__, 10); } } unset($plf, $p_obj, $pf); } //Split punch at midnight. //This has to be an Out punch, and the previous punch has to be an in punch in order for the split to occur. //Check to make sure there is an open punch pair. //Make sure this punch isn't right at midnight either, as no point in splitting a punch at that time. //FIXME: What happens if a supervisor edits a 11:30PM punch and makes it 5:00AM the next day? // We can't split punches when editing, because we have to split punch_control_ids prior to saving etc... if ($this->isNew() == TRUE and $this->getStatus() == 20 and $this->getEnableSplitAtMidnight() == TRUE and $this->getTimeStamp() != TTDate::getBeginDayEpoch($this->getTimeStamp()) and (is_object($this->getPunchControlObject()) and is_object($this->getPunchControlObject()->getPayPeriodScheduleObject()) and $this->getPunchControlObject()->getPayPeriodScheduleObject()->getShiftAssignedDay() == 40)) { $plf = new PunchListFactory(); $plf->getPreviousPunchByUserIdAndEpoch($this->getUser(), $this->getTimeStamp()); if ($plf->getRecordCount() > 0) { $p_obj = $plf->getCurrent(); Debug::text(' Found Last Punch: ', __FILE__, __LINE__, __METHOD__, 10); if ($p_obj->getStatus() == 10 and TTDate::doesRangeSpanMidnight($this->getTimeStamp(), $p_obj->getTimeStamp())) { Debug::text(' Last Punch was in and this is an out punch that spans midnight. Split Punch at midnight now: ', __FILE__, __LINE__, __METHOD__, 10); //FIXME: This will fail if a shift spans multiple days! //Make sure the current punch status is OUT //But we can split LUNCH/Break punches, because someone could punch in at 8PM, then out for lunch at 1:00AM, this would need to be split. $this->setStatus(20); //Out //Reduce the out punch by 60 seconds, and increase the current punch by 60seconds so no time is lost. $this->setTimeStamp($this->getTimeStamp() + 60); //FIXME: May need to use ActualTimeStamp here so we aren't double rounding. //Get new punch control ID for the midnight punch and this one. $new_punch_control_id = $this->getPunchControlObject()->getNextInsertId(); $this->setPunchControlID($new_punch_control_id); Debug::text(' Split Punch: Punching out just before midnight yesterday...', __FILE__, __LINE__, __METHOD__, 10); // //Punch out just before midnight // $pf = new PunchFactory(); $pf->setUser($this->getUser()); $pf->setEnableSplitAtMidnight(FALSE); $pf->setTransfer(FALSE); $pf->setEnableAutoTransfer(FALSE); $pf->setType(10); //Normal $pf->setStatus(20); //Out $before_midnight_timestamp = TTDate::getBeginDayEpoch($this->getTimeStamp()) - 60; $pf->setTimeStamp($before_midnight_timestamp, FALSE); //Disable rounding. $pf->setActualTimeStamp($before_midnight_timestamp); $pf->setOriginalTimeStamp($before_midnight_timestamp); $pf->setPunchControlID($p_obj->getPunchControlID()); if ($pf->isValid()) { if ($pf->Save(FALSE) == TRUE) { $p_obj->getPunchControlObject()->setEnableCalcTotalTime(TRUE); $p_obj->getPunchControlObject()->setEnableCalcSystemTotalTime(TRUE); $p_obj->getPunchControlObject()->setEnableCalcUserDateTotal(TRUE); $p_obj->getPunchControlObject()->setEnableCalcException(TRUE); $p_obj->getPunchControlObject()->setEnablePreMatureException(TRUE); $p_obj->getPunchControlObject()->Save(); } } unset($pf, $p_obj, $before_midnight_timestamp); Debug::text(' Split Punch: Punching int at midnight today...', __FILE__, __LINE__, __METHOD__, 10); // //Punch in again right at midnight. // $pf = new PunchFactory(); $pf->setUser($this->getUser()); $pf->setEnableSplitAtMidnight(FALSE); $pf->setTransfer(FALSE); $pf->setEnableAutoTransfer(FALSE); $pf->setType(10); //Normal $pf->setStatus(10); //In $at_midnight_timestamp = TTDate::getBeginDayEpoch($this->getTimeStamp()); $pf->setTimeStamp($at_midnight_timestamp, FALSE); //Disable rounding. $pf->setActualTimeStamp($at_midnight_timestamp); $pf->setOriginalTimeStamp($at_midnight_timestamp); $pf->setPunchControlID($new_punch_control_id); if ($pf->isValid()) { if ($pf->Save(FALSE) == TRUE) { $pcf = new PunchControlFactory(); $pcf->setId($pf->getPunchControlID()); $pcf->setPunchObject($pf); $pcf->setBranch($this->getPunchControlObject()->getBranch()); $pcf->setDepartment($this->getPunchControlObject()->getDepartment()); $pcf->setJob($this->getPunchControlObject()->getJob()); $pcf->setJobItem($this->getPunchControlObject()->getJobItem()); $pcf->setOtherID1($this->getPunchControlObject()->getOtherID1()); $pcf->setOtherID2($this->getPunchControlObject()->getOtherID2()); $pcf->setOtherID3($this->getPunchControlObject()->getOtherID3()); $pcf->setOtherID4($this->getPunchControlObject()->getOtherID4()); $pcf->setOtherID5($this->getPunchControlObject()->getOtherID5()); $pcf->setEnableStrictJobValidation(TRUE); $pcf->setEnableCalcUserDateID(TRUE); $pcf->setEnableCalcTotalTime(TRUE); $pcf->setEnableCalcSystemTotalTime(TRUE); $pcf->setEnableCalcWeeklySystemTotalTime(TRUE); $pcf->setEnableCalcUserDateTotal(TRUE); $pcf->setEnableCalcException(TRUE); if ($pcf->isValid() == TRUE) { $pcf->Save(TRUE, TRUE); //Force isNEW() lookup. } } } unset($pf, $at_midnight_timestamp, $new_punch_control_id); } else { Debug::text(' Last Punch was out. No Auto Punch ', __FILE__, __LINE__, __METHOD__, 10); } } } } return TRUE; }
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 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 the data we should need for this ROE in regards to pay period and such //Guess for end dates... //get User data for hire date $ulf = new UserListFactory(); $user_obj = $ulf->getById($user_id)->getCurrent(); $plf = new PunchListFactory(); //Is there a previous ROE? If so, find first shift back since ROE was issued. $rlf = new ROEListFactory(); $rlf->getLastROEByUserId($user_id); if ($rlf->getRecordCount() > 0) { $roe_obj = $rlf->getCurrent(); Debug::Text('Previous ROE Last Date: ' . TTDate::getDate('DATE+TIME', $roe_obj->getLastDate()), __FILE__, __LINE__, __METHOD__, 10); //$plf->getFirstPunchByUserIDAndEpoch( $user_id, $roe_obj->getLastDate() ); $plf->getNextPunchByUserIdAndEpoch($user_id, $roe_obj->getLastDate()); if ($plf->getRecordCount() > 0) { $first_date = $plf->getCurrent()->getTimeStamp(); } } if (!isset($first_date) or $first_date == '') { $first_date = $user_obj->getHireDate(); } Debug::Text('First Date: ' . TTDate::getDate('DATE+TIME', $first_date), __FILE__, __LINE__, __METHOD__, 10); //Get last shift worked (not scheduled) $plf->getLastPunchByUserId($user_id); if ($plf->getRecordCount() > 0) { $punch_obj = $plf->getCurrent(); $last_date = $punch_obj->getPunchControlObject()->getUserDateObject()->getDateStamp(); } else { $last_date = TTDate::getTime(); } Debug::Text('Last Punch Date: ' . TTDate::getDate('DATE+TIME', $last_date), __FILE__, __LINE__, __METHOD__, 10);