Esempio n. 1
0
 function createSchedule($user_id, $date_stamp, $data = NULL)
 {
     $sf = new ScheduleFactory();
     $sf->setUserDateId(UserDateFactory::findOrInsertUserDate($user_id, $date_stamp));
     if (isset($data['status_id'])) {
         $sf->setStatus($data['status_id']);
     } else {
         $sf->setStatus(10);
     }
     if (isset($data['schedule_policy_id'])) {
         $sf->setSchedulePolicyID($data['schedule_policy_id']);
     }
     if (isset($data['absence_policy_id'])) {
         $sf->setAbsencePolicyID($data['absence_policy_id']);
     }
     if (isset($data['branch_id'])) {
         $sf->setBranch($data['branch_id']);
     }
     if (isset($data['department_id'])) {
         $sf->setDepartment($data['department_id']);
     }
     if (isset($data['job_id'])) {
         $sf->setJob($data['job_id']);
     }
     if (isset($data['job_item_id'])) {
         $sf->setJobItem($data['job_item_id']);
     }
     if ($data['start_time'] != '') {
         $start_time = strtotime($data['start_time'], $date_stamp);
     }
     if ($data['end_time'] != '') {
         Debug::Text('End Time: ' . $data['end_time'] . ' Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10);
         $end_time = strtotime($data['end_time'], $date_stamp);
         Debug::Text('bEnd Time: ' . $data['end_time'] . ' - ' . TTDate::getDate('DATE+TIME', $data['end_time']), __FILE__, __LINE__, __METHOD__, 10);
     }
     $sf->setStartTime($start_time);
     $sf->setEndTime($end_time);
     if ($sf->isValid()) {
         $sf->setEnableReCalculateDay(FALSE);
         $insert_id = $sf->Save();
         Debug::Text('Schedule ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
         return $insert_id;
     }
     Debug::Text('Failed Creating Schedule!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
 }
 if (isset($recurring_schedule_shift['job_item_id'])) {
     $sf->setJobItem($recurring_schedule_shift['job_item_id']);
 }
 if ($sf->isValid()) {
     //Recalculate if its a absence schedule, so the holiday
     //policy takes effect.
     //Always re-calculate, this way it automatically applies dock time and holiday time.
     //Recalculate at the end of the day in a cronjob.
     //Part of the reason is that if they have a dock policy, it will show up as
     //docking them time during the entire day.
     //$sf->setEnableReCalculateDay(FALSE);
     //Only for holidays do we calculate the day right away.
     //So they don't have to wait 24hrs to see stat time.
     if ($status_id == 20 and $rsc_obj->getAutoFill() == FALSE) {
         $sf->setEnableReCalculateDay(TRUE);
     } else {
         $sf->setEnableReCalculateDay(FALSE);
         //Don't need to re-calc right now?
     }
     $schedule_result = $sf->Save();
     $sf->CommitTransaction();
     $profiler->startTimer("Add Punch");
     Debug::text('Schedule Checks out, saving: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_start_time), __FILE__, __LINE__, __METHOD__, 10);
     if ($schedule_result == TRUE and $rsc_obj->getAutoFill() == TRUE and $status_id == 10) {
         //Make sure they are working for Auto-fill to kickin.
         Debug::text('Schedule has AutoFill enabled!', __FILE__, __LINE__, __METHOD__, 10);
         $commit_punch_transaction = FALSE;
         Debug::text('Punch In: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_start_time), __FILE__, __LINE__, __METHOD__, 10);
         $pf_in = new PunchFactory();
         $pf_in->StartTransaction();