function getShiftData($user_date_id = NULL, $user_id = NULL, $epoch = NULL, $filter = NULL, $tmp_punch_control_obj = NULL, $maximum_shift_time = NULL, $new_shift_trigger_time = NULL, $plf = NULL)
 {
     global $profiler;
     $profiler->startTimer('PayPeriodScheduleFactory::getShiftData()');
     if (is_numeric($user_date_id) and $user_date_id > 0) {
         $user_id = $epoch = NULL;
     }
     if ($user_date_id == '' and $user_id == '' and $epoch == '') {
         return FALSE;
     }
     if ($maximum_shift_time === NULL) {
         $maximum_shift_time = $this->getMaximumShiftTime();
     }
     //Debug::text('User Date ID: '. $user_date_id .' User ID: '. $user_id .' TimeStamp: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
     if ($new_shift_trigger_time === NULL) {
         $new_shift_trigger_time = $this->getNewDayTriggerTime();
     }
     if (!is_object($plf)) {
         $plf = TTnew('PunchListFactory');
         if ($user_date_id != '') {
             $plf->getByUserDateId($user_date_id);
         } else {
             //Get punches by time stamp.
             $punch_control_id = 0;
             if (is_object($tmp_punch_control_obj)) {
                 $punch_control_id = $tmp_punch_control_obj->getId();
             }
             //We need to double the maximum shift time when searching for punches.
             //Assuming a maximum punch time of 14hrs:
             // In: 10:00AM Out: 2:00PM
             // In: 6:00PM Out: 6:00AM (next day)
             // The above scenario when adding the last 6:00AM punch on the next day will only look back 14hrs and not find the first
             // punch pair, therefore allowing more than 14hrs on the same day.
             // So we need to extend the maximum shift time just when searching for punches and let getShiftData() sort out the proper maximum shift time itself.
             $plf->getShiftPunchesByUserIDAndEpoch($user_id, $epoch, $punch_control_id, $maximum_shift_time * 2);
             unset($punch_control_id);
         }
     }
     Debug::text('Punch Rows: ' . $plf->getRecordCount() . ' UserID: ' . $user_id . ' Date: ' . TTDate::getDate('DATE+TIME', $epoch) . '(' . $epoch . ') MaximumShiftTime: ' . $maximum_shift_time . ' Filter: ' . $filter, __FILE__, __LINE__, __METHOD__, 10);
     if ($plf->getRecordCount() > 0) {
         $shift = 0;
         $i = 0;
         $nearest_shift_id = 0;
         $nearest_punch_difference = FALSE;
         $prev_punch_obj = FALSE;
         foreach ($plf as $p_obj) {
             //Debug::text('Shift: '. $shift .' Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
             //If we're editing a punch, we need to use the object passed to this function instead of the one
             //from the database.
             if ($epoch == NULL) {
                 //If user_date_id is passed without epoch, set epoch to the first punch we find.
                 $epoch = $p_obj->getTimeStamp();
             }
             if (isset($prev_punch_arr) and $p_obj->getTimeStamp() > $prev_punch_arr['time_stamp']) {
                 $shift_data[$shift]['previous_punch_key'] = $i - 1;
                 if ($shift_data[$shift]['previous_punch_key'] < 0) {
                     $shift_data[$shift]['previous_punch_key'] = NULL;
                 }
             }
             //Determine if a non-saved PunchControl object was passed, and if so, match the IDs to use that instead.
             if (is_object($tmp_punch_control_obj) and $p_obj->getPunchControlID() == $tmp_punch_control_obj->getId()) {
                 Debug::text('Passed non-saved punch control object that matches, using that instead... Using ID: ' . (int) $tmp_punch_control_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 $punch_control_obj = $tmp_punch_control_obj;
             } else {
                 $punch_control_obj = $p_obj->getPunchControlObject();
             }
             //Can't use PunchControl object total_time because the record may not be saved yet when editing
             //an already existing punch.
             //When editing, simply pass the existing PunchControl object to this function so we can
             //use it instead of the one in the database perhaps?
             $total_time = $punch_control_obj->getTotalTime();
             //We can't skip records with total_time == 0, because then when deleting one of the two
             //punches in a pair, the remaining punch is ignored and causing punches to jump around between days in some cases.
             if ($i > 0 and isset($shift_data[$shift]['last_out']) and ($p_obj->getStatus() == 10 or $p_obj->getStatus() == $prev_punch_arr['status_id'])) {
                 Debug::text('Checking for new shift... This Control ID: ' . $p_obj->getPunchControlID() . ' Last Out Control ID: ' . $shift_data[$shift]['last_out']['punch_control_id'] . ' Last Out Time: ' . TTDate::getDate('DATE+TIME', $shift_data[$shift]['last_out']['time_stamp']), __FILE__, __LINE__, __METHOD__, 10);
                 //Assume that if two punches are assigned to the same punch_control_id are the same shift, even if the time between
                 //them exceeds the new_shift_trigger_time. This helps fix the bug where you could add a In punch then add a Out
                 //punch BEFORE the In punch as long as it was more than the Maximum Shift Time before the In Punch.
                 //ie: Add: In Punch 10-Dec-09 @ 8:00AM, Add: Out Punch 09-Dec-09 @ 5:00PM.
                 //Basically it just helps the validation checks to determine the error.
                 //
                 //It used to be that if shifts are split at midnight, new_shift_trigger_time must be 0, so the "split" punch can occur at midnight.
                 //However we have since added a check to see if punches span midnight and trigger a new shift based on that, regardless of the new shift trigger time.
                 //As the new_shift_trigger_time of 0 also affected lunch/break automatic detection by Punch Time, since an Out punch and a In punch of any time
                 //would trigger a new shift, and it wouldn't be detected as lunch/break.
                 //
                 //What happens when the employee takes lunch/break over midnight? Lunch out at 11:30PM Lunch IN at 12:30AM
                 //  We need to split those into two lunches, or two breaks? But then that can affect those policies if they are only allowed one break.
                 // 	Or do we not split the shift at all when this occurs? Currently we don't split at all.
                 if ($p_obj->getPunchControlID() != $shift_data[$shift]['last_out']['punch_control_id'] and ($p_obj->getTimeStamp() - $shift_data[$shift]['last_out']['time_stamp'] >= $new_shift_trigger_time or $this->getShiftAssignedDay() == 40 and $p_obj->getType() == 10 and $shift_data[$shift]['last_out']['type_id'] == 10 and TTDate::doesRangeSpanMidnight($shift_data[$shift]['last_out']['time_stamp'], $p_obj->getTimeStamp(), TRUE) == TRUE)) {
                     $shift++;
                 }
             } elseif ($i > 0 and isset($prev_punch_arr['time_stamp']) and $prev_punch_arr['punch_control_id'] != $p_obj->getPunchControlId() and abs($prev_punch_arr['time_stamp'] - $p_obj->getTimeStamp()) > $maximum_shift_time) {
                 //Debug::text('  New shift because two punch_control records exist and punch timestamp exceed maximum shift time.', __FILE__, __LINE__, __METHOD__, 10);
                 $shift++;
             }
             if (!isset($shift_data[$shift]['total_time'])) {
                 $shift_data[$shift]['total_time'] = 0;
             }
             $punch_day_epoch = TTDate::getBeginDayEpoch($p_obj->getTimeStamp());
             if (!isset($shift_data[$shift]['total_time_per_day'][$punch_day_epoch])) {
                 $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] = 0;
             }
             //Determine which shift is closest to the given epoch.
             $punch_difference_from_epoch = abs($epoch - $p_obj->getTimeStamp());
             if ($nearest_punch_difference === FALSE or $punch_difference_from_epoch <= $nearest_punch_difference) {
                 Debug::text('Nearest Shift Determined to be: ' . $shift . ' Nearest Punch Diff: ' . (int) $nearest_punch_difference . ' Punch Diff: ' . $punch_difference_from_epoch, __FILE__, __LINE__, __METHOD__, 10);
                 //If two punches have the same timestamp, use the shift that matches the passed punch control object, which is usually the one we are currently editing...
                 //This is for splitting shifts at exactly midnight.
                 if ($punch_difference_from_epoch != $nearest_punch_difference or $punch_difference_from_epoch == $nearest_punch_difference and (is_object($tmp_punch_control_obj) and $tmp_punch_control_obj->getId() == $p_obj->getPunchControlID())) {
                     //Debug::text('Found two punches with the same timestamp... Tmp Punch Control: '.$tmp_punch_control_obj->getId() .' Punch Control: '. $p_obj->getPunchControlID() , __FILE__, __LINE__, __METHOD__, 10);
                     $nearest_shift_id = $shift;
                     $nearest_punch_difference = $punch_difference_from_epoch;
                 }
             }
             $punch_arr = array('id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_date_id' => $punch_control_obj->getUserDateID(), 'time_stamp' => $p_obj->getTimeStamp(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType());
             $shift_data[$shift]['punches'][] = $punch_arr;
             $shift_data[$shift]['punch_control_ids'][] = $p_obj->getPunchControlId();
             if ($punch_control_obj->getUserDateID() != FALSE) {
                 $shift_data[$shift]['user_date_ids'][] = $punch_control_obj->getUserDateID();
             }
             if (!isset($shift_data[$shift]['span_midnight'])) {
                 $shift_data[$shift]['span_midnight'] = FALSE;
             }
             if (!isset($shift_data[$shift]['first_in']) and $p_obj->getStatus() == 10) {
                 //Debug::text('First In -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
                 $shift_data[$shift]['first_in'] = $punch_arr;
             } elseif ($p_obj->getStatus() == 20) {
                 //Debug::text('Last Out -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
                 $shift_data[$shift]['last_out'] = $punch_arr;
                 //Debug::text('Total Time: '. $total_time, __FILE__, __LINE__, __METHOD__, 10);
                 $shift_data[$shift]['total_time'] += $total_time;
                 //Check to see if the previous punch was on a different day then the current punch.
                 if (isset($prev_punch_arr) and is_array($prev_punch_arr) and ($p_obj->getStatus() == 20 and $prev_punch_arr['status_id'] != 20) and TTDate::doesRangeSpanMidnight($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()) == TRUE) {
                     Debug::text('Punch PAIR DOES span midnight', __FILE__, __LINE__, __METHOD__, 10);
                     $shift_data[$shift]['span_midnight'] = TRUE;
                     $total_time_for_each_day_arr = TTDate::calculateTimeOnEachDayBetweenRange($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp());
                     if (is_array($total_time_for_each_day_arr)) {
                         foreach ($total_time_for_each_day_arr as $begin_day_epoch => $day_total_time) {
                             if (!isset($shift_data[$shift]['total_time_per_day'][$begin_day_epoch])) {
                                 $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] = 0;
                             }
                             $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] += $day_total_time;
                         }
                     }
                     unset($total_time_for_each_day_arr, $begin_day_epoch, $day_total_time, $prev_day_total_time);
                 } else {
                     $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] += $total_time;
                 }
             }
             $prev_punch_arr = $punch_arr;
             $i++;
         }
         //Debug::Arr($shift_data, 'aShift Data:', __FILE__, __LINE__, __METHOD__, 10);
         if (isset($shift_data)) {
             //Loop through each shift to determine the day with the most time.
             foreach ($shift_data as $tmp_shift_key => $tmp_shift_data) {
                 krsort($shift_data[$tmp_shift_key]['total_time_per_day']);
                 //Sort by day first
                 arsort($shift_data[$tmp_shift_key]['total_time_per_day']);
                 //Sort by total time per day.
                 reset($shift_data[$tmp_shift_key]['total_time_per_day']);
                 $shift_data[$tmp_shift_key]['day_with_most_time'] = key($shift_data[$tmp_shift_key]['total_time_per_day']);
                 $shift_data[$tmp_shift_key]['punch_control_ids'] = array_unique($shift_data[$tmp_shift_key]['punch_control_ids']);
                 if (isset($shift_data[$tmp_shift_key]['user_date_ids'])) {
                     $shift_data[$tmp_shift_key]['user_date_ids'] = array_unique($shift_data[$tmp_shift_key]['user_date_ids']);
                 }
             }
             unset($tmp_shift_key, $tmp_shift_data);
             if ($filter == 'first_shift') {
                 //Only return first shift.
                 $shift_data = $shift_data[0];
             } elseif ($filter == 'last_shift') {
                 //Only return last shift.
                 $shift_data = $shift_data[$shift];
             } elseif ($filter == 'nearest_shift') {
                 $shift_data = $shift_data[$nearest_shift_id];
                 //Check to make sure the nearest shift is within the new shift trigger time of EPOCH.
                 if (isset($shift_data['first_in']['time_stamp'])) {
                     $first_in = $shift_data['first_in']['time_stamp'];
                 } elseif (isset($shift_data['last_out']['time_stamp'])) {
                     $first_in = $shift_data['last_out']['time_stamp'];
                 }
                 if (isset($shift_data['last_out']['time_stamp'])) {
                     $last_out = $shift_data['last_out']['time_stamp'];
                 } elseif (isset($shift_data['first_in']['time_stamp'])) {
                     $last_out = $shift_data['first_in']['time_stamp'];
                 }
                 //The check below must occur so if the user attempts to add an In punch that occurs AFTER the Out punch, this function
                 //still returns the shift data, so the validation checks can occur in PunchControl factory.
                 if ($first_in > $last_out) {
                     //It appears that the first in punch has occurred after the OUT punch, so swap first_in and last_out, so we don't return FALSE in this case.
                     list($first_in, $last_out) = array($last_out, $first_in);
                 }
                 if (TTDate::isTimeOverLap($epoch, $epoch, $first_in - $new_shift_trigger_time, $last_out + $new_shift_trigger_time) == FALSE) {
                     Debug::Text('Nearest shift is outside the new shift trigger time... Epoch: ' . $epoch . ' First In: ' . $first_in . ' Last Out: ' . $last_out . ' New Shift Trigger: ' . $new_shift_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                     return FALSE;
                 }
                 unset($first_in, $last_out);
             }
             $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
             //Debug::Arr($shift_data, 'bShift Data:', __FILE__, __LINE__, __METHOD__, 10);
             return $shift_data;
         }
     }
     $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
     return FALSE;
 }
