function getArrayByPolicyGroupUserId($user_id, $start_date, $end_date)
 {
     $hlf = new HolidayListFactory();
     $hlf->getByPolicyGroupUserIdAndStartDateAndEndDate($user_id, $start_date, $end_date);
     if ($hlf->getRecordCount() > 0) {
         foreach ($hlf as $h_obj) {
             $list[$h_obj->getDateStamp()] = $h_obj->getName();
         }
         return $list;
     }
     return FALSE;
 }
                                $off_duty = ($user_schedule_shift['start_time'] - $tmp_min_start_date) / 900;
                                //15 Min increments
                                $on_duty = ($user_schedule_shift['end_time'] - $user_schedule_shift['start_time']) / 900;
                                $user_schedule_shift['off_duty'] = $off_duty;
                                $user_schedule_shift['on_duty'] = $on_duty;
                                $schedule_shifts[$day_epoch][$branch][$department][$user_id][] = $user_schedule_shift;
                                $prev_user_schedule_shift = $user_schedule_shift;
                                $x++;
                            }
                        }
                    }
                }
            }
        }
        $smarty->assign_by_ref('header_hours', $header_hours);
        $smarty->assign_by_ref('total_span_hours', $total_span_hours);
        $smarty->assign('total_span_columns', $total_span_hours * 4 + 1);
        $smarty->assign('column_widths', round(floor(99 / $total_span_hours) / 4));
        $calendar_array = TTDate::getCalendarArray($start_date, $end_date, $current_user_prefs->getStartWeekDay(), FALSE);
        //var_dump($calendar_array);
        $smarty->assign_by_ref('calendar_array', $calendar_array);
        $hlf = new HolidayListFactory();
        $holiday_array = $hlf->getArrayByPolicyGroupUserId($user_ids, $start_date, $end_date);
        //var_dump($holiday_array);
        $smarty->assign_by_ref('holidays', $holiday_array);
        $smarty->assign_by_ref('schedule_shifts', $schedule_shifts);
        $smarty->assign_by_ref('schedule_shift_totals', $schedule_shift_totals);
        $smarty->assign_by_ref('do', $do);
        break;
}
$smarty->display('schedule/ViewScheduleLinear.tpl');
 function getScheduleArray($filter_data)
 {
     global $current_user, $current_user_prefs;
     //Get all schedule data by general filter criteria.
     Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__, 10);
     if (!isset($filter_data['start_date']) or $filter_data['start_date'] == '') {
         return FALSE;
     }
     if (!isset($filter_data['end_date']) or $filter_data['end_date'] == '') {
         return FALSE;
     }
     $filter_data['start_date'] = TTDate::getBeginDayEpoch($filter_data['start_date']);
     $filter_data['end_date'] = TTDate::getEndDayEpoch($filter_data['end_date']);
     $blf = new BranchListFactory();
     $branch_options = $blf->getByCompanyIdArray($current_user->getCompany(), FALSE);
     $dlf = new DepartmentListFactory();
     $department_options = $dlf->getByCompanyIdArray($current_user->getCompany(), FALSE);
     $slf = new ScheduleListFactory();
     $slf->getSearchByCompanyIdAndArrayCriteria($current_user->getCompany(), $filter_data);
     Debug::text('Found Scheduled Rows: ' . $slf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($slf->getRecordCount() > 0) {
         foreach ($slf as $s_obj) {
             Debug::text('Schedule ID: ' . $s_obj->getId() . ' User ID: ' . $s_obj->getColumn('user_id') . ' Start Time: ' . $s_obj->getStartTime(), __FILE__, __LINE__, __METHOD__, 10);
             if (is_object($s_obj->getAbsencePolicyObject())) {
                 $absence_policy_name = (string) $s_obj->getAbsencePolicyObject()->getName();
             } else {
                 $absence_policy_name = 'N/A';
             }
             $iso_date_stamp = TTDate::getISODateStamp($s_obj->getStartTime());
             $schedule_shifts[$iso_date_stamp][$s_obj->getColumn('user_id') . $s_obj->getStartTime()] = array('id' => (int) $s_obj->getID(), 'user_id' => (int) $s_obj->getColumn('user_id'), 'user_created_by' => (int) $s_obj->getColumn('user_created_by'), 'user_full_name' => Misc::getFullName($s_obj->getColumn('first_name'), NULL, $s_obj->getColumn('last_name'), FALSE, FALSE), 'first_name' => $s_obj->getColumn('first_name'), 'last_name' => $s_obj->getColumn('last_name'), 'status_id' => (int) $s_obj->getStatus(), 'date_stamp' => TTDate::getAPIDate('DATE', TTDate::parseDateTime($s_obj->getColumn('date_stamp'))), 'start_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $s_obj->getStartTime()) : $s_obj->getStartTime(), 'end_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $s_obj->getEndTime()) : $s_obj->getEndTime(), 'start_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $s_obj->getStartTime()) : $s_obj->getStartTime(), 'end_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $s_obj->getEndTime()) : $s_obj->getEndTime(), 'total_time' => $s_obj->getTotalTime(), 'schedule_policy_id' => (int) $s_obj->getSchedulePolicyID(), 'absence_policy_id' => (int) $s_obj->getAbsencePolicyID(), 'absence_policy' => $absence_policy_name, 'branch_id' => (int) $s_obj->getBranch(), 'branch' => Option::getByKey($s_obj->getBranch(), $branch_options, NULL), 'department_id' => (int) $s_obj->getDepartment(), 'department' => Option::getByKey($s_obj->getDepartment(), $department_options, NULL));
             $schedule_shifts_index[$iso_date_stamp][$s_obj->getColumn('user_id')][] = $s_obj->getColumn('user_id') . $s_obj->getStartTime();
             unset($absence_policy_name);
         }
         //Debug::Arr($schedule_shifts, 'Committed Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10);
         //Debug::Arr($schedule_shifts_index, 'Committed Schedule Shifts Index: ', __FILE__, __LINE__, __METHOD__, 10);
     } else {
         $schedule_shifts = array();
     }
     unset($slf);
     //Get holidays
     //FIXME: What if there are two holiday policies, one that defaults to working, and another that defaults to not working, and they are assigned
     //to two different groups of employees? For that matter what if the holiday policy isn't assigned to a specific user at all.
     $holiday_data = array();
     $hlf = new HolidayListFactory();
     $hlf->getByCompanyIdAndStartDateAndEndDate($current_user->getCompany(), $filter_data['start_date'], $filter_data['end_date']);
     Debug::text('Found Holiday Rows: ' . $hlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     foreach ($hlf as $h_obj) {
         if (is_object($h_obj->getHolidayPolicyObject()) and is_object($h_obj->getHolidayPolicyObject()->getAbsencePolicyObject())) {
             $holiday_data[TTDate::getISODateStamp($h_obj->getDateStamp())] = array('status_id' => (int) $h_obj->getHolidayPolicyObject()->getDefaultScheduleStatus(), 'absence_policy_id' => $h_obj->getHolidayPolicyObject()->getAbsencePolicyID(), 'absence_policy' => $h_obj->getHolidayPolicyObject()->getAbsencePolicyObject()->getName());
         } else {
             $holiday_data[TTDate::getISODateStamp($h_obj->getDateStamp())] = array('status_id' => 10);
             //Working
         }
     }
     unset($hlf);
     $recurring_schedule_shifts = array();
     $recurring_schedule_shifts_index = array();
     $rstlf = new RecurringScheduleTemplateListFactory();
     $rstlf->getSearchByCompanyIdAndArrayCriteria($current_user->getCompany(), $filter_data);
     Debug::text('Found Recurring Schedule Template Rows: ' . $rstlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($rstlf->getRecordCount() > 0) {
         foreach ($rstlf as $rst_obj) {
             //Debug::text('Recurring Schedule Template ID: '. $rst_obj->getID() , __FILE__, __LINE__, __METHOD__, 10);
             $rst_obj->getShifts($filter_data['start_date'], $filter_data['end_date'], $holiday_data, $branch_options, $department_options, &$schedule_shifts, &$schedule_shifts_index);
         }
     } else {
         Debug::text('DID NOT find Recurring Schedule for this time period: ', __FILE__, __LINE__, __METHOD__, 10);
     }
     //Debug::Arr($schedule_shifts, 'Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10);
     unset($schedule_shifts_index, $recurring_schedule_shifts_index);
     if (isset($schedule_shifts)) {
         return $schedule_shifts;
     }
     return FALSE;
 }
 function getTransactionBusinessDay($epoch)
 {
     Debug::Text('Epoch: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
     $holiday_epochs = array();
     $user_ids = $this->getUser();
     if (count($user_ids) > 0) {
         $hlf = new HolidayListFactory();
         $hlf->getByPolicyGroupUserIdAndStartDateAndEndDate($user_ids, $epoch - 86400 * 14, $epoch + 86400 * 2);
         if ($hlf->getRecordCount() > 0) {
             foreach ($hlf as $h_obj) {
                 Debug::Text('Found Holiday Epoch: ' . TTDate::getDate('DATE+TIME', $h_obj->getDateStamp()) . ' Name: ' . $h_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
                 $holiday_epochs[] = $h_obj->getDateStamp();
             }
             //Debug::Arr($holiday_epochs, 'Holiday Epochs: ', __FILE__, __LINE__, __METHOD__, 10);
         }
         while (TTDate::isWeekDay($epoch) == FALSE or in_array(TTDate::getBeginDayEpoch($epoch), $holiday_epochs)) {
             Debug::text('<b>FOUND WeekDay/HOLIDAY!</b>', __FILE__, __LINE__, __METHOD__, 10);
             switch ($this->getTransactionDateBusinessDay()) {
                 case 0:
                     //No adjustment
                     break 2;
                 case 1:
                     //Previous day
                     $epoch -= 86400;
                     break;
                 case 2:
                     //Next day
                     $epoch += 86400;
                     break;
                 case 3:
                     //Closest day
                     $forward_epoch = $epoch;
                     $forward_days = 0;
                     while (TTDate::isWeekDay($forward_epoch) == FALSE or in_array(TTDate::getBeginDayEpoch($forward_epoch), $holiday_epochs)) {
                         $forward_epoch += 86400;
                         $forward_days++;
                     }
                     $backward_epoch = $epoch;
                     $backward_days = 0;
                     while (TTDate::isWeekDay($backward_epoch) == FALSE or in_array(TTDate::getBeginDayEpoch($backward_epoch), $holiday_epochs)) {
                         $backward_epoch -= 86400;
                         $backward_days++;
                     }
                     if ($backward_days <= $forward_days) {
                         $epoch = $backward_epoch;
                     } else {
                         $epoch = $forward_epoch;
                     }
                     break;
             }
         }
     }
     return $epoch;
 }
 $recurring_schedule_days = $rsc_obj->getShiftsByStartDateAndEndDate($start_date, $end_date);
 //Debug::Arr($recurring_schedule_days, 'Recurring Schedule Shifts', __FILE__, __LINE__, __METHOD__, 10);
 if ($recurring_schedule_days !== FALSE) {
     foreach ($recurring_schedule_days as $date_stamp => $recurring_schedule_shifts) {
         Debug::text('Recurring Schedule Shift Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10);
         foreach ($recurring_schedule_shifts as $recurring_schedule_shift) {
             $recurring_schedule_shift_start_time = TTDate::strtotime($recurring_schedule_shift['start_time']);
             $recurring_schedule_shift_end_time = TTDate::strtotime($recurring_schedule_shift['end_time']);
             Debug::text('(After User TimeZone)Recurring Schedule Shift Start Time: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_start_time) . ' End Time: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_end_time), __FILE__, __LINE__, __METHOD__, 10);
             //Make sure punch pairs fall within limits
             if ($recurring_schedule_shift_start_time < $current_epoch + $add_shift_offset) {
                 Debug::text('Recurring Schedule Shift Start Time falls within Limits: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_start_time), __FILE__, __LINE__, __METHOD__, 10);
                 $status_id = 10;
                 //Working
                 //Is this a holiday?
                 $hlf = new HolidayListFactory();
                 $hlf->getByPolicyGroupUserIdAndDate($user_id, TTDate::getBeginDayEpoch($recurring_schedule_shift_start_time));
                 if ($hlf->getRecordCount() > 0) {
                     $h_obj = $hlf->getCurrent();
                     Debug::text('Found Holiday! Name: ' . $h_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
                     if ($h_obj->isEligible($user_id)) {
                         Debug::text('User is Eligible...', __FILE__, __LINE__, __METHOD__, 10);
                         //Get Holiday Policy info
                         $status_id = $h_obj->getHolidayPolicyObject()->getDefaultScheduleStatus();
                         $absence_policy_id = $h_obj->getHolidayPolicyObject()->getAbsencePolicyID();
                         Debug::text('Default Schedule Status: ' . $status_id, __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         Debug::text('User is NOT Eligible...', __FILE__, __LINE__, __METHOD__, 10);
                     }
                 } else {
                     Debug::text('No Holidays on this day: ', __FILE__, __LINE__, __METHOD__, 10);
 //Working
 //Make sure we not already added this schedule shift.
 //And that no schedule shifts overlap this one.
 //Use the isValid() function for this
 $sf = new ScheduleFactory();
 $sf->StartTransaction();
 $sf->setCompany($c_obj->getID());
 $sf->setUser($user_id);
 //Find the date that the shift will be assigned to so we know if its a holiday or not.
 if (is_object($sf->getPayPeriodScheduleObject())) {
     $date_stamp = $sf->getPayPeriodScheduleObject()->getShiftAssignedDate($recurring_schedule_shift_start_time, $recurring_schedule_shift_end_time, $sf->getPayPeriodScheduleObject()->getShiftAssignedDay());
 } else {
     $date_stamp = $recurring_schedule_shift_start_time;
 }
 //Is this a holiday?
 $hlf = new HolidayListFactory();
 $hlf->getByPolicyGroupUserIdAndDate($user_id, TTDate::getBeginDayEpoch($date_stamp));
 if ($hlf->getRecordCount() > 0) {
     $h_obj = $hlf->getCurrent();
     Debug::text('Found Holiday! Name: ' . $h_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
     //Ignore after holiday eligibility when scheduling, since it will always fail.
     if ($h_obj->isEligible($user_id, TRUE)) {
         Debug::text('User is Eligible...', __FILE__, __LINE__, __METHOD__, 10);
         //Get Holiday Policy info
         $status_id = $h_obj->getHolidayPolicyObject()->getDefaultScheduleStatus();
         $absence_policy_id = $h_obj->getHolidayPolicyObject()->getAbsencePolicyID();
         Debug::text('Default Schedule Status: ' . $status_id, __FILE__, __LINE__, __METHOD__, 10);
     } else {
         Debug::text('User is NOT Eligible...', __FILE__, __LINE__, __METHOD__, 10);
     }
 } else {
Example #7
0
        $hf->setId($data['id']);
        if (isset($data['holiday_policy_id'])) {
            $hf->setHolidayPolicyId($data['holiday_policy_id']);
        }
        //Set datestamp first.
        $hf->setDateStamp($data['date_stamp']);
        $hf->setName($data['name']);
        if ($hf->isValid()) {
            $hf->Save();
            Redirect::Page(URLBuilder::getURL(array('id' => $data['holiday_policy_id']), 'HolidayList.php'));
            break;
        }
    default:
        if (isset($id) and $id != '') {
            BreadCrumb::setCrumb($title);
            $hlf = new HolidayListFactory();
            $hlf->getByIdAndHolidayPolicyID($id, $holiday_policy_id);
            if ($hlf->getRecordCount() > 0) {
                foreach ($hlf as $h_obj) {
                    //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
                    $data = array('id' => $h_obj->getId(), 'holiday_policy_id' => $h_obj->getHolidayPolicyID(), 'date_stamp' => $h_obj->getDateStamp(), 'name' => $h_obj->getName(), 'created_date' => $h_obj->getCreatedDate(), 'created_by' => $h_obj->getCreatedBy(), 'updated_date' => $h_obj->getUpdatedDate(), 'updated_by' => $h_obj->getUpdatedBy(), 'deleted_date' => $h_obj->getDeletedDate(), 'deleted_by' => $h_obj->getDeletedBy());
                }
                $holiday_policy_id = $h_obj->getHolidayPolicyID();
            }
        } elseif ($action != 'submit') {
            $data = array('date_stamp' => TTDate::getTime(), 'holiday_policy_id' => $holiday_policy_id);
        }
        $smarty->assign_by_ref('holiday_policy_id', $holiday_policy_id);
        $smarty->assign_by_ref('data', $data);
        break;
}
Example #8
0
        }
        $hlf = new HolidayListFactory();
        foreach ($ids as $id) {
            $hlf->getById($id);
            foreach ($hlf as $h_obj) {
                $h_obj->setDeleted($delete);
                if ($h_obj->isValid()) {
                    $h_obj->Save();
                }
            }
        }
        Redirect::Page(URLBuilder::getURL(array('id' => $holiday_policy_id), 'HolidayList.php'));
        break;
    default:
        if (isset($id)) {
            BreadCrumb::setCrumb($title);
            $hlf = new HolidayListFactory();
            $hlf->getByCompanyIdAndHolidayPolicyId($current_company->getId(), $id);
            $pager = new Pager($hlf);
            foreach ($hlf as $h_obj) {
                $rows[] = array('id' => $h_obj->getId(), 'date_stamp' => $h_obj->getDateStamp(), 'name' => $h_obj->getName(), 'deleted' => $h_obj->getDeleted());
            }
        }
        $smarty->assign_by_ref('holiday_policy_id', $id);
        $smarty->assign_by_ref('rows', $rows);
        $smarty->assign_by_ref('sort_column', $sort_column);
        $smarty->assign_by_ref('sort_order', $sort_order);
        $smarty->assign_by_ref('paging_data', $pager->getPageVariables());
        break;
}
$smarty->display('policy/HolidayList.tpl');
 function getHolidayUserDateIDs()
 {
     Debug::text('reCalculating Holiday...', __FILE__, __LINE__, __METHOD__, 10);
     //Get Holiday policies and determine how many days we need to look ahead/behind in order
     //to recalculate the holiday eligilibility/time.
     $holiday_before_days = 0;
     $holiday_after_days = 0;
     $hplf = new HolidayPolicyListFactory();
     $hplf->getByCompanyId($this->getUserDateObject()->getUserObject()->getCompany());
     if ($hplf->getRecordCount() > 0) {
         foreach ($hplf as $hp_obj) {
             if ($hp_obj->getMinimumWorkedPeriodDays() > $holiday_before_days) {
                 $holiday_before_days = $hp_obj->getMinimumWorkedPeriodDays();
             }
             if ($hp_obj->getAverageTimeDays() > $holiday_before_days) {
                 $holiday_before_days = $hp_obj->getAverageTimeDays();
             }
             if ($hp_obj->getMinimumWorkedAfterPeriodDays() > $holiday_after_days) {
                 $holiday_after_days = $hp_obj->getMinimumWorkedAfterPeriodDays();
             }
         }
     }
     Debug::text('Holiday Before Days: ' . $holiday_before_days . ' Holiday After Days: ' . $holiday_after_days, __FILE__, __LINE__, __METHOD__, 10);
     if ($holiday_before_days > 0 or $holiday_after_days > 0) {
         $retarr = array();
         $search_start_date = TTDate::getBeginWeekEpoch($this->getUserDateObject()->getDateStamp() - $holiday_after_days * 86400);
         $search_end_date = TTDate::getEndWeekEpoch(TTDate::getEndDayEpoch($this->getUserDateObject()->getDateStamp()) + $holiday_before_days * 86400 + 3601);
         Debug::text('Holiday search start date: ' . TTDate::getDate('DATE', $search_start_date) . ' End date: ' . TTDate::getDate('DATE', $search_end_date) . ' Current Date: ' . TTDate::getDate('DATE', $this->getUserDateObject()->getDateStamp()), __FILE__, __LINE__, __METHOD__, 10);
         $hlf = new HolidayListFactory();
         //$hlf->getByPolicyGroupUserIdAndStartDateAndEndDate( $this->getUserDateObject()->getUser(), TTDate::getEndWeekEpoch( $this->getUserDateObject()->getDateStamp() )+86400, TTDate::getEndDayEpoch()+($max_average_time_days*86400)+3601 );
         $hlf->getByPolicyGroupUserIdAndStartDateAndEndDate($this->getUserDateObject()->getUser(), $search_start_date, $search_end_date);
         if ($hlf->getRecordCount() > 0) {
             Debug::text('Found Holidays within range: ' . $hlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             $udlf = new UserDateListFactory();
             foreach ($hlf as $h_obj) {
                 Debug::text('ReCalculating Day due to Holiday: ' . TTDate::getDate('DATE', $h_obj->getDateStamp()), __FILE__, __LINE__, __METHOD__, 10);
                 $user_date_ids = $udlf->getArrayByListFactory($udlf->getByUserIdAndDate($this->getUserDateObject()->getUser(), $h_obj->getDateStamp()));
                 if (is_array($user_date_ids)) {
                     $retarr = array_merge($retarr, $user_date_ids);
                 }
                 unset($user_date_ids);
             }
         }
     }
     if (isset($retarr) and is_array($retarr) and count($retarr) > 0) {
         //Debug::Arr($retarr, 'Holiday UserDateIDs: ', __FILE__, __LINE__, __METHOD__, 10);
         return $retarr;
     }
     Debug::text('No Holidays within range...', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }