function setPremiumPolicy($id)
 {
     $id = trim($id);
     $pplf = new PremiumPolicyListFactory();
     if ($id == 0 or $this->Validator->isResultSetWithRows('premium_policy', $pplf->getByID($id), TTi18n::gettext('Selected Premium Policy is invalid'))) {
         $this->data['premium_policy_id'] = $id;
         return TRUE;
     }
     return FALSE;
 }
Ejemplo n.º 2
0
 default:
     if (isset($id)) {
         BreadCrumb::setCrumb($title);
         $pglf = new PolicyGroupListFactory();
         $pglf->getByIdAndCompanyID($id, $current_company->getID());
         foreach ($pglf as $pg_obj) {
             //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
             $data = array('id' => $pg_obj->getId(), 'name' => $pg_obj->getName(), 'meal_policy_ids' => $pg_obj->getMealPolicy(), 'break_policy_ids' => $pg_obj->getBreakPolicy(), 'holiday_policy_ids' => $pg_obj->getHolidayPolicy(), 'exception_policy_control_id' => $pg_obj->getExceptionPolicyControlID(), 'user_ids' => $pg_obj->getUser(), 'over_time_policy_ids' => $pg_obj->getOverTimePolicy(), 'premium_policy_ids' => $pg_obj->getPremiumPolicy(), 'round_interval_policy_ids' => $pg_obj->getRoundIntervalPolicy(), 'accrual_policy_ids' => $pg_obj->getAccrualPolicy(), 'created_date' => $pg_obj->getCreatedDate(), 'created_by' => $pg_obj->getCreatedBy(), 'updated_date' => $pg_obj->getUpdatedDate(), 'updated_by' => $pg_obj->getUpdatedBy(), 'deleted_date' => $pg_obj->getDeletedDate(), 'deleted_by' => $pg_obj->getDeletedBy());
         }
     }
     $none_array_option = array('0' => TTi18n::gettext('-- None --'));
     $ulf = new UserListFactory();
     $user_options = $ulf->getByCompanyIDArray($current_company->getId(), FALSE, TRUE);
     $otplf = new OverTimePolicyListFactory();
     $over_time_policy_options = Misc::prependArray($none_array_option, $otplf->getByCompanyIDArray($current_company->getId(), FALSE));
     $pplf = new PremiumPolicyListFactory();
     $premium_policy_options = Misc::prependArray($none_array_option, $pplf->getByCompanyIDArray($current_company->getId(), FALSE));
     $riplf = new RoundIntervalPolicyListFactory();
     $round_interval_policy_options = Misc::prependArray($none_array_option, $riplf->getByCompanyIDArray($current_company->getId(), FALSE));
     $mplf = new MealPolicyListFactory();
     $meal_options = Misc::prependArray($none_array_option, $mplf->getByCompanyIdArray($current_company->getId(), FALSE));
     $bplf = new BreakPolicyListFactory();
     $break_options = Misc::prependArray($none_array_option, $bplf->getByCompanyIdArray($current_company->getId(), FALSE));
     $epclf = new ExceptionPolicyControlListFactory();
     $exception_options = Misc::prependArray($none_array_option, $epclf->getByCompanyIdArray($current_company->getId(), FALSE));
     $hplf = new HolidayPolicyListFactory();
     $holiday_policy_options = Misc::prependArray($none_array_option, $hplf->getByCompanyIdArray($current_company->getId(), FALSE));
     $aplf = new AccrualPolicyListFactory();
     $aplf->getByCompanyIdAndTypeID($current_company->getId(), array(20, 30));
     //Calendar and Hour based.
     $accrual_options = Misc::prependArray($none_array_option, $aplf->getArrayByListFactory($aplf, FALSE));
 function getByCompanyIdArray($company_id, $include_blank = TRUE, $where = NULL)
 {
     $pplf = new PremiumPolicyListFactory();
     $pplf->getByCompanyId($company_id, $where);
     if ($include_blank == TRUE) {
         $list[0] = '--';
     }
     foreach ($pplf as $pp_obj) {
         $list[$pp_obj->getID()] = $pp_obj->getName();
     }
     if (isset($list)) {
         return $list;
     }
     return FALSE;
 }
Ejemplo n.º 4
0
 if ($user_date_id != '') {
     $udtlf = new UserDateTotalListFactory();
     $udtlf->getByUserDateIDAndStatusAndType($user_date_id, array(10, 20, 30), array(10, 20, 30, 40, 100), $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
     $pager = new Pager($udtlf);
     $blf = new BranchListFactory();
     $branch_options = $blf->getByCompanyIdArray($current_company->getId());
     $dlf = new DepartmentListFactory();
     $department_options = $dlf->getByCompanyIdArray($current_company->getId());
     //Absence policies
     $otplf = new AbsencePolicyListFactory();
     $absence_policy_options = $otplf->getByCompanyIDArray($current_company->getId(), TRUE);
     //Overtime policies
     $otplf = new OverTimePolicyListFactory();
     $over_time_policy_options = $otplf->getByCompanyIDArray($current_company->getId(), TRUE);
     //Premium policies
     $pplf = new PremiumPolicyListFactory();
     $premium_policy_options = $pplf->getByCompanyIDArray($current_company->getId(), TRUE);
     $job_options = array();
     $job_item_options = array();
     if ($current_company->getProductEdition() == 20) {
         $jlf = new JobListFactory();
         $job_options = $jlf->getByCompanyIdArray($current_company->getId(), FALSE);
         $jilf = new JobItemListFactory();
         $job_item_options = $jilf->getByCompanyIdArray($current_company->getId(), TRUE);
     }
     $day_total_time = array('total_time' => 0, 'worked_time' => 0, 'difference' => 0);
     foreach ($udtlf as $udt_obj) {
         if ($udt_obj->getStatus() == 20) {
             $day_total_time['worked_time'] += $udt_obj->getTotalTime();
         } elseif ($udt_obj->getStatus() == 10 and $udt_obj->getType() == 10) {
             $day_total_time['total_time'] += $udt_obj->getTotalTime();
Ejemplo n.º 5
0
extract(FormVariables::GetVariables(array('action', 'generic_data', 'filter_data')));
URLBuilder::setURL($_SERVER['SCRIPT_NAME'], array('filter_data' => $filter_data));
$static_columns = array('-1000-full_name' => TTi18n::gettext('Full Name'), '-1002-employee_number' => TTi18n::gettext('Employee #'), '-1005-status' => TTi18n::gettext('Status'), '-1010-title' => TTi18n::gettext('Title'), '-1020-province' => TTi18n::gettext('Province/State'), '-1030-country' => TTi18n::gettext('Country'), '-1039-group' => TTi18n::gettext('Group'), '-1040-default_branch' => TTi18n::gettext('Default Branch'), '-1050-default_department' => TTi18n::gettext('Default Department'), '-1060-verified_time_sheet' => TTi18n::gettext('Verified TimeSheet'), '-1062-pending_request' => TTi18n::gettext('Pending Requests'), '-1065-pay_period' => TTi18n::gettext('Pay Period'));
$columns = array('-1070-schedule_working' => TTi18n::gettext('Scheduled Time'), '-1080-schedule_absence' => TTi18n::gettext('Scheduled Absence'), '-1085-worked_days' => TTi18n::gettext('Worked Days'), '-1090-worked_time' => TTi18n::gettext('Worked Time'), '-1100-actual_time' => TTi18n::gettext('Actual Time'), '-1110-actual_time_diff' => TTi18n::gettext('Actual Time Diff.'), '-1120-actual_time_diff_wage' => TTi18n::gettext('Actual Time Diff. Wage'), '-1130-paid_time' => TTi18n::gettext('Paid Time'), '-1140-regular_time' => TTi18n::gettext('Regular Time'));
$columns = Misc::prependArray($static_columns, $columns);
//Get all Overtime policies.
$otplf = new OverTimePolicyListFactory();
$otplf->getByCompanyId($current_company->getId());
if ($otplf->getRecordCount() > 0) {
    foreach ($otplf as $otp_obj) {
        $otp_columns['over_time_policy-' . $otp_obj->getId()] = $otp_obj->getName();
    }
    $columns = array_merge($columns, $otp_columns);
}
//Get all Premium policies.
$pplf = new PremiumPolicyListFactory();
$pplf->getByCompanyId($current_company->getId());
if ($pplf->getRecordCount() > 0) {
    foreach ($pplf as $pp_obj) {
        $pp_columns['premium_policy-' . $pp_obj->getId()] = $pp_obj->getName();
    }
    $columns = array_merge($columns, $pp_columns);
}
//Get all Absence Policies.
$aplf = new AbsencePolicyListFactory();
$aplf->getByCompanyId($current_company->getId());
if ($aplf->getRecordCount() > 0) {
    foreach ($aplf as $ap_obj) {
        $ap_columns['absence_policy-' . $ap_obj->getId()] = $ap_obj->getName();
    }
    $columns = array_merge($columns, $ap_columns);
Ejemplo n.º 6
0
     }
     $pplf = new PremiumPolicyListFactory();
     foreach ($ids as $id) {
         $pplf->getByIdAndCompanyId($id, $current_company->getId());
         foreach ($pplf as $pp_obj) {
             $pp_obj->setDeleted($delete);
             if ($pp_obj->isValid()) {
                 $pp_obj->Save();
             }
         }
     }
     Redirect::Page(URLBuilder::getURL(NULL, 'PremiumPolicyList.php'));
     break;
 default:
     BreadCrumb::setCrumb($title);
     $pplf = new PremiumPolicyListFactory();
     $pplf->getByCompanyId($current_company->getId());
     $pager = new Pager($pplf);
     $type_options = $pplf->getOptions('type');
     $show_no_policy_group_notice = FALSE;
     foreach ($pplf as $pp_obj) {
         if ((int) $pp_obj->getColumn('assigned_policy_groups') == 0) {
             $show_no_policy_group_notice = TRUE;
         }
         $policies[] = array('id' => $pp_obj->getId(), 'name' => $pp_obj->getName(), 'type_id' => $pp_obj->getType(), 'type' => $type_options[$pp_obj->getType()], 'assigned_policy_groups' => (int) $pp_obj->getColumn('assigned_policy_groups'), 'deleted' => $pp_obj->getDeleted());
     }
     $smarty->assign_by_ref('policies', $policies);
     $smarty->assign_by_ref('show_no_policy_group_notice', $show_no_policy_group_notice);
     $smarty->assign_by_ref('sort_column', $sort_column);
     $smarty->assign_by_ref('sort_order', $sort_order);
     $smarty->assign_by_ref('paging_data', $pager->getPageVariables());
Ejemplo n.º 7
0
             $date_data['total_time'] = $date_data['total_time'] + $prev_total_time;
             $date_job_item_total_group[$user_date_stamp][$date_data['job_item_id']] = $date_data;
         }
     }
     unset($prev_total_time, $date_rows, $date_data);
     //var_dump($date_department_total_group);
     $date_worked_total_job_item_ids = array_unique($date_worked_total_job_item_ids);
     sort($date_worked_total_job_item_ids);
     if ($date_worked_total_job_item_ids[0] != FALSE or count($date_worked_total_job_item_ids) > 1) {
         $date_job_item_total_rows = TimeSheetFormatArrayByDate($date_job_item_total_group, $date_worked_total_job_item_ids, $calendar_array, 'job_item', 'job_item_id');
     }
 }
 /*
 	Get Premium Time
 */
 $pplf_b = new PremiumPolicyListFactory();
 $premium_policy_options = $pplf_b->getByCompanyIdArray($current_company->getId());
 unset($pplf_b);
 $udtlf = new UserDateTotalListFactory();
 //Get only worked totals.
 $udtlf->getByCompanyIDAndUserIdAndStatusAndTypeAndStartDateAndEndDate($current_company->getId(), $user_id, 10, 40, $start_date, $end_date);
 if ($udtlf->getRecordCount() > 0) {
     foreach ($udtlf as $udt_obj) {
         $user_date_stamp = TTDate::strtotime($udt_obj->getColumn('user_date_stamp'));
         if ($udt_obj->getPremiumPolicyID() !== FALSE and isset($premium_policy_options[$udt_obj->getPremiumPolicyID()])) {
             $premium_policy = $premium_policy_options[$udt_obj->getPremiumPolicyID()];
         } else {
             $premium_policy = TTi18n::gettext('No Policy');
         }
         $date_premium_totals[$user_date_stamp][] = array('date_stamp' => $udt_obj->getColumn('user_date_stamp'), 'id' => $udt_obj->getId(), 'user_date_id' => $udt_obj->getUserDateId(), 'status_id' => $udt_obj->getStatus(), 'type_id' => $udt_obj->getType(), 'over_time_policy_id' => $udt_obj->getOverTimePolicyID(), 'premium_policy_id' => $udt_obj->getPremiumPolicyID(), 'premium_policy' => $premium_policy, 'department_id' => $udt_obj->getDepartment(), 'total_time' => $udt_obj->getTotalTime(), 'override' => $udt_obj->getOverride());
         $date_premium_total_policy_ids[] = (int) $udt_obj->getPremiumPolicyID();
Ejemplo n.º 8
0
     if ($uwlf->getRecordCount() > 0) {
         foreach ($uwlf as $uw_obj) {
             $user_wage_rows[$uw_obj->getUser()][] = array('type_id' => $uw_obj->getType(), 'type' => Option::getByKey($uw_obj->getType(), $uw_obj->getOptions('type')), 'wage' => $uw_obj->getWage(), 'currency_symbol' => $uw_obj->getUserObject()->getCurrencyObject()->getSymbol(), 'effective_date' => $uw_obj->getEffectiveDate(), 'effective_date_since' => TTDate::getHumanTimeSince($uw_obj->getEffectiveDate()));
         }
     }
 }
 /*
 	Get Attendance History
 */
 if (isset($columns['attendance'])) {
     //Get policy names.
     $oplf = new OverTimePolicyListFactory();
     $over_time_policy_arr = $oplf->getByCompanyIdArray($current_company->getId(), FALSE);
     $aplf = new AbsencePolicyListFactory();
     $absence_policy_arr = $aplf->getByCompanyIdArray($current_company->getId(), FALSE);
     $pplf = new PremiumPolicyListFactory();
     $premium_policy_arr = $pplf->getByCompanyIdArray($current_company->getId(), FALSE);
     //Get stats on number of days worked per month/week
     $udlf = new UserDateListFactory();
     $udlf->getDaysWorkedByTimePeriodAndUserIdAndCompanyIdAndStartDateAndEndDate('month', $filter_data['user_ids'], $current_company->getId(), $filter_data['start_date'], $filter_data['end_date']);
     if ($udlf->getRecordCount() > 0) {
         foreach ($udlf as $ud_obj) {
             //$user_days_worked[$ud_obj->getUser()]['month']
             $user_attendance_rows[$ud_obj->getUser()]['days_worked']['month'] = array('avg' => round($ud_obj->getColumn('avg'), 2), 'min' => $ud_obj->getColumn('min'), 'max' => $ud_obj->getColumn('max'));
         }
     }
     $udlf->getDaysWorkedByTimePeriodAndUserIdAndCompanyIdAndStartDateAndEndDate('week', $filter_data['user_ids'], $current_company->getId(), $filter_data['start_date'], $filter_data['end_date']);
     if ($udlf->getRecordCount() > 0) {
         foreach ($udlf as $ud_obj) {
             $user_attendance_rows[$ud_obj->getUser()]['days_worked']['week'] = array('avg' => round($ud_obj->getColumn('avg'), 2), 'min' => $ud_obj->getColumn('min'), 'max' => $ud_obj->getColumn('max'));
         }
 function calcPremiumPolicyTotalTime($udt_meal_policy_adjustment_arr, $udt_break_policy_adjustment_arr, $daily_total_time = FALSE)
 {
     global $profiler;
     $profiler->startTimer("UserDateTotal::calcPremiumPolicyTotalTime() - Part 1");
     if ($daily_total_time === FALSE) {
         $daily_total_time = $this->getDailyTotalTime();
     }
     $pplf = new PremiumPolicyListFactory();
     $pplf->getByPolicyGroupUserId($this->getUserDateObject()->getUser());
     if ($pplf->getRecordCount() > 0) {
         Debug::text('Found Premium Policies to apply.', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($pplf as $pp_obj) {
             Debug::text('Found Premium Policy: ID: ' . $pp_obj->getId() . ' Type: ' . $pp_obj->getType(), __FILE__, __LINE__, __METHOD__, 10);
             //FIXME: Support manually setting a premium policy through the Edit Hours page?
             //In those cases, just skip auto-calculating it and accept it?
             switch ($pp_obj->getType()) {
                 case 10:
                     //Date/Time
                     Debug::text(' Date/Time Premium Policy...', __FILE__, __LINE__, __METHOD__, 10);
                     //Make sure this is a valid day
                     //Take into account shifts that span midnight though, where one half of the shift is eligilble for premium time.
                     //ie: Premium Policy starts 7AM to 7PM on Sat/Sun. Punches in at 9PM Friday and out at 9AM Sat, we need to check if both days are valid.
                     //FIXME: Handle shifts that are longer than 24hrs in length.
                     if ($pp_obj->isActive($this->getUserDateObject()->getDateStamp() - 86400, $this->getUserDateObject()->getDateStamp() + 86400)) {
                         Debug::text(' Premium Policy Is Active On OR Around This Day.', __FILE__, __LINE__, __METHOD__, 10);
                         $total_daily_time_used = 0;
                         $daily_trigger_time = 0;
                         $udtlf = new UserDateTotalListFactory();
                         if ($pp_obj->isHourRestricted() == TRUE) {
                             if ($pp_obj->getWeeklyTriggerTime() > 0) {
                                 //Get Pay Period Schedule info
                                 if (is_object($this->getUserDateObject()->getPayPeriodObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject())) {
                                     $start_week_day_id = $this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()->getStartWeekDay();
                                 } else {
                                     $start_week_day_id = 0;
                                 }
                                 Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10);
                                 $weekly_total_time = $udtlf->getWeekRegularTimeSumByUserIDAndEpochAndStartWeekEpoch($this->getUserDateObject()->getUser(), $this->getUserDateObject()->getDateStamp(), TTDate::getBeginWeekEpoch($this->getUserDateObject()->getDateStamp(), $start_week_day_id));
                                 if ($weekly_total_time > $pp_obj->getWeeklyTriggerTime()) {
                                     $daily_trigger_time = 0;
                                 } else {
                                     $daily_trigger_time = $pp_obj->getWeeklyTriggerTime() - $weekly_total_time;
                                 }
                                 Debug::text(' Weekly Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                             }
                             if ($pp_obj->getDailyTriggerTime() > 0 and $pp_obj->getDailyTriggerTime() > $daily_trigger_time) {
                                 $daily_trigger_time = $pp_obj->getDailyTriggerTime();
                             }
                         }
                         Debug::text(' Daily Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                         //Loop through all worked (status: 20) UserDateTotalRows
                         $udtlf->getByUserDateIdAndStatus($this->getUserDateID(), 20);
                         $i = 1;
                         if ($udtlf->getRecordCount() > 0) {
                             Debug::text('Found Total Hours to attempt to apply premium policy... Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                             foreach ($udtlf as $udt_obj) {
                                 Debug::text('UserDateTotal ID: ' . $udt_obj->getID() . ' Total Time: ' . $udt_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10);
                                 //Ignore incomplete punches
                                 if ($udt_obj->getTotalTime() == 0) {
                                     continue;
                                 }
                                 //How do we handle actual shifts for premium time?
                                 //So if premium policy starts at 1PM for shifts, to not
                                 //include employees who return from lunch at 1:30PM.
                                 //Create a function that takes all punches for a day, and returns
                                 //the first in and last out time for a given shift when taking
                                 //into account minimum time between shifts, as well as the total time for that shift.
                                 //We can then use that time for ActiveTime on premium policies, and determine if a
                                 //punch falls within the active time, then we add it to the total.
                                 if ($pp_obj->isTimeRestricted() == TRUE and $udt_obj->getPunchControlID() != FALSE) {
                                     Debug::text('Time Restricted Premium Policy, lookup punches to get times.', __FILE__, __LINE__, __METHOD__, 10);
                                     if ($pp_obj->getIncludePartialPunch() == FALSE) {
                                         $shift_data = $this->getShiftDataByUserDateID($this->getUserDateID());
                                     }
                                     $plf = new PunchListFactory();
                                     $plf->getByPunchControlId($udt_obj->getPunchControlID());
                                     if ($plf->getRecordCount() > 0) {
                                         Debug::text('Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                                         foreach ($plf as $punch_obj) {
                                             if ($pp_obj->getIncludePartialPunch() == TRUE) {
                                                 //Debug::text('Including Partial Punches...', __FILE__, __LINE__, __METHOD__, 10);
                                                 if ($punch_obj->getStatus() == 10) {
                                                     $punch_times['in'] = $punch_obj->getTimeStamp();
                                                 } elseif ($punch_obj->getStatus() == 20) {
                                                     $punch_times['out'] = $punch_obj->getTimeStamp();
                                                 }
                                             } else {
                                                 if (isset($shift_data) and is_array($shift_data)) {
                                                     foreach ($shift_data as $shift) {
                                                         if ($punch_obj->getTimeStamp() >= $shift['first_in'] and $punch_obj->getTimeStamp() <= $shift['last_out']) {
                                                             //Debug::Arr($shift,'Shift Data...', __FILE__, __LINE__, __METHOD__, 10);
                                                             Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') inside shift time...', __FILE__, __LINE__, __METHOD__, 10);
                                                             $punch_times['in'] = $shift['first_in'];
                                                             $punch_times['out'] = $shift['last_out'];
                                                             break;
                                                         } else {
                                                             Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') outside shift time...', __FILE__, __LINE__, __METHOD__, 10);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         if (isset($punch_times) and count($punch_times) == 2 and $pp_obj->isActiveTime($punch_times['in'], $punch_times['out']) == TRUE) {
                                             //Debug::Arr($punch_times, 'Punch Times: ', __FILE__, __LINE__, __METHOD__, 10);
                                             $punch_total_time = $pp_obj->getPartialPunchTotalTime($punch_times['in'], $punch_times['out'], $udt_obj->getTotalTime());
                                             Debug::text('Valid Punch pair in active time, Partial Punch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                         } else {
                                             Debug::text('InValid Punch Pair or outside Active Time...', __FILE__, __LINE__, __METHOD__, 10);
                                             $punch_total_time = 0;
                                         }
                                     }
                                 } elseif ($pp_obj->isActive($udt_obj->getUserDateObject()->getDateStamp()) == TRUE) {
                                     $punch_total_time = $udt_obj->getTotalTime();
                                 } else {
                                     $punch_total_time = 0;
                                 }
                                 Debug::text('aPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                 //Apply meal policy adjustment as early as possible.
                                 if ($pp_obj->getIncludeMealPolicy() == TRUE and isset($udt_meal_policy_adjustment_arr[$udt_obj->getId()])) {
                                     Debug::text(' Meal Policy Adjustment Found: ' . $udt_meal_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10);
                                     $punch_total_time = bcadd($punch_total_time, $udt_meal_policy_adjustment_arr[$udt_obj->getId()]);
                                     $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_meal_policy_adjustment_arr[$udt_obj->getId()]);
                                 } else {
                                     $tmp_punch_total_time = $udt_obj->getTotalTime();
                                 }
                                 Debug::text('bPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                 //Apply break policy adjustment as early as possible.
                                 if ($pp_obj->getIncludeBreakPolicy() == TRUE and isset($udt_break_policy_adjustment_arr[$udt_obj->getId()])) {
                                     Debug::text(' Break Policy Adjustment Found: ' . $udt_break_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10);
                                     $punch_total_time = bcadd($punch_total_time, $udt_break_policy_adjustment_arr[$udt_obj->getId()]);
                                     $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_break_policy_adjustment_arr[$udt_obj->getId()]);
                                 } else {
                                     $tmp_punch_total_time = $udt_obj->getTotalTime();
                                 }
                                 Debug::text('cPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                 $total_daily_time_used += $tmp_punch_total_time;
                                 Debug::text('Daily Total Time Used: ' . $total_daily_time_used, __FILE__, __LINE__, __METHOD__, 10);
                                 //FIXME: Should the daily/weekly trigger time be >= instead of >.
                                 //That way if the policy is active after 7.5hrs, punch time of exactly 7.5hrs will still
                                 //activate the policy, rather then requiring 7.501hrs+
                                 if ($punch_total_time > 0 and $total_daily_time_used > $daily_trigger_time) {
                                     Debug::text('Past Trigger Time!!', __FILE__, __LINE__, __METHOD__, 10);
                                     //Calculate how far past trigger time we are.
                                     $past_trigger_time = $total_daily_time_used - $daily_trigger_time;
                                     if ($punch_total_time > $past_trigger_time) {
                                         $punch_total_time = $past_trigger_time;
                                         Debug::text('Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                                     } else {
                                         Debug::text('NOT Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                     $total_time = $punch_total_time;
                                     if ($pp_obj->getMinimumTime() > 0 or $pp_obj->getMaximumTime() > 0) {
                                         $premium_policy_daily_total_time = (int) $udtlf->getPremiumPolicySumByUserDateIDAndPremiumPolicyID($this->getUserDateID(), $pp_obj->getId());
                                         Debug::text(' Premium Policy Daily Total Time: ' . $premium_policy_daily_total_time . ' Minimum Time: ' . $pp_obj->getMinimumTime() . ' Maximum Time: ' . $pp_obj->getMaximumTime() . ' Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                         if ($pp_obj->getMinimumTime() > 0) {
                                             //FIXME: Split the minimum time up between all the punches somehow.
                                             //Apply the minimum time on the last punch, otherwise if there are two punch pairs of 15min each
                                             //and a 1hr minimum time, if the minimum time is applied to the first, it will be 1hr and 15min
                                             //for the day. If its applied to the last it will be just 1hr.
                                             //Min & Max time is based on the shift time, rather then per punch pair time.
                                             //FIXME: If there is a minimum time set to say 9hrs, and the punches go like this:
                                             // In: 7:00AM Out: 3:00:PM, Out: 3:30PM (missing 2nd In Punch), the minimum time won't be calculated due to the invalid punch pair.
                                             if ($i == $udtlf->getRecordCount() and bcadd($premium_policy_daily_total_time, $total_time) < $pp_obj->getMinimumTime()) {
                                                 $total_time = bcsub($pp_obj->getMinimumTime(), $premium_policy_daily_total_time);
                                             }
                                         }
                                         Debug::text(' Total Time After Minimum is applied: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                         if ($pp_obj->getMaximumTime() > 0) {
                                             //Min & Max time is based on the shift time, rather then per punch pair time.
                                             if (bcadd($premium_policy_daily_total_time, $total_time) > $pp_obj->getMaximumTime()) {
                                                 Debug::text(' bMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10);
                                                 $total_time = bcsub($total_time, bcsub(bcadd($premium_policy_daily_total_time, $total_time), $pp_obj->getMaximumTime()));
                                             }
                                         }
                                     }
                                     Debug::text(' Premium Punch Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                     if ($total_time > 0) {
                                         Debug::text(' Applying  Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                         $udtf = new UserDateTotalFactory();
                                         $udtf->setUserDateID($this->getUserDateID());
                                         $udtf->setStatus(10);
                                         //System
                                         $udtf->setType(40);
                                         //Premium
                                         $udtf->setPremiumPolicyId($pp_obj->getId());
                                         $udtf->setBranch($udt_obj->getBranch());
                                         $udtf->setDepartment($udt_obj->getDepartment());
                                         $udtf->setJob($udt_obj->getJob());
                                         $udtf->setJobItem($udt_obj->getJobItem());
                                         $udtf->setQuantity($udt_obj->getQuantity());
                                         $udtf->setBadQuantity($udt_obj->getBadQuantity());
                                         $udtf->setTotalTime($total_time);
                                         $udtf->setEnableCalcSystemTotalTime(FALSE);
                                         if ($udtf->isValid() == TRUE) {
                                             $udtf->Save();
                                         }
                                         unset($udtf);
                                     } else {
                                         Debug::text(' Premium Punch Total Time is 0...', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     Debug::text('Not Past Trigger Time Yet or Punch Time is 0...', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                                 $i++;
                             }
                         }
                     }
                     break;
                 case 20:
                     //Differential
                     Debug::text(' Differential Premium Policy...', __FILE__, __LINE__, __METHOD__, 10);
                     //Loop through all worked (status: 20) UserDateTotalRows
                     $udtlf = new UserDateTotalListFactory();
                     $udtlf->getByUserDateIdAndStatus($this->getUserDateID(), 20);
                     if ($udtlf->getRecordCount() > 0) {
                         Debug::text('Found Total Hours to attempt to apply premium policy... Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                         foreach ($udtlf as $udt_obj) {
                             //Ignore incomplete punches
                             if ($udt_obj->getTotalTime() == 0) {
                                 continue;
                             }
                             if ($pp_obj->getBranchSelectionType() == 10 and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 20 and in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 30 and !in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch())) {
                                 Debug::text(' Shift Differential... Meets Branch Criteria! Select Type: ' . $pp_obj->getBranchSelectionType() . ' Exclude Default Branch: ' . (int) $pp_obj->getExcludeDefaultBranch() . ' Default Branch: ' . $this->getUserDateObject()->getUserObject()->getDefaultBranch(), __FILE__, __LINE__, __METHOD__, 10);
                                 if ($pp_obj->getDepartmentSelectionType() == 10 and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 20 and in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 30 and !in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment())) {
                                     Debug::text(' Shift Differential... Meets Department Criteria! Select Type: ' . $pp_obj->getDepartmentSelectionType() . ' Exclude Default Department: ' . (int) $pp_obj->getExcludeDefaultDepartment() . ' Default Department: ' . $this->getUserDateObject()->getUserObject()->getDefaultDepartment(), __FILE__, __LINE__, __METHOD__, 10);
                                     if ($pp_obj->getJobGroupSelectionType() == 10 or $pp_obj->getJobGroupSelectionType() == 20 and (is_object($udt_obj->getJobObject()) and in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup())) or $pp_obj->getJobGroupSelectionType() == 30 and (is_object($udt_obj->getJobObject()) and !in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup()))) {
                                         Debug::text(' Shift Differential... Meets Job Group Criteria! Select Type: ' . $pp_obj->getJobGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                         if ($pp_obj->getJobSelectionType() == 10 or $pp_obj->getJobSelectionType() == 20 and in_array($udt_obj->getJob(), (array) $pp_obj->getJob()) or $pp_obj->getJobSelectionType() == 30 and !in_array($udt_obj->getJob(), (array) $pp_obj->getJob())) {
                                             Debug::text(' Shift Differential... Meets Job Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                             if ($pp_obj->getJobItemGroupSelectionType() == 10 or $pp_obj->getJobItemGroupSelectionType() == 20 and (is_object($udt_obj->getJobItemObject()) and in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup())) or $pp_obj->getJobItemGroupSelectionType() == 30 and (is_object($udt_obj->getJobItemObject()) and !in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup()))) {
                                                 Debug::text(' Shift Differential... Meets Task Group Criteria! Select Type: ' . $pp_obj->getJobItemGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                                 if ($pp_obj->getJobItemSelectionType() == 10 or $pp_obj->getJobItemSelectionType() == 20 and in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem()) or $pp_obj->getJobItemSelectionType() == 30 and !in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem())) {
                                                     Debug::text(' Shift Differential... Meets Task Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                                     $premium_policy_daily_total_time = 0;
                                                     $punch_total_time = $udt_obj->getTotalTime();
                                                     $total_time = 0;
                                                     //Apply meal policy adjustment BEFORE min/max times
                                                     if ($pp_obj->getIncludeMealPolicy() == TRUE and isset($udt_meal_policy_adjustment_arr[$udt_obj->getId()])) {
                                                         Debug::text(' Meal Policy Adjustment Found: ' . $udt_meal_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10);
                                                         $punch_total_time = bcadd($punch_total_time, $udt_meal_policy_adjustment_arr[$udt_obj->getId()]);
                                                     }
                                                     if ($pp_obj->getIncludeBreakPolicy() == TRUE and isset($udt_break_policy_adjustment_arr[$udt_obj->getId()])) {
                                                         Debug::text(' Break Policy Adjustment Found: ' . $udt_break_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10);
                                                         $punch_total_time = bcadd($punch_total_time, $udt_break_policy_adjustment_arr[$udt_obj->getId()]);
                                                     }
                                                     if ($pp_obj->getMinimumTime() > 0 or $pp_obj->getMaximumTime() > 0) {
                                                         $premium_policy_daily_total_time = $udtlf->getPremiumPolicySumByUserDateIDAndPremiumPolicyID($this->getUserDateID(), $pp_obj->getId());
                                                         Debug::text(' Premium Policy Daily Total Time: ' . $premium_policy_daily_total_time . ' Minimum Time: ' . $pp_obj->getMinimumTime() . ' Maximum Time: ' . $pp_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10);
                                                         if ($pp_obj->getMinimumTime() > 0) {
                                                             if ($daily_total_time < $pp_obj->getMinimumTime()) {
                                                                 //Split the minimum time up between all punches
                                                                 //We only get IN punches, so we don't need to divide $total_punches by 2.
                                                                 //This won't calculate the proper amount if punches aren't paired, but everything
                                                                 //is broken then anyways.
                                                                 $total_time = bcdiv($pp_obj->getMinimumTime(), $total_punches);
                                                                 Debug::text(' Daily Total Time is less the Minimum, using: ' . $total_time . ' Total Punches: ' . $total_punches, __FILE__, __LINE__, __METHOD__, 10);
                                                             } else {
                                                                 Debug::text(' Daily Total is more then minimum...', __FILE__, __LINE__, __METHOD__, 10);
                                                                 $total_time = $punch_total_time;
                                                             }
                                                         } else {
                                                             $total_time = $punch_total_time;
                                                         }
                                                         Debug::text(' Total Time After Minimum is applied: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                         if ($pp_obj->getMaximumTime() > 0) {
                                                             if ($total_time > $pp_obj->getMaximumTime()) {
                                                                 Debug::text(' aMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10);
                                                                 $total_time = $pp_obj->getMaximumTime();
                                                             } elseif (bcadd($premium_policy_daily_total_time, $total_time) > $pp_obj->getMaximumTime()) {
                                                                 Debug::text(' bMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10);
                                                                 $total_time = bcsub(bcadd($premium_policy_daily_total_time, $total_time), $pp_obj->getMaximumTime());
                                                             }
                                                         }
                                                     } else {
                                                         $total_time = $punch_total_time;
                                                     }
                                                     Debug::text(' Premium Punch Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                     if ($total_time > 0) {
                                                         Debug::text(' Applying  Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                         $udtf = new UserDateTotalFactory();
                                                         $udtf->setUserDateID($this->getUserDateID());
                                                         $udtf->setStatus(10);
                                                         //System
                                                         $udtf->setType(40);
                                                         //Premium
                                                         $udtf->setPremiumPolicyId($pp_obj->getId());
                                                         $udtf->setBranch($udt_obj->getBranch());
                                                         $udtf->setDepartment($udt_obj->getDepartment());
                                                         $udtf->setJob($udt_obj->getJob());
                                                         $udtf->setJobItem($udt_obj->getJobItem());
                                                         $udtf->setQuantity($udt_obj->getQuantity());
                                                         $udtf->setBadQuantity($udt_obj->getBadQuantity());
                                                         $udtf->setTotalTime($total_time);
                                                         $udtf->setEnableCalcSystemTotalTime(FALSE);
                                                         if ($udtf->isValid() == TRUE) {
                                                             $udtf->Save();
                                                         }
                                                         unset($udtf);
                                                     } else {
                                                         Debug::text(' Premium Punch Total Time is 0...', __FILE__, __LINE__, __METHOD__, 10);
                                                     }
                                                 } else {
                                                     Debug::text(' Shift Differential... DOES NOT Meet Task Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                                 }
                                             } else {
                                                 Debug::text(' Shift Differential... DOES NOT Meet Task Group Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                         } else {
                                             Debug::text(' Shift Differential... DOES NOT Meet Job Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     } else {
                                         Debug::text(' Shift Differential... DOES NOT Meet Job Group Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     Debug::text(' Shift Differential... DOES NOT Meet Department Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             } else {
                                 Debug::text(' Shift Differential... DOES NOT Meet Branch Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                             }
                         }
                     }
                     break;
                 case 30:
                     //Meal/Break
                     Debug::text(' Meal/Break Premium Policy...', __FILE__, __LINE__, __METHOD__, 10);
                     if ($pp_obj->getDailyTriggerTime() == 0 or $pp_obj->getDailyTriggerTime() > 0 and $daily_total_time >= $pp_obj->getDailyTriggerTime()) {
                         //Find maximum worked without a break.
                         $plf = new PunchListFactory();
                         $plf->getByUserDateId($this->getUserDateID());
                         //Get all punches for the day.
                         if ($plf->getRecordCount() > 0) {
                             Debug::text('Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                             foreach ($plf as $p_obj) {
                                 Debug::text('TimeStamp: ' . $p_obj->getTimeStamp() . ' Status: ' . $p_obj->getStatus(), __FILE__, __LINE__, __METHOD__, 10);
                                 $punch_pairs[$p_obj->getPunchControlID()][] = array('status_id' => $p_obj->getStatus(), 'punch_control_id' => $p_obj->getPunchControlID(), 'time_stamp' => $p_obj->getTimeStamp());
                             }
                             if (isset($punch_pairs)) {
                                 $prev_punch_timestamp = NULL;
                                 $maximum_time_worked_without_break = 0;
                                 foreach ($punch_pairs as $punch_pair) {
                                     if (count($punch_pair) > 1) {
                                         //Total Punch Time
                                         $total_punch_pair_time = $punch_pair[1]['time_stamp'] - $punch_pair[0]['time_stamp'];
                                         $maximum_time_worked_without_break += $total_punch_pair_time;
                                         Debug::text('Total Punch Pair Time: ' . $total_punch_pair_time . ' Maximum No Break Time: ' . $maximum_time_worked_without_break, __FILE__, __LINE__, __METHOD__, 10);
                                         if ($prev_punch_timestamp !== NULL) {
                                             $break_time = $punch_pair[0]['time_stamp'] - $prev_punch_timestamp;
                                             if ($break_time > $pp_obj->getMinimumBreakTime()) {
                                                 Debug::text('Exceeded Minimum Break Time: ' . $break_time . ' Minimum: ' . $pp_obj->getMinimumBreakTime(), __FILE__, __LINE__, __METHOD__, 10);
                                                 $maximum_time_worked_without_break = 0;
                                             }
                                         }
                                         if ($maximum_time_worked_without_break > $pp_obj->getMaximumNoBreakTime()) {
                                             Debug::text('Exceeded maximum no break time!', __FILE__, __LINE__, __METHOD__, 10);
                                             if ($pp_obj->getMaximumTime() > $pp_obj->getMinimumTime()) {
                                                 $total_time = $pp_obj->getMaximumTime();
                                             } else {
                                                 $total_time = $pp_obj->getMinimumTime();
                                             }
                                             if ($total_time > 0) {
                                                 Debug::text(' Applying Meal/Break Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                 //Get Punch Control obj.
                                                 $pclf = new PunchControlListFactory();
                                                 $pclf->getById($punch_pair[0]['punch_control_id']);
                                                 if ($pclf->getRecordCount() > 0) {
                                                     $pc_obj = $pclf->getCurrent();
                                                 }
                                                 $udtf = new UserDateTotalFactory();
                                                 $udtf->setUserDateID($this->getUserDateID());
                                                 $udtf->setStatus(10);
                                                 //System
                                                 $udtf->setType(40);
                                                 //Premium
                                                 $udtf->setPremiumPolicyId($pp_obj->getId());
                                                 if (isset($pc_obj) and is_object($pc_obj)) {
                                                     $udtf->setBranch($pc_obj->getBranch());
                                                     $udtf->setDepartment($pc_obj->getDepartment());
                                                     $udtf->setJob($pc_obj->getJob());
                                                     $udtf->setJobItem($pc_obj->getJobItem());
                                                 }
                                                 $udtf->setTotalTime($total_time);
                                                 $udtf->setEnableCalcSystemTotalTime(FALSE);
                                                 if ($udtf->isValid() == TRUE) {
                                                     $udtf->Save();
                                                 }
                                                 unset($udtf);
                                                 break;
                                                 //Stop looping through punches.
                                             }
                                         } else {
                                             Debug::text('Did not exceed maximum no break time yet...', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                         $prev_punch_timestamp = $punch_pair[1]['time_stamp'];
                                     } else {
                                         Debug::text('Found UnPaired Punch, Ignorning...', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 }
                                 unset($plf, $punch_pairs, $punch_pair, $prev_punch_timestamp, $maximum_time_worked_without_break, $total_time);
                             }
                         }
                     } else {
                         Debug::text(' Not within Daily Total Time: ' . $daily_total_time . ' Trigger Time: ' . $pp_obj->getDailyTriggerTime(), __FILE__, __LINE__, __METHOD__, 10);
                     }
                     break;
                 case 100:
                     //Advanced
                     Debug::text(' Advanced Premium Policy...', __FILE__, __LINE__, __METHOD__, 10);
                     //Make sure this is a valid day
                     if ($pp_obj->isActive($this->getUserDateObject()->getDateStamp() - 86400, $this->getUserDateObject()->getDateStamp() + 86400)) {
                         Debug::text(' Premium Policy Is Active On This Day.', __FILE__, __LINE__, __METHOD__, 10);
                         $total_daily_time_used = 0;
                         $daily_trigger_time = 0;
                         $udtlf = new UserDateTotalListFactory();
                         if ($pp_obj->isHourRestricted() == TRUE) {
                             if ($pp_obj->getWeeklyTriggerTime() > 0) {
                                 //Get Pay Period Schedule info
                                 if (is_object($this->getUserDateObject()->getPayPeriodObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject())) {
                                     $start_week_day_id = $this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()->getStartWeekDay();
                                 } else {
                                     $start_week_day_id = 0;
                                 }
                                 Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10);
                                 $weekly_total_time = $udtlf->getWeekRegularTimeSumByUserIDAndEpochAndStartWeekEpoch($this->getUserDateObject()->getUser(), $this->getUserDateObject()->getDateStamp(), TTDate::getBeginWeekEpoch($this->getUserDateObject()->getDateStamp(), $start_week_day_id));
                                 if ($weekly_total_time > $pp_obj->getWeeklyTriggerTime()) {
                                     $daily_trigger_time = 0;
                                 } else {
                                     $daily_trigger_time = $pp_obj->getWeeklyTriggerTime() - $weekly_total_time;
                                 }
                                 Debug::text(' Weekly Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                             }
                             if ($pp_obj->getDailyTriggerTime() > 0 and $pp_obj->getDailyTriggerTime() > $daily_trigger_time) {
                                 $daily_trigger_time = $pp_obj->getDailyTriggerTime();
                             }
                         }
                         Debug::text(' Daily Trigger Time: ' . $daily_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                         //Loop through all worked (status: 20) UserDateTotalRows
                         $udtlf->getByUserDateIdAndStatus($this->getUserDateID(), 20);
                         $i = 1;
                         if ($udtlf->getRecordCount() > 0) {
                             Debug::text('Found Total Hours to attempt to apply premium policy... Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                             foreach ($udtlf as $udt_obj) {
                                 //Ignore incomplete punches
                                 if ($udt_obj->getTotalTime() == 0) {
                                     continue;
                                 }
                                 //Check Shift Differential criteria before calculatating daily/weekly time which
                                 //is more resource intensive.
                                 if ($pp_obj->getBranchSelectionType() == 10 and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 20 and in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch()) or $pp_obj->getBranchSelectionType() == 30 and !in_array($udt_obj->getBranch(), (array) $pp_obj->getBranch()) and ($pp_obj->getExcludeDefaultBranch() == FALSE or $pp_obj->getExcludeDefaultBranch() == TRUE and $udt_obj->getBranch() != $this->getUserDateObject()->getUserObject()->getDefaultBranch())) {
                                     Debug::text(' Shift Differential... Meets Branch Criteria! Select Type: ' . $pp_obj->getBranchSelectionType() . ' Exclude Default Branch: ' . (int) $pp_obj->getExcludeDefaultBranch() . ' Default Branch: ' . $this->getUserDateObject()->getUserObject()->getDefaultBranch(), __FILE__, __LINE__, __METHOD__, 10);
                                     if ($pp_obj->getDepartmentSelectionType() == 10 and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 20 and in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment()) or $pp_obj->getDepartmentSelectionType() == 30 and !in_array($udt_obj->getDepartment(), (array) $pp_obj->getDepartment()) and ($pp_obj->getExcludeDefaultDepartment() == FALSE or $pp_obj->getExcludeDefaultDepartment() == TRUE and $udt_obj->getDepartment() != $this->getUserDateObject()->getUserObject()->getDefaultDepartment())) {
                                         Debug::text(' Shift Differential... Meets Department Criteria! Select Type: ' . $pp_obj->getDepartmentSelectionType() . ' Exclude Default Department: ' . (int) $pp_obj->getExcludeDefaultDepartment() . ' Default Department: ' . $this->getUserDateObject()->getUserObject()->getDefaultDepartment(), __FILE__, __LINE__, __METHOD__, 10);
                                         if ($pp_obj->getJobGroupSelectionType() == 10 or $pp_obj->getJobGroupSelectionType() == 20 and is_object($udt_obj->getJobObject()) and in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup()) or $pp_obj->getJobGroupSelectionType() == 30 and is_object($udt_obj->getJobObject()) and !in_array($udt_obj->getJobObject()->getGroup(), (array) $pp_obj->getJobGroup())) {
                                             Debug::text(' Shift Differential... Meets Job Group Criteria! Select Type: ' . $pp_obj->getJobGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                             if ($pp_obj->getJobSelectionType() == 10 or $pp_obj->getJobSelectionType() == 20 and in_array($udt_obj->getJob(), (array) $pp_obj->getJob()) or $pp_obj->getJobSelectionType() == 30 and !in_array($udt_obj->getJob(), (array) $pp_obj->getJob())) {
                                                 Debug::text(' Shift Differential... Meets Job Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                                 if ($pp_obj->getJobItemGroupSelectionType() == 10 or $pp_obj->getJobItemGroupSelectionType() == 20 and is_object($udt_obj->getJobItemObject()) and in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup()) or $pp_obj->getJobItemGroupSelectionType() == 30 and is_object($udt_obj->getJobItemObject()) and !in_array($udt_obj->getJobItemObject()->getGroup(), (array) $pp_obj->getJobItemGroup())) {
                                                     Debug::text(' Shift Differential... Meets Task Group Criteria! Select Type: ' . $pp_obj->getJobItemGroupSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                                     if ($pp_obj->getJobItemSelectionType() == 10 or $pp_obj->getJobItemSelectionType() == 20 and in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem()) or $pp_obj->getJobItemSelectionType() == 30 and !in_array($udt_obj->getJobItem(), (array) $pp_obj->getJobItem())) {
                                                         Debug::text(' Shift Differential... Meets Task Criteria! Select Type: ' . $pp_obj->getJobSelectionType(), __FILE__, __LINE__, __METHOD__, 10);
                                                         if ($pp_obj->isTimeRestricted() == TRUE and $udt_obj->getPunchControlID() != FALSE) {
                                                             Debug::text('Time Restricted Premium Policy, lookup punches to get times.', __FILE__, __LINE__, __METHOD__, 10);
                                                             if ($pp_obj->getIncludePartialPunch() == FALSE) {
                                                                 $shift_data = $this->getShiftDataByUserDateID($this->getUserDateID());
                                                             }
                                                             $plf = new PunchListFactory();
                                                             $plf->getByPunchControlId($udt_obj->getPunchControlID());
                                                             if ($plf->getRecordCount() > 0) {
                                                                 Debug::text('Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                                                                 foreach ($plf as $punch_obj) {
                                                                     if ($pp_obj->getIncludePartialPunch() == TRUE) {
                                                                         //Debug::text('Including Partial Punches...', __FILE__, __LINE__, __METHOD__, 10);
                                                                         if ($punch_obj->getStatus() == 10) {
                                                                             $punch_times['in'] = $punch_obj->getTimeStamp();
                                                                         } elseif ($punch_obj->getStatus() == 20) {
                                                                             $punch_times['out'] = $punch_obj->getTimeStamp();
                                                                         }
                                                                     } else {
                                                                         if (isset($shift_data) and is_array($shift_data)) {
                                                                             foreach ($shift_data as $shift) {
                                                                                 if ($punch_obj->getTimeStamp() >= $shift['first_in'] and $punch_obj->getTimeStamp() <= $shift['last_out']) {
                                                                                     //Debug::Arr($shift,'Shift Data...', __FILE__, __LINE__, __METHOD__, 10);
                                                                                     Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') inside shift time...', __FILE__, __LINE__, __METHOD__, 10);
                                                                                     $punch_times['in'] = $shift['first_in'];
                                                                                     $punch_times['out'] = $shift['last_out'];
                                                                                     break;
                                                                                 } else {
                                                                                     Debug::text('Punch (' . TTDate::getDate('DATE+TIME', $punch_obj->getTimeStamp()) . ') outside shift time...', __FILE__, __LINE__, __METHOD__, 10);
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                                 if (isset($punch_times) and count($punch_times) == 2 and $pp_obj->isActiveTime($punch_times['in'], $punch_times['out']) == TRUE) {
                                                                     //Debug::Arr($punch_times, 'Punch Times: ', __FILE__, __LINE__, __METHOD__, 10);
                                                                     $punch_total_time = $pp_obj->getPartialPunchTotalTime($punch_times['in'], $punch_times['out'], $udt_obj->getTotalTime());
                                                                     Debug::text('Valid Punch pair in active time, Partial Punch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                                 } else {
                                                                     Debug::text('InValid Punch Pair or outside Active Time...', __FILE__, __LINE__, __METHOD__, 10);
                                                                     $punch_total_time = 0;
                                                                 }
                                                             }
                                                         } elseif ($pp_obj->isActive($udt_obj->getUserDateObject()->getDateStamp()) == TRUE) {
                                                             $punch_total_time = $udt_obj->getTotalTime();
                                                         } else {
                                                             $punch_total_time = 0;
                                                         }
                                                         Debug::text('aPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                         //Apply meal policy adjustment as early as possible.
                                                         if ($pp_obj->getIncludeMealPolicy() == TRUE and isset($udt_meal_policy_adjustment_arr[$udt_obj->getId()])) {
                                                             Debug::text(' Meal Policy Adjustment Found: ' . $udt_meal_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10);
                                                             $punch_total_time = bcadd($punch_total_time, $udt_meal_policy_adjustment_arr[$udt_obj->getId()]);
                                                             $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_meal_policy_adjustment_arr[$udt_obj->getId()]);
                                                         } else {
                                                             $tmp_punch_total_time = $udt_obj->getTotalTime();
                                                         }
                                                         Debug::text('bPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                         if ($pp_obj->getIncludeBreakPolicy() == TRUE and isset($udt_break_policy_adjustment_arr[$udt_obj->getId()])) {
                                                             Debug::text(' Break Policy Adjustment Found: ' . $udt_break_policy_adjustment_arr[$udt_obj->getId()], __FILE__, __LINE__, __METHOD__, 10);
                                                             $punch_total_time = bcadd($punch_total_time, $udt_break_policy_adjustment_arr[$udt_obj->getId()]);
                                                             $tmp_punch_total_time = bcadd($udt_obj->getTotalTime(), $udt_break_policy_adjustment_arr[$udt_obj->getId()]);
                                                         } else {
                                                             $tmp_punch_total_time = $udt_obj->getTotalTime();
                                                         }
                                                         Debug::text('cPunch Total Time: ' . $punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                         $total_daily_time_used += $tmp_punch_total_time;
                                                         Debug::text('Daily Total Time Used: ' . $total_daily_time_used, __FILE__, __LINE__, __METHOD__, 10);
                                                         if ($punch_total_time > 0 and $total_daily_time_used > $daily_trigger_time) {
                                                             Debug::text('Past Trigger Time!!', __FILE__, __LINE__, __METHOD__, 10);
                                                             //Calculate how far past trigger time we are.
                                                             $past_trigger_time = $total_daily_time_used - $daily_trigger_time;
                                                             if ($punch_total_time > $past_trigger_time) {
                                                                 $punch_total_time = $past_trigger_time;
                                                                 Debug::text('Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                                                             } else {
                                                                 Debug::text('NOT Using Past Trigger Time as punch total time: ' . $past_trigger_time, __FILE__, __LINE__, __METHOD__, 10);
                                                             }
                                                             $total_time = $punch_total_time;
                                                             if ($pp_obj->getMinimumTime() > 0 or $pp_obj->getMaximumTime() > 0) {
                                                                 $premium_policy_daily_total_time = (int) $udtlf->getPremiumPolicySumByUserDateIDAndPremiumPolicyID($this->getUserDateID(), $pp_obj->getId());
                                                                 Debug::text(' Premium Policy Daily Total Time: ' . $premium_policy_daily_total_time . ' Minimum Time: ' . $pp_obj->getMinimumTime() . ' Maximum Time: ' . $pp_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10);
                                                                 if ($pp_obj->getMinimumTime() > 0) {
                                                                     //FIXME: Split the minimum time up between all the punches somehow.
                                                                     if ($i == $udtlf->getRecordCount() and bcadd($premium_policy_daily_total_time, $total_time) < $pp_obj->getMinimumTime()) {
                                                                         $total_time = bcsub($pp_obj->getMinimumTime(), $premium_policy_daily_total_time);
                                                                     }
                                                                 }
                                                                 Debug::text(' Total Time After Minimum is applied: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                                 if ($pp_obj->getMaximumTime() > 0) {
                                                                     if ($total_time > $pp_obj->getMaximumTime()) {
                                                                         Debug::text(' aMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10);
                                                                         $total_time = $pp_obj->getMaximumTime();
                                                                     } elseif (bcadd($premium_policy_daily_total_time, $total_time) > $pp_obj->getMaximumTime()) {
                                                                         Debug::text(' bMore than Maximum Time...', __FILE__, __LINE__, __METHOD__, 10);
                                                                         //$total_time = bcsub( bcadd( $premium_policy_daily_total_time, $total_time ), $pp_obj->getMaximumTime() );
                                                                         $total_time = bcsub($total_time, bcsub(bcadd($premium_policy_daily_total_time, $total_time), $pp_obj->getMaximumTime()));
                                                                     }
                                                                 }
                                                             }
                                                             Debug::text(' Premium Punch Total Time: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                             if ($total_time > 0) {
                                                                 Debug::text(' Applying  Premium Time!: ' . $total_time, __FILE__, __LINE__, __METHOD__, 10);
                                                                 $udtf = new UserDateTotalFactory();
                                                                 $udtf->setUserDateID($this->getUserDateID());
                                                                 $udtf->setStatus(10);
                                                                 //System
                                                                 $udtf->setType(40);
                                                                 //Premium
                                                                 $udtf->setPremiumPolicyId($pp_obj->getId());
                                                                 $udtf->setBranch($udt_obj->getBranch());
                                                                 $udtf->setDepartment($udt_obj->getDepartment());
                                                                 $udtf->setJob($udt_obj->getJob());
                                                                 $udtf->setJobItem($udt_obj->getJobItem());
                                                                 $udtf->setQuantity($udt_obj->getQuantity());
                                                                 $udtf->setBadQuantity($udt_obj->getBadQuantity());
                                                                 $udtf->setTotalTime($total_time);
                                                                 $udtf->setEnableCalcSystemTotalTime(FALSE);
                                                                 if ($udtf->isValid() == TRUE) {
                                                                     $udtf->Save();
                                                                 }
                                                                 unset($udtf);
                                                             } else {
                                                                 Debug::text(' Premium Punch Total Time is 0...', __FILE__, __LINE__, __METHOD__, 10);
                                                             }
                                                         } else {
                                                             Debug::text('Not Past Trigger Time Yet or Punch Time is 0...', __FILE__, __LINE__, __METHOD__, 10);
                                                         }
                                                     } else {
                                                         Debug::text(' Shift Differential... DOES NOT Meet Task Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                                     }
                                                 } else {
                                                     Debug::text(' Shift Differential... DOES NOT Meet Task Group Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                                 }
                                             } else {
                                                 Debug::text(' Shift Differential... DOES NOT Meet Job Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                         } else {
                                             Debug::text(' Shift Differential... DOES NOT Meet Job Group Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     } else {
                                         Debug::text(' Shift Differential... DOES NOT Meet Department Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     Debug::text(' Shift Differential... DOES NOT Meet Branch Criteria!', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                                 $i++;
                             }
                         }
                     }
                     break;
             }
         }
     }
     $profiler->stopTimer("UserDateTotal::calcPremiumPolicyTotalTime() - Part 1");
     return TRUE;
 }
Ejemplo n.º 10
0
                 $ppf->setJobItem(array());
             }
         }
         if ($ppf->isValid()) {
             $ppf->Save(TRUE);
             //$ppf->FailTransaction();
             $ppf->CommitTransaction();
             Redirect::Page(URLBuilder::getURL(NULL, 'PremiumPolicyList.php'));
             break;
         }
     }
     $ppf->FailTransaction();
 default:
     if (isset($id)) {
         BreadCrumb::setCrumb($title);
         $pplf = new PremiumPolicyListFactory();
         $pplf->getByIdAndCompanyID($id, $current_company->getID());
         foreach ($pplf as $pp_obj) {
             //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
             $data = array('id' => $pp_obj->getId(), 'name' => $pp_obj->getName(), 'type_id' => $pp_obj->getType(), 'pay_type_id' => $pp_obj->getPayType(), 'start_date' => $pp_obj->getStartDate(), 'end_date' => $pp_obj->getEndDate(), 'start_time' => $pp_obj->getStartTime(), 'end_time' => $pp_obj->getEndTime(), 'daily_trigger_time' => $pp_obj->getDailyTriggerTime(), 'weekly_trigger_time' => $pp_obj->getWeeklyTriggerTime(), 'sun' => $pp_obj->getSun(), 'mon' => $pp_obj->getMon(), 'tue' => $pp_obj->getTue(), 'wed' => $pp_obj->getWed(), 'thu' => $pp_obj->getThu(), 'fri' => $pp_obj->getFri(), 'sat' => $pp_obj->getSat(), 'include_partial_punch' => $pp_obj->getIncludePartialPunch(), 'maximum_no_break_time' => $pp_obj->getMaximumNoBreakTime(), 'minimum_break_time' => $pp_obj->getMinimumBreakTime(), 'minimum_time' => $pp_obj->getMinimumTime(), 'maximum_time' => $pp_obj->getMaximumTime(), 'include_meal_policy' => $pp_obj->getIncludeMealPolicy(), 'include_break_policy' => $pp_obj->getIncludeBreakPolicy(), 'wage_group_id' => $pp_obj->getWageGroup(), 'rate' => Misc::removeTrailingZeros($pp_obj->getRate()), 'accrual_rate' => Misc::removeTrailingZeros($pp_obj->getAccrualRate()), 'accrual_policy_id' => $pp_obj->getAccrualPolicyID(), 'pay_stub_entry_account_id' => $pp_obj->getPayStubEntryAccountId(), 'branch_selection_type_id' => $pp_obj->getBranchSelectionType(), 'exclude_default_branch' => $pp_obj->getExcludeDefaultBranch(), 'branch_ids' => $pp_obj->getBranch(), 'department_selection_type_id' => $pp_obj->getDepartmentSelectionType(), 'exclude_default_department' => $pp_obj->getExcludeDefaultDepartment(), 'department_ids' => $pp_obj->getDepartment(), 'job_group_selection_type_id' => $pp_obj->getJobGroupSelectionType(), 'job_group_ids' => $pp_obj->getJobGroup(), 'job_selection_type_id' => $pp_obj->getJobSelectionType(), 'job_ids' => $pp_obj->getJob(), 'job_item_group_selection_type_id' => $pp_obj->getJobItemGroupSelectionType(), 'job_item_group_ids' => $pp_obj->getJobItemGroup(), 'job_item_selection_type_id' => $pp_obj->getJobItemSelectionType(), 'job_item_ids' => $pp_obj->getJobItem(), 'created_date' => $pp_obj->getCreatedDate(), 'created_by' => $pp_obj->getCreatedBy(), 'updated_date' => $pp_obj->getUpdatedDate(), 'updated_by' => $pp_obj->getUpdatedBy(), 'deleted_date' => $pp_obj->getDeletedDate(), 'deleted_by' => $pp_obj->getDeletedBy());
         }
     } elseif ($action != 'submit') {
         $data = array('start_time' => NULL, 'end_time' => NULL, 'sun' => TRUE, 'mon' => TRUE, 'tue' => TRUE, 'wed' => TRUE, 'thu' => TRUE, 'fri' => TRUE, 'sat' => TRUE, 'wage_group_id' => 0, 'rate' => '1.00', 'accrual_rate' => '1.00', 'daily_trigger_time' => 0, 'weekly_trigger_time' => 0, 'maximum_no_break_time' => 0, 'minimum_break_time' => 0, 'minimum_time' => 0, 'maximum_time' => 0, 'include_meal_policy' => TRUE, 'include_break_policy' => TRUE);
     }
     $data = Misc::preSetArrayValues($data, array('branch_ids', 'department_ids', 'job_group_ids', 'job_ids', 'job_item_group_ids', 'job_item_ids'), NULL);
     $aplf = new AccrualPolicyListFactory();
     $accrual_options = $aplf->getByCompanyIDArray($current_company->getId(), TRUE);
     $psealf = new PayStubEntryAccountListFactory();
     $pay_stub_entry_options = $psealf->getByCompanyIdAndStatusIdAndTypeIdArray($current_company->getId(), 10, array(10, 20, 30, 50));
     //Get branches
     $blf = new BranchListFactory();