Exemplo n.º 1
0
 function createRecurringScheduleTemplate($company_id, $type, $schedule_policy_id = NULL)
 {
     $rstcf = new RecurringScheduleTemplateControlFactory();
     $rstcf->setCompany($company_id);
     switch ($type) {
         case 10:
             //Morning Shift
             $rstcf->setName('Morning Shift');
             $rstcf->setDescription('6:00AM - 3:00PM');
             if ($rstcf->isValid()) {
                 $rstc_id = $rstcf->Save();
                 Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10);
                 //Week 1
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(1);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('06:00 AM'));
                 $rstf->setEndTime(strtotime('03:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 return $rstc_id;
             }
             break;
         case 20:
             //Afternoon Shift
             $rstcf->setName('Afternoon Shift');
             $rstcf->setDescription('10:00AM - 7:00PM');
             if ($rstcf->isValid()) {
                 $rstc_id = $rstcf->Save();
                 Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10);
                 //Week 1
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(1);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('10:00 AM'));
                 $rstf->setEndTime(strtotime('07:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 return $rstc_id;
             }
             break;
         case 30:
             //Evening Shift
             $rstcf->setName('Evening Shift');
             $rstcf->setDescription('2:00PM - 11:00PM');
             if ($rstcf->isValid()) {
                 $rstc_id = $rstcf->Save();
                 Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10);
                 //Week 1
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(1);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('02:00 PM'));
                 $rstf->setEndTime(strtotime('11:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 return $rstc_id;
             }
             break;
         case 40:
             //Split Shift
             $rstcf->setName('Split Shift');
             $rstcf->setDescription('8:00AM-12:00PM, 5:00PM-9:00PM ');
             if ($rstcf->isValid()) {
                 $rstc_id = $rstcf->Save();
                 Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10);
                 //Week 1
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(1);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('08:00 AM'));
                 $rstf->setEndTime(strtotime('12:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 //Week 1
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(1);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('05:00 PM'));
                 $rstf->setEndTime(strtotime('9:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 return $rstc_id;
             }
             break;
         case 50:
             //Full Rotation
             $rstcf->setName('Full Rotation');
             $rstcf->setDescription('1wk-Morning, 1wk-Afternoon, 1wk-Evening');
             if ($rstcf->isValid()) {
                 $rstc_id = $rstcf->Save();
                 Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10);
                 //Week 1
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(1);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('06:00 AM'));
                 $rstf->setEndTime(strtotime('03:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 //Week 2
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(2);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('10:00 AM'));
                 $rstf->setEndTime(strtotime('07:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 //Week 3
                 $rstf = new RecurringScheduleTemplateFactory();
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek(3);
                 $rstf->setSun(FALSE);
                 $rstf->setMon(TRUE);
                 $rstf->setTue(TRUE);
                 $rstf->setWed(TRUE);
                 $rstf->setThu(TRUE);
                 $rstf->setFri(TRUE);
                 $rstf->setSat(FALSE);
                 $rstf->setStartTime(strtotime('02:00 PM'));
                 $rstf->setEndTime(strtotime('11:00 PM'));
                 if ($schedule_policy_id > 0) {
                     $rstf->setSchedulePolicyID($schedule_policy_id);
                 }
                 $rstf->setBranch('-1');
                 //Default
                 $rstf->setDepartment('-1');
                 //Default
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
                 return $rstc_id;
             }
             break;
     }
     Debug::Text('ERROR Saving schedule template!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
             Debug::Text('Row ID: ' . $week_row_id . ' Week: ' . $week_row['week'], __FILE__, __LINE__, __METHOD__, 10);
             if ($week_row['week'] != '' and $week_row['week'] > 0) {
                 $rstf->setRecurringScheduleTemplateControl($rstc_id);
                 $rstf->setWeek($week_row['week']);
                 $rstf->setSun($week_row['sun']);
                 $rstf->setMon($week_row['mon']);
                 $rstf->setTue($week_row['tue']);
                 $rstf->setWed($week_row['wed']);
                 $rstf->setThu($week_row['thu']);
                 $rstf->setFri($week_row['fri']);
                 $rstf->setSat($week_row['sat']);
                 $rstf->setStartTime($week_row['start_time']);
                 $rstf->setEndTime($week_row['end_time']);
                 $rstf->setSchedulePolicyID($week_row['schedule_policy_id']);
                 $rstf->setBranch($week_row['branch_id']);
                 $rstf->setDepartment($week_row['department_id']);
                 if (isset($week_row['job_id'])) {
                     $rstf->setJob($week_row['job_id']);
                 }
                 if (isset($week_row['job_item_id'])) {
                     $rstf->setJobItem($week_row['job_item_id']);
                 }
                 if ($rstf->isValid()) {
                     Debug::Text('Saving Week Row ID: ' . $week_row_id, __FILE__, __LINE__, __METHOD__, 10);
                     $rstf->Save();
                 }
             }
         }
     }
     $rstc_obj->CommitTransaction();
 }