예제 #2
0
if ($permission->Check('schedule', 'view') == FALSE) {
    if ($permission->Check('schedule', 'view_child') == FALSE) {
        $permission_children_ids = array();
    }
    if ($permission->Check('schedule', 'view_own')) {
        $permission_children_ids[] = $current_user->getId();
    }
    $filter_data['permission_children_ids'] = $permission_children_ids;
}
$do = Misc::findSubmitButton('do');
switch ($do) {
    case 'view_schedule':
    default:
        $user_ids = array();
        if ($filter_data['start_date'] != '' and $filter_data['show_days'] != '') {
            $start_date = $filter_data['start_date'] = TTDate::getBeginDayEpoch(TTDate::parseDateTime($filter_data['start_date']));
            $end_date = $filter_data['end_date'] = $start_date + ($filter_data['show_days'] * 86400 - 3601);
        } else {
            $start_date = $filter_data['start_date'] = TTDate::getBeginWeekEpoch(TTDate::getTime(), $current_user_prefs->getStartWeekDay());
            $end_date = $filter_data['end_date'] = $start_date + $filter_data['show_days'] * (86400 - 3601);
        }
        Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
        $sf = TTnew('ScheduleFactory');
        $raw_schedule_shifts = $sf->getScheduleArray($filter_data);
        if (is_array($raw_schedule_shifts)) {
            foreach ($raw_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                foreach ($day_schedule_shifts as $day_schedule_shift) {
                    $user_ids[] = $day_schedule_shift['user_id'];
                    $day_schedule_shift['is_owner'] = $permission->isOwner($day_schedule_shift['user_created_by'], $day_schedule_shift['user_id']);
                    $day_schedule_shift['is_child'] = $permission->isChild($day_schedule_shift['user_id'], $permission_children_ids);
                    $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
 function isActiveDate($epoch)
 {
     $epoch = TTDate::getBeginDayEpoch($epoch);
     if ($this->getStartDate() == '' and $this->getEndDate() == '') {
         return TRUE;
     }
     if ($epoch >= (int) $this->getStartDate() and ($epoch <= (int) $this->getEndDate() or $this->getEndDate() == '')) {
         Debug::text('Within Start/End Date.', __FILE__, __LINE__, __METHOD__, 10);
         return TRUE;
     }
     Debug::text('Outside Start/End Date.', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
예제 #4
0
     $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);
     }
 } elseif ($user_id != '') {
     Debug::Text(' User ID was passed: ' . $user_id . ' Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10);
     //Don't guess too much. If they click a day to add a punch. Make sure that punch is on that day.
     if (isset($date_stamp) and $date_stamp != '') {
         $time_stamp = $date_stamp + 3600 * 12;
         //Noon
     } else {
         $time_stamp = TTDate::getBeginDayEpoch(TTDate::getTime()) + 3600 * 12;
         //Noon
     }
     /*
     if ( isset($date_stamp) AND $date_stamp != '' ) {
     	$epoch = $date_stamp;
     } else {
     	$epoch = TTDate::getTime();
     }
     //Get previous punch, and default timestamp to that.
     $plf = new PunchListFactory();
     $plf->getPreviousPunchByUserIDAndEpoch( $user_id, $epoch );
     if ( $plf->getRecordCount() > 0 ) {
     	Debug::Text(' Found Previous punch: ', __FILE__, __LINE__, __METHOD__,10);
     	$prev_punch_obj = $plf->getCurrent();
     	$time_stamp = $prev_punch_obj->getTimeStamp()+3600;
 function getShiftsByStartDateAndEndDate($start_date, $end_date)
 {
     //Make sure timezone isn't in the time format. Because recurring schedules
     //are timezone agnostic. 7:00AM in PST is also 7:00AM in EST.
     //This causes an issue where the previous users timezone carries over to the next
     //users timezone, causing errors.
     //TTDate::setTimeFormat('g:i A');
     if ($start_date == '') {
         return FALSE;
     }
     if ($end_date == '') {
         return FALSE;
     }
     if ($start_date < $this->getStartDate()) {
         $start_date = $this->getStartDate();
     }
     if ($this->getEndDate(TRUE) != NULL and $end_date > $this->getEndDate()) {
         $end_date = $this->getEndDate();
     }
     Debug::text('Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . '(' . $start_date . ') End Date: ' . TTDate::getDate('DATE+TIME', $end_date) . '(' . $end_date . ')', __FILE__, __LINE__, __METHOD__, 10);
     //Get week data
     $rstlf = TTnew('RecurringScheduleTemplateListFactory');
     $rstlf->getByRecurringScheduleTemplateControlId($this->getRecurringScheduleTemplateControl())->getCurrent();
     $max_week = 1;
     $weeks = array();
     if ($rstlf->getRecordCount() > 0) {
         foreach ($rstlf as $rst_obj) {
             //Debug::text('Week: '. $rst_obj->getWeek(), __FILE__, __LINE__, __METHOD__, 10);
             $template_week_rows[$rst_obj->getWeek()][] = $rst_obj->getObjectAsArray();
             $weeks[$rst_obj->getWeek()] = $rst_obj->getWeek();
             if ($rst_obj->getWeek() > $max_week) {
                 $max_week = $rst_obj->getWeek();
             }
         }
     }
     $weeks = $this->ReMapWeeks($weeks);
     //Get week of start_date
     $start_date_week = TTDate::getBeginWeekEpoch($this->getStartDate(), 0);
     //Start week on Sunday to match Recurring Schedule.
     //Debug::text('Week of Start Date: '. $start_date_week .' Date: '. TTDate::getDate('DATE+TIME', $this->getStartDate() ) ,__FILE__, __LINE__, __METHOD__, 10);
     //Since we add 43200 to each iteration (even though its removed right after), we need to add 43200 to the end_date as well so we loop the
     //proper amount of times, otherwise schedules may be added too late.
     for ($i = $start_date; $i <= $end_date + 43200; $i += 86400 + 43200) {
         //Handle DST by adding 12hrs to the date to get the mid-day epoch, then forcing it back to the beginning of the day.
         $i = TTDate::getBeginDayEpoch($i);
         //This needs to take into account weeks spanning January 1st of each year. Where the week goes from 53 to 1.
         //Rather then use the week of the year, calculate the weeks between the recurring schedule start date and now.
         $current_week = round((TTDate::getBeginWeekEpoch($i, 0) - $start_date_week) / 604800);
         //Find out which week we are on based on the recurring schedule start date. Use round due to DST the week might be 6.9 or 7.1, so we need to round to the nearest full week.
         //Debug::text('I: '. $i .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Week: '. $start_date_week,__FILE__, __LINE__, __METHOD__, 10);
         $template_week = $current_week % $max_week + 1;
         //Debug::text('Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
         $day_of_week = strtolower(date('D', $i));
         //Debug::text('Day Of Week: '. $day_of_week,__FILE__, __LINE__, __METHOD__, 10);
         if (isset($weeks[$template_week])) {
             $mapped_template_week = $weeks[$template_week];
             //Debug::text('&nbsp;&nbsp;Mapped Template Week: '. $mapped_template_week,__FILE__, __LINE__, __METHOD__, 10);
             if (isset($template_week_rows[$mapped_template_week])) {
                 //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;Starting Looping...!',__FILE__, __LINE__, __METHOD__, 10);
                 foreach ($template_week_rows[$mapped_template_week] as $template_week_arr) {
                     if ($template_week_arr['days'][$day_of_week] == TRUE) {
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Found Scheduled Time: Start Time: '. TTDate::getDate('DATE+TIME', TTDate::getTimeLockedDate( $template_week_arr['start_time'], $i ) ),__FILE__, __LINE__, __METHOD__, 10);
                         $start_time = TTDate::getTimeLockedDate($template_week_arr['raw_start_time'], $i);
                         $end_time = TTDate::getTimeLockedDate($template_week_arr['raw_end_time'], $i);
                         if ($end_time < $start_time) {
                             //Spans the day boundary, add 86400 to end_time
                             $end_time = $end_time + 86400;
                             //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Schedule spans day boundary, bumping endtime to next day: ',__FILE__, __LINE__, __METHOD__, 10);
                         }
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start Date: '. TTDate::getDate('DATE+TIME', $start_time) .' End Date: '. TTDate::getDate('DATE+TIME', $end_time),__FILE__, __LINE__, __METHOD__, 10);
                         //$shifts[TTDate::getBeginDayEpoch($i)][] = array(
                         $shifts[TTDate::getISODateStamp($i)][] = array('status_id' => $template_week_arr['status_id'], 'start_time' => $start_time, 'raw_start_time' => TTDate::getDate('DATE+TIME', $start_time), 'end_time' => $end_time, 'raw_end_time' => TTDate::getDate('DATE+TIME', $end_time), 'total_time' => $template_week_arr['total_time'], 'schedule_policy_id' => $template_week_arr['schedule_policy_id'], 'branch_id' => $template_week_arr['branch_id'], 'department_id' => $template_week_arr['department_id'], 'job_id' => $template_week_arr['job_id'], 'job_item_id' => $template_week_arr['job_item_id']);
                         unset($start_time, $end_time);
                     } else {
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aSkipping!',__FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
             } else {
                 //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;bSkipping!',__FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             //Debug::text('&nbsp;&nbsp;cSkipping!',__FILE__, __LINE__, __METHOD__, 10);
         }
     }
     //var_dump($shifts);
     if (isset($shifts)) {
         return $shifts;
     }
     return FALSE;
 }
 function _outputPDFSchedule($format)
 {
     Debug::Text(' Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     $current_company = $this->getUserObject()->getCompanyObject();
     if (!is_object($current_company)) {
         Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $filter_data = $this->getFilterConfig();
     $columns = Misc::trimSortPrefix($this->getOptions('columns'));
     $adjust_x = 10;
     $adjust_y = 10;
     //Required fields
     // 'first_name', 'last_name', 'branch', 'department', 'start_time', 'end_time'
     $start_week_day = 0;
     if (is_object($this->getUserObject()) and is_object($this->getUserObject()->getUserPreferenceObject())) {
         $start_week_day = $this->getUserObject()->getUserPreferenceObject()->getStartWeekDay();
     }
     //Debug::Arr($this->form_data, 'Form Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->data, 'Data: ', __FILE__, __LINE__, __METHOD__,10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), 2, NULL, TTi18n::getText('Querying Database...'));
     //Iterations need to be 2, otherwise progress bar is not created.
     $this->getProgressBarObject()->set($this->getAMFMessageID(), 2);
     $sf = TTNew('ScheduleFactory');
     //getScheduleArray() doesn't accept pay_period_ids, so no data is returned if a time period of "last_pay_period" is selected.
     if (isset($filter_data['pay_period_id'])) {
         unset($filter_data['pay_period_id']);
         $filter_data['start_date'] = TTDate::getBeginDayEpoch(time() - 86400 * 14);
         //Default to the last 14days.
         $filter_data['end_date'] = TTDate::getEndDayEpoch(time() - 86400);
     }
     $raw_schedule_shifts = $sf->getScheduleArray($filter_data);
     if (is_array($raw_schedule_shifts)) {
         //Debug::Arr($raw_schedule_shifts, 'Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
         $this->getProgressBarObject()->start($this->getAMFMessageID(), count($raw_schedule_shifts, COUNT_RECURSIVE), NULL, TTi18n::getText('Retrieving Data...'));
         $key = 0;
         foreach ($raw_schedule_shifts as $date_stamp => $day_schedule_shifts) {
             foreach ($day_schedule_shifts as $shift_arr) {
                 $this->form_data['schedule_by_branch'][$shift_arr['branch']][$shift_arr['department']][$shift_arr['last_name'] . $shift_arr['first_name']][$date_stamp][] = $shift_arr;
                 //Need to be able to sort employees by last name first. Use names as keys instead of user_ids.
                 //$this->form_data['schedule_by_user'][$shift_arr['user_id']][$date_stamp][$shift_arr['branch']][$shift_arr['department']][] = $shift_arr;
                 $this->form_data['schedule_by_user'][$shift_arr['last_name'] . '_' . $shift_arr['first_name']][$date_stamp][$shift_arr['branch']][$shift_arr['department']][] = $shift_arr;
                 if (!isset($this->form_data['dates']['start_date']) or $this->form_data['dates']['start_date'] > $date_stamp) {
                     $this->form_data['dates']['start_date'] = $date_stamp;
                 }
                 if (!isset($this->form_data['dates']['end_date']) or $this->form_data['dates']['end_date'] < $date_stamp) {
                     $this->form_data['dates']['end_date'] = $date_stamp;
                 }
                 $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                 $key++;
             }
         }
         unset($date_stamp, $raw_schedule_shifts, $day_schedule_shifts);
     } else {
         Debug::Text('No schedule shifts returned...', __FILE__, __LINE__, __METHOD__, 10);
     }
     //Initialize array element if it doesn't exist to prevent PHP warning.
     if (!isset($this->form_data['schedule_by_user'])) {
         $this->form_data['schedule_by_user'] = array();
     }
     //Debug::Arr($this->form_data['schedule_by_branch'], '2Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->form_data['dates'], 'Dates: ', __FILE__, __LINE__, __METHOD__,10);
     //If pay periods are requested, we need to convert those to start/end dates.
     if (isset($this->form_data['dates']['start_date']) and isset($this->form_data['dates']['end_date']) and (!isset($filter_data['start_date']) or !isset($filter_data['end_date']))) {
         $filter_data['start_date'] = strtotime($this->form_data['dates']['start_date']);
         $filter_data['end_date'] = strtotime($this->form_data['dates']['end_date']);
     }
     if (isset($filter_data['start_date']) and isset($filter_data['end_date'])) {
         $pdf_created_date = time();
         $this->pdf = new TTPDF($this->config['other']['page_orientation'], 'mm', $this->config['other']['page_format'], $this->getUserObject()->getCompanyObject()->getEncoding());
         $this->pdf->SetAuthor(APPLICATION_NAME);
         $this->pdf->SetTitle($this->title);
         $this->pdf->SetSubject(APPLICATION_NAME . ' ' . TTi18n::getText('Report'));
         $this->pdf->setMargins($this->config['other']['left_margin'], $this->config['other']['top_margin'], $this->config['other']['right_margin']);
         //Debug::Arr($this->config['other'], 'Margins: ', __FILE__, __LINE__, __METHOD__,10);
         $this->pdf->SetAutoPageBreak(FALSE, 0);
         $this->pdf->SetFont($this->config['other']['default_font'], '', $this->_pdf_fontSize(10));
         //Debug::Arr($this->form_data, 'zabUser Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
         $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
         //Debug::Arr($calendar_array, 'Calendar Array: ', __FILE__, __LINE__, __METHOD__,10);
         switch ($format) {
             case 'pdf_schedule_group':
             case 'pdf_schedule_group_print':
             case 'pdf_schedule_group_pagebreak':
             case 'pdf_schedule_group_pagebreak_print':
                 //
                 // Group - Separate (branch/department on their own pages)
                 //
                 //Start displaying dates/times here. Start with header.
                 $column_widths = array('line' => 5, 'label' => 30, 'day' => ($this->pdf->getPageWidth() - $this->config['other']['left_margin'] - $this->config['other']['right_margin'] - 30) / 7);
                 if (isset($this->form_data['schedule_by_branch'])) {
                     $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                     $n = 0;
                     ksort($this->form_data['schedule_by_branch']);
                     foreach ($this->form_data['schedule_by_branch'] as $branch => $level_2) {
                         ksort($level_2);
                         foreach ($level_2 as $department => $level_3) {
                             ksort($level_3);
                             if ($format == 'pdf_schedule_group_pagebreak' or $format == 'pdf_schedule_group_pagebreak_print') {
                                 //Insert page breaks after each branch/department in this mode.
                                 if ($n > 0) {
                                     $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                                 }
                                 $page_break = TRUE;
                             } else {
                                 $page_break = $n == 0 ? TRUE : $this->scheduleCheckPageBreak(30, TRUE);
                             }
                             $this->scheduleHeader($branch, $department, NULL, $page_break);
                             $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                             //FIXME: Find a better way to determine how many iterations there will be in this loop.
                             $this->getProgressBarObject()->start($this->getAMFMessageID(), count($calendar_array), NULL, TTi18n::getText('Generating Schedules...'));
                             $key = 0;
                             $i = 0;
                             foreach ($calendar_array as $calendar_day) {
                                 if ($i % 7 == 0) {
                                     $calendar_week_array = array_slice($calendar_array, $i, 7);
                                     if ($i != 0) {
                                         $this->scheduleFooterWeek();
                                     }
                                     $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format);
                                     $s = 0;
                                     foreach ($level_3 as $user_id => $user_schedule) {
                                         if ($this->_pdf_checkMaximumPageLimit() == FALSE) {
                                             Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10);
                                             //Exceeded maximum pages, stop processing.
                                             $this->_pdf_displayMaximumPageLimitError();
                                             break 4;
                                         }
                                         //Handle page break.
                                         $page_break_height = 5;
                                         if ($this->scheduleCheckPageBreak($page_break_height, TRUE) == TRUE) {
                                             $this->scheduleHeader($branch, $department);
                                             $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                                             $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format, TRUE);
                                         }
                                         if ($s % 2 == 0) {
                                             $this->pdf->setFillColor(255, 255, 255);
                                         } else {
                                             $this->pdf->setFillColor(245, 245, 245);
                                         }
                                         if ($this->scheduleUserWeek($user_schedule, $calendar_week_array, $start_week_day, $column_widths, $format, $key) == TRUE) {
                                             $s++;
                                         }
                                     }
                                 }
                                 $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                                 if ($key % 25 == 0 and $this->isSystemLoadValid() == FALSE) {
                                     return FALSE;
                                 }
                                 $key++;
                                 $i++;
                             }
                             $this->scheduleFooterWeek($column_widths);
                             $this->scheduleFooter();
                         }
                         $n++;
                     }
                 } else {
                     $this->scheduleNoData();
                 }
                 break;
             case 'pdf_schedule_group_combined':
             case 'pdf_schedule_group_combined_print':
                 ksort($this->form_data['schedule_by_user']);
                 //Start displaying dates/times here. Start with header.
                 $column_widths = array('line' => 5, 'label' => 30, 'day' => ($this->pdf->getPageWidth() - $this->config['other']['left_margin'] - $this->config['other']['right_margin'] - 30) / 7);
                 $this->getProgressBarObject()->start($this->getAMFMessageID(), count($this->form_data['schedule_by_user']) * (count($calendar_array) / 7), NULL, TTi18n::getText('Generating Schedules...'));
                 $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                 $this->scheduleHeader();
                 $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                 $key = 0;
                 $i = 0;
                 foreach ($calendar_array as $calendar_day) {
                     if ($i % 7 == 0) {
                         $calendar_week_array = array_slice($calendar_array, $i, 7);
                         if ($i != 0) {
                             $this->scheduleFooterWeek();
                         }
                         $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format);
                         foreach ($this->form_data['schedule_by_user'] as $user_id => $user_schedule) {
                             if ($this->_pdf_checkMaximumPageLimit() == FALSE) {
                                 Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10);
                                 //Exceeded maximum pages, stop processing.
                                 $this->_pdf_displayMaximumPageLimitError();
                                 break 2;
                             }
                             $s = 0;
                             //Handle page break.
                             if ($this->scheduleCheckPageBreak(5, TRUE) == TRUE) {
                                 $this->scheduleFooterWeek($column_widths);
                                 $this->scheduleHeader();
                                 $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                                 $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format, TRUE);
                             }
                             $this->pdf->setFillColor(255, 255, 255);
                             if ($this->scheduleUserWeek($user_schedule, $calendar_week_array, $start_week_day, $column_widths, $format, $key) == TRUE) {
                                 $s++;
                             }
                             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                             if ($key % 25 == 0 and $this->isSystemLoadValid() == FALSE) {
                                 return FALSE;
                             }
                             $key++;
                         }
                         $this->scheduleFooterWeek($column_widths);
                     }
                     $i++;
                 }
                 $this->scheduleFooter();
                 break;
             case 'pdf_schedule':
             case 'pdf_schedule_print':
                 ksort($this->form_data['schedule_by_user']);
                 //Start displaying dates/times here. Start with header.
                 $column_widths = array('line' => 5, 'label' => 0, 'day' => ($this->pdf->getPageWidth() - $this->config['other']['left_margin'] - $this->config['other']['right_margin'] - 0) / 7);
                 if (isset($this->form_data['schedule_by_user'])) {
                     $this->getProgressBarObject()->start($this->getAMFMessageID(), count($this->form_data['schedule_by_user']) * (count($calendar_array) / 7), NULL, TTi18n::getText('Generating Schedules...'));
                     $key = 0;
                     foreach ($this->form_data['schedule_by_user'] as $user_full_name => $user_schedule) {
                         $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                         $split_name = explode('_', $user_full_name);
                         $this->scheduleHeader(NULL, NULL, $split_name[1] . ' ' . $split_name[0]);
                         unset($split_name);
                         $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                         $i = 0;
                         foreach ($calendar_array as $calendar_day) {
                             if ($i % 7 == 0) {
                                 if ($this->_pdf_checkMaximumPageLimit() == FALSE) {
                                     Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10);
                                     //Exceeded maximum pages, stop processing.
                                     $this->_pdf_displayMaximumPageLimitError();
                                     break 2;
                                 }
                                 $calendar_week_array = array_slice($calendar_array, $i, 7);
                                 if ($i != 0) {
                                     $this->scheduleFooterWeek();
                                 }
                                 $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format);
                                 //Handle page break.
                                 $page_break_height = 5;
                                 if ($this->scheduleCheckPageBreak($page_break_height, TRUE) == TRUE) {
                                     $this->scheduleHeader();
                                     $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                                     $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format, TRUE);
                                 }
                                 $this->pdf->setFillColor(255, 255, 255);
                                 $this->scheduleUserWeek($user_schedule, $calendar_week_array, $start_week_day, $column_widths, $format, $key);
                             }
                             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                             if ($key % 25 == 0 and $this->isSystemLoadValid() == FALSE) {
                                 return FALSE;
                             }
                             $key++;
                             $i++;
                         }
                         $this->scheduleFooterWeek($column_widths);
                         $this->scheduleFooter();
                     }
                 } else {
                     $this->scheduleNoData();
                 }
                 break;
         }
         $output = $this->pdf->Output('', 'S');
         return $output;
     } else {
         Debug::Text('No start/end date specified...', __FILE__, __LINE__, __METHOD__, 10);
     }
     Debug::Text('No data to return...', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
 function getShifts($start_date, $end_date, &$holiday_data = array(), &$branch_options = array(), &$department_options = array(), &$n, &$shifts = array(), &$shifts_index = array(), $open_shift_conflict_index = array(), $permission_children_ids = NULL)
 {
     //Debug::text('Start Date: '. TTDate::getDate('DATE+TIME', $start_date) .' End Date: '. TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
     $recurring_schedule_control_start_date = TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date'));
     //Debug::text('Recurring Schedule Control Start Date: '. TTDate::getDate('DATE+TIME', $recurring_schedule_control_start_date),__FILE__, __LINE__, __METHOD__, 10);
     $current_template_week = $this->getColumn('remapped_week');
     $max_week = $this->getColumn('max_week');
     //Debug::text('Template Week: '. $current_template_week .' Max Week: '. $this->getColumn('max_week') .' ReMapped Week: '. $this->getColumn('remapped_week') ,__FILE__, __LINE__, __METHOD__, 10);
     if ($recurring_schedule_control_start_date == '') {
         return FALSE;
     }
     //Get week of start_date
     $start_date_week = TTDate::getBeginWeekEpoch($recurring_schedule_control_start_date, 0);
     //Start week on Sunday to match Recurring Schedule.
     //Debug::text('Week of Start Date: '. $start_date_week ,__FILE__, __LINE__, __METHOD__, 10);
     $apf = TTnew('AbsencePolicyFactory');
     $absence_policy_paid_type_options = $apf->getOptions('paid_type');
     for ($i = $start_date; $i <= $end_date; $i += 86400 + 43200) {
         //Handle DST by adding 12hrs to the date to get the mid-day epoch, then forcing it back to the beginning of the day.
         $i = TTDate::getBeginDayEpoch($i);
         if ($this->getColumn('hire_date') != '' and $i < $this->getColumn('hire_date') or $this->getColumn('termination_date') != '' and $i > $this->getColumn('termination_date')) {
             //Debug::text('Skipping due to Hire/Termination date: User ID: '. $this->getColumn('user_id') .' I: '. $i .' Hire Date: '. $this->getColumn('hire_date') .' Termination Date: '. $this->getColumn('termination_date') ,__FILE__, __LINE__, __METHOD__, 10);
             continue;
         }
         //This needs to take into account weeks spanning January 1st of each year. Where the week goes from 53 to 1.
         //Rather then use the week of the year, calculate the weeks between the recurring schedule start date and now.
         $current_week = round((TTDate::getBeginWeekEpoch($i, 0) - $start_date_week) / 604800);
         //Find out which week we are on based on the recurring schedule start date. Use round due to DST the week might be 6.9 or 7.1, so we need to round to the nearest full week.
         //Debug::text('I: '. $i .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Week: '. $start_date_week,__FILE__, __LINE__, __METHOD__, 10);
         $template_week = $current_week % $max_week + 1;
         //Debug::text('Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
         if ($template_week == $current_template_week) {
             //Debug::text('Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week,__FILE__, __LINE__, __METHOD__, 10);
             //Debug::text('&nbsp;Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
             if ($this->isActiveShiftDay($i)) {
                 //Debug::text('&nbsp;&nbsp;Active Shift on this day...',__FILE__, __LINE__, __METHOD__, 10);
                 $start_time = TTDate::getTimeLockedDate($this->getStartTime(), $i);
                 $end_time = TTDate::getTimeLockedDate($this->getEndTime(), $i);
                 if ($end_time < $start_time) {
                     //Spans the day boundary, add 86400 to end_time
                     $end_time = $end_time + 86400;
                     //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Schedule spans day boundary, bumping endtime to next day: ',__FILE__, __LINE__, __METHOD__, 10);
                 }
                 $iso_date_stamp = TTDate::getISODateStamp(PayPeriodScheduleFactory::getShiftAssignedDate($start_time, $end_time, $this->getColumn('shift_assigned_day_id')));
                 //$iso_date_stamp = TTDate::getISODateStamp( $i );
                 $open_shift_multiplier = $this->getColumn('user_id') == 0 ? $this->getOpenShiftMultiplier() : 1;
                 //Debug::text('Open Shift Multiplier: '. $open_shift_multiplier,__FILE__, __LINE__, __METHOD__, 10);
                 for ($x = 0; $x < $open_shift_multiplier; $x++) {
                     //Check all non-OPEN shifts for conflicts.
                     if ($this->getColumn('user_id') > 0 and isset($shifts_index[$iso_date_stamp][$this->getColumn('user_id')])) {
                         //User has previous recurring schedule shifts, check for overlap.
                         //Loop over each employees shift for this day and check for conflicts
                         foreach ($shifts_index[$iso_date_stamp][$this->getColumn('user_id')] as $shift_key) {
                             if (isset($shifts[$iso_date_stamp][$shift_key])) {
                                 //Must use parseDateTime() when called from the API due to date formats that strtotime() fails on.
                                 if (TTDate::isTimeOverLap(defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['start_date']) : $shifts[$iso_date_stamp][$shift_key]['start_date'], defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['end_date']) : $shifts[$iso_date_stamp][$shift_key]['end_date'], $start_time, $end_time) == TRUE) {
                                     //Debug::text('&nbsp;&nbsp;Found overlapping recurring schedules! User ID: '. $this->getColumn('user_id') .' Start Time: '. $start_time,__FILE__, __LINE__, __METHOD__, 10);
                                     continue 2;
                                 }
                             }
                         }
                         unset($shift_key);
                     } elseif ($this->getColumn('user_id') == 0 and isset($shifts_index[$iso_date_stamp])) {
                         //Debug::text('    Checking OPEN shift conflicts... Date: '. $iso_date_stamp,__FILE__, __LINE__, __METHOD__, 10);
                         //Check all OPEN shifts for conflicts.
                         //This is special, since there can be multiple open shifts for the same branch,department,job,task, so we need to check if are conflicts with *any* employee.
                         //Do we allow conflicting shifts between committed and recurring OPEN shifts? For example what if there are two open shifts on the same day
                         //6AM-3PM (x2) and they want to override one of those shifts to 7AM-4PM? If we use this check:
                         //   ( $shifts[$iso_date_stamp][$shift_key]['user_id'] > 0 OR ( isset($shifts[$iso_date_stamp][$shift_key]['id']) AND $shifts[$iso_date_stamp][$shift_key]['id'] > 0 ) )
                         //That allows committed OPEN shifts to override recurring open shifts, which is great, but it prevents adding additional open shifts that may
                         //also overlap unless they override all recurring shifts first. I think this is the trade-off we have to make as its more likely that they
                         //will adjust an open shift time rather than add/remove specific shifts. Removing recurring OPEN shifts can be done by making them ABSENT.
                         //This will also affect when recurring OPEN shifts are committed by preventing the shifts from doubling up.
                         foreach ($shifts_index[$iso_date_stamp] as $tmp_index_user_id => $tmp_index_arr) {
                             foreach ($tmp_index_arr as $shift_key) {
                                 $tmp_start_date = defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['start_date']) : $shifts[$iso_date_stamp][$shift_key]['start_date'];
                                 $tmp_end_date = defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['end_date']) : $shifts[$iso_date_stamp][$shift_key]['end_date'];
                                 if (($shifts[$iso_date_stamp][$shift_key]['user_id'] > 0 or isset($shifts[$iso_date_stamp][$shift_key]['id']) and $shifts[$iso_date_stamp][$shift_key]['id'] > 0) and (!isset($open_shift_conflict_index['open'][$this->getID()][$shift_key]) and (isset($shifts[$iso_date_stamp][$shift_key]['id']) and !isset($open_shift_conflict_index['scheduled'][$shifts[$iso_date_stamp][$shift_key]['id']]))) and $this->getColumn('schedule_branch_id') == $shifts[$iso_date_stamp][$shift_key]['branch_id'] and $this->getColumn('schedule_department_id') == $shifts[$iso_date_stamp][$shift_key]['department_id'] and $this->getColumn('job_id') == $shifts[$iso_date_stamp][$shift_key]['job_id'] and $this->getColumn('job_item_id') == $shifts[$iso_date_stamp][$shift_key]['job_item_id'] and ($tmp_start_date == $start_time and $tmp_end_date == $end_time)) {
                                     //Debug::text('      Found OPEN shift conflict... Skipping...! Shift Key: '. $shift_key,__FILE__, __LINE__, __METHOD__, 10);
                                     //We need to track each shift_key that caused a conflict so it can't cause another conflict later on.
                                     //  Make sure we just track it on a per template basis though, otherwise the same $shift_key from a previous template can affect other templates.
                                     //  The above issue would show up as OPEN shifts not being overridden.
                                     //We also need to track which scheduled shift that caused a conflict so it can't cause another one later on.
                                     //  This prevents a single scheduled shift from overriding multiple OPEN shifts of different times.
                                     //However we need to be smarter about which shifts override which OPEN shifts...
                                     //  So if there are two open shifts, 10AM-4PM and 3:50PM-9PM, a 10AM-4PM scheduled shift overrides the OPEN shift that best fits it (10AM to 4PM, *not* 3:50-9PM)
                                     //  For now require an exact match to override an OPEN shift, if we start using partial schedules it gets much more complicated.
                                     //  Or we could introduce a hardcoded "fudge factor" setting (ie: 5 mins) that is always used instead.
                                     $open_shift_conflict_index['open'][$this->getID()][$shift_key] = TRUE;
                                     $open_shift_conflict_index['scheduled'][$shifts[$iso_date_stamp][$shift_key]['id']] = TRUE;
                                     continue 3;
                                 }
                                 unset($tmp_start_date, $tmp_end_date);
                             }
                         }
                         unset($tmp_index_user_id, $tmp_index_arr);
                     }
                     //This check has to occurr after the committed schedule check, otherwise no committed schedules will appear.
                     if ($this->getColumn('recurring_schedule_control_start_date') != '' and $i < TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date')) or $this->getColumn('recurring_schedule_control_end_date') != '' and $i > TTDate::strtotime($this->getColumn('recurring_schedule_control_end_date'))) {
                         //Debug::text('Skipping due to Recurring Schedule Start/End date: ID: '. $this->getColumn('id') .' User ID: '. $this->getColumn('user_id') .' I: '. $i .' Start Date: '. $this->getColumn('recurring_schedule_control_start_date') .' ('. TTDate::strtotime( $this->getColumn('recurring_schedule_control_start_date') ) .') End Date: '. $this->getColumn('recurring_schedule_control_end_date') ,__FILE__, __LINE__, __METHOD__, 10);
                         continue;
                     }
                     //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start Date: '. TTDate::getDate('DATE+TIME', $start_time) .' End Date: '. TTDate::getDate('DATE+TIME', $end_time),__FILE__, __LINE__, __METHOD__, 10);
                     $status_id = $this->getColumn('status_id');
                     $absence_policy_id = $this->getColumn('absence_policy_id');
                     $absence_policy_type_id = $this->getColumn('absence_policy_type_id');
                     $absence_policy = $this->getColumn('absence_policy') != '' ? $this->getColumn('absence_policy') : NULL;
                     //Must be NULL to be converted to N/A
                     if (isset($holiday_data[$iso_date_stamp])) {
                         //We have to assume they are eligible, because we really won't know
                         //if they will have worked enough days or not. We could assume they
                         //work whatever their schedule is, but chances are they will be eligible then anyways.
                         //Debug::text('&nbsp;&nbsp;Found Holiday on this day...',__FILE__, __LINE__, __METHOD__, 10);
                         $status_id = $holiday_data[$iso_date_stamp]['status_id'];
                         if (isset($holiday_data[$iso_date_stamp]['absence_policy_id'])) {
                             $absence_policy_id = $holiday_data[$iso_date_stamp]['absence_policy_id'];
                             $absence_policy_type_id = $holiday_data[$iso_date_stamp]['type_id'];
                             $absence_policy = $holiday_data[$iso_date_stamp]['absence_policy'];
                         }
                     }
                     $hourly_rate = Misc::MoneyFormat($this->getColumn('user_wage_hourly_rate'), FALSE);
                     if ($absence_policy_id > 0 and in_array($absence_policy_type_id, $absence_policy_paid_type_options) == FALSE) {
                         //UnPaid Absence.
                         $total_time_wage = Misc::MoneyFormat(0);
                     } else {
                         $total_time_wage = Misc::MoneyFormat(bcmul(TTDate::getHours($this->getTotalTime()), $hourly_rate), FALSE);
                     }
                     //Debug::text('I: '. $i .' N: '. $n .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Time: '. TTDate::getDate('DATE+TIME', $start_time ) .' Absence Policy: '. $absence_policy,__FILE__, __LINE__, __METHOD__, 10);
                     //$shifts[$iso_date_stamp][$this->getColumn('user_id').$start_time] = array(
                     $shifts[$iso_date_stamp][$n] = array('pay_period_id' => FALSE, 'user_id' => (int) $this->getColumn('user_id'), 'user_created_by' => $this->getColumn('user_created_by'), 'user_full_name' => $this->getColumn('user_id') > 0 ? Misc::getFullName($this->getColumn('first_name'), NULL, $this->getColumn('last_name'), FALSE, FALSE) : TTi18n::getText('OPEN'), 'first_name' => $this->getColumn('first_name'), 'last_name' => $this->getColumn('last_name'), 'title_id' => $this->getColumn('title_id'), 'title' => $this->getColumn('title'), 'group_id' => $this->getColumn('group_id'), 'group' => $this->getColumn('group'), 'default_branch_id' => $this->getColumn('default_branch_id'), 'default_branch' => $this->getColumn('default_branch'), 'default_department_id' => $this->getColumn('default_department_id'), 'default_department' => $this->getColumn('default_department'), 'job_id' => $this->getJob(), 'job' => $this->getColumn('job'), 'job_status_id' => $this->getColumn('job_status_id'), 'job_manual_id' => $this->getColumn('job_manual_id'), 'job_branch_id' => $this->getColumn('job_branch_id'), 'job_department_id' => $this->getColumn('job_department_id'), 'job_group_id' => $this->getColumn('job_group_id'), 'job_item_id' => $this->getJobItem(), 'job_item' => $this->getColumn('job_item'), 'type_id' => 20, 'status_id' => $status_id, 'date_stamp' => TTDate::getAPIDate('DATE', strtotime($iso_date_stamp)), 'start_date_stamp' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE', $start_time) : $start_time, 'start_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $start_time) : $start_time, 'end_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $end_time) : $end_time, 'start_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $start_time) : $start_time, 'end_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $end_time) : $end_time, 'start_time_stamp' => $start_time, 'end_time_stamp' => $end_time, 'total_time' => $this->getTotalTime(), 'hourly_rate' => $hourly_rate, 'total_time_wage' => $total_time_wage, 'note' => FALSE, 'schedule_policy_id' => $this->getSchedulePolicyID(), 'absence_policy_id' => $absence_policy_id, 'absence_policy' => $absence_policy, 'branch_id' => $this->getColumn('schedule_branch_id'), 'branch' => $this->getColumn('schedule_branch'), 'department_id' => $this->getColumn('schedule_department_id'), 'department' => $this->getColumn('schedule_department'), 'created_by_id' => $this->getColumn('recurring_schedule_control_created_by'), 'created_date' => $this->getCreatedDate(), 'updated_date' => $this->getUpdatedDate());
                     //Make sure we add in permission columns.
                     $this->getPermissionColumns($shifts[$iso_date_stamp][$n], (int) $this->getColumn('user_id'), $this->getColumn('recurring_schedule_control_created_by'), $permission_children_ids);
                     //$shifts_index[$iso_date_stamp][$this->getColumn('user_id')][] = $this->getColumn('user_id').$start_time;
                     $shifts_index[$iso_date_stamp][$this->getColumn('user_id')][] = $n;
                     $n++;
                 }
                 unset($open_shift_multiplier);
                 unset($start_time, $end_time);
             } else {
                 //Debug::text('&nbsp;&nbsp;NOT active shift on this day... ID: '. $this->getColumn('id') .' User ID: '. $this->getColumn('user_id') .' Start Time: '. TTDate::getDate('DATE+TIME', $i),__FILE__, __LINE__, __METHOD__, 10);
             }
         }
     }
     if (isset($shifts)) {
         //Debug::Arr($shifts, 'Template Shifts: ',__FILE__, __LINE__, __METHOD__, 10);
         return $shifts;
     }
     return FALSE;
 }
예제 #8
0
    function getPreviousPunchByUserIdAndEpoch($user_id, $epoch, $order = NULL)
    {
        Debug::Text(' User ID: ' . $user_id . ' Epoch: ' . $epoch, __FILE__, __LINE__, __METHOD__, 10);
        if ($user_id == '') {
            return FALSE;
        }
        if ($epoch == '') {
            return FALSE;
        }
        $maximum_shift_time = $this->getPayPeriodMaximumShiftTime($user_id);
        $begin_day_epoch = TTDate::getBeginDayEpoch($epoch);
        $start_time = $epoch - $maximum_shift_time;
        Debug::Text(' Start Time: ' . TTDate::getDate('DATE+TIME', $start_time), __FILE__, __LINE__, __METHOD__, 10);
        $udf = new UserDateFactory();
        $pcf = new PunchControlFactory();
        $ph = array('user_id' => $user_id, 'start_date' => $this->db->BindDate($start_time), 'end_date' => $this->db->BindDate($epoch), 'start_time' => $this->db->BindTimeStamp($start_time), 'end_time' => $this->db->BindTimeStamp($epoch));
        //Status order matters, because if its a.status_id desc, OUT comes first, but if the last
        //punch doesn't have OUT yet, it defaults to IN
        // with a.status_id asc...
        //Include date_stamp filter on user_date table as this greatly speeds up the query when its not already cached.
        $query = '
					select 	a.*
					from 	' . $this->getTable() . ' as a,
							' . $pcf->getTable() . ' as b,
							' . $udf->getTable() . ' as c
					where	a.punch_control_id = b.id
						AND b.user_date_id = c.id
						AND c.user_id = ?
						AND c.date_stamp >= ?
						AND c.date_stamp <= ?
						AND a.time_stamp >= ?
						AND a.time_stamp <= ?
						AND ( a.deleted = 0 AND b.deleted=0 AND c.deleted=0)
					ORDER BY a.time_stamp desc, a.status_id asc
					LIMIT 1
					';
        $query .= $this->getSortSQL($order);
        //Debug::Text(' Query: '. $query, __FILE__, __LINE__, __METHOD__,10);
        $this->ExecuteSQL($query, $ph);
        return $this;
    }
예제 #9
0
 function testBreakPunchTimeWindowD()
 {
     global $dd;
     $policy_ids['break'][] = $this->createBreakPolicy($this->company_id, 110);
     //Create Policy Group
     $dd->createPolicyGroup($this->company_id, NULL, NULL, NULL, NULL, NULL, NULL, array($this->user_id), $policy_ids['break']);
     $date_epoch = TTDate::getBeginWeekEpoch(time());
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     $dd->createPunch($this->user_id, 10, 10, strtotime($date_stamp . ' 8:00AM'), array('branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $punch_time = strtotime($date_stamp . ' 10:00AM');
     $prev_punch_obj = $this->getPreviousPunch($punch_time);
     $punch_type_id = $prev_punch_obj->getNextType($punch_time);
     $punch_status_id = $prev_punch_obj->getNextStatus();
     $this->assertEquals($punch_type_id, 10);
     //Normal - Because when using punch time it can't be detected on the first out punch.
     $this->assertEquals($punch_status_id, 20);
     //Out
     $dd->createPunch($this->user_id, $punch_type_id, $punch_status_id, $punch_time, array('branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $punch_time = strtotime($date_stamp . ' 10:15AM');
     $prev_punch_obj = $this->getPreviousPunch($punch_time);
     $punch_type_id = $prev_punch_obj->getNextType($punch_time);
     $punch_status_id = $prev_punch_obj->getNextStatus();
     $this->assertEquals($punch_type_id, 30);
     //Break
     $this->assertEquals($punch_status_id, 10);
     //In
     $dd->createPunch($this->user_id, $punch_type_id, $punch_status_id, $punch_time, array('branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $punch_time = strtotime($date_stamp . ' 2:00PM');
     $prev_punch_obj = $this->getPreviousPunch($punch_time);
     $punch_type_id = $prev_punch_obj->getNextType($punch_time);
     $punch_status_id = $prev_punch_obj->getNextStatus();
     $this->assertEquals($punch_type_id, 10);
     //Normal - Because when using punch time it can't be detected on the first out punch.
     $this->assertEquals($punch_status_id, 20);
     //Out
     $dd->createPunch($this->user_id, $punch_type_id, $punch_status_id, $punch_time, array('branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $punch_time = strtotime($date_stamp . ' 2:15PM');
     $prev_punch_obj = $this->getPreviousPunch($punch_time);
     $punch_type_id = $prev_punch_obj->getNextType($punch_time);
     $punch_status_id = $prev_punch_obj->getNextStatus();
     $this->assertEquals($punch_type_id, 30);
     //Break
     $this->assertEquals($punch_status_id, 10);
     //In
     $dd->createPunch($this->user_id, $punch_type_id, $punch_status_id, $punch_time, array('branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $punch_time = strtotime($date_stamp . ' 5:00PM');
     $prev_punch_obj = $this->getPreviousPunch($punch_time);
     $punch_type_id = $prev_punch_obj->getNextType($punch_time);
     $punch_status_id = $prev_punch_obj->getNextStatus();
     $this->assertEquals($punch_type_id, 10);
     //Normal
     $this->assertEquals($punch_status_id, 20);
     //Out
     $dd->createPunch($this->user_id, $punch_type_id, $punch_status_id, $punch_time, array('branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $punch_arr = $this->getPunchDataArray(TTDate::getBeginDayEpoch($date_epoch), TTDate::getEndDayEpoch($date_epoch));
     //print_r($punch_arr);
     $this->assertEquals(3, count($punch_arr[$date_epoch]));
     $this->assertEquals($date_epoch, $punch_arr[$date_epoch][0]['date_stamp']);
     $this->assertEquals(6, count($punch_arr[$date_epoch][0]['shift_data']['punches']));
     $this->assertEquals(10, $punch_arr[$date_epoch][0]['shift_data']['punches'][0]['type_id']);
     $this->assertEquals(10, $punch_arr[$date_epoch][0]['shift_data']['punches'][0]['status_id']);
     $this->assertEquals(30, $punch_arr[$date_epoch][0]['shift_data']['punches'][1]['type_id']);
     $this->assertEquals(20, $punch_arr[$date_epoch][0]['shift_data']['punches'][1]['status_id']);
     $this->assertEquals(30, $punch_arr[$date_epoch][0]['shift_data']['punches'][2]['type_id']);
     $this->assertEquals(10, $punch_arr[$date_epoch][0]['shift_data']['punches'][2]['status_id']);
     $this->assertEquals(30, $punch_arr[$date_epoch][0]['shift_data']['punches'][3]['type_id']);
     $this->assertEquals(20, $punch_arr[$date_epoch][0]['shift_data']['punches'][3]['status_id']);
     $this->assertEquals(30, $punch_arr[$date_epoch][0]['shift_data']['punches'][4]['type_id']);
     $this->assertEquals(10, $punch_arr[$date_epoch][0]['shift_data']['punches'][4]['status_id']);
     $this->assertEquals(10, $punch_arr[$date_epoch][0]['shift_data']['punches'][5]['type_id']);
     $this->assertEquals(20, $punch_arr[$date_epoch][0]['shift_data']['punches'][5]['status_id']);
     return TRUE;
 }
 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;
 }
예제 #11
0
 function calcExperience()
 {
     if ($this->getFirstUsedDate() != '') {
         $last_used_date = $this->getLastUsedDate();
         if ($this->getLastUsedDate() == '') {
             $last_used_date = TTDate::getEndDayEpoch(time());
         }
         $total_time = round(TTDate::getYears($last_used_date - TTDate::getBeginDayEpoch($this->getFirstUsedDate())), 2);
         if ($total_time < 0) {
             $total_time = 0;
         }
         Debug::text(' First Used Date: ' . $this->getFirstUsedDate() . ' Last Used Date: ' . $last_used_date . ' Total Yrs: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
         return $total_time;
     }
     return FALSE;
 }
예제 #12
0
        if ($c_obj->getStatus() != 30) {
            $ppslf = new PayPeriodScheduleListFactory();
            $ulf = new UserListFactory();
            $ulf->getByCompanyId($c_obj->getId());
            if ($ulf->getRecordCount() > 0) {
                $i = 0;
                foreach ($ulf as $u_obj) {
                    if ($u_obj->getStatus() != 10) {
                        continue;
                    }
                    Debug::text($i . '. User: '******'22-Jan-08');
                        UserDateFactory::findOrInsertUserDate($u_obj->getId(), TTDate::getBeginDayEpoch($epoch));
                    }
                    $i++;
                }
            }
        } else {
            Debug::text('Company is not ACTIVE: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
        }
    }
}
Debug::writeToLog();
Debug::Display();
예제 #13
0
 function calcAccrualTime($company_id, $accrual_policy_id, $start_date, $end_date)
 {
     $start_date = TTDate::getMiddleDayEpoch($start_date);
     $end_date = TTDate::getMiddleDayEpoch($end_date);
     $total_days = TTDate::getDays($end_date - $start_date);
     $offset = 79200;
     $apf = TTnew('AccrualPolicyFactory');
     $aplf = TTnew('AccrualPolicyListFactory');
     $aplf->getByIdAndCompanyId((int) $accrual_policy_id, $company_id);
     if ($aplf->getRecordCount() > 0) {
         foreach ($aplf as $ap_obj) {
             $aplf->StartTransaction();
             $x = 0;
             for ($i = $start_date; $i < $end_date; $i += 86400) {
                 Debug::Text('Recalculating Accruals for Date: ' . TTDate::getDate('DATE+TIME', TTDate::getBeginDayEpoch($i)), __FILE__, __LINE__, __METHOD__, 10);
                 $ap_obj->addAccrualPolicyTime(TTDate::getBeginDayEpoch($i) + 7201, $offset);
                 Debug::Text('----------------------------------', __FILE__, __LINE__, __METHOD__, 10);
                 $x++;
             }
             $aplf->CommitTransaction();
         }
     }
     return TRUE;
 }
예제 #14
0
 if ($date_type != 'last') {
     echo "Searching for Pay Period " . ucfirst($date_type) . " Date: " . TTDate::getDate('DATE', $pay_period_date) . "...\n";
 } else {
     echo "Searching for Last Pay Period...\n";
 }
 $pplf = new PayPeriodListFactory();
 $pplf->getPayPeriodsWithPayStubsByCompanyId($company_id, NULL, array('a.start_date' => 'desc'));
 if ($pplf->getRecordCount() > 0) {
     $x = 0;
     $found_pay_period = FALSE;
     foreach ($pplf as $pp_obj) {
         if ($date_type == 'start' and TTDate::getBeginDayEpoch($pp_obj->getStartDate()) == $pay_period_date) {
             $found_pay_period = TRUE;
         } elseif ($date_type == 'end' and TTDate::getBeginDayEpoch($pp_obj->getEndDate()) == $pay_period_date) {
             $found_pay_period = TRUE;
         } elseif ($date_type == 'transaction' and TTDate::getBeginDayEpoch($pp_obj->getTransactionDate()) == $pay_period_date) {
             $found_pay_period = TRUE;
         } elseif ($date_type == 'last') {
             //Last pay period
             $found_pay_period = TRUE;
         }
         if ($found_pay_period == TRUE) {
             echo "Found Pay Period: Start: " . TTDate::getDate('DATE', $pp_obj->getStartDate()) . ' End: ' . TTDate::getDate('DATE', $pp_obj->getEndDate()) . ' Transaction: ' . TTDate::getDate('DATE', $pp_obj->getTransactionDate()) . "\n";
             $pay_period_id = $pp_obj->getId();
             break;
         }
         $x++;
     }
 }
 if (isset($pay_period_id)) {
     $pslf = new PayStubListFactory();
 function getShiftData($user_date_id = NULL, $user_id = NULL, $epoch = NULL, $filter = NULL, $tmp_punch_control_obj = NULL)
 {
     global $profiler;
     $profiler->startTimer('PayPeriodScheduleFactory::getShiftData()');
     if (is_numeric($user_date_id) and $user_date_id > 0) {
         $user_id = $epoch = NULL;
     }
     if ($user_date_id == '' and $user_id == '' and $epoch == '') {
         return FALSE;
     }
     //Debug::text('User Date ID: '. $user_date_id .' User ID: '. $user_id .' TimeStamp: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
     $new_shift_trigger_time = $this->getNewDayTriggerTime();
     $plf = new PunchListFactory();
     if ($user_date_id != '') {
         $plf->getByUserDateId($user_date_id);
     } else {
         //Get punches by time stamp.
         $punch_control_id = 0;
         if (is_object($tmp_punch_control_obj)) {
             $punch_control_id = $tmp_punch_control_obj->getId();
         }
         $plf->getShiftPunchesByUserIDAndEpoch($user_id, $epoch, $punch_control_id, $this->getMaximumShiftTime());
         unset($punch_control_id);
     }
     Debug::text('Punch Rows: ' . $plf->getRecordCount() . ' UserID: ' . $user_id . ' Date: ' . TTDate::getDate('DATE+TIME', $epoch) . '(' . $epoch . ') MaximumShiftTime: ' . $this->getMaximumShiftTime(), __FILE__, __LINE__, __METHOD__, 10);
     //Debug::Arr($punches, ' Punches: ', __FILE__, __LINE__, __METHOD__, 10);
     if ($plf->getRecordCount() > 0) {
         $shift = 0;
         $i = 0;
         $nearest_shift_id = 0;
         $nearest_punch_difference = FALSE;
         $prev_punch_obj = FALSE;
         foreach ($plf as $p_obj) {
             //Debug::text('Shift: '. $shift .' Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
             //If we're editing a punch, we need to use the object passed to this function instead of the one
             //from the database.
             if ($epoch == NULL) {
                 //If user_date_id is passed without epoch, set epoch to the first punch we find.
                 $epoch = $p_obj->getTimeStamp();
             }
             if (isset($prev_punch_arr) and $p_obj->getTimeStamp() > $prev_punch_arr['time_stamp']) {
                 $shift_data[$shift]['previous_punch_key'] = $i - 1;
                 if ($shift_data[$shift]['previous_punch_key'] < 0) {
                     $shift_data[$shift]['previous_punch_key'] = NULL;
                 }
             }
             //Determine if a non-saved PunchControl object was passed, and if so, match the IDs to use that instead.
             if (is_object($tmp_punch_control_obj) and $p_obj->getPunchControlID() == $tmp_punch_control_obj->getId()) {
                 Debug::text('Passed non-saved punch control object that matches, using that instead... Using ID: ' . (int) $tmp_punch_control_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 $punch_control_obj = $tmp_punch_control_obj;
             } else {
                 $punch_control_obj = $p_obj->getPunchControlObject();
             }
             //Can't use PunchControl object total_time because the record may not be saved yet when editing
             //an already existing punch.
             //When editing, simply pass the existing PunchControl object to this function so we can
             //use it instead of the one in the database perhaps?
             $total_time = $punch_control_obj->getTotalTime();
             /*
             				//We can't skip records with total_time == 0, because then when deleting one of the two
             				//punches in a pair, the remaining punch is ignored and causing punches to jump around between days in some cases.
             				if ( $total_time == 0 ) {
             					Debug::text('Total time is 0, skipping this punch control object...', __FILE__, __LINE__, __METHOD__, 10);
             					//continue;
             				}
             */
             if ($i > 0 and isset($shift_data[$shift]['last_out']) and ($p_obj->getStatus() == 10 or $p_obj->getStatus() == $prev_punch_arr['status_id'])) {
                 Debug::text('Checking for new shift...', __FILE__, __LINE__, __METHOD__, 10);
                 if ($p_obj->getTimeStamp() - $shift_data[$shift]['last_out']['time_stamp'] > $new_shift_trigger_time) {
                     $shift++;
                 }
             }
             if (!isset($shift_data[$shift]['total_time'])) {
                 $shift_data[$shift]['total_time'] = 0;
             }
             $punch_day_epoch = TTDate::getBeginDayEpoch($p_obj->getTimeStamp());
             if (!isset($shift_data[$shift]['total_time_per_day'][$punch_day_epoch])) {
                 $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] = 0;
             }
             //Determine which shift is closest to the given epoch.
             $punch_difference_from_epoch = abs($epoch - $p_obj->getTimeStamp());
             if ($nearest_punch_difference === FALSE or $punch_difference_from_epoch < $nearest_punch_difference) {
                 Debug::text('Nearest Shift Determined to be: ' . $shift . ' Nearest Punch Diff: ' . (int) $nearest_punch_difference . ' Punch Diff: ' . $punch_difference_from_epoch, __FILE__, __LINE__, __METHOD__, 10);
                 $nearest_shift_id = $shift;
                 $nearest_punch_difference = $punch_difference_from_epoch;
             }
             $punch_arr = array('id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_date_id' => $punch_control_obj->getUserDateID(), 'time_stamp' => $p_obj->getTimeStamp(), 'status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType());
             $shift_data[$shift]['punches'][] = $punch_arr;
             $shift_data[$shift]['punch_control_ids'][] = $p_obj->getPunchControlId();
             if ($punch_control_obj->getUserDateID() != FALSE) {
                 $shift_data[$shift]['user_date_ids'][] = $punch_control_obj->getUserDateID();
             }
             $shift_data[$shift]['span_midnight'] = FALSE;
             if (!isset($shift_data[$shift]['first_in']) and $p_obj->getStatus() == 10) {
                 //Debug::text('First In -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
                 $shift_data[$shift]['first_in'] = $punch_arr;
             } elseif ($p_obj->getStatus() == 20) {
                 //Debug::text('Last Out -- Punch ID: '. $p_obj->getID() .' Punch Control ID: '. $p_obj->getPunchControlID() .' TimeStamp: '. TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp() ), __FILE__, __LINE__, __METHOD__, 10);
                 $shift_data[$shift]['last_out'] = $punch_arr;
                 //Debug::text('Total Time: '. $total_time, __FILE__, __LINE__, __METHOD__, 10);
                 $shift_data[$shift]['total_time'] += $total_time;
                 //Check to see if the previous punch was on a different day then the current punch.
                 if (isset($prev_punch_arr) and is_array($prev_punch_arr) and ($p_obj->getStatus() == 20 and $prev_punch_arr['status_id'] != 20) and TTDate::doesRangeSpanMidnight($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp()) == TRUE) {
                     Debug::text('Punch pair DOES span midnight', __FILE__, __LINE__, __METHOD__, 10);
                     $shift_data[$shift]['span_midnight'] = TRUE;
                     $total_time_for_each_day_arr = TTDate::calculateTimeOnEachDayBetweenRange($prev_punch_arr['time_stamp'], $p_obj->getTimeStamp());
                     if (is_array($total_time_for_each_day_arr)) {
                         foreach ($total_time_for_each_day_arr as $begin_day_epoch => $day_total_time) {
                             if (!isset($shift_data[$shift]['total_time_per_day'][$begin_day_epoch])) {
                                 $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] = 0;
                             }
                             $shift_data[$shift]['total_time_per_day'][$begin_day_epoch] += $day_total_time;
                         }
                     }
                     unset($total_time_for_each_day_arr, $begin_day_epoch, $day_total_time, $prev_day_total_time);
                 } else {
                     $shift_data[$shift]['total_time_per_day'][$punch_day_epoch] += $total_time;
                 }
             }
             $prev_punch_arr = $punch_arr;
             $i++;
         }
         //Debug::Arr($shift_data, 'aShift Data:', __FILE__, __LINE__, __METHOD__, 10);
         if (isset($shift_data)) {
             //Loop through each shift to determine the day with the most time.
             foreach ($shift_data as $tmp_shift_key => $tmp_shift_data) {
                 krsort($shift_data[$tmp_shift_key]['total_time_per_day']);
                 //Sort by day first
                 arsort($shift_data[$tmp_shift_key]['total_time_per_day']);
                 //Sort by total time per day.
                 reset($shift_data[$tmp_shift_key]['total_time_per_day']);
                 $shift_data[$tmp_shift_key]['day_with_most_time'] = key($shift_data[$tmp_shift_key]['total_time_per_day']);
                 $shift_data[$tmp_shift_key]['punch_control_ids'] = array_unique($shift_data[$tmp_shift_key]['punch_control_ids']);
                 if (isset($shift_data[$tmp_shift_key]['user_date_ids'])) {
                     $shift_data[$tmp_shift_key]['user_date_ids'] = array_unique($shift_data[$tmp_shift_key]['user_date_ids']);
                 }
             }
             unset($tmp_shift_key, $tmp_shift_data);
             if ($filter == 'first_shift') {
                 //Only return first shift.
                 $shift_data = $shift_data[0];
             } elseif ($filter == 'last_shift') {
                 //Only return last shift.
                 $shift_data = $shift_data[$shift];
             } elseif ($filter == 'nearest_shift') {
                 $shift_data = $shift_data[$nearest_shift_id];
                 //Check to make sure the nearest shift is within the new shift trigger time of EPOCH.
                 if (isset($shift_data['first_in']['time_stamp'])) {
                     $first_in = $shift_data['first_in']['time_stamp'];
                 } elseif (isset($shift_data['last_out']['time_stamp'])) {
                     $first_in = $shift_data['last_out']['time_stamp'];
                 }
                 if (isset($shift_data['last_out']['time_stamp'])) {
                     $last_out = $shift_data['last_out']['time_stamp'];
                 } elseif (isset($shift_data['first_in']['time_stamp'])) {
                     $last_out = $shift_data['first_in']['time_stamp'];
                 }
                 if (TTDate::isTimeOverLap($epoch, $epoch, $first_in - $new_shift_trigger_time, $last_out + $new_shift_trigger_time) == FALSE) {
                     Debug::Text('Nearest shift is outside the new shift trigger time... Epoch: ' . $epoch . ' First In: ' . $first_in . ' Last Out: ' . $last_out . ' New Shift Trigger: ' . $new_shift_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                     return FALSE;
                 }
                 unset($first_in, $last_out);
             }
             $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
             //Debug::Arr($shift_data, 'bShift Data:', __FILE__, __LINE__, __METHOD__, 10);
             return $shift_data;
         }
     }
     $profiler->stopTimer('PayPeriodScheduleFactory::getShiftData()');
     return FALSE;
 }
 function createPayStubAmendments($epoch = NULL)
 {
     //Get all recurring pay stub amendments and generate single pay stub amendments if appropriate.
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     $ulf = TTnew('UserListFactory');
     Debug::text('Recurring PS Amendment ID: ' . $this->getId() . ' Frequency: ' . $this->getFrequency(), __FILE__, __LINE__, __METHOD__, 10);
     $this->StartTransaction();
     $tmp_user_ids = $this->getUser();
     if ($tmp_user_ids[0] == -1) {
         $ulf->getByCompanyIdAndStatus($this->getCompany(), 10);
         foreach ($ulf as $user_obj) {
             $user_ids[] = $user_obj->getId();
         }
         unset($user_obj);
     } else {
         $user_ids = $this->getUser();
     }
     unset($tmp_user_ids);
     Debug::text('Total User IDs: ' . count($user_ids), __FILE__, __LINE__, __METHOD__, 10);
     if (is_array($user_ids) and count($user_ids) > 0) {
         //Make the PS amendment duplicate check start/end date separate
         //Make the PS amendment effective date separate.
         switch ($this->getFrequency()) {
             case 10:
                 //Get all open pay periods
                 $pplf = TTnew('PayPeriodListFactory');
                 //FIXME: Get all non-closed pay periods AFTER the start date.
                 $pplf->getByUserIdListAndNotStatusAndStartDateAndEndDate($user_ids, 20, $this->getStartDate(), $this->getEndDate());
                 //All non-closed pay periods
                 Debug::text('Found Open Pay Periods: ' . $pplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 foreach ($pplf as $pay_period_obj) {
                     Debug::text('Working on Pay Period: ' . $pay_period_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                     //If near the end of a pay period, or a pay period is already ended, add PS amendment if
                     //it does not already exist.
                     if ($epoch >= $pay_period_obj->getEndDate() and $this->checkTimeFrame($epoch)) {
                         Debug::text('After end of pay period. Start Date: ' . TTDate::getDate('DATE+TIME', $pay_period_obj->getStartDate()) . ' End Date: ' . TTDate::getDate('DATE+TIME', $pay_period_obj->getEndDate()), __FILE__, __LINE__, __METHOD__, 10);
                         $psalf = TTnew('PayStubAmendmentListFactory');
                         //Loop through each user of this Pay Period Schedule adding PS amendments if they don't already exist.
                         $pay_period_schedule_users = $pay_period_obj->getPayPeriodScheduleObject()->getUser();
                         Debug::text(' Pay Period Schedule Users: ' . count($pay_period_schedule_users), __FILE__, __LINE__, __METHOD__, 10);
                         foreach ($pay_period_schedule_users as $user_id) {
                             //Make sure schedule user is in the PS amendment user list and user is active.
                             Debug::text(' Pay Period Schedule User: '******' Recurring PS Amendment Selected Users: ', __FILE__, __LINE__, __METHOD__,10);
                             if ($ulf->getById($user_id)->getCurrent()->getStatus() == 10 and in_array($user_id, $user_ids)) {
                                 //Check to see if the amendment was added already.
                                 if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $pay_period_obj->getStartDate(), $pay_period_obj->getEndDate())->getRecordCount() == 0) {
                                     //No amendment, good to insert one
                                     Debug::text('Inserting Recurring PS Amendment for User: '******'PayStubAmendmentFactory');
                                     $psaf->setUser($user_id);
                                     $psaf->setStatus(50);
                                     $psaf->setType($this->getType());
                                     $psaf->setRecurringPayStubAmendmentId($this->getId());
                                     $psaf->setPayStubEntryNameId($this->getPayStubEntryNameId());
                                     if ($this->getType() == 10) {
                                         $psaf->setRate($this->getRate());
                                         $psaf->setUnits($this->getUnits());
                                         $psaf->setAmount($this->getAmount());
                                     } else {
                                         $psaf->setPercentAmount($this->getPercentAmount());
                                         $psaf->setPercentAmountEntryNameID($this->getPercentAmountEntryNameId());
                                     }
                                     $psaf->setDescription($this->getPayStubAmendmentDescription());
                                     $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($pay_period_obj->getEndDate()));
                                     if ($psaf->isValid()) {
                                         $psaf->Save();
                                     }
                                 } else {
                                     //Amendment already inserted!
                                     Debug::text('Recurring PS Amendment already inserted for User: '******'Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                 //continue;
                             }
                         }
                     } else {
                         Debug::text('Not in TimeFrame, not inserting amendments: Epoch: ' . $epoch . ' Pay Period End Date: ' . $pay_period_obj->getEndDate(), __FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
                 break;
             case 30:
                 //Weekly
             //Weekly
             case 40:
                 //Monthly
             //Monthly
             case 70:
                 //Annually
                 switch ($this->getFrequency()) {
                     case 30:
                         $trigger_date = TTDate::getDateOfNextDayOfWeek(TTDate::getBeginWeekEpoch($epoch), $this->getStartDate());
                         $start_date = TTDate::getBeginWeekEpoch($epoch);
                         $end_date = TTDate::getEndWeekEpoch($epoch);
                         break;
                     case 40:
                         $trigger_date = TTDate::getDateOfNextDayOfMonth(TTDate::getBeginMonthEpoch($epoch), $this->getStartDate());
                         //$monthly_date = TTDate::getDateOfNextDayOfMonth( TTDate::getBeginMonthEpoch($epoch), $this->getStartDate() );
                         $start_date = TTDate::getBeginMonthEpoch($epoch);
                         $end_date = TTDate::getEndMonthEpoch($epoch);
                         break;
                     case 70:
                         $trigger_date = TTDate::getDateOfNextYear($this->getStartDate(), $epoch);
                         //$start_date = TTDate::getBeginYearEpoch($epoch);
                         //$end_date = TTDate::getEndYearEpoch($epoch);
                         $start_date = TTDate::getBeginDayEpoch($epoch - 86400 * 365);
                         $end_date = TTDate::getEndDayEpoch($epoch);
                         break;
                 }
                 Debug::text('Trigger Date: ' . TTDate::getDate('DATE', $trigger_date), __FILE__, __LINE__, __METHOD__, 10);
                 if ($epoch >= $trigger_date and $this->checkTimeFrame($epoch)) {
                     Debug::text('Within timeframe... Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
                     foreach ($user_ids as $user_id) {
                         //Make sure schedule user is in the PS amendment user list and user is active.
                         if ($ulf->getById($user_id)->getCurrent()->getStatus() != 10 and !in_array($user_id, $user_ids)) {
                             Debug::text('Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                             continue;
                         }
                         $psalf = TTnew('PayStubAmendmentListFactory');
                         if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $start_date, $end_date)->getRecordCount() == 0) {
                             //No amendment, good to insert one
                             Debug::text('Inserting Recurring PS Amendment for User: '******'PayStubAmendmentFactory');
                             $psaf->setUser($user_id);
                             $psaf->setStatus(50);
                             $psaf->setType($this->getType());
                             $psaf->setRecurringPayStubAmendmentId($this->getId());
                             $psaf->setPayStubEntryNameId($this->getPayStubEntryNameId());
                             if ($this->getType() == 10) {
                                 $psaf->setRate($this->getRate());
                                 $psaf->setUnits($this->getUnits());
                                 $psaf->setAmount($this->getAmount());
                             } else {
                                 $psaf->setPercentAmount($this->getPercentAmount());
                                 $psaf->setPercentAmountEntryNameID($this->getPercentAmountEntryNameId());
                             }
                             $psaf->setDescription($this->getDescription());
                             $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($trigger_date));
                             if ($psaf->isValid()) {
                                 $psaf->Save();
                             }
                         } else {
                             //Amendment already inserted!
                             Debug::text('Recurring PS Amendment already inserted for User: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                 }
                 break;
         }
     }
     //$this->FailTransaction();
     $this->CommitTransaction();
     return TRUE;
 }
예제 #17
0
 /**
  * Get all necessary dates for building the schedule in a single call, this is mainly as a performance optimization.
  * @param array $data filter data
  * @return array
  */
 function getScheduleDates($base_date, $type, $strict = TRUE)
 {
     $epoch = TTDate::parseDateTime($base_date);
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     if ($type == '') {
         $type = 'week';
     }
     switch (strtolower($type)) {
         case 'day':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getEndDayEpoch($epoch);
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 86400);
             }
             break;
         case 'week':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginWeekEpoch($epoch, $this->getCurrentUserPreferenceObject()->getStartWeekDay());
                 $end_date = TTDate::getEndWeekEpoch($epoch, $this->getCurrentUserPreferenceObject()->getStartWeekDay());
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 7 * 86400);
             }
             break;
         case 'month':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginWeekEpoch(TTDate::getBeginMonthEpoch($epoch), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
                 $end_date = TTDate::getEndWeekEpoch(TTDate::getEndMonthEpoch($epoch), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 30 * 86400);
             }
             break;
         case 'year':
             if ($strict == TRUE) {
                 $start_date = TTDate::getBeginWeekEpoch(TTDate::getBeginMonthEpoch($epoch), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
                 $end_date = TTDate::getEndWeekEpoch(TTDate::getEndMonthEpoch(TTDate::getEndMonthEpoch($epoch) + 86400 * 2), $this->getCurrentUserPreferenceObject()->getStartWeekDay());
             } else {
                 $start_date = TTDate::getBeginDayEpoch($epoch);
                 $end_date = TTDate::getBeginDayEpoch(TTDate::getMiddleDayEpoch($epoch) + 62 * 86400);
             }
             break;
     }
     $retarr = array('base_date' => $epoch, 'start_date' => $start_date, 'end_date' => $end_date, 'base_display_date' => TTDate::getAPIDate('DATE', $epoch), 'start_display_date' => TTDate::getAPIDate('DATE', $start_date), 'end_display_date' => TTDate::getAPIDate('DATE', $end_date));
     Debug::Arr($retarr, 'Schedule Dates: Base Date: ' . $base_date . ' Type: ' . $type . ' Strict: ' . (int) $strict, __FILE__, __LINE__, __METHOD__, 10);
     return $retarr;
 }
 function exportPayStub($pslf = NULL, $export_type = NULL)
 {
     global $current_company;
     if (!is_object($pslf) and $this->getId() != '') {
         $pslf = new PayStubListFactory();
         $pslf->getById($this->getId());
     }
     if (get_class($pslf) !== 'PayStubListFactory') {
         return FALSE;
     }
     if ($export_type == '') {
         return FALSE;
     }
     if ($pslf->getRecordCount() > 0) {
         Debug::Text('aExporting...', __FILE__, __LINE__, __METHOD__, 10);
         switch (strtolower($export_type)) {
             case 'hsbc':
             case '1464':
             case '105':
             case 'ach':
                 //Get file creation number
                 $ugdlf = new UserGenericDataListFactory();
                 $ugdlf->getByCompanyIdAndScriptAndDefault($current_company->getId(), 'PayStubFactory', TRUE);
                 if ($ugdlf->getRecordCount() > 0) {
                     Debug::Text('Found Script Setup Data!', __FILE__, __LINE__, __METHOD__, 10);
                     $ugd_obj = $ugdlf->getCurrent();
                     $setup_data = $ugd_obj->getData();
                 } else {
                     $ugd_obj = new UserGenericDataFactory();
                 }
                 Debug::Text('bExporting...', __FILE__, __LINE__, __METHOD__, 10);
                 //get User Bank account info
                 $balf = new BankAccountListFactory();
                 $balf->getCompanyAccountByCompanyId($current_company->getID());
                 if ($balf->getRecordCount() > 0) {
                     $company_bank_obj = $balf->getCurrent();
                     //Debug::Arr($company_bank_obj,'Company Bank Object', __FILE__, __LINE__, __METHOD__,10);
                 }
                 if (isset($setup_data['file_creation_number'])) {
                     $setup_data['file_creation_number']++;
                 } else {
                     //Start at a high number, in attempt to eliminate conflicts.
                     $setup_data['file_creation_number'] = 500;
                 }
                 Debug::Text('bFile Creation Number: ' . $setup_data['file_creation_number'], __FILE__, __LINE__, __METHOD__, 10);
                 //Increment file creation number in DB
                 if ($ugd_obj->getId() == '') {
                     $ugd_obj->setID($ugd_obj->getId());
                 }
                 $ugd_obj->setCompany($current_company->getId());
                 $ugd_obj->setName('PayStubFactory');
                 $ugd_obj->setScript('PayStubFactory');
                 $ugd_obj->setData($setup_data);
                 $ugd_obj->setDefault(TRUE);
                 if ($ugd_obj->isValid()) {
                     $ugd_obj->Save();
                 }
                 $eft = new EFT();
                 $eft->setFileFormat($export_type);
                 $eft->setOriginatorID($current_company->getOriginatorID());
                 $eft->setFileCreationNumber($setup_data['file_creation_number']);
                 $eft->setDataCenter($current_company->getDataCenterID());
                 $eft->setOriginatorShortName($current_company->getShortName());
                 $psealf = new PayStubEntryAccountListFactory();
                 foreach ($pslf as $pay_stub_obj) {
                     Debug::Text('Looping over Pay Stub... ID: ' . $pay_stub_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                     //Get pay stub entries.
                     $pself = new PayStubEntryListFactory();
                     $pself->getByPayStubId($pay_stub_obj->getId());
                     $prev_type = NULL;
                     $description_subscript_counter = 1;
                     foreach ($pself as $pay_stub_entry) {
                         $description_subscript = NULL;
                         //$pay_stub_entry_name_obj = $psenlf->getById( $pay_stub_entry->getPayStubEntryNameId() ) ->getCurrent();
                         $pay_stub_entry_name_obj = $psealf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
                         if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                             $type = $pay_stub_entry_name_obj->getType();
                         }
                         //var_dump( $pay_stub_entry->getDescription() );
                         if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE and strlen($pay_stub_entry->getDescription()) > 0) {
                             $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                             $description_subscript = $description_subscript_counter;
                             $description_subscript_counter++;
                         }
                         if ($type != 40 or $type == 40 and $pay_stub_entry->getAmount() != 0) {
                             $pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getName(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
                         }
                         $prev_type = $pay_stub_entry_name_obj->getType();
                     }
                     if (isset($pay_stub_entries)) {
                         $pay_stub = array('id' => $pay_stub_obj->getId(), 'display_id' => str_pad($pay_stub_obj->getId(), 12, 0, STR_PAD_LEFT), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'start_date' => $pay_stub_obj->getStartDate(), 'end_date' => $pay_stub_obj->getEndDate(), 'transaction_date' => $pay_stub_obj->getTransactionDate(), 'status' => $pay_stub_obj->getStatus(), 'entries' => $pay_stub_entries, 'created_date' => $pay_stub_obj->getCreatedDate(), 'created_by' => $pay_stub_obj->getCreatedBy(), 'updated_date' => $pay_stub_obj->getUpdatedDate(), 'updated_by' => $pay_stub_obj->getUpdatedBy(), 'deleted_date' => $pay_stub_obj->getDeletedDate(), 'deleted_by' => $pay_stub_obj->getDeletedBy());
                         unset($pay_stub_entries);
                         //Get User information
                         $ulf = new UserListFactory();
                         $user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
                         //Get company information
                         $clf = new CompanyListFactory();
                         $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
                         //get User Bank account info
                         $balf = new BankAccountListFactory();
                         $user_bank_obj = $balf->getUserAccountByCompanyIdAndUserId($user_obj->getCompany(), $user_obj->getId());
                         if ($user_bank_obj->getRecordCount() > 0) {
                             $user_bank_obj = $user_bank_obj->getCurrent();
                         } else {
                             continue;
                         }
                         $record = new EFT_Record();
                         $record->setType('C');
                         $amount = $pay_stub['entries'][40][0]['amount'];
                         $record->setCPACode(200);
                         $record->setAmount($amount);
                         unset($amount);
                         $record->setDueDate(TTDate::getBeginDayEpoch($pay_stub_obj->getTransactionDate()));
                         //$record->setDueDate( strtotime("24-Sep-99") );
                         $record->setInstitution($user_bank_obj->getInstitution());
                         $record->setTransit($user_bank_obj->getTransit());
                         $record->setAccount($user_bank_obj->getAccount());
                         $record->setName($user_obj->getFullName());
                         $record->setOriginatorShortName($company_obj->getShortName());
                         $record->setOriginatorLongName(substr($company_obj->getName(), 0, 30));
                         $record->setOriginatorReferenceNumber('TT' . $pay_stub_obj->getId());
                         if (isset($company_bank_obj) and is_object($company_bank_obj)) {
                             $record->setReturnInstitution($company_bank_obj->getInstitution());
                             $record->setReturnTransit($company_bank_obj->getTransit());
                             $record->setReturnAccount($company_bank_obj->getAccount());
                         }
                         $eft->setRecord($record);
                     }
                 }
                 $eft->compile();
                 $output = $eft->getCompiledData();
                 break;
             case 'cheque_9085':
             case 'cheque_9209p':
             case 'cheque_dlt103':
             case 'cheque_dlt104':
             case 'cheque_cr_standard_form_1':
             case 'cheque_cr_standard_form_2':
                 $border = 0;
                 $show_background = 0;
                 $pdf = new TTPDF();
                 $pdf->setMargins(0, 0, 0, 0);
                 $pdf->SetAutoPageBreak(FALSE);
                 $pdf->SetFont('freeserif', '', 10);
                 $psealf = new PayStubEntryAccountListFactory();
                 $i = 0;
                 foreach ($pslf as $pay_stub_obj) {
                     //Get pay stub entries.
                     $pself = new PayStubEntryListFactory();
                     $pself->getByPayStubId($pay_stub_obj->getId());
                     $pay_stub_entries = NULL;
                     $prev_type = NULL;
                     $description_subscript_counter = 1;
                     foreach ($pself as $pay_stub_entry) {
                         $description_subscript = NULL;
                         //$pay_stub_entry_name_obj = $psenlf->getById( $pay_stub_entry->getPayStubEntryNameId() ) ->getCurrent();
                         $pay_stub_entry_name_obj = $psealf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
                         //Use this to put the total for each type at the end of the array.
                         if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                             $type = $pay_stub_entry_name_obj->getType();
                         }
                         //Debug::text('Pay Stub Entry Name ID: '. $pay_stub_entry_name_obj->getId() .' Type ID: '. $pay_stub_entry_name_obj->getType() .' Type: '. $type, __FILE__, __LINE__, __METHOD__,10);
                         //var_dump( $pay_stub_entry->getDescription() );
                         if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE and strlen($pay_stub_entry->getDescription()) > 0) {
                             $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                             $description_subscript = $description_subscript_counter;
                             $description_subscript_counter++;
                         }
                         $amount_words = str_pad(ucwords(Numbers_Words::toWords(floor($pay_stub_entry->getAmount()), "en_US")) . ' ', 65, "-", STR_PAD_RIGHT);
                         //echo "Amount: ". floor($pay_stub_entry->getAmount()) ." - Words: ". $amount_words ."<br>\n";
                         //var_dump($amount_words);
                         if ($type != 40 or $type == 40 and $pay_stub_entry->getAmount() != 0) {
                             $pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getName(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'amount_padded' => str_pad($pay_stub_entry->getAmount(), 12, '*', STR_PAD_LEFT), 'amount_words' => $amount_words, 'amount_cents' => Misc::getAfterDecimal($pay_stub_entry->getAmount()), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
                         }
                         unset($amount_words);
                         //Only for net pay, make a total YTD of Advance plus Net.
                         /*
                         if ( $type == 40 ) {
                         	$pay_stub_entries[$type][0]['ytd_net_plus_advance'] =
                         }
                         */
                         $prev_type = $pay_stub_entry_name_obj->getType();
                     }
                     //Get User information
                     $ulf = new UserListFactory();
                     $user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
                     //Get company information
                     $clf = new CompanyListFactory();
                     $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
                     if ($user_obj->getCountry() == 'CA') {
                         $date_format = 'd/m/Y';
                     } else {
                         $date_format = 'm/d/Y';
                     }
                     $pay_stub = array('id' => $pay_stub_obj->getId(), 'display_id' => str_pad($pay_stub_obj->getId(), 15, 0, STR_PAD_LEFT), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'start_date' => $pay_stub_obj->getStartDate(), 'end_date' => $pay_stub_obj->getEndDate(), 'transaction_date' => $pay_stub_obj->getTransactionDate(), 'transaction_date_display' => date($date_format, $pay_stub_obj->getTransactionDate()), 'status' => $pay_stub_obj->getStatus(), 'entries' => $pay_stub_entries, 'tainted' => $pay_stub_obj->getTainted(), 'created_date' => $pay_stub_obj->getCreatedDate(), 'created_by' => $pay_stub_obj->getCreatedBy(), 'updated_date' => $pay_stub_obj->getUpdatedDate(), 'updated_by' => $pay_stub_obj->getUpdatedBy(), 'deleted_date' => $pay_stub_obj->getDeletedDate(), 'deleted_by' => $pay_stub_obj->getDeletedBy());
                     unset($pay_stub_entries);
                     Debug::text($i . '. Pay Stub Transaction Date: ' . $pay_stub_obj->getTransactionDate(), __FILE__, __LINE__, __METHOD__, 10);
                     //Get Pay Period information
                     $pplf = new PayPeriodListFactory();
                     $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
                     $pp_start_date = $pay_period_obj->getStartDate();
                     $pp_end_date = $pay_period_obj->getEndDate();
                     $pp_transaction_date = $pay_period_obj->getTransactionDate();
                     //Get pay period numbers
                     $ppslf = new PayPeriodScheduleListFactory();
                     $pay_period_schedule_obj = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
                     $pay_period_data = array('start_date' => TTDate::getDate('DATE', $pp_start_date), 'end_date' => TTDate::getDate('DATE', $pp_end_date), 'transaction_date' => TTDate::getDate('DATE', $pp_transaction_date), 'annual_pay_periods' => $pay_period_schedule_obj->getAnnualPayPeriods());
                     $pdf->AddPage();
                     switch ($export_type) {
                         case 'cheque_9085':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9085.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(42, $adjust_y));
                             $pdf->Cell(100, 5, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 5, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY(50, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub['transaction_date_display'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY(50, $adjust_y));
                             $pdf->Cell(23, 5, ' ' . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(55, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(60, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getAddress1() . ' ' . $user_obj->getAddress2(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(65, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 95;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_9209p':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9209P.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(42, $adjust_y));
                             $pdf->Cell(100, 10, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 10, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(25, $adjust_y));
                             $pdf->Cell(10, 10, TTi18n::gettext('Date:') . ' ', $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(182, $adjust_x), Misc::AdjustXY(25, $adjust_y));
                             $pdf->Cell(25, 10, $pay_stub['transaction_date_display'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(42, $adjust_y));
                             $pdf->Cell(35, 10, $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(57, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(62, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getAddress1() . ' ' . $user_obj->getAddress2(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(67, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 100;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_dlt103':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_dlt103.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(54, $adjust_y));
                             $pdf->Cell(100, 10, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 10, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(10, 10, TTi18n::gettext('Date:') . ' ', $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(182, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(25, 10, $pay_stub['transaction_date_display'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(46, $adjust_y));
                             $pdf->Cell(35, 10, $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(46, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 100;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_dlt104':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_dlt104.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(52, $adjust_y));
                             $pdf->Cell(100, 10, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 10, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(10, 10, TTi18n::gettext('Date:') . ' ', $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(182, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(25, 10, $pay_stub['transaction_date_display'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(43, $adjust_y));
                             $pdf->Cell(35, 10, $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(48, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 100;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_cr_standard_form_1':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9085.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(41, $adjust_y));
                             $pdf->Cell(100, 5, $pay_stub['entries'][40][0]['amount_words'] . TTi18n::gettext(' and ') . $pay_stub['entries'][40][0]['amount_cents'] . '/100 *****', $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(100, $adjust_x), Misc::AdjustXY(23, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub['transaction_date_display'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(136, $adjust_x), Misc::AdjustXY(32, $adjust_y));
                             $pdf->Cell(24, 5, '  $' . $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 95;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: $') . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: $') . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             //Signature lines
                             $pdf->setXY(Misc::AdjustXY(7, $adjust_x), Misc::AdjustXY(250, $adjust_y));
                             $border = 0;
                             $pdf->Cell(40, 5, TTi18n::gettext('Employee Signature:'), $border, 0, 'L');
                             $pdf->Cell(60, 5, '_____________________________', $border, 0, 'L');
                             $pdf->Cell(40, 5, TTi18n::gettext('Supervisor Signature:'), $border, 0, 'R');
                             $pdf->Cell(60, 5, '_____________________________', $border, 0, 'L');
                             $pdf->Ln();
                             $pdf->Cell(40, 5, '', $border, 0, 'R');
                             $pdf->Cell(60, 5, $user_obj->getFullName(), $border, 0, 'C');
                             $pdf->Ln();
                             $pdf->Cell(147, 5, '', $border, 0, 'R');
                             $pdf->Cell(60, 5, '_____________________________', $border, 0, 'C');
                             $pdf->Ln();
                             $pdf->Cell(140, 5, '', $border, 0, 'R');
                             $pdf->Cell(60, 5, TTi18n::gettext('(print name)'), $border, 0, 'C');
                             break;
                         case 'cheque_cr_standard_form_2':
                             $pdf_created_date = time();
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9085.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(41, $adjust_y));
                             $pdf->Cell(100, 5, $pay_stub['entries'][40][0]['amount_words'] . TTi18n::gettext(' and ') . $pay_stub['entries'][40][0]['amount_cents'] . '/100 *****', $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(100, $adjust_x), Misc::AdjustXY(23, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub['transaction_date_display'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(136, $adjust_x), Misc::AdjustXY(32, $adjust_y));
                             $pdf->Cell(24, 5, '$  ' . $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 110;
                             $pdf->SetFont('', 'U', 14);
                             $pdf->setXY(Misc::AdjustXY(65, $adjust_x), Misc::AdjustXY(100, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Recipient Copy:'), $border, 0, 'C');
                             $pdf->SetFont('', '', 10);
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Date of Issue:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(130, 5, TTDate::getDate('DATE+TIME', $pdf_created_date), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Date of Issue:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(130, 5, TTDate::getDate('DATE+TIME', $pdf_created_date), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Recipient:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(110, 5, $user_obj->getFullName(), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Recipient:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(130, 5, $user_obj->getFullName(), $border, 0, 'J');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(130, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Amount:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, ' $' . $pay_stub['entries'][40][0]['amount'], $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(130 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Amount:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, ' $' . $pay_stub['entries'][40][0]['amount'], $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(140, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Regarding:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, TTi18n::gettext('Payment from') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']) . ' ' . TTi18n::gettext('to') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(140 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Regarding:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, TTi18n::gettext('Payment from') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']) . ' ' . TTi18n::gettext('to') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'J');
                             $pdf->SetFont('', 'U', 14);
                             $pdf->setXY(Misc::AdjustXY(65, $adjust_x), Misc::AdjustXY(210, $adjust_y));
                             $pdf->Cell(75, 5, $company_obj->getName() . ' ' . TTi18n::gettext('Copy:'), $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(30, $adjust_x), Misc::AdjustXY(260, $adjust_y));
                             $column_widths = array('generated_by' => 25, 'signed_by' => 25, 'received_by' => 35, 'date' => 35, 'sin_ssn' => 35);
                             $line_h = 4;
                             $cell_h_min = $cell_h_max = $line_h * 4;
                             $pdf->SetFont('', '', 8);
                             $pdf->setFillColor(255, 255, 255);
                             $pdf->MultiCell($column_widths['generated_by'], $line_h, TTi18n::gettext('Generated By') . "\n\n\n ", 1, 'C', 1, 0);
                             $pdf->MultiCell($column_widths['signed_by'], $line_h, TTi18n::gettext('Signed By') . "\n\n\n ", 1, 'C', 1, 0);
                             $pdf->MultiCell($column_widths['received_by'], $line_h, TTi18n::gettext('Received By') . "\n\n\n ", 'T,L,B', 'C', 1, 0);
                             $pdf->MultiCell($column_widths['date'], $line_h, TTi18n::gettext('Date') . "\n\n\n ", 'T,B', 'C', 1, 0);
                             $pdf->MultiCell($column_widths['sin_ssn'], $line_h, TTi18n::gettext('SIN / SSN') . "\n\n\n ", 'T,R,B', 'C', 1, 0);
                             $pdf->Ln();
                             $pdf->SetFont('', '', 10);
                             break;
                     }
                     $i++;
                 }
                 $output = $pdf->Output('', 'S');
                 break;
         }
     }
     if (isset($output)) {
         return $output;
     }
     return FALSE;
 }
예제 #19
0
 static function getNextScheduleDate($min_col, $hour_col, $dom_col, $month_col, $dow_col, $epoch = NULL)
 {
     if ($epoch == '') {
         $epoch = 0;
     }
     $month_arr = self::parseScheduleString($month_col, 'month');
     $day_of_month_arr = self::parseScheduleString($dom_col, 'day_of_month');
     $day_of_week_arr = self::parseScheduleString($dow_col, 'day_of_week');
     $hour_arr = self::parseScheduleString($hour_col, 'hour');
     $minute_arr = self::parseScheduleString($min_col, 'minute');
     $retval = $epoch;
     $i = 0;
     while ($i < 500) {
         //Prevent infinite loop
         $date_arr = getdate($retval);
         $i++;
         //Order from minute to month, least granular to most granular.
         if (!in_array($date_arr['minutes'], $minute_arr)) {
             $retval = TTDate::incrementDate($retval, 1, 'minute');
             //Debug::text(' Minute: Retval: '. TTDate::getDate('DATE+TIME', $retval) .' Current Epoch: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__,10);
             continue;
         }
         if (!in_array($date_arr['hours'], $hour_arr)) {
             $retval = TTDate::incrementDate($retval, 1, 'hour');
             //Debug::text(' Hour: Retval: '. TTDate::getDate('DATE+TIME', $retval) .' Current Epoch: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__,10);
             continue;
         }
         if (!in_array($date_arr['mday'], $day_of_month_arr) or !in_array($date_arr['wday'], $day_of_week_arr)) {
             $retval = TTDate::getBeginDayEpoch(TTDate::incrementDate($retval, 1, 'day'));
             //Debug::text(' Day: Retval: '. TTDate::getDate('DATE+TIME', $retval) .' Current Epoch: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__,10);
             continue;
         }
         if (!in_array($date_arr['mon'], $month_arr)) {
             $retval = TTDate::getBeginDayEpoch(TTDate::incrementDate($retval, 1, 'month'));
             //Debug::text(' Month: Retval: '. TTDate::getDate('DATE+TIME', $retval) .' Current Epoch: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__,10);
             continue;
         }
         //Debug::text(' None: Retval: '. TTDate::getDate('DATE+TIME', $retval) .' Current Epoch: '. TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__,10);
         //Halt the loop...
         break;
     }
     Debug::text(' Next Scheduled Date: ' . TTDate::getDate('DATE+TIME', $retval) . ' Based on Current Epoch: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
     //Debug::text('  JOB is NOT SCHEDULED TO RUN YET!', __FILE__, __LINE__, __METHOD__,10);
     return $retval;
 }
 function getLookbackStartAndEndDates($pay_period_obj)
 {
     $retarr = array('start_date' => FALSE, 'end_date' => TTDate::getEndDayEpoch((int) $pay_period_obj->getTransactionDate() - 86400));
     if ($this->getCompanyValue3() == 100) {
         //Pay Periods
         //Not implemented for now, as it has many issues, things like gaps between pay periods, employees switching between pay period schedules, etc...
         //We could just count the number of pay stubs, but this has issues with employees leaving and returning and such.
     } else {
         $length_of_service_days = bcmul((double) $this->getCompanyValue2(), $this->length_of_service_multiplier[(int) $this->getCompanyValue3()], 4);
         $retarr['start_date'] = TTDate::getBeginDayEpoch((int) $pay_period_obj->getTransactionDate() - $length_of_service_days * 86400);
     }
     Debug::text('Start Date: ' . TTDate::getDate('DATE+TIME', $retarr['start_date']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $retarr['end_date']), __FILE__, __LINE__, __METHOD__, 10);
     return $retarr;
 }
예제 #21
0
 /**
  * Returns array of notifications message to be displayed to the user.
  * @param string $action Action that is being performed, possible values: 'login', 'preference', 'notification', 'pay_period'
  * @return array
  */
 function getNotifications($action = FALSE)
 {
     global $config_vars, $disable_database_connection;
     $retarr = FALSE;
     //Skip this step if disable_database_connection is enabled or the user is going through the installer still
     switch (strtolower($action)) {
         case 'login':
             if ((!isset($disable_database_connection) or isset($disable_database_connection) and $disable_database_connection != TRUE) and (!isset($config_vars['other']['installer_enabled']) or isset($config_vars['other']['installer_enabled']) and $config_vars['other']['installer_enabled'] != TRUE)) {
                 //Get all system settings, so they can be used even if the user isn't logged in, such as the login page.
                 $sslf = new SystemSettingListFactory();
                 $system_settings = $sslf->getAllArray();
             }
             unset($sslf);
             //Check license validity
             if ((DEPLOYMENT_ON_DEMAND == FALSE and $this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id']) and getTTProductEdition() > 10) {
                 if (!isset($system_settings['license'])) {
                     $system_settings['license'] = NULL;
                 }
                 $license = new TTLicense();
                 $license_validate = $license->validateLicense($system_settings['license']);
                 $license_message = $license->getFullErrorMessage($license_validate, TRUE);
                 if ($license_message != '') {
                     $destination_url = 'http://www.timetrex.com/r.php?id=899';
                     if ($license_validate === TRUE) {
                         //License likely expires soon.
                         $retarr[] = array('delay' => 0, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('WARNING: %1', $license_message), 'destination' => $destination_url);
                     } else {
                         //License error.
                         $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1', $license_message), 'destination' => $destination_url);
                     }
                 }
                 unset($license, $license_validate, $license_message, $destination);
             }
             //System Requirements not being met.
             if (isset($system_settings['valid_install_requirements']) and DEPLOYMENT_ON_DEMAND == FALSE and (int) $system_settings['valid_install_requirements'] == 0) {
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 system requirement check has failed! Please contact your %1 administrator immediately to re-run the %1 installer to correct the issue.', APPLICATION_NAME), 'destination' => NULL);
             }
             //Check version mismatch
             if (isset($system_settings['system_version']) and DEPLOYMENT_ON_DEMAND == FALSE and APPLICATION_VERSION != $system_settings['system_version']) {
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 application version does not match database version. Please re-run the %1 installer to complete the upgrade process.', APPLICATION_NAME), 'destination' => NULL);
             }
             //Only display message to the primary company.
             if (time() - (int) APPLICATION_VERSION_DATE > 86400 * 475 and ($this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id'])) {
                 //~1yr and 3mths
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: This %1 version (v%2) is severely out of date and may no longer be supported. Please upgrade to the latest version as soon as possible as invalid calculations may already be occurring.', array(APPLICATION_NAME, APPLICATION_VERSION)), 'destination' => NULL);
             }
             //New version available notification.
             if (DEMO_MODE == FALSE and (isset($system_settings['new_version']) and $system_settings['new_version'] == 1) and ($this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id'])) {
                 //Only display this every two weeks.
                 $new_version_available_notification_arr = UserSettingFactory::getUserSetting($this->getCurrentUserObject()->getID(), 'new_version_available_notification');
                 if (!isset($new_version_available_notification_arr['value']) or isset($new_version_available_notification_arr['value']) and $new_version_available_notification_arr['value'] <= time() - 86400 * 14) {
                     UserSettingFactory::setUserSetting($this->getCurrentUserObject()->getID(), 'new_version_available_notification', time());
                     $retarr[] = array('delay' => -1, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: A new version of %1 available, it is highly recommended that you upgrade as soon as possible. Click here to download the latest version.', array(APPLICATION_NAME)), 'destination' => getTTProductEdition() == TT_PRODUCT_COMMUNITY ? 'http://www.timetrex.com/r.php?id=19' : 'http://www.timetrex.com/r.php?id=9');
                 }
                 unset($new_version_available_notification);
             }
             //Check for major new version.
             $new_version_notification_arr = UserSettingFactory::getUserSetting($this->getCurrentUserObject()->getID(), 'new_version_notification');
             if (DEMO_MODE == FALSE and (!isset($config_vars['branding']['application_name']) or ($this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id'])) and $this->getPermissionObject()->getLevel() >= 20 and $this->getCurrentUserObject()->getCreatedDate() <= APPLICATION_VERSION_DATE and (!isset($new_version_notification_arr['value']) or isset($new_version_notification_arr['value']) and Misc::MajorVersionCompare(APPLICATION_VERSION, $new_version_notification_arr['value'], '>'))) {
                 UserSettingFactory::setUserSetting($this->getCurrentUserObject()->getID(), 'new_version_notification', APPLICATION_VERSION);
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: Your instance of %1 has been upgraded to v%2, click here to see whats new.', array(APPLICATION_NAME, APPLICATION_VERSION)), 'destination' => 'http://www.timetrex.com/r.php?id=300');
             }
             unset($new_version_notification);
             //Check installer enabled.
             if (isset($config_vars['other']['installer_enabled']) and $config_vars['other']['installer_enabled'] == 1) {
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 is currently in INSTALL MODE. Please go to your timetrex.ini.php file and set "installer_enabled" to "FALSE".', APPLICATION_NAME), 'destination' => NULL);
             }
             //Make sure CronJobs are running correctly.
             $cjlf = new CronJobListFactory();
             $cjlf->getMostRecentlyRun();
             if ($cjlf->getRecordCount() > 0) {
                 //Is last run job more then 48hrs old?
                 $cj_obj = $cjlf->getCurrent();
                 if (PRODUCTION == TRUE and DEMO_MODE == FALSE and $cj_obj->getLastRunDate() < time() - 172800 and $cj_obj->getCreatedDate() < time() - 172800) {
                     $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: Critical maintenance jobs have not run in the last 48hours. Please contact your %1 administrator immediately.', APPLICATION_NAME), 'destination' => NULL);
                 }
             }
             unset($cjlf, $cj_obj);
             //Check if any pay periods are past their transaction date and not closed.
             if (DEMO_MODE == FALSE and $this->getPermissionObject()->Check('pay_period_schedule', 'enabled') and $this->getPermissionObject()->Check('pay_period_schedule', 'view')) {
                 $pplf = TTnew('PayPeriodListFactory');
                 $pplf->getByCompanyIdAndStatusAndTransactionDate($this->getCurrentCompanyObject()->getId(), array(10, 30), TTDate::getBeginDayEpoch(time()));
                 //Open or Post Adjustment pay periods.
                 if ($pplf->getRecordCount() > 0) {
                     foreach ($pplf as $pp_obj) {
                         if ($pp_obj->getCreatedDate() < time() - 86400 * 40) {
                             //Ignore pay period schedules newer than 40 days. They are automatically closed after 45 days.
                             $retarr[] = array('delay' => 0, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: Pay periods past their transaction date have not been closed yet. It\'s critical that these pay periods are closed to prevent data loss, click here to close them now.'), 'destination' => array('menu_name' => 'Pay Periods'));
                             break;
                         }
                     }
                 }
                 unset($pplf, $pp_obj);
             }
             //CHeck for unread messages
             $mclf = new MessageControlListFactory();
             $unread_messages = $mclf->getNewMessagesByCompanyIdAndUserId($this->getCurrentCompanyObject()->getId(), $this->getCurrentUserObject()->getId());
             Debug::text('UnRead Messages: ' . $unread_messages, __FILE__, __LINE__, __METHOD__, 10);
             if ($unread_messages > 0) {
                 $retarr[] = array('delay' => 25, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: You have %1 new message(s) waiting, click here to read them now.', $unread_messages), 'destination' => array('menu_name' => 'Messages'));
             }
             unset($mclf, $unread_messages);
             if (DEMO_MODE == FALSE) {
                 $elf = new ExceptionListFactory();
                 $elf->getFlaggedExceptionsByUserIdAndPayPeriodStatus($this->getCurrentUserObject()->getId(), 10);
                 $display_exception_flag = FALSE;
                 if ($elf->getRecordCount() > 0) {
                     foreach ($elf as $e_obj) {
                         if ($e_obj->getColumn('severity_id') == 30) {
                             $display_exception_flag = 'red';
                         }
                         break;
                     }
                 }
                 if (isset($display_exception_flag) and $display_exception_flag !== FALSE) {
                     Debug::Text('Exception Flag to Display: ' . $display_exception_flag, __FILE__, __LINE__, __METHOD__, 10);
                     $retarr[] = array('delay' => 30, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: You have critical severity exceptions pending, click here to view them now.'), 'destination' => array('menu_name' => 'Exceptions'));
                 }
                 unset($elf, $e_obj, $display_exception_flag);
             }
             if (DEMO_MODE == FALSE and $this->getPermissionObject()->getLevel() >= 20 and ($this->getCurrentUserObject()->getWorkEmail() == '' and $this->getCurrentUserObject()->getHomeEmail() == '')) {
                 $retarr[] = array('delay' => 30, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: Please click here and enter an email address for your account, this is required to receive important notices and prevent your account from being locked out.'), 'destination' => array('menu_name' => 'Contact Information'));
             }
             break;
         default:
             break;
     }
     //Check timezone is proper.
     $current_user_prefs = $this->getCurrentUserObject()->getUserPreferenceObject();
     if ($current_user_prefs->setDateTimePreferences() == FALSE) {
         //Setting timezone failed, alert user to this fact.
         //WARNING: %1 was unable to set your time zone. Please contact your %1 administrator immediately.{/t} {if $permission->Check('company','enabled') AND $permission->Check('company','edit_own')}<a href="http://forums.timetrex.com/viewtopic.php?t=40">{t}For more information please click here.{/t}</a>{/if}
         if ($this->getPermissionObject()->Check('company', 'enabled') and $this->getPermissionObject()->Check('company', 'edit_own')) {
             $destination_url = 'http://www.timetrex.com/r.php?id=1010';
             $sub_message = TTi18n::getText('For more information please click here.');
         } else {
             $destination_url = NULL;
             $sub_message = NULL;
         }
         $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 was unable to set your time zone. Please contact your %1 administrator immediately.', APPLICATION_NAME) . ' ' . $sub_message, 'destination' => $destination_url);
         unset($destination_url, $sub_message);
     }
     return $retarr;
 }
예제 #22
0
 function _outputPDFForm($format = NULL)
 {
     $show_background = TRUE;
     if ($format == 'pdf_form_print' or $format == 'pdf_form_print_government' or $format == 'efile') {
         $show_background = FALSE;
     }
     Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     $setup_data = $this->getFormConfig();
     $filter_data = $this->getFilterConfig();
     //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10);
     $current_company = $this->getUserObject()->getCompanyObject();
     if (!is_object($current_company)) {
         Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $current_user = $this->getUserObject();
     if (!is_object($current_user)) {
         Debug::Text('Invalid user object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     if ($format == 'efile_xml') {
         $return1040 = $this->getRETURN1040Object();
         // Ceate the all needed data for Return1040.xsd at here.
         $return1040->return_created_timestamp = TTDate::getDBTimeStamp(TTDate::getTime(), FALSE);
         $return1040->year = TTDate::getYear($filter_data['end_date']);
         $return1040->tax_period_begin_date = TTDate::getDate('Y-m-d', TTDate::getBeginDayEpoch($filter_data['start_date']));
         $return1040->tax_period_end__date = TTDate::getDate('Y-m-d', TTDate::getEndDayEpoch($filter_data['end_date']));
         $return1040->software_id = '';
         $return1040->originator_efin = '';
         $return1040->originator_type_code = '';
         $return1040->pin_type_code = '';
         $return1040->jurat_disclosure_code = '';
         $return1040->pin_entered_by = '';
         $return1040->signature_date = TTDate::getDate('Y-m-d', TTDate::getTime());
         $return1040->return_type = '';
         $return1040->ssn = '';
         $return1040->name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName();
         $return1040->name_control = '';
         $return1040->address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2();
         $return1040->city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
         $return1040->state = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
         $return1040->zip_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
         $return1040->ip_address = '';
         $return1040->ip_date = TTDate::getDate('Y-m-d', TTDate::getTime());
         $return1040->ip_time = TTDate::getDate('H:i:s', TTDate::getTime());
         $return1040->timezone = TTDate::getTimeZone();
         $this->getFormObject()->addForm($return1040);
     }
     $this->sortFormData();
     //Make sure forms are sorted.
     $fw2 = $this->getFW2Object();
     $fw2->setDebug(FALSE);
     //if ( $format == 'efile' ) {
     //	$fw2->setDebug(TRUE);
     //}
     $fw2->setShowBackground($show_background);
     if (stristr($format, 'government')) {
         $form_type = 'government';
     } else {
         $form_type = 'employee';
     }
     Debug::Text('Form Type: ' . $form_type, __FILE__, __LINE__, __METHOD__, 10);
     $fw2->setType($form_type);
     $fw2->year = TTDate::getYear($filter_data['end_date']);
     //Add support for the user to manually set this data in the setup_data. That way they can use multiple tax IDs for different employees, all beit manually.
     $fw2->ein = (isset($setup_data['ein']) and $setup_data['ein'] != '') ? $setup_data['ein'] : $current_company->getBusinessNumber();
     $fw2->name = (isset($setup_data['name']) and $setup_data['name'] != '') ? $setup_data['name'] : $this->getUserObject()->getFullName();
     $fw2->trade_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName();
     $fw2->company_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2();
     $fw2->company_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
     $fw2->company_state = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
     $fw2->company_zip_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
     $fw2->efile_user_id = (isset($setup_data['efile_user_id']) and $setup_data['efile_user_id'] != '') ? $setup_data['efile_user_id'] : NULL;
     $fw2->efile_state = (isset($setup_data['efile_state']) and $setup_data['efile_state'] != '') ? $setup_data['efile_state'] : 0;
     $fw2->contact_name = $current_user->getFullName();
     $fw2->contact_phone = $current_user->getWorkPhone();
     $fw2->contact_phone_ext = $current_user->getWorkPhoneExt();
     $fw2->contact_email = $current_user->getWorkEmail();
     if (isset($this->form_data) and count($this->form_data) > 0) {
         $i = 0;
         $n = 1;
         foreach ((array) $this->form_data as $row) {
             if (!isset($row['user_id'])) {
                 Debug::Text('User ID not set!', __FILE__, __LINE__, __METHOD__, 10);
                 continue;
             }
             $ulf = TTnew('UserListFactory');
             $ulf->getById((int) $row['user_id']);
             if ($ulf->getRecordCount() == 1) {
                 $user_obj = $ulf->getCurrent();
                 $ee_data = array('control_number' => $n, 'first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'address1' => $user_obj->getAddress1(), 'address2' => $user_obj->getAddress2(), 'city' => $user_obj->getCity(), 'state' => $user_obj->getProvince(), 'employment_province' => $user_obj->getProvince(), 'zip_code' => $user_obj->getPostalCode(), 'ssn' => $user_obj->getSIN(), 'employee_number' => $user_obj->getEmployeeNumber(), 'l1' => $row['l1'], 'l2' => $row['l2'], 'l3' => $row['l3'], 'l4' => $row['l4'], 'l5' => $row['l5'], 'l6' => $row['l6'], 'l7' => $row['l7'], 'l8' => $row['l8'], 'l10' => $row['l10'], 'l11' => $row['l11'], 'l12a_code' => NULL, 'l12a' => NULL, 'l12b_code' => NULL, 'l12b' => NULL, 'l12c_code' => NULL, 'l12c' => NULL, 'l12d_code' => NULL, 'l12d' => NULL, 'l14a_name' => NULL, 'l14a' => NULL, 'l14b_name' => NULL, 'l14b' => NULL, 'l14c_name' => NULL, 'l14c' => NULL, 'l14d_name' => NULL, 'l14d' => NULL);
                 if ($row['l12a'] > 0 and isset($setup_data['l12a_code']) and $setup_data['l12a_code'] != '') {
                     $ee_data['l12a_code'] = $setup_data['l12a_code'];
                     $ee_data['l12a'] = $row['l12a'];
                 }
                 if ($row['l12b'] > 0 and isset($setup_data['l12b_code']) and $setup_data['l12b_code'] != '') {
                     $ee_data['l12b_code'] = $setup_data['l12b_code'];
                     $ee_data['l12b'] = $row['l12b'];
                 }
                 if ($row['l12c'] > 0 and isset($setup_data['l12c_code']) and $setup_data['l12c_code'] != '') {
                     $ee_data['l12c_code'] = $setup_data['l12c_code'];
                     $ee_data['l12c'] = $row['l12c'];
                 }
                 if ($row['l12d'] > 0 and isset($setup_data['l12d_code']) and $setup_data['l12d_code'] != '') {
                     $ee_data['l12d_code'] = $setup_data['l12d_code'];
                     $ee_data['l12d'] = $row['l12d'];
                 }
                 if ($row['l14a'] > 0 and isset($setup_data['l14a_name']) and $setup_data['l14a_name'] != '') {
                     $ee_data['l14a_name'] = $setup_data['l14a_name'];
                     $ee_data['l14a'] = $row['l14a'];
                 }
                 if ($row['l14b'] > 0 and isset($setup_data['l14b_name']) and $setup_data['l14b_name'] != '') {
                     $ee_data['l14b_name'] = $setup_data['l14b_name'];
                     $ee_data['l14b'] = $row['l14b'];
                 }
                 if ($row['l14c'] > 0 and isset($setup_data['l14c_name']) and $setup_data['l14c_name'] != '') {
                     $ee_data['l14c_name'] = $setup_data['l14c_name'];
                     $ee_data['l14c'] = $row['l14c'];
                 }
                 if ($row['l14d'] > 0 and isset($setup_data['l14d_name']) and $setup_data['l14d_name'] != '') {
                     $ee_data['l14d_name'] = $setup_data['l14d_name'];
                     $ee_data['l14d'] = $row['l14d'];
                 }
                 foreach (range('a', 'z') as $z) {
                     //State income tax
                     if (isset($row['l16' . $z])) {
                         if (isset($setup_data['state'][$row['l15' . $z . '_state']])) {
                             $ee_data['l15' . $z . '_state_id'] = $setup_data['state'][$row['l15' . $z . '_state']]['state_id'];
                         }
                         $ee_data['l15' . $z . '_state'] = $row['l15' . $z . '_state'];
                         $ee_data['l16' . $z] = $row['l16' . $z];
                         $ee_data['l17' . $z] = $row['l17' . $z];
                     } else {
                         $ee_data['l15' . $z . '_state_id'] = NULL;
                         $ee_data['l15' . $z . '_state'] = NULL;
                         $ee_data['l16' . $z] = NULL;
                         $ee_data['l17' . $z] = NULL;
                     }
                     //District income tax
                     if (isset($row['l18' . $z])) {
                         $ee_data['l18' . $z] = $row['l18' . $z];
                         $ee_data['l19' . $z] = $row['l19' . $z];
                         $ee_data['l20' . $z] = $row['l20' . $z];
                     } else {
                         $ee_data['l18' . $z] = NULL;
                         $ee_data['l19' . $z] = NULL;
                         $ee_data['l20' . $z] = NULL;
                     }
                 }
                 $fw2->addRecord($ee_data);
                 unset($ee_data);
                 $i++;
                 $n++;
             }
         }
     }
     $this->getFormObject()->addForm($fw2);
     if ($form_type == 'government') {
         //Handle W3
         $fw3 = $this->getFW3Object();
         $fw3->setShowBackground($show_background);
         $fw3->year = $fw2->year;
         $fw3->ein = $fw2->ein;
         $fw3->name = $fw2->name;
         $fw3->trade_name = $fw2->trade_name;
         $fw3->company_address1 = $fw2->company_address1;
         $fw3->company_address2 = $fw2->company_address2;
         $fw3->company_city = $fw2->company_city;
         $fw3->company_state = $fw2->company_state;
         $fw3->company_zip_code = $fw2->company_zip_code;
         $fw3->contact_name = $current_user->getFullName();
         $fw3->contact_phone = $current_user->getWorkPhoneExt() != '' ? $current_user->getWorkPhone() . 'x' . $current_user->getWorkPhoneExt() : $current_user->getWorkPhone();
         $fw3->contact_email = $current_user->getWorkEmail();
         $fw3->kind_of_payer = '941';
         $fw3->kind_of_employer = 'none';
         //$fw3->third_party_sick_pay = TRUE;
         if (isset($setup_data['state'][$fw2->company_state]) and isset($setup_data['state'][$fw2->company_state]['state_id']) and $setup_data['state'][$fw2->company_state]['state_id'] != '') {
             $fw3->state_id1 = $setup_data['state'][$fw2->company_state]['state_id'];
         }
         $fw3->lc = count($this->form_data);
         $fw3->control_number = $fw3->lc + 1;
         //$fw3->ld = '1234568';
         $total_row = Misc::ArrayAssocSum($this->form_data);
         //Debug::Arr($total_row, 'Total Row Data: ', __FILE__, __LINE__, __METHOD__,10);
         if (is_array($total_row)) {
             $fw3->l1 = $total_row['l1'];
             $fw3->l2 = $total_row['l2'];
             $fw3->l3 = $total_row['l3'];
             $fw3->l4 = $total_row['l4'];
             $fw3->l5 = $total_row['l5'];
             $fw3->l6 = $total_row['l6'];
             $fw3->l7 = $total_row['l7'];
             $fw3->l8 = $total_row['l8'];
             $fw3->l10 = $total_row['l10'];
             $fw3->l11 = $total_row['l11'];
             foreach (range('a', 'z') as $z) {
                 //State income tax
                 if (isset($total_row['l16' . $z])) {
                     $fw3->l16 += $total_row['l16' . $z];
                     $fw3->l17 += $total_row['l17' . $z];
                 }
                 //District income tax
                 if (isset($total_row['l18' . $z])) {
                     $fw3->l18 += $total_row['l18' . $z];
                     $fw3->l19 += $total_row['l19' . $z];
                 }
             }
         }
         $this->getFormObject()->addForm($fw3);
     }
     if ($format == 'efile') {
         $output_format = 'EFILE';
         if ($fw2->getDebug() == TRUE) {
             $file_name = 'w2_efile_' . date('Y_m_d') . '.csv';
         } else {
             $file_name = 'w2_efile_' . date('Y_m_d') . '.txt';
         }
         $mime_type = 'applications/octet-stream';
         //Force file to download.
     } elseif ($format == 'efile_xml') {
         $output_format = 'XML';
         $file_name = 'w2_efile_' . date('Y_m_d') . '.xml';
         $mime_type = 'applications/octet-stream';
         //Force file to download.
     } else {
         $output_format = 'PDF';
         $file_name = $this->file_name;
         $mime_type = $this->file_mime_type;
     }
     $output = $this->getFormObject()->output($output_format);
     return array('file_name' => $file_name, 'mime_type' => $mime_type, 'data' => $output);
 }
예제 #23
0
                 $init_progress_bar = FALSE;
             }
             $progress_bar->setValue(0);
             $progress_bar->display();
             $apf = TTnew('AccrualPolicyFactory');
             $aplf = TTnew('AccrualPolicyListFactory');
             $aplf->getByIdAndCompanyId((int) $data['accrual_policy_id'], $current_company->getId());
             if ($aplf->getRecordCount() > 0) {
                 foreach ($aplf as $ap_obj) {
                     $aplf->StartTransaction();
                     TTLog::addEntry($current_user->getId(), 500, 'Recalculate Accrual Policy: ' . $ap_obj->getName() . ' Start Date: ' . TTDate::getDate('TIME', $data['start_date']) . ' End Date: ' . TTDate::getDate('TIME', $data['end_date']) . ' Total Days: ' . round($total_days), $current_user->getId(), $ap_obj->getTable());
                     $x = 0;
                     for ($i = $start_date; $i < $end_date; $i += 86400) {
                         //$i = TTDate::getBeginDayEpoch( $i ); //This causes infinite loops during DST transitions.
                         Debug::Text('Recalculating Accruals for Date: ' . TTDate::getDate('DATE+TIME', TTDate::getBeginDayEpoch($i)), __FILE__, __LINE__, __METHOD__, 10);
                         $ap_obj->addAccrualPolicyTime(TTDate::getBeginDayEpoch($i), $offset);
                         $progress_bar->setValue(Misc::calculatePercent($x, $total_days));
                         $progress_bar->display();
                         $x++;
                     }
                     //$aplf->FailTransaction();
                     $aplf->CommitTransaction();
                 }
             }
             $progress_bar->setValue(100);
             $progress_bar->display();
         }
     }
     break;
 default:
     //Test
예제 #24
0
    $user_id = $filter_user_id;
} else {
    $user_id = $current_user->getId();
}
if ($filter_date != '') {
    $filter_date = TTDate::getBeginDayEpoch(TTDate::parseDateTime($filter_date));
}
if (isset($prev_day)) {
    $filter_date = TTDate::getBeginDayEpoch($filter_date - 86400);
} elseif (isset($next_day)) {
    $filter_date = TTDate::getBeginDayEpoch($filter_date + 86400);
}
if (isset($prev_week)) {
    $filter_date = TTDate::getBeginDayEpoch($filter_date - 86400 * 7);
} elseif (isset($next_week)) {
    $filter_date = TTDate::getBeginDayEpoch($filter_date + 86400 * 7);
}
//This must be below any filter_date modifications
URLBuilder::setURL($_SERVER['SCRIPT_NAME'], array('filter_date' => $filter_date, 'filter_user_id' => $filter_user_id, 'filter_system_time' => $filter_system_time, 'sort_column' => $sort_column, 'sort_order' => $sort_order, 'page' => $page));
$sort_array = NULL;
if ($sort_column != '') {
    $sort_array = array($sort_column => $sort_order);
}
Debug::Arr($ids, 'Selected Objects', __FILE__, __LINE__, __METHOD__, 10);
switch ($action) {
    case 'add':
        //Redirect::Page( URLBuilder::getURL(array('user_id' => $user_id), 'EditUserWage.php', FALSE) );
        break;
    case 'delete' or 'undelete':
        if (strtolower($action) == 'delete') {
            $delete = TRUE;
예제 #25
0
     }
     Debug::text(' bSetting Max Hour: ' . $max_hour, __FILE__, __LINE__, __METHOD__, 10);
 }
 if (TTDate::getDayOfMonth($day_schedule_shift['start_time']) != TTDate::getDayOfMonth($day_schedule_shift['end_time'] - 1)) {
     //-1 from end time to handle a 12:00AM end time without going to next day.
     Debug::text(' aSchedule Spans the Day boundary!', __FILE__, __LINE__, __METHOD__, 10);
     $day_schedule_shift['span_day'] = TRUE;
     $min_hour = 0;
     $max_hour = 24;
 }
 if ($day_schedule_shift['span_day'] == TRUE) {
     //Cut shift into two days.
     $tmp_schedule_shift_day1 = $tmp_schedule_shift_day2 = $day_schedule_shift;
     $tmp_schedule_shift_day1['span_day_split'] = TRUE;
     $tmp_schedule_shift_day1['end_time'] = TTDate::getEndDayEpoch($day_schedule_shift['start_time']) + 1;
     $tmp_schedule_shift_day2['start_time'] = TTDate::getBeginDayEpoch($day_schedule_shift['end_time']);
     $tmp_schedule_shift_day2['span_day_split'] = FALSE;
     $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][$day_schedule_shift['user_id']][] = $tmp_schedule_shift_day1;
     $tmp_schedule_shifts[$tmp_schedule_shift_day2['start_time']][$day_schedule_shift['branch']][$day_schedule_shift['department']][$day_schedule_shift['user_id']][] = $tmp_schedule_shift_day2;
     Debug::text(' Shift SPans the Day Boundary: First End Date: ' . TTDate::getDate('DATE+TIME', $tmp_schedule_shift_day1['end_time']) . ' Second Start Date: ' . TTDate::getDate('DATE+TIME', $tmp_schedule_shift_day2['start_time']), __FILE__, __LINE__, __METHOD__, 10);
 } else {
     $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][$day_schedule_shift['user_id']][] = $day_schedule_shift;
 }
 //$schedule_shifts[$day_epoch][] = $day_schedule_shift;
 if ($day_schedule_shift['status_id'] == 10) {
     //Working
     if (isset($schedule_shift_totals[$day_epoch]['total_time'])) {
         $schedule_shift_totals[$day_epoch]['total_time'] += $day_schedule_shift['total_time'];
     } else {
         $schedule_shift_totals[$day_epoch]['total_time'] = $day_schedule_shift['total_time'];
     }
예제 #26
0
 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;
 }
예제 #27
0
     if (!($data['start_full_time_stamp'] != '' and $data['end_full_time_stamp'] != '' and $data['start_full_time_stamp'] >= time() - 86400 * 365 and $data['end_full_time_stamp'] <= time() + 86400 * 365)) {
         $sf->Validator->isTrue('date_stamp', FALSE, TTi18n::getText('Start or End dates are invalid'));
     }
     if ($sf->Validator->isValid()) {
         Redirect::Page(URLBuilder::getURL(array('action' => 'add_mass_schedule', 'filter_user_id' => $filter_user_id, 'data' => $data), '../progress_bar/ProgressBarControl.php'));
     }
 default:
     if ($action != 'submit' and !is_array($data)) {
         Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
         $user_id = NULL;
         $user_date_id = NULL;
         $user_full_name = NULL;
         $user_default_branch = NULL;
         $user_default_department = NULL;
         $pay_period_is_locked = FALSE;
         $time_stamp = $start_date_stamp = $end_date_stamp = TTDate::getBeginDayEpoch(TTDate::getTime()) + 3600 * 12;
         //Noon
         $data = array('start_date_stamp' => $start_date_stamp, 'end_date_stamp' => $end_date_stamp, 'start_time' => strtotime('08:00 AM'), 'parsed_start_time' => strtotime('08:00 AM'), 'end_time' => strtotime('05:00 PM'), 'parsed_end_time' => strtotime('05:00 PM'), 'total_time' => 3600 * 9, 'branch_id' => $user_default_branch, 'department_id' => $user_default_department, 'dow' => array(1 => TRUE, 2 => TRUE, 3 => TRUE, 4 => TRUE, 5 => TRUE));
     }
     //var_dump($data);
     $ulf = TTnew('UserListFactory');
     $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);
     $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 = TTnew('SchedulePolicyListFactory');
     $schedule_policy_options = $splf->getByCompanyIdArray($current_company->getId());
     $aplf = TTnew('AbsencePolicyListFactory');
     $absence_policy_options = $aplf->getByCompanyIdArray($current_company->getId());
     $blf = TTnew('BranchListFactory');
예제 #28
0
 function testHolidayAndDailyAndWeeklyOverTimePolicyA()
 {
     global $dd;
     $date_epoch = TTDate::getBeginWeekEpoch(time());
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     //Holiday
     $policy_ids['holiday'][] = $this->createHolidayPolicy($this->company_id, 10);
     $this->createHoliday($this->company_id, 10, $date_epoch, $policy_ids['holiday'][0]);
     //Daily
     $policy_ids['overtime'][] = $this->createOverTimePolicy($this->company_id, 100);
     $policy_ids['overtime'][] = $this->createOverTimePolicy($this->company_id, 110);
     $policy_ids['overtime'][] = $this->createOverTimePolicy($this->company_id, 120);
     //Weekly
     $policy_ids['overtime'][] = $this->createOverTimePolicy($this->company_id, 230);
     $policy_ids['overtime'][] = $this->createOverTimePolicy($this->company_id, 240);
     $policy_ids['overtime'][] = $this->createOverTimePolicy($this->company_id, 250);
     //Holiday overtime policy
     $policy_ids['overtime'][] = $this->createOverTimePolicy($this->company_id, 500);
     //Create Policy Group
     $dd->createPolicyGroup($this->company_id, NULL, NULL, $policy_ids['holiday'], $policy_ids['overtime'], NULL, NULL, array($this->user_id));
     //
     //Day of Week: 1
     //
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 8:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 12 * 3600);
     //Holiday Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 8 * 3600);
     //Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][4]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][4]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][4]['over_time_policy_id'], $policy_ids['overtime'][0]);
     $this->assertEquals($udt_arr[$date_epoch][4]['total_time'], 1 * 3600);
     //Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][3]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][3]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][3]['over_time_policy_id'], $policy_ids['overtime'][1]);
     $this->assertEquals($udt_arr[$date_epoch][3]['total_time'], 1 * 3600);
     //Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][2]['over_time_policy_id'], $policy_ids['overtime'][2]);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 2 * 3600);
     //
     //Day of Week: 2
     //
     $date_epoch = TTDate::getBeginDayEpoch(TTDate::getBeginWeekEpoch(time()) + (1 * 86400 + 3601));
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 8:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 12 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 8 * 3600);
     //Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][4]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][4]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][4]['over_time_policy_id'], $policy_ids['overtime'][0]);
     $this->assertEquals($udt_arr[$date_epoch][4]['total_time'], 1 * 3600);
     //Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][3]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][3]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][3]['over_time_policy_id'], $policy_ids['overtime'][1]);
     $this->assertEquals($udt_arr[$date_epoch][3]['total_time'], 1 * 3600);
     //Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][2]['over_time_policy_id'], $policy_ids['overtime'][2]);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 2 * 3600);
     //
     //Day of Week: 3
     //
     $date_epoch = TTDate::getBeginDayEpoch(TTDate::getBeginWeekEpoch(time()) + (2 * 86400 + 3601));
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 8:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 12 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 8 * 3600);
     //Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][4]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][4]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][4]['over_time_policy_id'], $policy_ids['overtime'][0]);
     $this->assertEquals($udt_arr[$date_epoch][4]['total_time'], 1 * 3600);
     //Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][3]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][3]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][3]['over_time_policy_id'], $policy_ids['overtime'][1]);
     $this->assertEquals($udt_arr[$date_epoch][3]['total_time'], 1 * 3600);
     //Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][2]['over_time_policy_id'], $policy_ids['overtime'][2]);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 2 * 3600);
     //
     //Day of Week: 4
     //
     $date_epoch = TTDate::getBeginDayEpoch(TTDate::getBeginWeekEpoch(time()) + (3 * 86400 + 3601));
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 8:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 12 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 8 * 3600);
     //Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][4]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][4]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][4]['over_time_policy_id'], $policy_ids['overtime'][0]);
     $this->assertEquals($udt_arr[$date_epoch][4]['total_time'], 1 * 3600);
     //Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][3]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][3]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][3]['over_time_policy_id'], $policy_ids['overtime'][1]);
     $this->assertEquals($udt_arr[$date_epoch][3]['total_time'], 1 * 3600);
     //Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][2]['over_time_policy_id'], $policy_ids['overtime'][2]);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 2 * 3600);
     //
     //Day of Week: 5
     //
     $date_epoch = TTDate::getBeginDayEpoch(TTDate::getBeginWeekEpoch(time()) + (4 * 86400 + 3601));
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 8:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 12 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 7 * 3600);
     //Weekly Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][2]['over_time_policy_id'], $policy_ids['overtime'][3]);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 1 * 3600);
     //Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][5]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][5]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][5]['over_time_policy_id'], $policy_ids['overtime'][0]);
     $this->assertEquals($udt_arr[$date_epoch][5]['total_time'], 1 * 3600);
     //Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][4]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][4]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][4]['over_time_policy_id'], $policy_ids['overtime'][1]);
     $this->assertEquals($udt_arr[$date_epoch][4]['total_time'], 1 * 3600);
     //Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][3]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][3]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][3]['over_time_policy_id'], $policy_ids['overtime'][2]);
     $this->assertEquals($udt_arr[$date_epoch][3]['total_time'], 2 * 3600);
     //
     //Day of Week: 6
     //
     $date_epoch = TTDate::getBeginDayEpoch(TTDate::getBeginWeekEpoch(time()) + (5 * 86400 + 3601));
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 8:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 12 * 3600);
     //Weekly Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][1]['over_time_policy_id'], $policy_ids['overtime'][4]);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 1 * 3600);
     //Weekly Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][2]['over_time_policy_id'], $policy_ids['overtime'][3]);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 7 * 3600);
     //Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][5]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][5]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][5]['over_time_policy_id'], $policy_ids['overtime'][0]);
     $this->assertEquals($udt_arr[$date_epoch][5]['total_time'], 1 * 3600);
     //Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][4]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][4]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][4]['over_time_policy_id'], $policy_ids['overtime'][1]);
     $this->assertEquals($udt_arr[$date_epoch][4]['total_time'], 1 * 3600);
     //Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][3]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][3]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][3]['over_time_policy_id'], $policy_ids['overtime'][2]);
     $this->assertEquals($udt_arr[$date_epoch][3]['total_time'], 2 * 3600);
     //
     //Day of Week: 7
     //
     $date_epoch = TTDate::getBeginDayEpoch(TTDate::getBeginWeekEpoch(time()) + (6 * 86400 + 3601));
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 8:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 12 * 3600);
     //Weekly Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][1]['over_time_policy_id'], $policy_ids['overtime'][5]);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 1 * 3600);
     //Weekly Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][2]['over_time_policy_id'], $policy_ids['overtime'][4]);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 7 * 3600);
     //Overtime 1
     $this->assertEquals($udt_arr[$date_epoch][5]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][5]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][5]['over_time_policy_id'], $policy_ids['overtime'][0]);
     $this->assertEquals($udt_arr[$date_epoch][5]['total_time'], 1 * 3600);
     //Overtime 2
     $this->assertEquals($udt_arr[$date_epoch][4]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][4]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][4]['over_time_policy_id'], $policy_ids['overtime'][1]);
     $this->assertEquals($udt_arr[$date_epoch][4]['total_time'], 1 * 3600);
     //Overtime 3
     $this->assertEquals($udt_arr[$date_epoch][3]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][3]['type_id'], 30);
     $this->assertEquals($udt_arr[$date_epoch][3]['over_time_policy_id'], $policy_ids['overtime'][2]);
     $this->assertEquals($udt_arr[$date_epoch][3]['total_time'], 2 * 3600);
     return TRUE;
 }
예제 #29
0
 function Validate()
 {
     Debug::Text('User Date ID: ' . $this->getUserDateID(), __FILE__, __LINE__, __METHOD__, 10);
     $this->handleDayBoundary();
     $this->findUserDate();
     Debug::text('User Date Id: ' . $this->getUserDateID(), __FILE__, __LINE__, __METHOD__, 10);
     //Check to make sure EnableOverwrite isn't enabled when editing an existing record.
     if ($this->isNew() == FALSE and $this->getEnableOverwrite() == TRUE) {
         Debug::Text('Overwrite enabled when editing existing record, disabling overwrite.', __FILE__, __LINE__, __METHOD__, 10);
         $this->setEnableOverwrite(FALSE);
     }
     if ($this->getUserDateObject() == FALSE or !is_object($this->getUserDateObject())) {
         Debug::Text('UserDateID is INVALID! ID: ' . $this->getUserDateID(), __FILE__, __LINE__, __METHOD__, 10);
         $this->Validator->isTrue('date_stamp', FALSE, TTi18n::gettext('Date/Time is incorrect, or pay period does not exist for this date. Please create a pay period schedule and assign this employee to it if you have not done so already'));
     }
     if (is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()) and $this->getUserDateObject()->getPayPeriodObject()->getIsLocked() == TRUE) {
         $this->Validator->isTrue('date_stamp', FALSE, TTi18n::gettext('Pay Period is Currently Locked'));
     }
     if ($this->getCompany() == FALSE) {
         $this->Validator->isTrue('company_id', FALSE, TTi18n::gettext('Company is invalid'));
     }
     if ($this->getDeleted() == FALSE and is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getUserObject())) {
         if ($this->getUserDateObject()->getUserObject()->getHireDate() != '' and TTDate::getBeginDayEpoch($this->getUserDateObject()->getDateStamp()) < TTDate::getBeginDayEpoch($this->getUserDateObject()->getUserObject()->getHireDate())) {
             $this->Validator->isTRUE('date_stamp', FALSE, TTi18n::gettext('Shift is before employees hire date'));
         }
         if ($this->getUserDateObject()->getUserObject()->getTerminationDate() != '' and TTDate::getEndDayEpoch($this->getUserDateObject()->getDateStamp()) > TTDate::getEndDayEpoch($this->getUserDateObject()->getUserObject()->getTerminationDate())) {
             $this->Validator->isTRUE('date_stamp', FALSE, TTi18n::gettext('Shift is after employees termination date'));
         }
     }
     //Ignore conflicting time check when EnableOverwrite is set, as we will just be deleting any conflicting shift anyways.
     //Also ignore when setting OPEN shifts to allow for multiple.
     if ($this->getEnableOverwrite() == FALSE and $this->getDeleted() == FALSE and (is_object($this->getUserDateObject()) and $this->getUserDateObject()->getUser() > 0)) {
         $this->Validator->isTrue('start_time', !$this->isConflicting(), TTi18n::gettext('Conflicting start/end time, schedule already exists for this employee'));
     } else {
         Debug::text('Not checking for conflicts... UserDateObject: ' . (int) is_object($this->getUserDateObject()), __FILE__, __LINE__, __METHOD__, 10);
     }
     if ($this->isNew() == TRUE) {
         $obj_class = "TTLicense";
         $obj_function = "validateLicense";
         $obj_error_msg_function = "getFullErrorMessage";
         @($obj = new $obj_class());
         $retval = $obj->{$obj_function}();
         if ($retval !== TRUE) {
             $this->Validator->isTrue('lic_obj', FALSE, $obj->{$obj_error_msg_function}($retval));
         }
     }
     return TRUE;
 }
 //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);
                 }