function _getFactoryOptions($name)
 {
     $retval = NULL;
     switch ($name) {
         case 'status':
             $sf = TTNew('ScheduleFactory');
             $retval = $sf->getOptions('status');
             break;
         case 'columns':
             $retval = array('-1010-week' => TTi18n::gettext('Week'), '-1101-sun' => TTi18n::gettext('S'), '-1102-mon' => TTi18n::gettext('M'), '-1103-tue' => TTi18n::gettext('T'), '-1104-wed' => TTi18n::gettext('W'), '-1105-thu' => TTi18n::gettext('T'), '-1106-fri' => TTi18n::gettext('F'), '-1107-sat' => TTi18n::gettext('S'), '-1200-start_time' => TTi18n::gettext('In'), '-1210-end_time' => TTi18n::gettext('Out'), '-1220-schedule_policy' => TTi18n::gettext('Schedule Policy'), '-1225-status' => TTi18n::gettext('Status'), '-1230-branch' => TTi18n::gettext('Branch'), '-1240-department' => TTi18n::gettext('Department'), '-1250-job' => TTi18n::gettext('Job'), '-1260-job_item' => TTi18n::gettext('Task'), '-2000-created_by' => TTi18n::gettext('Created By'), '-2010-created_date' => TTi18n::gettext('Created Date'), '-2020-updated_by' => TTi18n::gettext('Updated By'), '-2030-updated_date' => TTi18n::gettext('Updated Date'));
             break;
         case 'list_columns':
             $retval = Misc::arrayIntersectByKey($this->getOptions('default_display_columns'), Misc::trimSortPrefix($this->getOptions('columns')));
             break;
         case 'default_display_columns':
             //Columns that are displayed by default.
             $retval = array('week', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'start_time', 'end_time', 'schedule_policy', 'branch', 'department', 'job', 'job_item');
             break;
         case 'unique_columns':
             //Columns that are unique, and disabled for mass editing.
             $retval = array();
             break;
         case 'linked_columns':
             //Columns that are linked together, mainly for Mass Edit, if one changes, they all must.
             $retval = array();
             break;
     }
     return $retval;
 }
 function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Make sure Medicare Employer uses the same include/exclude accounts as Medicare Employee.
     $clf = TTnew('CompanyListFactory');
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             Debug::text('Company: ' . $c_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
             if ($c_obj->getStatus() != 30) {
                 $ppslf = TTNew('PayPeriodScheduleListFactory');
                 $ppslf->getByCompanyID($c_obj->getId());
                 if ($ppslf->getRecordCount() > 0) {
                     $minimum_time_between_shifts = $ppslf->getCurrent()->getNewDayTriggerTime();
                 }
                 if (isset($minimum_time_between_shifts)) {
                     $pplf = TTNew('PremiumPolicyListFactory');
                     $pplf->getAPISearchByCompanyIdAndArrayCriteria($c_obj->getID(), array('type_id' => 50));
                     if ($pplf->getRecordCount() > 0) {
                         foreach ($pplf as $pp_obj) {
                             $pp_obj->setMinimumTimeBetweenShift($minimum_time_between_shifts);
                             if ($pp_obj->isValid()) {
                                 $pp_obj->Save();
                             }
                         }
                     }
                 }
             }
         }
     }
     return TRUE;
 }
Пример #3
0
 function __construct()
 {
     global $db;
     $this->db = $db;
     $this->rl = TTNew('RateLimit');
     $this->rl->setID('authentication_' . $_SERVER['REMOTE_ADDR']);
     $this->rl->setAllowedCalls(20);
     $this->rl->setTimeFrame(900);
     //15 minutes
     return TRUE;
 }
Пример #4
0
 public function __construct()
 {
     parent::__construct();
     //Make sure parent constructor is always called.
     //$company_obj = $this->getCurrentCompanyObject();
     //$user_obj = $this->getCurrentUserObject();
     //if ( isset($this->main_class) AND class_exists( $this->main_class, TRUE ) == TRUE ) {
     //$report_obj = new $this->main_class;
     $report_obj = TTNew($this->main_class);
     //Allow plugins to work with reports.
     $report_obj->setUserObject($this->getCurrentUserObject());
     $report_obj->setPermissionObject($this->getPermissionObject());
     $this->setMainClassObject($report_obj);
     //}
     return TRUE;
 }
Пример #5
0
 function _getFactoryOptions($name, $parent = NULL)
 {
     $retval = NULL;
     switch ($name) {
         case 'columns':
             $bf = TTNew('DepartmentFactory');
             $retval = $bf->getOptions('columns');
             break;
         case 'import_options':
             $retval = array('-1010-fuzzy_match' => TTi18n::getText('Enable smart matching.'));
             break;
         case 'parse_hint':
             $retval = array();
             break;
     }
     return $retval;
 }
Пример #6
0
 function _getFactoryOptions($name)
 {
     $retval = NULL;
     switch ($name) {
         case 'type':
             $retval = array(10 => TTi18n::gettext('Banked'), 20 => TTi18n::gettext('Used'), 30 => TTi18n::gettext('Awarded'), 40 => TTi18n::gettext('Un-Awarded'), 50 => TTi18n::gettext('Gift'), 55 => TTi18n::gettext('Paid Out'), 60 => TTi18n::gettext('Rollover Adjustment'), 70 => TTi18n::gettext('Initial Balance'), 75 => TTi18n::gettext('Accrual Policy'), 80 => TTi18n::gettext('Other'));
             break;
         case 'system_type':
             $retval = array_intersect_key($this->getOptions('type'), array_flip($this->system_type_ids));
             break;
         case 'add_type':
         case 'edit_type':
         case 'user_type':
             $retval = array_diff_key($this->getOptions('type'), array_flip($this->system_type_ids));
             break;
         case 'delete_type':
             //Types that can be deleted
             $retval = $this->getOptions('type');
             unset($retval[10], $retval[20]);
             //Remove just Banked/Used as those can't be deleted.
             break;
         case 'accrual_policy_type':
             $apf = TTNew('AccrualPolicyFactory');
             $retval = $apf->getOptions('type');
             break;
         case 'columns':
             $retval = array('-1010-first_name' => TTi18n::gettext('First Name'), '-1020-last_name' => TTi18n::gettext('Last Name'), '-1030-accrual_policy' => TTi18n::gettext('Accrual Policy'), '-1040-type' => TTi18n::gettext('Type'), '-1050-date_stamp' => TTi18n::gettext('Date'), '-1060-amount' => TTi18n::gettext('Amount'), '-1090-title' => TTi18n::gettext('Title'), '-1099-user_group' => TTi18n::gettext('Group'), '-1100-default_branch' => TTi18n::gettext('Branch'), '-1110-default_department' => TTi18n::gettext('Department'), '-2000-created_by' => TTi18n::gettext('Created By'), '-2010-created_date' => TTi18n::gettext('Created Date'), '-2020-updated_by' => TTi18n::gettext('Updated By'), '-2030-updated_date' => TTi18n::gettext('Updated Date'));
             break;
         case 'list_columns':
             $retval = Misc::arrayIntersectByKey(array('accrual_policy', 'type', 'date_stamp', 'amount'), Misc::trimSortPrefix($this->getOptions('columns')));
             break;
         case 'default_display_columns':
             //Columns that are displayed by default.
             $retval = array('first_name', 'last_name', 'accrual_policy', 'type', 'amount', 'date_stamp');
             break;
         case 'linked_columns':
             //Columns that are linked together, mainly for Mass Edit, if one changes, they all must.
             break;
     }
     return $retval;
 }
Пример #7
0
 function _getFactoryOptions($name, $parent = NULL)
 {
     $retval = NULL;
     switch ($name) {
         case 'columns':
             $baf = TTNew('BankAccountFactory');
             $retval = Misc::prependArray($this->getUserIdentificationColumns(), Misc::arrayIntersectByKey(array('transit', 'institution', 'account'), Misc::trimSortPrefix($baf->getOptions('columns'))));
             break;
         case 'column_aliases':
             //Used for converting column names after they have been parsed.
             $retval = array();
             break;
         case 'import_options':
             $retval = array('-1010-fuzzy_match' => TTi18n::getText('Enable smart matching.'));
             break;
         case 'parse_hint':
         case 'parse_hint':
             //$upf = TTnew('UserPreferenceFactory');
             $retval = array();
             break;
     }
     return $retval;
 }
Пример #8
0
 function getWageGroupOptions()
 {
     //Get job titles
     $wglf = TTNew('WageGroupListFactory');
     $wglf->getByCompanyId($this->company_id);
     $this->wage_group_options = (array) $wglf->getArrayByListFactory($wglf, FALSE, TRUE);
     unset($wglf);
     return TRUE;
 }
    function getTotalMonthlyMinAvgMaxByCompanyStatusAndStartDateAndEndDate($status_id, $start_date, $end_date, $limit = NULL, $page = NULL, $where = NULL, $order = NULL)
    {
        if ($start_date == '') {
            return FALSE;
        }
        if ($end_date == '') {
            return FALSE;
        }
        $cf = TTNew('CompanyFactory');
        $ph = array('status_id' => $status_id, 'start_date' => $this->db->BindDate($start_date), 'end_date' => $this->db->BindDate($end_date));
        if (strncmp($this->db->databaseType, 'mysql', 5) == 0) {
            //$month_sql = '(month( date_stamp ))';
            $month_sql = '( date_format( a.date_stamp, \'%Y-%m-01\') )';
        } else {
            //$month_sql = '( date_part(\'month\', date_stamp) )';
            $month_sql = '( to_char(a.date_stamp, \'YYYY-MM-01\') )';
        }
        $query = '
					select
							date_stamp,
							sum(min_active_users) as min_active_users,
							sum(avg_active_users) as avg_active_users,
							sum(max_active_users) as max_active_users,

							sum(min_inactive_users) as min_inactive_users,
							sum(avg_inactive_users) as avg_inactive_users,
							sum(max_inactive_users) as max_inactive_users,

							sum(min_deleted_users) as min_deleted_users,
							sum(avg_deleted_users) as avg_deleted_users,
							sum(max_deleted_users) as max_deleted_users
					FROM (
							select
									company_id,
									' . $month_sql . ' as date_stamp,
									min(a.active_users) as min_active_users,
									ceil(avg(a.active_users)) as avg_active_users,
									max(a.active_users) as max_active_users,

									min(a.inactive_users) as min_inactive_users,
									ceil(avg(a.inactive_users)) as avg_inactive_users,
									max(a.inactive_users) as max_inactive_users,

									min(a.deleted_users) as min_deleted_users,
									ceil(avg(a.deleted_users)) as avg_deleted_users,
									max(a.deleted_users) as max_deleted_users

							from	' . $this->getTable() . ' as a
								LEFT JOIN ' . $cf->getTable() . ' as cf ON ( a.company_id = cf.id )
							where
								cf.status_id = ?
								AND a.date_stamp >= ?
								AND a.date_stamp <= ?
								AND ( cf.deleted = 0 )
							GROUP BY company_id,' . $month_sql . '
						) as tmp
					GROUP BY date_stamp
						';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order);
        $this->ExecuteSQL($query, $ph, $limit, $page);
        return $this;
    }
Пример #10
0
 static function getNextAvailableEmployeeNumber($company_id = NULL)
 {
     global $current_company;
     if ($company_id == '' and is_object($current_company)) {
         $company_id = $current_company->getId();
     } elseif ($company_id == '' and isset($this) and is_object($this)) {
         $company_id = $this->getCompany();
     }
     $ulf = TTNew('UserListFactory');
     $ulf->getHighestEmployeeNumberByCompanyId($company_id);
     if ($ulf->getRecordCount() > 0) {
         Debug::Text('Highest Employee Number: ' . $ulf->getCurrent()->getEmployeeNumber(), __FILE__, __LINE__, __METHOD__, 10);
         if (is_numeric($ulf->getCurrent()->getEmployeeNumber()) == TRUE) {
             return $ulf->getCurrent()->getEmployeeNumber() + 1;
         } else {
             Debug::Text('Highest Employee Number is not an integer.', __FILE__, __LINE__, __METHOD__, 10);
             return NULL;
         }
     } else {
         return 1;
     }
 }
Пример #11
0
 function getHierarchyControlOptions()
 {
     //Get job titles
     $hclf = TTNew('HierarchyControlListFactory');
     $hclf->getByCompanyId($this->company_id);
     $this->hierarchy_control_options = (array) $hclf->getArrayByListFactory($hclf, TRUE, FALSE, TRUE);
     unset($pglf);
     return TRUE;
 }
 function Validate()
 {
     //When the user changes just the hierarchy objects, we need to loop through ALL users and confirm no conflicting hierarchies exist.
     //Only do this for existing hierarchies and ones that are already valid up to this point.
     if (!$this->isNew() and $this->Validator->isValid() == TRUE) {
         $user_ids = $this->getUser();
         if (is_array($user_ids)) {
             $huf = TTNew('HierarchyUserFactory');
             $huf->setHierarchyControl($this->getID());
             foreach ($user_ids as $user_id) {
                 if ($huf->isUniqueUser($user_id) == FALSE) {
                     $ulf = TTnew('UserListFactory');
                     $ulf->getById($user_id);
                     if ($ulf->getRecordCount() > 0) {
                         $obj = $ulf->getCurrent();
                         TTi18n::gettext('Selected subordinate is invalid or already assigned to another hierarchy with the same objects ') . ' (' . $obj->getFullName() . ')';
                         if ($this->Validator->isTrue('user', $huf->isUniqueUser($user_id, $this->getID()), TTi18n::gettext('Selected subordinate is invalid or already assigned to another hierarchy with the same objects ') . ' (' . $obj->getFullName() . ')')) {
                         }
                     } else {
                         TTi18n::gettext('Selected subordinate is invalid or already assigned to another hierarchy with the same object. User ID: ' . $user_id);
                     }
                 }
             }
         }
     }
     return TRUE;
 }
Пример #13
0
 function getAccrualPolicyOptions()
 {
     //Get accrual policies
     $aplf = TTNew('AccrualPolicyListFactory');
     $aplf->getByCompanyId($this->company_id);
     $this->accrual_policy_options = (array) $aplf->getArrayByListFactory($aplf, FALSE, TRUE);
     unset($aplf);
     return TRUE;
 }
Пример #14
0
 function createCompanyDeduction($company_id)
 {
     //$retval = CompanyDeductionFactory::addPresets( $company_id );
     $sp = TTNew('SetupPresets');
     $sp->setCompany($company_id);
     $retval = $sp->CompanyDeductions();
     $retval = $sp->CompanyDeductions('us');
     $retval = $sp->CompanyDeductions('us', 'ny');
     if ($retval == TRUE) {
         Debug::Text('Created Company Deductions!', __FILE__, __LINE__, __METHOD__, 10);
         return TRUE;
     }
     Debug::Text('Failed Creating Company Deductions for Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
 function addAccrualPolicyTime($epoch = NULL, $offset = 79200)
 {
     //22hr offset
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     Debug::Text('Accrual Policy ID: ' . $this->getId() . ' Current EPOCH: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
     $pglf = TTnew('PolicyGroupListFactory');
     $pglf->StartTransaction();
     $pglf->getSearchByCompanyIdAndArrayCriteria($this->getCompany(), array('accrual_policy_id' => array($this->getId())));
     if ($pglf->getRecordCount() > 0) {
         Debug::Text('Found Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($pglf as $pg_obj) {
             //Get all users assigned to this policy group.
             $policy_group_users = $pg_obj->getUser();
             if (is_array($policy_group_users) and count($policy_group_users) > 0) {
                 Debug::Text('Found Policy Group Users: ' . count($policy_group_users), __FILE__, __LINE__, __METHOD__, 10);
                 foreach ($policy_group_users as $user_id) {
                     Debug::Text('Policy Group User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                     //Get User Object
                     $ulf = TTnew('UserListFactory');
                     $ulf->getByIDAndCompanyID($user_id, $this->getCompany());
                     if ($ulf->getRecordCount() == 1) {
                         $u_obj = $ulf->getCurrent();
                         $ppslf = TTNew('PayPeriodScheduleListFactory');
                         $ppslf->getByCompanyIdAndUserId($u_obj->getCompany(), $u_obj->getId());
                         if ($ppslf->getRecordCount() > 0) {
                             $pps_obj = $ppslf->getCurrent();
                             $accrual_balance = $this->getCurrentAccrualBalance($u_obj->getID(), $this->getId());
                             $pay_period_arr = array();
                             if ($this->getApplyFrequency() == 10) {
                                 $pay_period_arr = $this->getPayPeriodArray($pps_obj, $u_obj, $epoch - $offset, $epoch - $offset);
                             }
                             $this->calcAccrualPolicyTime($u_obj, $epoch, $offset, $pps_obj, $pay_period_arr, $accrual_balance, TRUE);
                         }
                     } else {
                         Debug::Text('No User Found. Company ID: ' . $this->getCompany(), __FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
             }
         }
     }
     $pglf->CommitTransaction();
     return TRUE;
 }
 static function calcExceptions($user_date_id, $enable_premature_exceptions = FALSE, $enable_future_exceptions = TRUE)
 {
     global $profiler;
     $profiler->startTimer("ExceptionPolicy::calcExceptions()");
     if ($user_date_id == '') {
         return FALSE;
     }
     Debug::text(' User Date ID: ' . $user_date_id . ' PreMature: ' . (int) $enable_premature_exceptions, __FILE__, __LINE__, __METHOD__, 10);
     $current_epoch = TTDate::getTime();
     //Get user date info
     $udlf = TTnew('UserDateListFactory');
     $udlf->getById($user_date_id);
     if ($udlf->getRecordCount() > 0) {
         $user_date_obj = $udlf->getCurrent();
         if ($enable_future_exceptions == FALSE and $user_date_obj->getDateStamp() > TTDate::getEndDayEpoch($current_epoch)) {
             return FALSE;
         }
     } else {
         return FALSE;
     }
     //16hrs... If punches are older then this time, its no longer premature.
     //This should actually be the PayPeriod Schedule maximum shift time.
     if (is_object($user_date_obj->getPayPeriodObject()) and is_object($user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject())) {
         self::$premature_delay = $user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject()->getMaximumShiftTime();
         Debug::text(' Setting preMature Exception delay to maximum shift time: ' . self::$premature_delay, __FILE__, __LINE__, __METHOD__, 10);
     } else {
         self::$premature_delay = 57600;
     }
     //Get list of existing exceptions, so we can determine if we need to delete any. We can't delete them all blindly and re-create them
     //as this will send duplicate email notifications for every single punch.
     $existing_exceptions = array();
     $elf = TTnew('ExceptionListFactory');
     $elf->getByUserDateID($user_date_id);
     if ($elf->getRecordCount() > 0) {
         foreach ($elf as $e_obj) {
             $existing_exceptions[] = array('id' => $e_obj->getId(), 'user_date_id' => $e_obj->getUserDateID(), 'exception_policy_id' => $e_obj->getExceptionPolicyID(), 'type_id' => $e_obj->getType(), 'punch_id' => $e_obj->getPunchID(), 'punch_control_id' => $e_obj->getPunchControlID());
         }
     }
     unset($elf, $e_obj);
     //Get all Punches on this date for this user.
     $plf = TTnew('PunchListFactory');
     $plf->getByUserDateId($user_date_id);
     if ($plf->getRecordCount() > 0) {
         Debug::text(' Found Punches: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     }
     $slf = TTnew('ScheduleListFactory');
     $slf->getByUserDateIdAndStatusId($user_date_id, 10);
     if ($slf->getRecordCount() > 0) {
         Debug::text(' Found Schedule: ' . $slf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     }
     $schedule_id_cache = NULL;
     //Cache schedule IDs so we don't need to do a lookup for every exception.
     $current_exceptions = array();
     //Array holding current exception data.
     //Get all active exceptions.
     $eplf = TTnew('ExceptionPolicyListFactory');
     $eplf->getByPolicyGroupUserIdAndActive($user_date_obj->getUser(), TRUE);
     if ($eplf->getRecordCount() > 0) {
         Debug::text(' Found Active Exceptions: ' . $eplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
         foreach ($eplf as $ep_obj) {
             //Debug::text(' Found Exception Type: '. $ep_obj->getType() .' ID: '. $ep_obj->getID() .' Control ID: '. $ep_obj->getExceptionPolicyControl(), __FILE__, __LINE__, __METHOD__,10);
             if ($enable_premature_exceptions == TRUE and self::isPreMature($ep_obj->getType()) == TRUE) {
                 //Debug::text(' Premature Exception: '. $ep_obj->getType() , __FILE__, __LINE__, __METHOD__,10);
                 $type_id = 5;
                 //Pre-Mature
             } else {
                 //Debug::text(' NOT Premature Exception: '. $ep_obj->getType() , __FILE__, __LINE__, __METHOD__,10);
                 $type_id = 50;
                 //Active
             }
             switch (strtolower($ep_obj->getType())) {
                 case 's1':
                     //Unscheduled Absence... Anytime they are scheduled and have not punched in.
                     //Ignore these exceptions if the schedule is after today (not including today),
                     //so if a supervisors schedules an employee two days in advance they don't get a unscheduled
                     //absence appearing right away.
                     //Since we now trigger In Late/Out Late exceptions immediately after schedule time, only trigger this exception after
                     //the schedule end time has passed.
                     //**We also need to handle shifts that start at 11:00PM on one day, end at 8:00AM the next day, and they are assigned to the day where
                     //the most time is worked (ie: the next day).
                     //Handle split shifts too...
                     //- This has a side affect that if the schedule policy start/stop time is set to 0, it will trigger both a UnScheduled Absence
                     //  and a Not Scheduled exception for the same schedule/punch.
                     //Loop through all schedules, then find punches to match.
                     if ($slf->getRecordCount() > 0) {
                         foreach ($slf as $s_obj) {
                             if ($s_obj->getStatus() == 10 and $current_epoch >= $s_obj->getEndTime()) {
                                 $add_exception = TRUE;
                                 //Debug::text(' Found Schedule: Start Time: '. TTDate::getDate('DATE+TIME', $s_obj->getStartTime() ), __FILE__, __LINE__, __METHOD__,10);
                                 //Find punches that fall within this schedule time including start/stop window.
                                 if (TTDate::doesRangeSpanMidnight($s_obj->getStartTime(), $s_obj->getEndTime()) and is_object($user_date_obj) and is_object($user_date_obj->getPayPeriodObject()) and is_object($user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject())) {
                                     //Get punches from both days.
                                     $plf_tmp = TTnew('PunchListFactory');
                                     $plf_tmp->getShiftPunchesByUserIDAndEpoch($user_date_obj->getUser(), $s_obj->getStartTime(), 0, $user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject()->getMaximumShiftTime());
                                     Debug::text(' Schedule spans midnight... Found rows from expanded search: ' . $plf_tmp->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                                     if ($plf_tmp->getRecordCount() > 0) {
                                         foreach ($plf_tmp as $p_obj_tmp) {
                                             if ($s_obj->inSchedule($p_obj_tmp->getTimeStamp())) {
                                                 Debug::text(' aFound punch for schedule...', __FILE__, __LINE__, __METHOD__, 10);
                                                 $add_exception = FALSE;
                                                 break;
                                             }
                                         }
                                     }
                                     unset($plf_tmp, $p_obj_tmp);
                                 } else {
                                     //Get punches from just this day.
                                     foreach ($plf as $p_obj) {
                                         if ($s_obj->inSchedule($p_obj->getTimeStamp())) {
                                             //Debug::text(' bFound punch for schedule...', __FILE__, __LINE__, __METHOD__,10);
                                             $add_exception = FALSE;
                                             break;
                                         }
                                     }
                                 }
                                 if ($add_exception == TRUE) {
                                     //Debug::text(' Adding S1 exception...', __FILE__, __LINE__, __METHOD__,10);
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => FALSE, 'schedule_obj' => $s_obj);
                                 }
                             }
                         }
                     }
                     unset($s_obj, $add_exception);
                     break;
                 case 's2':
                     //Not Scheduled
                     //**We also need to handle shifts that start at 11:00PM on one day, end at 8:00AM the next day, and they are assigned to the day where
                     //the most time is worked (ie: the next day).
                     //Handle split shifts too...
                     if ($plf->getRecordCount() > 1) {
                         //Make sure at least two punche exist.
                         //Loop through each punch, find out if they are scheduled, and if they are in early
                         $prev_punch_time_stamp = FALSE;
                         foreach ($plf as $p_obj) {
                             //Ignore punches that have the exact same timestamp, as they are likely transfer punches.
                             if ($prev_punch_time_stamp != $p_obj->getTimeStamp() and $p_obj->getType() == 10 and $p_obj->getStatus() == 10) {
                                 //Normal In
                                 if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                     $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                 }
                                 //Check if no schedule exists, or an absent schedule exists. If they work when not scheduled (no schedule) or schedule absent, both should trigger this.
                                 if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == FALSE or is_object($p_obj->getScheduleObject()) and $p_obj->getScheduleObject()->getStatus() == 20) {
                                     //Debug::text(' Worked when wasnt scheduled', __FILE__, __LINE__, __METHOD__,10);
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getID(), 'punch_control_id' => FALSE);
                                 } else {
                                     Debug::text('    Schedule Found', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                             $prev_punch_time_stamp = $p_obj->getTimeStamp();
                         }
                     }
                     unset($scheduled_id_cache, $prev_punch_time_stamp, $p_obj);
                     break;
                 case 's3':
                     //In Early
                     if ($plf->getRecordCount() > 0) {
                         //Loop through each punch, find out if they are scheduled, and if they are in early
                         $prev_punch_time_stamp = FALSE;
                         foreach ($plf as $p_obj) {
                             //Ignore punches that have the exact same timestamp, as they are likely transfer punches.
                             if ($prev_punch_time_stamp != $p_obj->getTimeStamp() and $p_obj->getType() == 10 and $p_obj->getStatus() == 10) {
                                 //Normal In
                                 if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                     $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                 }
                                 if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) {
                                     if ($p_obj->getTimeStamp() < $p_obj->getScheduleObject()->getStartTime()) {
                                         if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getGrace()) == TRUE) {
                                             Debug::text('    Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                         } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getWatchWindow()) == TRUE) {
                                             Debug::text('    NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getID(), 'punch_control_id' => FALSE, 'punch_obj' => $p_obj, 'schedule_obj' => $p_obj->getScheduleObject());
                                         }
                                     }
                                 } else {
                                     Debug::text('    NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                             $prev_punch_time_stamp = $p_obj->getTimeStamp();
                         }
                     }
                     break;
                 case 's4':
                     //In Late
                     if ($plf->getRecordCount() > 0) {
                         $prev_punch_time_stamp = FALSE;
                         foreach ($plf as $p_obj) {
                             Debug::text('    In Late. Punch: ' . TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp()), __FILE__, __LINE__, __METHOD__, 10);
                             //Ignore punches that have the exact same timestamp and/or punches with the transfer flag, as they are likely transfer punches.
                             if ($prev_punch_time_stamp != $p_obj->getTimeStamp() and $p_obj->getTransfer() == FALSE and $p_obj->getType() == 10 and $p_obj->getStatus() == 10) {
                                 //Normal In
                                 if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                     $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                 }
                                 if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) {
                                     if ($p_obj->getTimeStamp() > $p_obj->getScheduleObject()->getStartTime()) {
                                         if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getGrace()) == TRUE) {
                                             Debug::text('    Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                         } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getStartTime(), $ep_obj->getWatchWindow()) == TRUE) {
                                             Debug::text('    NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getID(), 'punch_control_id' => FALSE, 'punch_obj' => $p_obj, 'schedule_obj' => $p_obj->getScheduleObject());
                                         }
                                     }
                                 } else {
                                     Debug::text('    NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                             $prev_punch_time_stamp = $p_obj->getTimeStamp();
                         }
                     }
                     unset($scheduled_id_cache);
                     //Late Starting their shift, with no punch yet, trigger exception if:
                     //  - Schedule is found
                     //	- Current time is after schedule start time and before schedule end time.
                     // 	- Current time is after exception grace time
                     //Make sure we take into account split shifts.
                     Debug::text('    Checking Late Starting Shift exception... Current time: ' . TTDate::getDate('DATE+TIME', $current_epoch), __FILE__, __LINE__, __METHOD__, 10);
                     if ($slf->getRecordCount() > 0) {
                         foreach ($slf as $s_obj) {
                             if ($s_obj->getStatus() == 10 and ($current_epoch >= $s_obj->getStartTime() and $current_epoch <= $s_obj->getEndTime())) {
                                 if (TTDate::inWindow($current_epoch, $s_obj->getStartTime(), $ep_obj->getGrace()) == TRUE) {
                                     Debug::text('    Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                 } else {
                                     //See if we can find a punch within the schedule time, if so assume we already created the exception above.
                                     //Make sure we take into account the schedule policy start/stop window.
                                     //However in the case where a single schedule shift and just one punch exists, if an employee comes in really
                                     //early (1AM) before the schedule start/stop window it will trigger an In Late exception.
                                     //This could still be correct though if they only come in for an hour, then come in late for their shift later.
                                     //Schedule start/stop time needs to be correct.
                                     //Also need to take into account shifts that span midnight, ie: 10:30PM to 6:00AM, as its important the schedules/punches match up properly.
                                     $add_exception = TRUE;
                                     Debug::text(' Found Schedule: Start Time: ' . TTDate::getDate('DATE+TIME', $s_obj->getStartTime()), __FILE__, __LINE__, __METHOD__, 10);
                                     //Find punches that fall within this schedule time including start/stop window.
                                     if (TTDate::doesRangeSpanMidnight($s_obj->getStartTime(), $s_obj->getEndTime()) and is_object($user_date_obj) and is_object($user_date_obj->getPayPeriodObject()) and is_object($user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject())) {
                                         //Get punches from both days.
                                         $plf_tmp = TTnew('PunchListFactory');
                                         $plf_tmp->getShiftPunchesByUserIDAndEpoch($user_date_obj->getUser(), $s_obj->getStartTime(), 0, $user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject()->getMaximumShiftTime());
                                         Debug::text(' Schedule spans midnight... Found rows from expanded search: ' . $plf_tmp->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                                         if ($plf_tmp->getRecordCount() > 0) {
                                             foreach ($plf_tmp as $p_obj_tmp) {
                                                 if ($s_obj->inSchedule($p_obj_tmp->getTimeStamp())) {
                                                     Debug::text('    Found punch for this schedule, skipping schedule...', __FILE__, __LINE__, __METHOD__, 10);
                                                     $add_exception = FALSE;
                                                     continue 2;
                                                     //Skip to next schedule without creating exception.
                                                 }
                                             }
                                         }
                                         unset($plf_tmp, $p_obj_tmp);
                                     } else {
                                         //Get punches from just this day.
                                         foreach ($plf as $p_obj) {
                                             if ($s_obj->inSchedule($p_obj->getTimeStamp())) {
                                                 Debug::text(' bFound punch for schedule...', __FILE__, __LINE__, __METHOD__, 10);
                                                 $add_exception = FALSE;
                                                 break;
                                             }
                                         }
                                     }
                                     if ($add_exception == TRUE) {
                                         Debug::text('    NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                         $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => FALSE, 'schedule_obj' => $s_obj);
                                     }
                                 }
                             }
                         }
                     } else {
                         Debug::text('    NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     break;
                 case 's5':
                     //Out Early
                     if ($plf->getRecordCount() > 0) {
                         //Loop through each punch, find out if they are scheduled, and if they are in early
                         $prev_punch_time_stamp = FALSE;
                         $total_punches = $plf->getRecordCount();
                         $x = 1;
                         foreach ($plf as $p_obj) {
                             //Ignore punches that have the exact same timestamp and/or punches with the transfer flag, as they are likely transfer punches.
                             //For Out Early, we have to wait until we are at the last punch, or there is a subsequent punch
                             // to see if it matches the exact same time (transfer)
                             //Therefore we need a two step confirmation before this exception can be triggered. Current punch, then next punch if it exists.
                             if ($p_obj->getTransfer() == FALSE and $p_obj->getType() == 10 and $p_obj->getStatus() == 20) {
                                 //Normal Out
                                 if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                     $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                 }
                                 if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) {
                                     if ($p_obj->getTimeStamp() < $p_obj->getScheduleObject()->getEndTime()) {
                                         if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getGrace()) == TRUE) {
                                             Debug::text('    Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                         } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getWatchWindow()) == TRUE) {
                                             Debug::text('    NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                             $tmp_exception = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getID(), 'punch_control_id' => FALSE, 'punch_obj' => $p_obj, 'schedule_obj' => $p_obj->getScheduleObject());
                                             if ($x == $total_punches) {
                                                 //Trigger exception if we're the last punch.
                                                 $current_exceptions[] = $tmp_exception;
                                             } else {
                                                 //Save exception to be triggered if the next punch doesn't match the same time.
                                             }
                                         }
                                     }
                                 } else {
                                     Debug::text('    NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             } elseif ($p_obj->getType() == 10 and $p_obj->getStatus() == 10) {
                                 //Normal In
                                 //This comes after an OUT punch, so we need to check if there are two punches
                                 //in a row with the same timestamp, if so ignore the exception.
                                 if (isset($tmp_exception) and $p_obj->getTimeStamp() == $prev_punch_time_stamp) {
                                     unset($tmp_exception);
                                 } elseif (isset($tmp_exception)) {
                                     $current_exceptions[] = $tmp_exception;
                                     //Set exception.
                                 }
                             }
                             $prev_punch_time_stamp = $p_obj->getTimeStamp();
                             $x++;
                         }
                     }
                     unset($tmp_exception, $x, $prev_punch_time_stamp);
                     break;
                 case 's6':
                     //Out Late
                     if ($plf->getRecordCount() > 0) {
                         $prev_punch_time_stamp = FALSE;
                         foreach ($plf as $p_obj) {
                             $punch_pairs[$p_obj->getPunchControlID()][] = array('status_id' => $p_obj->getStatus(), 'punch_control_id' => $p_obj->getPunchControlID(), 'time_stamp' => $p_obj->getTimeStamp());
                             if ($prev_punch_time_stamp != $p_obj->getTimeStamp() and $p_obj->getType() == 10 and $p_obj->getStatus() == 20) {
                                 //Normal Out
                                 if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                     $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                 }
                                 if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE) {
                                     if ($p_obj->getTimeStamp() > $p_obj->getScheduleObject()->getEndTime()) {
                                         if (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getGrace()) == TRUE) {
                                             Debug::text('    Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                         } elseif (TTDate::inWindow($p_obj->getTimeStamp(), $p_obj->getScheduleObject()->getEndTime(), $ep_obj->getWatchWindow()) == TRUE) {
                                             Debug::text('    NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getID(), 'punch_control_id' => FALSE, 'punch_obj' => $p_obj, 'schedule_obj' => $p_obj->getScheduleObject());
                                         }
                                     }
                                 } else {
                                     Debug::text('    NO Schedule Found', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                             $prev_punch_time_stamp = $p_obj->getTimeStamp();
                         }
                         //Trigger exception if no out punch and we have passed schedule out time.
                         //  - Schedule is found
                         //	- Make sure the user is missing an OUT punch.
                         //	- Current time is after schedule end time
                         // 	- Current time is after exception grace time
                         //  - Current time is before schedule end time + maximum shift time.
                         if (isset($punch_pairs) and $slf->getRecordCount() > 0) {
                             foreach ($punch_pairs as $punch_control_id => $punch_pair) {
                                 if (count($punch_pair) != 2) {
                                     Debug::text('aFound Missing Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                     if ($punch_pair[0]['status_id'] == 10) {
                                         //Missing Out Punch
                                         Debug::text('bFound Missing Out Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                         foreach ($slf as $s_obj) {
                                             Debug::text('Punch: ' . TTDate::getDate('DATE+TIME', $punch_pair[0]['time_stamp']) . ' Schedule Start Time: ' . TTDate::getDate('DATE+TIME', $s_obj->getStartTime()) . ' End Time: ' . TTDate::getDate('DATE+TIME', $s_obj->getEndTime()), __FILE__, __LINE__, __METHOD__, 10);
                                             //Because this is just an IN punch, make sure the IN punch is before the schedule end time
                                             //So we can eliminate split shift schedules.
                                             if ($punch_pair[0]['time_stamp'] <= $s_obj->getEndTime() and $current_epoch >= $s_obj->getEndTime() and $current_epoch <= $s_obj->getEndTime() + self::$premature_delay) {
                                                 if (TTDate::inWindow($current_epoch, $s_obj->getEndTime(), $ep_obj->getGrace()) == TRUE) {
                                                     Debug::text('    Within Grace time, IGNORE EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                                 } else {
                                                     Debug::text('    NOT Within Grace time, SET EXCEPTION: ', __FILE__, __LINE__, __METHOD__, 10);
                                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $punch_pair[0]['punch_control_id'], 'schedule_obj' => $s_obj);
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     Debug::text('No Missing Punches...', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         }
                         unset($punch_pairs, $punch_pair);
                     }
                     break;
                 case 'm1':
                     //Missing In Punch
                     if ($plf->getRecordCount() > 0) {
                         foreach ($plf as $p_obj) {
                             //Debug::text(' Punch: Status: '. $p_obj->getStatus() .' Punch Control ID: '. $p_obj->getPunchControlID() .' Punch ID: '. $p_obj->getId() .' TimeStamp: '. $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__,10);
                             if ($type_id == 5 and $p_obj->getTimeStamp() < $current_epoch - self::$premature_delay) {
                                 $type_id = 50;
                             }
                             $punch_pairs[$p_obj->getPunchControlID()][] = array('status_id' => $p_obj->getStatus(), 'punch_control_id' => $p_obj->getPunchControlID(), 'punch_id' => $p_obj->getId());
                         }
                         if (isset($punch_pairs)) {
                             foreach ($punch_pairs as $punch_control_id => $punch_pair) {
                                 //Debug::Arr($punch_pair, 'Punch Pair for Control ID:'. $punch_control_id, __FILE__, __LINE__, __METHOD__,10);
                                 if (count($punch_pair) != 2) {
                                     Debug::text('a1Found Missing Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                     if ($punch_pair[0]['status_id'] == 20) {
                                         //Missing In Punch
                                         Debug::text('b1Found Missing In Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                         $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $punch_pair[0]['punch_control_id']);
                                     }
                                 } else {
                                     Debug::text('No Missing Punches...', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         }
                         unset($punch_pairs, $punch_pair);
                     }
                     break;
                 case 'm2':
                     //Missing Out Punch
                     if ($plf->getRecordCount() > 0) {
                         foreach ($plf as $p_obj) {
                             Debug::text(' Punch: Status: ' . $p_obj->getStatus() . ' Punch Control ID: ' . $p_obj->getPunchControlID() . ' Punch ID: ' . $p_obj->getId() . ' TimeStamp: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10);
                             //This causes the exception to trigger if the first punch pair is more than the Maximum Shift time away from the current punch,
                             //ie: In: 1:00AM, Out: 2:00AM, In 3:00PM (Maximum Shift Time less than 12hrs). The missing punch exception will be triggered immediately upon the 3:00PM punch.
                             //if ( $type_id == 5 AND $p_obj->getTimeStamp() < ($current_epoch-self::$premature_delay) ) {
                             //	$type_id = 50;
                             //}
                             $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)) {
                             foreach ($punch_pairs as $punch_control_id => $punch_pair) {
                                 if (count($punch_pair) != 2) {
                                     Debug::text('a2Found Missing Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                     if ($punch_pair[0]['status_id'] == 10) {
                                         //Missing Out Punch
                                         Debug::text('b2Found Missing Out Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                         //Make sure we are at least MaximumShift Time from the matching In punch before trigging this exception.
                                         //Even when an supervisor is entering punches for today, make missing out punch pre-mature if the maximum shift time isn't exceeded.
                                         //This will prevent timesheet recalculations from having missing punches for everyone today.
                                         //if ( $type_id == 5 AND $punch_pair[0]['time_stamp'] < ($current_epoch-self::$premature_delay) ) {
                                         if ($punch_pair[0]['time_stamp'] < $current_epoch - self::$premature_delay) {
                                             $type_id = 50;
                                         } else {
                                             $type_id = 5;
                                         }
                                         $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $punch_pair[0]['punch_control_id']);
                                     }
                                 } else {
                                     Debug::text('No Missing Punches...', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         }
                         unset($punch_pairs, $punch_pair);
                     }
                     break;
                 case 'm3':
                     //Missing Lunch In/Out punch
                     if ($plf->getRecordCount() > 0) {
                         //We need to account for cases where they may punch IN from lunch first, then Out.
                         //As well as just a Lunch In punch and nothing else.
                         foreach ($plf as $p_obj) {
                             if ($type_id == 5 and $p_obj->getTimeStamp() < $current_epoch - self::$premature_delay) {
                                 $type_id = 50;
                             }
                             $punches[] = $p_obj;
                         }
                         if (isset($punches) and is_array($punches)) {
                             foreach ($punches as $key => $p_obj) {
                                 if ($p_obj->getType() == 20) {
                                     //Lunch
                                     Debug::text(' Punch: Status: ' . $p_obj->getStatus() . ' Punch Control ID: ' . $p_obj->getPunchControlID() . ' TimeStamp: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10);
                                     if ($p_obj->getStatus() == 10) {
                                         //Make sure previous punch is Lunch/Out
                                         if (!isset($punches[$key - 1]) or isset($punches[$key - 1]) and is_object($punches[$key - 1]) and ($punches[$key - 1]->getType() != 20 or $punches[$key - 1]->getStatus() != 20)) {
                                             //Invalid punch
                                             $invalid_punches[] = array('punch_id' => $p_obj->getId());
                                         }
                                     } else {
                                         //Make sure next punch is Lunch/In
                                         if (!isset($punches[$key + 1]) or isset($punches[$key + 1]) and is_object($punches[$key + 1]) and ($punches[$key + 1]->getType() != 20 or $punches[$key + 1]->getStatus() != 10)) {
                                             //Invalid punch
                                             $invalid_punches[] = array('punch_id' => $p_obj->getId());
                                         }
                                     }
                                 }
                             }
                             unset($punches, $key, $p_obj);
                             if (isset($invalid_punches) and count($invalid_punches) > 0) {
                                 foreach ($invalid_punches as $invalid_punch_arr) {
                                     Debug::text('Found Missing Lunch In/Out Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $invalid_punch_arr['punch_id'], 'punch_control_id' => FALSE);
                                 }
                                 unset($invalid_punch_arr);
                             } else {
                                 Debug::text('Lunch Punches match up.', __FILE__, __LINE__, __METHOD__, 10);
                             }
                             unset($invalid_punches);
                         }
                     }
                     break;
                 case 'm4':
                     //Missing Break In/Out punch
                     if ($plf->getRecordCount() > 0) {
                         //We need to account for cases where they may punch IN from break first, then Out.
                         //As well as just a break In punch and nothing else.
                         foreach ($plf as $p_obj) {
                             if ($type_id == 5 and $p_obj->getTimeStamp() < $current_epoch - self::$premature_delay) {
                                 $type_id = 50;
                             }
                             $punches[] = $p_obj;
                         }
                         if (isset($punches) and is_array($punches)) {
                             foreach ($punches as $key => $p_obj) {
                                 if ($p_obj->getType() == 30) {
                                     //Break
                                     Debug::text(' Punch: Status: ' . $p_obj->getStatus() . ' Type: ' . $p_obj->getType() . ' Punch Control ID: ' . $p_obj->getPunchControlID() . ' TimeStamp: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10);
                                     if ($p_obj->getStatus() == 10) {
                                         //Make sure previous punch is Break/Out
                                         if (!isset($punches[$key - 1]) or isset($punches[$key - 1]) and is_object($punches[$key - 1]) and ($punches[$key - 1]->getType() != 30 or $punches[$key - 1]->getStatus() != 20)) {
                                             //Invalid punch
                                             $invalid_punches[] = array('punch_id' => $p_obj->getId());
                                         }
                                     } else {
                                         //Make sure next punch is Break/In
                                         if (!isset($punches[$key + 1]) or isset($punches[$key + 1]) and is_object($punches[$key + 1]) and ($punches[$key + 1]->getType() != 30 or $punches[$key + 1]->getStatus() != 10)) {
                                             //Invalid punch
                                             $invalid_punches[] = array('punch_id' => $p_obj->getId());
                                         }
                                     }
                                 }
                             }
                             unset($punches, $key, $p_obj);
                             if (isset($invalid_punches) and count($invalid_punches) > 0) {
                                 foreach ($invalid_punches as $invalid_punch_arr) {
                                     Debug::text('Found Missing Break In/Out Punch: ', __FILE__, __LINE__, __METHOD__, 10);
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $invalid_punch_arr['punch_id'], 'punch_control_id' => FALSE);
                                 }
                                 unset($invalid_punch_arr);
                             } else {
                                 Debug::text('Lunch Punches match up.', __FILE__, __LINE__, __METHOD__, 10);
                             }
                             unset($invalid_punches);
                         }
                     }
                     break;
                 case 'c1':
                     //Missed Check-in
                     //Use grace period and make sure the employee punches within that period of time (usually a transfer punch, but break/lunch should work too)
                     if ($plf->getRecordCount() > 0 and $ep_obj->getGrace() > 0) {
                         $prev_punch_time_stamp = FALSE;
                         $prev_punch_obj = FALSE;
                         $x = 1;
                         foreach ($plf as $p_obj) {
                             Debug::text('   Missed Check-In Punch: ' . TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp()) . ' Delay: ' . self::$premature_delay . ' Current Epoch: ' . $current_epoch, __FILE__, __LINE__, __METHOD__, 10);
                             //Handle punch pairs below. Only trigger on OUT punches.
                             if (is_object($prev_punch_obj) and $prev_punch_obj->getStatus() == 10 and $p_obj->getStatus() == 20 and $p_obj->getTimeStamp() - $prev_punch_time_stamp > $ep_obj->getGrace()) {
                                 //Only check OUT punches when paired.
                                 Debug::text('   Triggering excepetion as employee missed check-in within: ' . ($p_obj->getTimeStamp() - $prev_punch_time_stamp), __FILE__, __LINE__, __METHOD__, 10);
                                 $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getID(), 'punch_control_id' => FALSE, 'punch_obj' => $p_obj, 'schedule_obj' => $p_obj->getScheduleObject());
                             } elseif ($prev_punch_time_stamp !== FALSE) {
                                 Debug::text('   Employee Checked-In within: ' . ($p_obj->getTimeStamp() - $prev_punch_time_stamp), __FILE__, __LINE__, __METHOD__, 10);
                             }
                             //Handle cases where there is a IN punch but no OUT punch yet.
                             //However ignore cases where there is a OUT punch but no IN punch.
                             if ($x == $plf->getRecordCount() and $p_obj->getStatus() == 10 and $current_epoch - $p_obj->getTimeStamp() > $ep_obj->getGrace() and $p_obj->getTimeStamp() > $current_epoch - self::$premature_delay) {
                                 Debug::text('   Triggering excepetion as employee hasnt checked in yet, within: ' . ($current_epoch - $prev_punch_time_stamp), __FILE__, __LINE__, __METHOD__, 10);
                                 $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $p_obj->getPunchControlID(), 'punch_obj' => $p_obj, 'schedule_obj' => $p_obj->getScheduleObject());
                             }
                             $prev_punch_time_stamp = $p_obj->getTimeStamp();
                             $prev_punch_obj = $p_obj;
                             $x++;
                         }
                     }
                     unset($prev_punch_obj, $prev_punch_time_stamp, $x);
                     break;
                 case 'd1':
                     //No Branch or Department
                     $add_exception = FALSE;
                     foreach ($plf as $p_obj) {
                         //In punches only
                         if ($p_obj->getStatus() == 10 and is_object($p_obj->getPunchControlObject())) {
                             //If no Tasks are setup, ignore checking them.
                             if ($p_obj->getPunchControlObject()->getBranch() == '' or $p_obj->getPunchControlObject()->getBranch() == 0 or $p_obj->getPunchControlObject()->getBranch() == FALSE) {
                                 $add_exception = TRUE;
                             }
                             if ($p_obj->getPunchControlObject()->getDepartment() == '' or $p_obj->getPunchControlObject()->getDepartment() == 0 or $p_obj->getPunchControlObject()->getDepartment() == FALSE) {
                                 //Make sure at least one task exists before triggering exception.
                                 $dlf = TTNew('DepartmentListFactory');
                                 $dlf->getByCompanyID($user_date_obj->getUserObject()->getCompany(), 1);
                                 //Limit to just 1 record.
                                 if ($dlf->getRecordCount() > 0) {
                                     $add_exception = TRUE;
                                 }
                             }
                             if ($add_exception === TRUE) {
                                 $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId());
                             }
                         }
                     }
                     break;
                 case 's7':
                     //Over Scheduled Hours
                     if ($plf->getRecordCount() > 0) {
                         //FIXME: Assign this exception to the last punch of the day, so it can be related back to a punch branch/department?
                         //This ONLY takes in to account WORKED hours, not paid absence hours.
                         //FIXME: Do we want to trigger this before their last out punch?
                         $schedule_total_time = 0;
                         if ($slf->getRecordCount() > 0) {
                             //Check for schedule policy
                             foreach ($slf as $s_obj) {
                                 Debug::text(' Schedule Total Time: ' . $s_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10);
                                 $schedule_total_time += $s_obj->getTotalTime();
                             }
                             $daily_total_time = 0;
                             if ($schedule_total_time > 0) {
                                 //Get daily total time.
                                 $udtlf = TTnew('UserDateTotalListFactory');
                                 //Take into account auto-deduct/add meal policies, but not paid absences.
                                 //$udtlf->getByUserDateIdAndStatusAndType( $user_date_id, 10, 10 );
                                 $udtlf->getByUserDateId($user_date_id);
                                 if ($udtlf->getRecordCount() > 0) {
                                     foreach ($udtlf as $udt_obj) {
                                         if ($udt_obj->getTimeCategory() == 'worked_time') {
                                             $daily_total_time += $udt_obj->getTotalTime();
                                         }
                                     }
                                 }
                                 Debug::text(' Daily Total Time: ' . $daily_total_time . ' Schedule Total Time: ' . $schedule_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                 if ($daily_total_time > 0 and $daily_total_time > $schedule_total_time + $ep_obj->getGrace()) {
                                     Debug::text(' Worked Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10);
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => FALSE);
                                 } else {
                                     Debug::text(' DID NOT Work Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         } else {
                             Debug::text(' Not Scheduled', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                     break;
                 case 's8':
                     //Under Scheduled Hours
                     if ($plf->getRecordCount() > 0) {
                         //FIXME: Assign this exception to the last punch of the day, so it can be related back to a punch branch/department?
                         //This ONLY takes in to account WORKED hours, not paid absence hours.
                         $schedule_total_time = 0;
                         if ($slf->getRecordCount() > 0) {
                             //Check for schedule policy
                             foreach ($slf as $s_obj) {
                                 Debug::text(' Schedule Total Time: ' . $s_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10);
                                 $schedule_total_time += $s_obj->getTotalTime();
                             }
                             $daily_total_time = 0;
                             if ($schedule_total_time > 0) {
                                 //Get daily total time.
                                 $udtlf = TTnew('UserDateTotalListFactory');
                                 //Take into account auto-deduct/add meal policies
                                 //$udtlf->getByUserDateIdAndStatusAndType( $user_date_id, 10, 10 );
                                 $udtlf->getByUserDateId($user_date_id);
                                 if ($udtlf->getRecordCount() > 0) {
                                     foreach ($udtlf as $udt_obj) {
                                         if ($udt_obj->getTimeCategory() == 'worked_time') {
                                             $daily_total_time += $udt_obj->getTotalTime();
                                         }
                                     }
                                 }
                                 Debug::text(' Daily Total Time: ' . $daily_total_time . ' Schedule Total Time: ' . $schedule_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                 if ($daily_total_time < $schedule_total_time - $ep_obj->getGrace()) {
                                     Debug::text(' Worked Under Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10);
                                     if ($type_id == 5 and $user_date_obj->getDateStamp() < TTDate::getBeginDayEpoch($current_epoch - self::$premature_delay)) {
                                         $type_id = 50;
                                     }
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => FALSE);
                                 } else {
                                     Debug::text(' DID NOT Work Under Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         } else {
                             Debug::text(' Not Scheduled', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                     break;
                 case 'o1':
                     //Over Daily Time.
                     if ($plf->getRecordCount() > 0) {
                         //FIXME: Assign this exception to the last punch of the day, so it can be related back to a punch branch/department?
                         //This ONLY takes in to account WORKED hours, not paid absence hours.
                         //FIXME: Do we want to trigger this before their last out punch?
                         $daily_total_time = 0;
                         //Get daily total time.
                         $udtlf = TTnew('UserDateTotalListFactory');
                         //Take into account auto-deduct/add meal policies
                         //$udtlf->getByUserDateIdAndStatusAndType( $user_date_id, 10, 10 );
                         $udtlf->getByUserDateId($user_date_id);
                         if ($udtlf->getRecordCount() > 0) {
                             foreach ($udtlf as $udt_obj) {
                                 if ($udt_obj->getTimeCategory() == 'worked_time') {
                                     $daily_total_time += $udt_obj->getTotalTime();
                                 }
                             }
                         }
                         Debug::text(' Daily Total Time: ' . $daily_total_time . ' Watch Window: ' . $ep_obj->getWatchWindow() . ' User Date ID: ' . $user_date_id, __FILE__, __LINE__, __METHOD__, 10);
                         if ($daily_total_time > 0 and $daily_total_time > $ep_obj->getWatchWindow()) {
                             Debug::text(' Worked Over Daily Hours', __FILE__, __LINE__, __METHOD__, 10);
                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => FALSE);
                         } else {
                             Debug::text(' DID NOT Work Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                     break;
                 case 'o2':
                     //Over Weekly Time.
                 //Over Weekly Time.
                 case 's9':
                     //Over Weekly Scheduled Time.
                     if ($plf->getRecordCount() > 0) {
                         //FIXME: Assign this exception to the last punch of the day, so it can be related back to a punch branch/department?
                         //Get Pay Period Schedule info
                         //FIXME: Do we want to trigger this before their last out punch?
                         if (is_object($user_date_obj->getPayPeriodObject()) and is_object($user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject())) {
                             $start_week_day_id = $user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject()->getStartWeekDay();
                         } else {
                             $start_week_day_id = 0;
                         }
                         Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10);
                         $weekly_scheduled_total_time = 0;
                         //Currently we only consider committed scheduled shifts. We may need to change this to take into account
                         //recurring scheduled shifts that haven't been committed yet as well.
                         //In either case though we should take into account the entires week worth of scheduled time even if we are only partially through
                         //the week, that way we won't be triggering s9 exceptions on a Wed and a Fri or something, it will only occur on the last days of the week.
                         if (strtolower($ep_obj->getType()) == 's9') {
                             $tmp_slf = TTnew('ScheduleListFactory');
                             $tmp_slf->getByUserIdAndStartDateAndEndDate($user_date_obj->getUser(), TTDate::getBeginWeekEpoch($user_date_obj->getDateStamp(), $start_week_day_id), TTDate::getEndWeekEpoch($user_date_obj->getDateStamp(), $start_week_day_id));
                             if ($tmp_slf->getRecordCount() > 0) {
                                 foreach ($tmp_slf as $s_obj) {
                                     if ($s_obj->getStatus() == 10) {
                                         //Only working shifts.
                                         $weekly_scheduled_total_time += $s_obj->getTotalTime();
                                     }
                                 }
                             }
                             unset($tmp_slf, $s_obj);
                         }
                         //This ONLY takes in to account WORKED hours, not paid absence hours.
                         $weekly_total_time = 0;
                         //Get daily total time.
                         $udtlf = TTnew('UserDateTotalListFactory');
                         $weekly_total_time = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($user_date_obj->getUser(), TTDate::getBeginWeekEpoch($user_date_obj->getDateStamp(), $start_week_day_id), $user_date_obj->getDateStamp());
                         Debug::text(' Weekly Total Time: ' . $weekly_total_time . ' Weekly Scheduled Total Time: ' . $weekly_scheduled_total_time . ' Watch Window: ' . $ep_obj->getWatchWindow() . ' Grace: ' . $ep_obj->getGrace() . ' User Date ID: ' . $user_date_id, __FILE__, __LINE__, __METHOD__, 10);
                         //Don't trigger either of these exceptions unless both the worked and scheduled time is greater than 0. If they aren't scheduled at all
                         //it should trigger a Unscheduled Absence exception instead of a over weekly scheduled time exception.
                         if (strtolower($ep_obj->getType()) == 'o2' and $weekly_total_time > 0 and $weekly_total_time > $ep_obj->getWatchWindow() or strtolower($ep_obj->getType()) == 's9' and $weekly_scheduled_total_time > 0 and $weekly_total_time > 0 and $weekly_total_time > $weekly_scheduled_total_time + $ep_obj->getGrace()) {
                             Debug::text(' Worked Over Weekly Hours', __FILE__, __LINE__, __METHOD__, 10);
                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => FALSE);
                         } else {
                             Debug::text(' DID NOT Work Over Scheduled Hours', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                     break;
                 case 'l1':
                     //Long Lunch
                 //Long Lunch
                 case 'l2':
                     //Short Lunch
                     if ($plf->getRecordCount() > 0) {
                         //Get all lunch punches.
                         $pair = 0;
                         $x = 0;
                         $out_for_lunch = FALSE;
                         foreach ($plf as $p_obj) {
                             if ($p_obj->getStatus() == 20 and $p_obj->getType() == 20) {
                                 $lunch_out_timestamp = $p_obj->getTimeStamp();
                                 $lunch_punch_arr[$pair]['punch_id'] = $p_obj->getId();
                                 $out_for_lunch = TRUE;
                             } elseif ($out_for_lunch == TRUE and $p_obj->getStatus() == 10 and $p_obj->getType() == 20) {
                                 $lunch_punch_arr[$pair][20] = $lunch_out_timestamp;
                                 $lunch_punch_arr[$pair][10] = $p_obj->getTimeStamp();
                                 $out_for_lunch = FALSE;
                                 $pair++;
                                 unset($lunch_out_timestamp);
                             } else {
                                 $out_for_lunch = FALSE;
                             }
                         }
                         if (isset($lunch_punch_arr)) {
                             //Debug::Arr($lunch_punch_arr, 'Lunch Punch Array: ', __FILE__, __LINE__, __METHOD__,10);
                             foreach ($lunch_punch_arr as $pair => $time_stamp_arr) {
                                 if (isset($time_stamp_arr[10]) and isset($time_stamp_arr[20])) {
                                     $lunch_total_time = bcsub($time_stamp_arr[10], $time_stamp_arr[20]);
                                     Debug::text(' Lunch Total Time: ' . $lunch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                     if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                         $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                     }
                                     //Check to see if they have a schedule policy
                                     if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE and is_object($p_obj->getScheduleObject()) == TRUE and is_object($p_obj->getScheduleObject()->getSchedulePolicyObject()) == TRUE) {
                                         $mp_obj = $p_obj->getScheduleObject()->getSchedulePolicyObject()->getMealPolicyObject();
                                     } else {
                                         $mplf = TTnew('MealPolicyListFactory');
                                         $mplf->getByPolicyGroupUserId($user_date_obj->getUserObject()->getId());
                                         if ($mplf->getRecordCount() > 0) {
                                             Debug::text('Found Meal Policy to apply.', __FILE__, __LINE__, __METHOD__, 10);
                                             $mp_obj = $mplf->getCurrent();
                                         }
                                     }
                                     if (isset($mp_obj) and is_object($mp_obj)) {
                                         $meal_policy_lunch_time = $mp_obj->getAmount();
                                         Debug::text('Meal Policy Time: ' . $meal_policy_lunch_time, __FILE__, __LINE__, __METHOD__, 10);
                                         $add_exception = FALSE;
                                         if (strtolower($ep_obj->getType()) == 'l1' and $meal_policy_lunch_time > 0 and $lunch_total_time > 0 and $lunch_total_time > $meal_policy_lunch_time + $ep_obj->getGrace()) {
                                             $add_exception = TRUE;
                                         } elseif (strtolower($ep_obj->getType()) == 'l2' and $meal_policy_lunch_time > 0 and $lunch_total_time > 0 and $lunch_total_time < $meal_policy_lunch_time - $ep_obj->getGrace()) {
                                             $add_exception = TRUE;
                                         }
                                         if ($add_exception == TRUE) {
                                             Debug::text('Adding Exception!', __FILE__, __LINE__, __METHOD__, 10);
                                             if (isset($time_stamp_arr['punch_id'])) {
                                                 $punch_id = $time_stamp_arr['punch_id'];
                                             } else {
                                                 $punch_id = FALSE;
                                             }
                                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $punch_id, 'punch_control_id' => FALSE);
                                             unset($punch_id);
                                         } else {
                                             Debug::text('Not Adding Exception!', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     }
                                 } else {
                                     Debug::text(' Lunch Punches not paired... Skipping!', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         } else {
                             Debug::text(' No Lunch Punches found, or none are paired.', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                     break;
                 case 'l3':
                     //No Lunch
                     if ($plf->getRecordCount() > 0) {
                         //If they are scheduled or not, we can check for a meal policy and base our
                         //decision off that. We don't want a No Lunch exception on a 3hr short shift though.
                         //Also ignore this exception if the lunch is auto-deduct.
                         //**Try to assign this exception to a specific punch control id, so we can do searches based on punch branch.
                         //Find meal policy
                         //Use scheduled meal policy first.
                         $meal_policy_obj = NULL;
                         if ($slf->getRecordCount() > 0) {
                             Debug::text('Schedule Found...', __FILE__, __LINE__, __METHOD__, 10);
                             foreach ($slf as $s_obj) {
                                 if ($s_obj->getSchedulePolicyObject() !== FALSE and $s_obj->getSchedulePolicyObject()->getMealPolicyObject() !== FALSE and $s_obj->getSchedulePolicyObject()->getMealPolicyObject()->getType() != 10) {
                                     Debug::text('Found Schedule Meal Policy... Trigger Time: ' . $s_obj->getSchedulePolicyObject()->getMealPolicyObject()->getTriggerTime(), __FILE__, __LINE__, __METHOD__, 10);
                                     $meal_policy_obj = $s_obj->getSchedulePolicyObject()->getMealPolicyObject();
                                 } else {
                                     Debug::text('Schedule Meal Policy does not exist, or is auto-deduct?', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         } else {
                             Debug::text('No Schedule Found...', __FILE__, __LINE__, __METHOD__, 10);
                             //Check if they have a meal policy, with no schedule.
                             $mplf = TTnew('MealPolicyListFactory');
                             $mplf->getByPolicyGroupUserId($user_date_obj->getUser());
                             if ($mplf->getRecordCount() > 0) {
                                 foreach ($mplf as $mp_obj) {
                                     if ($mp_obj->getType() != 10) {
                                         Debug::text('Found UnScheduled meal Policy... Trigger Time: ' . $mp_obj->getTriggerTime(), __FILE__, __LINE__, __METHOD__, 10);
                                         $meal_policy_obj = $mp_obj;
                                     }
                                 }
                                 unset($mplf, $mp_obj);
                             } else {
                                 //There is no  meal policy or schedule policy with a meal policy assigned to it
                                 //With out this we could still apply No meal exceptions, but they will happen even on
                                 //a 2minute shift.
                                 Debug::text('No Lunch policy, applying No meal exception.', __FILE__, __LINE__, __METHOD__, 10);
                                 $meal_policy_obj = TRUE;
                             }
                         }
                         if (is_object($meal_policy_obj) or $meal_policy_obj === TRUE) {
                             $punch_control_id = FALSE;
                             $daily_total_time = 0;
                             $udtlf = TTnew('UserDateTotalListFactory');
                             $udtlf->getByUserDateIdAndStatus($user_date_id, 20);
                             if ($udtlf->getRecordCount() > 0) {
                                 foreach ($udtlf as $udt_obj) {
                                     $daily_total_time += $udt_obj->getTotalTime();
                                     $punch_control_total_time[$udt_obj->getPunchControlID()] = $udt_obj->getTotalTime();
                                 }
                             }
                             Debug::text('Day Total Time: ' . $daily_total_time, __FILE__, __LINE__, __METHOD__, 10);
                             //Debug::Arr($punch_control_total_time, 'Punch Control Total Time: ', __FILE__, __LINE__, __METHOD__,10);
                             if ($daily_total_time > 0 and ($meal_policy_obj === TRUE or $daily_total_time > $meal_policy_obj->getTriggerTime())) {
                                 //Check for meal punch.
                                 $meal_punch = FALSE;
                                 $tmp_punch_total_time = 0;
                                 $tmp_punch_control_ids = array();
                                 foreach ($plf as $p_obj) {
                                     if ($p_obj->getType() == 20) {
                                         //20 = Lunch
                                         Debug::text('Found meal Punch: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10);
                                         $meal_punch = TRUE;
                                         break;
                                     }
                                     if (isset($punch_control_total_time[$p_obj->getPunchControlID()]) and !isset($tmp_punch_control_ids[$p_obj->getPunchControlID()])) {
                                         $tmp_punch_total_time += $punch_control_total_time[$p_obj->getPunchControlID()];
                                         if ($punch_control_id === FALSE and ($meal_policy_obj === TRUE or $tmp_punch_total_time > $meal_policy_obj->getTriggerTime())) {
                                             Debug::text('Found punch control for exception: ' . $p_obj->getPunchControlID() . ' Total Time: ' . $tmp_punch_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                             $punch_control_id = $p_obj->getPunchControlID();
                                             //Don't meal the loop here, as we have to continue on and check for other meals.
                                         }
                                     }
                                     $tmp_punch_control_ids[$p_obj->getPunchControlID()] = TRUE;
                                 }
                                 unset($tmp_punch_total_time, $tmp_punch_control_ids);
                                 if ($meal_punch == FALSE) {
                                     Debug::text('Triggering No Lunch exception!', __FILE__, __LINE__, __METHOD__, 10);
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $punch_control_id);
                                 }
                             }
                         }
                     }
                     break;
                 case 'b1':
                     //Long Break
                 //Long Break
                 case 'b2':
                     //Short Break
                     if ($plf->getRecordCount() > 0) {
                         //Get all break punches.
                         $pair = 0;
                         $x = 0;
                         $out_for_break = FALSE;
                         foreach ($plf as $p_obj) {
                             if ($p_obj->getStatus() == 20 and $p_obj->getType() == 30) {
                                 $break_out_timestamp = $p_obj->getTimeStamp();
                                 $break_punch_arr[$pair]['punch_id'] = $p_obj->getId();
                                 $out_for_break = TRUE;
                             } elseif ($out_for_break == TRUE and $p_obj->getStatus() == 10 and $p_obj->getType() == 30) {
                                 $break_punch_arr[$pair][20] = $break_out_timestamp;
                                 $break_punch_arr[$pair][10] = $p_obj->getTimeStamp();
                                 $out_for_break = FALSE;
                                 $pair++;
                                 unset($break_out_timestamp);
                             } else {
                                 $out_for_break = FALSE;
                             }
                         }
                         unset($pair);
                         if (isset($break_punch_arr)) {
                             //Debug::Arr($break_punch_arr, 'Break Punch Array: ', __FILE__, __LINE__, __METHOD__,10);
                             foreach ($break_punch_arr as $pair => $time_stamp_arr) {
                                 if (isset($time_stamp_arr[10]) and isset($time_stamp_arr[20])) {
                                     $break_total_time = bcsub($time_stamp_arr[10], $time_stamp_arr[20]);
                                     Debug::text(' Break Total Time: ' . $break_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                     if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                         $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                     }
                                     //Check to see if they have a schedule policy
                                     $bplf = TTnew('BreakPolicyListFactory');
                                     if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE and is_object($p_obj->getScheduleObject()) == TRUE and is_object($p_obj->getScheduleObject()->getSchedulePolicyObject()) == TRUE) {
                                         $break_policy_ids = $p_obj->getScheduleObject()->getSchedulePolicyObject()->getBreakPolicy();
                                         $bplf->getByIdAndCompanyId($break_policy_ids, $user_date_obj->getUserObject()->getCompany());
                                     } else {
                                         $bplf->getByPolicyGroupUserId($user_date_obj->getUser());
                                     }
                                     unset($break_policy_ids);
                                     if ($bplf->getRecordCount() > 0) {
                                         Debug::text('Found Break Policy(ies) to apply: ' . $bplf->getRecordCount() . ' Pair: ' . $pair, __FILE__, __LINE__, __METHOD__, 10);
                                         foreach ($bplf as $bp_obj) {
                                             $bp_objs[] = $bp_obj;
                                         }
                                         unset($bplf, $bp_obj);
                                         if (isset($bp_objs[$pair]) and is_object($bp_objs[$pair])) {
                                             $bp_obj = $bp_objs[$pair];
                                             $break_policy_break_time = $bp_obj->getAmount();
                                             Debug::text('Break Policy Time: ' . $break_policy_break_time . ' ID: ' . $bp_obj->getID(), __FILE__, __LINE__, __METHOD__, 10);
                                             $add_exception = FALSE;
                                             if (strtolower($ep_obj->getType()) == 'b1' and $break_policy_break_time > 0 and $break_total_time > 0 and $break_total_time > $break_policy_break_time + $ep_obj->getGrace()) {
                                                 $add_exception = TRUE;
                                             } elseif (strtolower($ep_obj->getType()) == 'b2' and $break_policy_break_time > 0 and $break_total_time > 0 and $break_total_time < $break_policy_break_time - $ep_obj->getGrace()) {
                                                 $add_exception = TRUE;
                                             }
                                             if ($add_exception == TRUE) {
                                                 Debug::text('Adding Exception! ' . $ep_obj->getType(), __FILE__, __LINE__, __METHOD__, 10);
                                                 if (isset($time_stamp_arr['punch_id'])) {
                                                     $punch_id = $time_stamp_arr['punch_id'];
                                                 } else {
                                                     $punch_id = FALSE;
                                                 }
                                                 $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $punch_id, 'punch_control_id' => FALSE);
                                                 unset($punch_id);
                                             } else {
                                                 Debug::text('Not Adding Exception!', __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                             unset($bp_obj);
                                         }
                                         unset($bp_objs);
                                     }
                                 } else {
                                     Debug::text(' Break Punches not paired... Skipping!', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         } else {
                             Debug::text(' No Break Punches found, or none are paired.', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                     break;
                 case 'b3':
                     //Too Many Breaks
                 //Too Many Breaks
                 case 'b4':
                     //Too Few Breaks
                     if ($plf->getRecordCount() > 0) {
                         //Get all break punches.
                         $pair = 0;
                         $x = 0;
                         $out_for_break = FALSE;
                         foreach ($plf as $p_obj) {
                             if ($p_obj->getStatus() == 20 and $p_obj->getType() == 30) {
                                 $break_out_timestamp = $p_obj->getTimeStamp();
                                 $break_punch_arr[$pair]['punch_id'] = $p_obj->getId();
                                 $out_for_break = TRUE;
                             } elseif ($out_for_break == TRUE and $p_obj->getStatus() == 10 and $p_obj->getType() == 30) {
                                 $break_punch_arr[$pair][20] = $break_out_timestamp;
                                 $break_punch_arr[$pair][10] = $p_obj->getTimeStamp();
                                 $out_for_break = FALSE;
                                 $pair++;
                                 unset($break_out_timestamp);
                             } else {
                                 $out_for_break = FALSE;
                             }
                         }
                         unset($pair);
                         //Get daily total time.
                         $daily_total_time = 0;
                         $udtlf = TTnew('UserDateTotalListFactory');
                         //$udtlf->getByUserDateIdAndStatusAndType( $user_date_id, 10, 10 );
                         $udtlf->getByUserDateId($user_date_id);
                         if ($udtlf->getRecordCount() > 0) {
                             foreach ($udtlf as $udt_obj) {
                                 if ($udt_obj->getTimeCategory() == 'worked_time') {
                                     $daily_total_time += $udt_obj->getTotalTime();
                                 }
                             }
                         }
                         Debug::text(' Daily Total Time: ' . $daily_total_time . ' User Date ID: ' . $user_date_id, __FILE__, __LINE__, __METHOD__, 10);
                         //Make sure we take into account how long they have currently worked, so we don't
                         //say too few breaks for 3hr shift that they employee took one break on.
                         //Trigger this exception if the employee doesn't take a break at all?
                         if (isset($break_punch_arr)) {
                             $total_breaks = count($break_punch_arr);
                             //Debug::Arr($break_punch_arr, 'Break Punch Array: ', __FILE__, __LINE__, __METHOD__,10);
                             foreach ($break_punch_arr as $pair => $time_stamp_arr) {
                                 if (isset($time_stamp_arr[10]) and isset($time_stamp_arr[20])) {
                                     $break_total_time = bcsub($time_stamp_arr[10], $time_stamp_arr[20]);
                                     Debug::text(' Break Total Time: ' . $break_total_time, __FILE__, __LINE__, __METHOD__, 10);
                                     if (!isset($scheduled_id_cache[$p_obj->getID()])) {
                                         $scheduled_id_cache[$p_obj->getID()] = $p_obj->findScheduleID(NULL, $user_date_obj->getUser());
                                     }
                                     //Check to see if they have a schedule policy
                                     $bplf = TTnew('BreakPolicyListFactory');
                                     if ($p_obj->setScheduleID($scheduled_id_cache[$p_obj->getID()]) == TRUE and is_object($p_obj->getScheduleObject()) == TRUE and is_object($p_obj->getScheduleObject()->getSchedulePolicyObject()) == TRUE) {
                                         $break_policy_ids = $p_obj->getScheduleObject()->getSchedulePolicyObject()->getBreakPolicy();
                                         $bplf->getByIdAndCompanyId($break_policy_ids, $user_date_obj->getUserObject()->getCompany());
                                     } else {
                                         //$bplf->getByPolicyGroupUserId( $user_date_obj->getUser() );
                                         $bplf->getByPolicyGroupUserIdAndDayTotalTime($user_date_obj->getUser(), $daily_total_time);
                                     }
                                     unset($break_policy_ids);
                                     $allowed_breaks = $bplf->getRecordCount();
                                     $add_exception = FALSE;
                                     if (strtolower($ep_obj->getType()) == 'b3' and $total_breaks > $allowed_breaks) {
                                         Debug::text(' Too many breaks taken...', __FILE__, __LINE__, __METHOD__, 10);
                                         $add_exception = TRUE;
                                     } elseif (strtolower($ep_obj->getType()) == 'b4' and $total_breaks < $allowed_breaks) {
                                         Debug::text(' Too few breaks taken...', __FILE__, __LINE__, __METHOD__, 10);
                                         $add_exception = TRUE;
                                     } else {
                                         Debug::text(' Proper number of breaks taken...', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                     if ($add_exception == TRUE and (strtolower($ep_obj->getType()) == 'b4' or strtolower($ep_obj->getType()) == 'b3' and $pair > $allowed_breaks - 1)) {
                                         Debug::text('Adding Exception! ' . $ep_obj->getType(), __FILE__, __LINE__, __METHOD__, 10);
                                         if (isset($time_stamp_arr['punch_id']) and strtolower($ep_obj->getType()) == 'b3') {
                                             $punch_id = $time_stamp_arr['punch_id'];
                                         } else {
                                             $punch_id = FALSE;
                                         }
                                         $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $punch_id, 'punch_control_id' => FALSE);
                                         unset($punch_id);
                                     } else {
                                         Debug::text('Not Adding Exception!', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 }
                             }
                         }
                     }
                     break;
                 case 'b5':
                     //No Break
                     if ($plf->getRecordCount() > 0) {
                         //If they are scheduled or not, we can check for a break policy and base our
                         //decision off that. We don't want a No Break exception on a 3hr short shift though.
                         //Also ignore this exception if the break is auto-deduct.
                         //**Try to assign this exception to a specific punch control id, so we can do searches based on punch branch.
                         //Find break policy
                         //Use scheduled break policy first.
                         $break_policy_obj = NULL;
                         if ($slf->getRecordCount() > 0) {
                             Debug::text('Schedule Found...', __FILE__, __LINE__, __METHOD__, 10);
                             foreach ($slf as $s_obj) {
                                 if ($s_obj->getSchedulePolicyObject() !== FALSE) {
                                     $break_policy_ids = $s_obj->getSchedulePolicyObject()->getBreakPolicy();
                                     if (is_array($break_policy_ids)) {
                                         $bplf = TTNew('BreakPolicyListFactory');
                                         $bplf->getByIdAndCompanyId($break_policy_ids, $user_date_obj->getUserObject()->getCompany());
                                         if ($bplf->getRecordCount() > 0) {
                                             foreach ($bplf as $bp_obj) {
                                                 if ($bp_obj->getType() != 10) {
                                                     $break_policy_obj = $bp_obj;
                                                     break;
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 unset($s_obj, $break_policy_ids, $bplf, $bp_obj);
                             }
                         } else {
                             Debug::text('No Schedule Found...', __FILE__, __LINE__, __METHOD__, 10);
                             //Check if they have a break policy, with no schedule.
                             $bplf = TTnew('BreakPolicyListFactory');
                             $bplf->getByPolicyGroupUserId($user_date_obj->getUser());
                             if ($bplf->getRecordCount() > 0) {
                                 Debug::text('Found UnScheduled Break Policy...', __FILE__, __LINE__, __METHOD__, 10);
                                 foreach ($bplf as $bp_obj) {
                                     if ($bp_obj->getType() != 10) {
                                         $break_policy_obj = $bp_obj;
                                         break;
                                     }
                                 }
                                 unset($bplf, $bp_obj);
                             } else {
                                 //There is no  break policy or schedule policy with a break policy assigned to it
                                 //With out this we could still apply No Break exceptions, but they will happen even on
                                 //a 2minute shift.
                                 Debug::text('No break policy, applying No break exception.', __FILE__, __LINE__, __METHOD__, 10);
                                 $break_policy_obj = TRUE;
                             }
                         }
                         if (is_object($break_policy_obj) or $break_policy_obj === TRUE) {
                             $punch_control_id = FALSE;
                             $daily_total_time = 0;
                             $udtlf = TTnew('UserDateTotalListFactory');
                             $udtlf->getByUserDateIdAndStatus($user_date_id, 20);
                             if ($udtlf->getRecordCount() > 0) {
                                 foreach ($udtlf as $udt_obj) {
                                     $daily_total_time += $udt_obj->getTotalTime();
                                     $punch_control_total_time[$udt_obj->getPunchControlID()] = $udt_obj->getTotalTime();
                                 }
                             }
                             Debug::text('Day Total Time: ' . $daily_total_time, __FILE__, __LINE__, __METHOD__, 10);
                             //Debug::Arr($punch_control_total_time, 'Punch Control Total Time: ', __FILE__, __LINE__, __METHOD__,10);
                             if ($daily_total_time > 0 and ($break_policy_obj === TRUE or $daily_total_time > $break_policy_obj->getTriggerTime())) {
                                 //Check for break punch.
                                 $break_punch = FALSE;
                                 $tmp_punch_total_time = 0;
                                 $tmp_punch_control_ids = array();
                                 foreach ($plf as $p_obj) {
                                     if ($p_obj->getType() == 30) {
                                         //30 = Break
                                         Debug::text('Found break Punch: ' . $p_obj->getTimeStamp(), __FILE__, __LINE__, __METHOD__, 10);
                                         $break_punch = TRUE;
                                         break;
                                     }
                                     if (isset($punch_control_total_time[$p_obj->getPunchControlID()]) and !isset($tmp_punch_control_ids[$p_obj->getPunchControlID()])) {
                                         $tmp_punch_total_time += $punch_control_total_time[$p_obj->getPunchControlID()];
                                         if ($punch_control_id === FALSE and ($break_policy_obj === TRUE or $tmp_punch_total_time > $break_policy_obj->getTriggerTime())) {
                                             Debug::text('Found punch control for exception: ' . $p_obj->getPunchControlID(), __FILE__, __LINE__, __METHOD__, 10);
                                             $punch_control_id = $p_obj->getPunchControlID();
                                             //Don't break the loop here, as we have to continue on and check for other breaks.
                                         }
                                     }
                                     $tmp_punch_control_ids[$p_obj->getPunchControlID()] = TRUE;
                                 }
                                 unset($tmp_punch_total_time, $tmp_punch_control_ids);
                                 if ($break_punch == FALSE) {
                                     Debug::text('Triggering No Break exception!', __FILE__, __LINE__, __METHOD__, 10);
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $punch_control_id);
                                 }
                             }
                         }
                     }
                     break;
                 case 'v1':
                     //TimeSheet Not Verified
                     //Get pay period schedule data, determine if timesheet verification is even enabled.
                     if (is_object($user_date_obj->getPayPeriodObject()) and is_object($user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject()) and $user_date_obj->getPayPeriodObject()->getPayPeriodScheduleObject()->getTimeSheetVerifyType() > 10) {
                         Debug::text('Verification enabled... Window Start: ' . TTDate::getDate('DATE+TIME', $user_date_obj->getPayPeriodObject()->getTimeSheetVerifyWindowStartDate()) . ' Grace Time: ' . $ep_obj->getGrace(), __FILE__, __LINE__, __METHOD__, 10);
                         //*Only* trigger this exception on the last day of the pay period, because when the pay period is verified it has to force the last day to be recalculated.
                         //Ignore timesheets without any time, (worked and absence). Or we could use the Watch Window to specify the minimum time required on
                         //a timesheet to trigger this instead?
                         //Make sure we are after the timesheet window start date + the grace period.
                         if ($user_date_obj->getPayPeriodObject()->getStatus() != 50 and $current_epoch >= $user_date_obj->getPayPeriodObject()->getTimeSheetVerifyWindowStartDate() + $ep_obj->getGrace() and TTDate::getBeginDayEpoch($user_date_obj->getDateStamp()) == TTDate::getBeginDayEpoch($user_date_obj->getPayPeriodObject()->getEndDate())) {
                             //Get pay period total time, include worked and paid absence time.
                             $udtlf = TTnew('UserDateTotalListFactory');
                             $total_time = $udtlf->getTimeSumByUserIDAndPayPeriodId($user_date_obj->getUser(), $user_date_obj->getPayPeriodObject()->getID());
                             if ($total_time > 0) {
                                 //Check to see if pay period has been verified or not yet.
                                 $pptsvlf = TTnew('PayPeriodTimeSheetVerifyListFactory');
                                 $pptsvlf->getByPayPeriodIdAndUserId($user_date_obj->getPayPeriodObject()->getId(), $user_date_obj->getUser());
                                 $pay_period_verified = FALSE;
                                 if ($pptsvlf->getRecordCount() > 0) {
                                     $pay_period_verified = $pptsvlf->getCurrent()->getAuthorized();
                                 }
                                 if ($pay_period_verified == FALSE) {
                                     //Always allow for emailing this exception because it can be triggered after a punch is modified and
                                     //any supervisor would need to be notified to verify the timesheet again.
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => FALSE, 'enable_email_notification' => TRUE);
                                 } else {
                                     Debug::text('TimeSheet has already been authorized!', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             } else {
                                 Debug::text('Timesheet does not have any worked or paid absence time...', __FILE__, __LINE__, __METHOD__, 10);
                             }
                             unset($udtlf, $total_time);
                         } else {
                             Debug::text('Not within timesheet verification window, or not after grace time.', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     } else {
                         Debug::text('No Pay Period Schedule or TimeSheet Verificiation disabled...', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     break;
                 case 'j1':
                     //Not Allowed on Job
                     if (getTTProductEdition() >= TT_PRODUCT_CORPORATE and $plf->getRecordCount() > 0) {
                         foreach ($plf as $p_obj) {
                             if ($p_obj->getStatus() == 10) {
                                 //In punches
                                 if (is_object($p_obj->getPunchControlObject()) and $p_obj->getPunchControlObject()->getJob() > 0) {
                                     //Found job punch, check job settings.
                                     $jlf = TTnew('JobListFactory');
                                     $jlf->getById($p_obj->getPunchControlObject()->getJob());
                                     if ($jlf->getRecordCount() > 0) {
                                         $j_obj = $jlf->getCurrent();
                                         if ($j_obj->isAllowedUser($user_date_obj->getUser()) == FALSE) {
                                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $p_obj->getPunchControlId());
                                         } else {
                                             Debug::text('    User allowed on Job!', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     } else {
                                         Debug::text('    Job not found!', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     //Debug::text('    Not a Job Punch...', __FILE__, __LINE__, __METHOD__,10);
                                 }
                             }
                         }
                         unset($j_obj);
                     }
                     break;
                 case 'j2':
                     //Not Allowed on Task
                     if (getTTProductEdition() >= TT_PRODUCT_CORPORATE and $plf->getRecordCount() > 0) {
                         foreach ($plf as $p_obj) {
                             if ($p_obj->getStatus() == 10) {
                                 //In punches
                                 if (is_object($p_obj->getPunchControlObject()) and $p_obj->getPunchControlObject()->getJob() > 0 and $p_obj->getPunchControlObject()->getJobItem() > 0) {
                                     //Found job punch, check job settings.
                                     $jlf = TTnew('JobListFactory');
                                     $jlf->getById($p_obj->getPunchControlObject()->getJob());
                                     if ($jlf->getRecordCount() > 0) {
                                         $j_obj = $jlf->getCurrent();
                                         if ($j_obj->isAllowedItem($p_obj->getPunchControlObject()->getJobItem()) == FALSE) {
                                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $p_obj->getPunchControlId());
                                         } else {
                                             Debug::text('    Job item allowed on job!', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     } else {
                                         Debug::text('    Job not found!', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     //Debug::text('    Not a Job Punch...', __FILE__, __LINE__, __METHOD__,10);
                                 }
                             }
                         }
                         unset($j_obj);
                     }
                     break;
                 case 'j3':
                     //Job already completed
                     if (getTTProductEdition() >= TT_PRODUCT_CORPORATE and $plf->getRecordCount() > 0) {
                         foreach ($plf as $p_obj) {
                             if ($p_obj->getStatus() == 10) {
                                 //In punches
                                 if (is_object($p_obj->getPunchControlObject()) and $p_obj->getPunchControlObject()->getJob() > 0) {
                                     //Found job punch, check job settings.
                                     $jlf = TTnew('JobListFactory');
                                     $jlf->getById($p_obj->getPunchControlObject()->getJob());
                                     if ($jlf->getRecordCount() > 0) {
                                         $j_obj = $jlf->getCurrent();
                                         //Status is completed and the User Date Stamp is greater then the job end date.
                                         //If no end date is set, ignore this.
                                         if ($j_obj->getStatus() == 30 and $j_obj->getEndDate() != FALSE and $user_date_obj->getDateStamp() > $j_obj->getEndDate()) {
                                             $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => FALSE, 'punch_control_id' => $p_obj->getPunchControlId());
                                         } else {
                                             Debug::text('    Job Not Completed!', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     } else {
                                         Debug::text('    Job not found!', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     Debug::text('    Not a Job Punch...', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                             }
                         }
                         unset($j_obj);
                     }
                     break;
                 case 'j4':
                     //No Job or Task
                     if (getTTProductEdition() >= TT_PRODUCT_CORPORATE and $plf->getRecordCount() > 0) {
                         foreach ($plf as $p_obj) {
                             $add_exception = FALSE;
                             //In punches only
                             if ($p_obj->getStatus() == 10 and is_object($p_obj->getPunchControlObject())) {
                                 //If no Tasks are setup, ignore checking them.
                                 if ($p_obj->getPunchControlObject()->getJob() == '' or $p_obj->getPunchControlObject()->getJob() == 0 or $p_obj->getPunchControlObject()->getJob() == FALSE) {
                                     $add_exception = TRUE;
                                 }
                                 if ($p_obj->getPunchControlObject()->getJobItem() == '' or $p_obj->getPunchControlObject()->getJobItem() == 0 or $p_obj->getPunchControlObject()->getJobItem() == FALSE) {
                                     //Make sure at least one task exists before triggering exception.
                                     $jilf = TTNew('JobItemListFactory');
                                     $jilf->getByCompanyID($user_date_obj->getUserObject()->getCompany(), 1);
                                     //Limit to just 1 record.
                                     if ($jilf->getRecordCount() > 0) {
                                         $add_exception = TRUE;
                                     }
                                 }
                                 if ($add_exception === TRUE) {
                                     $current_exceptions[] = array('user_date_id' => $user_date_id, 'exception_policy_id' => $ep_obj->getId(), 'type_id' => $type_id, 'punch_id' => $p_obj->getId(), 'punch_control_id' => $p_obj->getPunchControlId());
                                 }
                             }
                         }
                     }
                     break;
                 default:
                     Debug::text('BAD, should never get here: ', __FILE__, __LINE__, __METHOD__, 10);
                     break;
             }
         }
     }
     unset($ep_obj);
     $exceptions = self::diffExistingAndCurrentExceptions($existing_exceptions, $current_exceptions);
     if (is_array($exceptions)) {
         if (isset($exceptions['create_exceptions']) and is_array($exceptions['create_exceptions']) and count($exceptions['create_exceptions']) > 0) {
             Debug::text('Creating new exceptions... Total: ' . count($exceptions['create_exceptions']), __FILE__, __LINE__, __METHOD__, 10);
             foreach ($exceptions['create_exceptions'] as $tmp_exception) {
                 $ef = TTnew('ExceptionFactory');
                 $ef->setUserDateID($tmp_exception['user_date_id']);
                 $ef->setExceptionPolicyID($tmp_exception['exception_policy_id']);
                 $ef->setType($tmp_exception['type_id']);
                 if (isset($tmp_exception['punch_control_id']) and $tmp_exception['punch_control_id'] != '') {
                     $ef->setPunchControlId($tmp_exception['punch_control_id']);
                 }
                 if (isset($tmp_exception['punch_id']) and $tmp_exception['punch_id'] != '') {
                     $ef->setPunchId($tmp_exception['punch_id']);
                 }
                 $ef->setEnableDemerits(TRUE);
                 if ($ef->isValid()) {
                     $ef->Save(FALSE);
                     //Save exception prior to emailing it, otherwise we can't save audit logs.
                     if ($enable_premature_exceptions == TRUE or isset($tmp_exception['enable_email_notification']) and $tmp_exception['enable_email_notification'] == TRUE) {
                         $eplf = TTnew('ExceptionPolicyListFactory');
                         $eplf->getById($tmp_exception['exception_policy_id']);
                         if ($eplf->getRecordCount() == 1) {
                             $ep_obj = $eplf->getCurrent();
                             $ef->emailException($user_date_obj->getUserObject(), $user_date_obj, isset($tmp_exception['punch_obj']) ? $tmp_exception['punch_obj'] : NULL, isset($tmp_exception['schedule_obj']) ? $tmp_exception['schedule_obj'] : NULL, $ep_obj);
                         }
                     } else {
                         Debug::text('Not emailing new exception: User Date ID: ' . $tmp_exception['user_date_id'] . ' Type ID: ' . $tmp_exception['type_id'] . ' Enable PreMature: ' . (int) $enable_premature_exceptions, __FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
                 unset($ef);
             }
         }
         if (isset($exceptions['delete_exceptions']) and is_array($exceptions['delete_exceptions']) and count($exceptions['delete_exceptions']) > 0) {
             Debug::Text('Deleting no longer valid exceptions... Total: ' . count($exceptions['delete_exceptions']), __FILE__, __LINE__, __METHOD__, 10);
             $ef = TTnew('ExceptionFactory');
             $ef->bulkDelete($exceptions['delete_exceptions']);
         }
     }
     $profiler->stopTimer("ExceptionPolicy::calcExceptions()");
     return TRUE;
 }
Пример #17
0
     if ($cplf->getRecordCount() == 1) {
         //echo "File Name: $file_name<br>\n";
         $cp_obj = $cplf->getCurrent();
         $file_name = $cp_obj->getSignatureFileName();
         Debug::Text('File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10);
         if (file_exists($file_name)) {
             $params['file'] = $file_name;
             $params['ContentType'] = 'image/png';
             $params['ContentDisposition'] = array(HTTP_DOWNLOAD_ATTACHMENT, 'signature.png');
             $params['cache'] = FALSE;
         }
     }
     break;
 case 'invoice_config':
     Debug::Text('Invoice Config...', __FILE__, __LINE__, __METHOD__, 10);
     $icf = TTNew('InvoiceConfigFactory');
     $file_name = $icf->getLogoFileName($current_company->getId());
     Debug::Text('File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10);
     if (file_exists($file_name)) {
         $params['file'] = $file_name;
         $params['cache'] = TRUE;
     }
     break;
 case 'company_logo':
     Debug::Text('Company Logo...', __FILE__, __LINE__, __METHOD__, 10);
     $cf = TTnew('CompanyFactory');
     $file_name = $cf->getLogoFileName($current_company->getId());
     Debug::Text('File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10);
     if ($file_name != '' and file_exists($file_name)) {
         $params['file'] = $file_name;
         $params['ContentType'] = 'image/' . strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
 function Validate()
 {
     if ($this->validate_only == FALSE and $this->getUser() == FALSE and $this->Validator->hasError('user_id') == FALSE) {
         $this->Validator->isTrue('user_id', FALSE, TTi18n::gettext('Invalid Employee'));
     }
     //Only show this error if it wasn't already triggered earlier.
     if ($this->validate_only == FALSE and is_object($this->Validator) and $this->Validator->hasError('pay_stub_entry_name_id') == FALSE and $this->getPayStubEntryNameId() == FALSE) {
         $this->Validator->isTrue('pay_stub_entry_name_id', FALSE, TTi18n::gettext('Invalid Pay Stub Account'));
     }
     if ($this->getType() == 10) {
         //If rate and units are set, and not amount, calculate the amount for us.
         if ($this->getRate() !== NULL and $this->getUnits() !== NULL and $this->getAmount() == NULL) {
             $this->preSave();
         }
         //Make sure rate * units = amount
         if ($this->getAmount() === NULL) {
             Debug::Text('Amount is NULL...', __FILE__, __LINE__, __METHOD__, 10);
             $this->Validator->isTrue('amount', FALSE, TTi18n::gettext('Invalid Amount'));
         }
         //Make sure amount is sane given the rate and units.
         if ($this->getRate() !== NULL and $this->getUnits() !== NULL and $this->getRate() != 0 and $this->getUnits() != 0 and $this->getRate() != '' and $this->getUnits() != '' and Misc::MoneyFormat($this->calcAmount(), FALSE) != Misc::MoneyFormat($this->getAmount(), FALSE)) {
             Debug::text('Validate: Rate: ' . $this->getRate() . ' Units: ' . $this->getUnits() . ' Amount: ' . $this->getAmount() . ' Calc: Amount: ' . $this->calcAmount() . ' Raw: ' . bcmul($this->getRate(), $this->getUnits(), 4), __FILE__, __LINE__, __METHOD__, 10);
             $this->Validator->isTrue('amount', FALSE, TTi18n::gettext('Invalid Amount, calculation is incorrect'));
         }
     } else {
     }
     if ($this->getDeleted() == FALSE) {
         $this->Validator->isTrue('user_id', $this->isUnique(), TTi18n::gettext('Another Pay Stub Amendment already exists for the same employee, account, effective date and amount'));
     }
     //Don't allow these to be deleted in closed pay periods either.
     //Make sure effective date isn't in a CLOSED pay period?
     $pplf = TTNew('PayPeriodListFactory');
     $pplf->getByUserIdAndEndDate($this->getUser(), $this->getEffectiveDate());
     if ($pplf->getRecordCount() == 1) {
         $pp_obj = $pplf->getCurrent();
         //Only check for CLOSED (not locked) pay periods when the
         //status of the PSA is *not* 52 and 55
         if ($pp_obj->getStatus() == 20 and ($this->getStatus() != 52 and $this->getStatus() != 55)) {
             $this->Validator->isTrue('effective_date', FALSE, TTi18n::gettext('Pay Period that this effective date falls within is currently closed'));
         }
     }
     return TRUE;
 }
Пример #19
0
 function getJobItemOptions()
 {
     //Get job_items
     $this->job_item_options = $this->job_item_manual_id_options = array();
     $dlf = TTNew('JobItemListFactory');
     $dlf->getByCompanyId($this->company_id);
     if ($dlf->getRecordCount() > 0) {
         foreach ($dlf as $d_obj) {
             $this->job_item_options[$d_obj->getId()] = $d_obj->getName();
             $this->job_item_manual_id_options[$d_obj->getId()] = $d_obj->getManualId();
         }
     }
     unset($dlf, $d_obj);
     return TRUE;
 }
Пример #20
0
 function getUserObject($user_id)
 {
     $ulf = TTNew('UserListFactory');
     $ulf->getById($user_id);
     if ($ulf->getRecordCount() > 0) {
         return $ulf->getCurrent();
     }
     return FALSE;
 }
 function getLookbackPayStubs($user_id, $pay_period_obj)
 {
     $lookback_dates = $this->getLookbackStartAndEndDates($pay_period_obj);
     $pslf = TTNew('PayStubListFactory');
     $this->lookback_pay_stub_lf = $pslf->getByUserIdAndStartDateAndEndDate($user_id, $lookback_dates['start_date'], $lookback_dates['end_date']);
     if ($this->lookback_pay_stub_lf->getRecordCount() > 0) {
         //Get lookback first pay and last pay period dates.
         $retarr['first_pay_stub_start_date'] = $this->lookback_pay_stub_lf->getCurrent()->getStartDate();
         $retarr['first_pay_stub_end_date'] = $this->lookback_pay_stub_lf->getCurrent()->getEndDate();
         $retarr['first_pay_stub_transaction_date'] = $this->lookback_pay_stub_lf->getCurrent()->getTransactionDate();
         $this->lookback_pay_stub_lf->rs->MoveLast();
         $retarr['last_pay_stub_start_date'] = $this->lookback_pay_stub_lf->getCurrent()->getStartDate();
         $retarr['last_pay_stub_end_date'] = $this->lookback_pay_stub_lf->getCurrent()->getEndDate();
         $retarr['last_pay_stub_transaction_date'] = $this->lookback_pay_stub_lf->getCurrent()->getTransactionDate();
         $retarr['total_pay_stubs'] = $this->lookback_pay_stub_lf->getRecordCount();
         Debug::text('Total Pay Stubs: ' . $retarr['total_pay_stubs'] . ' First Transaction Date: ' . TTDate::getDate('DATE+TIME', $retarr['first_pay_stub_transaction_date']) . ' Last Transaction Date: ' . TTDate::getDate('DATE+TIME', $retarr['last_pay_stub_transaction_date']), __FILE__, __LINE__, __METHOD__, 10);
         $this->lookback_pay_stub_lf->rs->MoveFirst();
     } else {
         $retarr = FALSE;
     }
     return $retarr;
 }
 function _outputPayrollExport($format = NULL)
 {
     $setup_data = $this->getFormConfig();
     Debug::Text('Generating Payroll Export... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     if (isset($setup_data['export_type'])) {
         Debug::Text('Export Type: ' . $setup_data['export_type'], __FILE__, __LINE__, __METHOD__, 10);
     } else {
         Debug::Text('No Export Type defined!', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     Debug::Arr($setup_data, 'Setup Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $rows = $this->data;
     //Debug::Arr($rows, 'PreData: ', __FILE__, __LINE__, __METHOD__,10);
     $file_name = strtolower(trim($setup_data['export_type'])) . '_' . date('Y_m_d') . '.txt';
     $mime_type = 'application/text';
     $data = NULL;
     switch (strtolower(trim($setup_data['export_type']))) {
         case 'adp':
             //ADP export format.
             //File format supports multiple rows per employee (file #) all using the same columns. No need to jump through nasty hoops to fit everything on row.
             $export_column_map = array('company_code' => 'Co Code', 'batch_id' => 'Batch ID', 'temp_dept' => 'Temp Dept', 'employee_number' => 'File #', 'regular_time' => 'Reg Hours', 'overtime' => 'O/T Hours', '3_code' => 'Hours 3 Code', '3_amount' => 'Hours 3 Amount', '4_code' => 'Hours 4 Code', '4_amount' => 'Hours 4 Amount');
             ksort($setup_data['adp']['columns']);
             $setup_data['adp']['columns'] = Misc::trimSortPrefix($setup_data['adp']['columns']);
             foreach ($setup_data['adp']['columns'] as $column_id => $column_data) {
                 $column_name = NULL;
                 if ($column_data['hour_column'] == 'regular_time') {
                     $export_data_map[$column_id] = 'regular_time';
                 } elseif ($column_data['hour_column'] == 'overtime') {
                     $export_data_map[$column_id] = 'overtime';
                 } elseif ($column_data['hour_column'] >= 3) {
                     $export_data_map[$column_id] = $column_data;
                 }
             }
             if (!isset($setup_data['adp']['company_code_value'])) {
                 $setup_data['adp']['company_code_value'] = NULL;
             }
             if (!isset($setup_data['adp']['batch_id_value'])) {
                 $setup_data['adp']['batch_id_value'] = NULL;
             }
             if (!isset($setup_data['adp']['temp_dept_value'])) {
                 $setup_data['adp']['temp_dept_value'] = NULL;
             }
             $company_code_column = Misc::trimSortPrefix($setup_data['adp']['company_code']);
             $batch_id_column = Misc::trimSortPrefix($setup_data['adp']['batch_id']);
             $temp_dept_column = Misc::trimSortPrefix($setup_data['adp']['temp_dept']);
             foreach ($rows as $row) {
                 $static_columns = array('company_code' => isset($row[$company_code_column]) ? $row[$company_code_column] : $setup_data['adp']['company_code_value'], 'batch_id' => isset($row[$batch_id_column]) ? $row[$batch_id_column] : $setup_data['adp']['batch_id_value'], 'temp_dept' => isset($row[$temp_dept_column]) ? $row[$temp_dept_column] : $setup_data['adp']['temp_dept_value'], 'employee_number' => str_pad($row['employee_number'], 6, 0, STR_PAD_LEFT));
                 foreach ($setup_data['adp']['columns'] as $column_id => $column_data) {
                     $column_data = Misc::trimSortPrefix($column_data, TRUE);
                     Debug::Text('ADP Column ID: ' . $column_id . ' Hour Column: ' . $column_data['hour_column'] . ' Code: ' . $column_data['hour_code'], __FILE__, __LINE__, __METHOD__, 10);
                     if (isset($row[$column_id]) and $column_data['hour_column'] != '0') {
                         foreach ($export_column_map as $export_column_id => $export_column_name) {
                             Debug::Arr($row, 'Row: Column ID: ' . $column_id . ' Export Column ID: ' . $export_column_id . ' Name: ' . $export_column_name, __FILE__, __LINE__, __METHOD__, 10);
                             if (($column_data['hour_column'] == $export_column_id or $column_data['hour_column'] . '_code' == $export_column_id) and !in_array($export_column_id, array('company_code', 'batch_id', 'temp_dept', 'employee_number'))) {
                                 if ((int) substr($export_column_id, 0, 1) > 0) {
                                     $tmp_row[$column_data['hour_column'] . '_code'] = $column_data['hour_code'];
                                     $tmp_row[$column_data['hour_column'] . '_amount'] = TTDate::getTimeUnit($row[$column_id], 20);
                                 } else {
                                     $tmp_row[$export_column_id] = TTDate::getTimeUnit($row[$column_id], 20);
                                 }
                                 //Break out every column onto its own row, that way its easier to handle multiple columns of the same type.
                                 $tmp_rows[] = array_merge($static_columns, $tmp_row);
                                 unset($tmp_row);
                             }
                         }
                     }
                 }
             }
             $file_name = 'EPI000000.csv';
             if (isset($tmp_rows)) {
                 //File format supports multiple entries per employee (file #) all using the same columns. No need to jump through nasty hoops to fit everyone one row.
                 $file_name = 'EPI' . $tmp_rows[0]['company_code'] . $tmp_rows[0]['batch_id'] . '.csv';
                 $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE);
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         case 'adp_old':
             //ADP export format.
             $file_name = 'EPI' . $setup_data['adp']['company_code'] . $setup_data['adp']['batch_id'] . '.csv';
             $export_column_map = array();
             $static_export_column_map = array('company_code' => 'Co Code', 'batch_id' => 'Batch ID', 'employee_number' => 'File #');
             $static_export_data_map = array('company_code' => $setup_data['adp']['company_code'], 'batch_id' => $setup_data['adp']['batch_id']);
             //
             //Format allows for multiple duplicate columns.
             //ie: Hours 3 Code, Hours 3 Amount, Hours 3 Code, Hours 3 Amount, ...
             //However, we can only have a SINGLE O/T Hours column.
             //We also need to combine hours with the same code together.
             //
             ksort($setup_data['adp']['columns']);
             $setup_data['adp']['columns'] = Misc::trimSortPrefix($setup_data['adp']['columns']);
             foreach ($setup_data['adp']['columns'] as $column_id => $column_data) {
                 $column_name = NULL;
                 if ($column_data['hour_column'] == 'regular_time') {
                     $column_name = 'Reg Hours';
                     $export_data_map[$column_id] = trim($setup_data['adp']['columns'][$column_id]['hour_code']);
                 } elseif ($column_data['hour_column'] == 'overtime') {
                     $column_name = 'O/T Hours';
                     $export_data_map[$column_id] = trim($setup_data['adp']['columns'][$column_id]['hour_code']);
                 } elseif ($column_data['hour_column'] >= 3) {
                     $column_name = 'Hours ' . $column_data['hour_column'] . ' Amount';
                     $export_column_map[$setup_data['adp']['columns'][$column_id]['hour_code'] . '_code'] = 'Hours ' . $column_data['hour_column'] . ' Code';
                     $export_data_map[$column_id] = trim($setup_data['adp']['columns'][$column_id]['hour_code']);
                 }
                 if ($column_name != '') {
                     $export_column_map[trim($setup_data['adp']['columns'][$column_id]['hour_code'])] = $column_name;
                 }
             }
             $export_column_map = Misc::prependArray($static_export_column_map, $export_column_map);
             //
             //Combine time from all columns with the same hours code.
             //
             $i = 0;
             foreach ($rows as $row) {
                 foreach ($static_export_column_map as $column_id => $column_name) {
                     if (isset($static_export_data_map[$column_id])) {
                         //Copy over static config values like company code/batch_id.
                         $tmp_rows[$i][$column_id] = $static_export_data_map[$column_id];
                     } elseif (isset($row[$column_id])) {
                         if (isset($static_export_column_map[$column_id])) {
                             //Copy over employee_number. (File #)
                             $tmp_rows[$i][$column_id] = $row[$column_id];
                         }
                     }
                 }
                 foreach ($export_data_map as $column_id => $column_name) {
                     if (!isset($tmp_rows[$i][$column_name])) {
                         $tmp_rows[$i][$column_name] = 0;
                     }
                     if (isset($row[$column_id])) {
                         $tmp_rows[$i][$column_name] += $row[$column_id];
                     }
                     $tmp_rows[$i][$column_name . '_code'] = $column_name;
                 }
                 $i++;
             }
             //Convert time from seconds to hours.
             $convert_unit_columns = array_keys($static_export_column_map);
             foreach ($tmp_rows as $row => $data) {
                 foreach ($data as $column_id => $column_data) {
                     //var_dump($column_id,$column_data);
                     if (is_int($column_data) and !in_array($column_id, $convert_unit_columns)) {
                         $tmp_rows[$row][$column_id] = TTDate::getTimeUnit($column_data, 20);
                     }
                 }
             }
             unset($row, $data, $column_id, $column_data);
             $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE);
             break;
         case 'paychex_preview_advanced_job':
             //PayChex Preview with job information
             unset($rows);
             //Ignore any existing timesheet summary data, we will be using our own job data below.
             //Debug::Arr($setup_data, 'PayChex Advanced Job Setup Data: ', __FILE__, __LINE__, __METHOD__,10);
             $config['columns'][] = 'employee_number';
             $config['columns'][] = 'date_stamp';
             $config['columns'] = array_merge($config['columns'], (array) $setup_data['paychex_preview_advanced_job']['job_columns']);
             $config['columns'][] = $setup_data['paychex_preview_advanced_job']['state_columns'];
             $config['columns'] += array_keys(Misc::trimSortPrefix($this->getOptions('dynamic_columns')));
             $config['group'][] = 'employee_number';
             $config['group'][] = 'date_stamp';
             $config['group'] = array_merge($config['columns'], (array) $setup_data['paychex_preview_advanced_job']['job_columns']);
             $config['group'][] = $setup_data['paychex_preview_advanced_job']['state_columns'];
             $config['sort'][] = array('employee_number' => 'asc');
             $config['sort'][] = array('date_stamp' => 'asc');
             //Debug::Arr($config, 'Job Detail Report Config: ', __FILE__, __LINE__, __METHOD__,10);
             //Get job data...
             $jar = TTNew('JobDetailReport');
             $jar->setAMFMessageID($this->getAMFMessageID());
             $jar->setUserObject($this->getUserObject());
             $jar->setPermissionObject($this->getPermissionObject());
             $jar->setConfig($config);
             $jar->setFilterConfig($this->getFilterConfig());
             $jar->setSortConfig($config['sort']);
             $jar->_getData();
             $jar->_preProcess();
             $jar->sort();
             $rows = $jar->data;
             //Debug::Arr($rows, 'Raw Rows: ', __FILE__, __LINE__, __METHOD__,10);
             //Need to get job data from job report instead of TimeSheet Summary report.
             if (!isset($setup_data['paychex_preview_advanced_job']['client_number'])) {
                 $setup_data['paychex_preview_advanced_job']['client_number'] = '0000';
             }
             $file_name = $setup_data['paychex_preview_advanced_job']['client_number'] . '_TA.txt';
             ksort($setup_data['paychex_preview_advanced_job']['columns']);
             $setup_data['paychex_preview_advanced_job']['columns'] = Misc::trimSortPrefix($setup_data['paychex_preview_advanced_job']['columns']);
             $data = NULL;
             foreach ($rows as $row) {
                 foreach ($setup_data['paychex_preview_advanced_job']['columns'] as $column_id => $column_data) {
                     if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                         $data .= str_pad($row['employee_number'], 6, ' ', STR_PAD_LEFT);
                         $data .= str_pad('', 31, ' ', STR_PAD_LEFT);
                         //Blank space.
                         if (isset($setup_data['paychex_preview_advanced_job']['job_columns']) and is_array($setup_data['paychex_preview_advanced_job']['job_columns'])) {
                             $job_column = array();
                             foreach ($setup_data['paychex_preview_advanced_job']['job_columns'] as $tmp_job_column) {
                                 $job_column[] = isset($row[$tmp_job_column]) ? $row[$tmp_job_column] : NULL;
                             }
                             $data .= str_pad(substr(implode('-', $job_column), 0, 12), 12, ' ', STR_PAD_LEFT);
                             unset($job_column);
                         } else {
                             $data .= str_pad('', 12, ' ', STR_PAD_LEFT);
                         }
                         $data .= str_pad('', 1, ' ', STR_PAD_LEFT);
                         //Shift identifier.
                         //Allow user to specify three digit hour codes to specify their own E/D codes. If codes are two digit, always use E.
                         if (strlen(trim($column_data['hour_code'])) < 3) {
                             $column_data['hour_code'] = 'E' . trim($column_data['hour_code']);
                         }
                         //Should start at col51
                         $data .= str_pad(substr(trim($column_data['hour_code']), 0, 3), 3, ' ', STR_PAD_RIGHT);
                         if (isset($setup_data['paychex_preview_advanced_job']['include_hourly_rate']) and $setup_data['paychex_preview_advanced_job']['include_hourly_rate'] == TRUE) {
                             $data .= str_pad(isset($row[$column_id . '_hourly_rate']) ? number_format($row[$column_id . '_hourly_rate'], 4, '.', '') : NULL, 9, 0, STR_PAD_LEFT);
                             //Override rate
                         } else {
                             $data .= str_pad('', 9, 0, STR_PAD_LEFT);
                             //Override rate
                         }
                         $data .= str_pad(TTDate::getTimeUnit($row[$column_id], 20), 8, 0, STR_PAD_LEFT);
                         //Break out time by day.
                         $data .= str_pad(TTDate::getYear($row['time_stamp']), 4, 0, STR_PAD_LEFT);
                         //Year, based on time_stamp epoch column
                         $data .= str_pad(TTDate::getMonth($row['time_stamp']), 2, 0, STR_PAD_LEFT);
                         //Month, based on time_stamp epoch column. Can be space padded.
                         $data .= str_pad(TTDate::getDayOfMonth($row['time_stamp']), 2, 0, STR_PAD_LEFT);
                         //Day, based on time_stamp epoch column. Can be space padded.
                         $data .= str_pad('', 4, ' ', STR_PAD_LEFT);
                         //Filler
                         $data .= str_pad('', 9, ' ', STR_PAD_LEFT);
                         //Amount. This can always be calculated from hours and hourly rate above though.
                         $data .= str_pad('', 13, ' ', STR_PAD_LEFT);
                         //Blank space
                         if (isset($setup_data['paychex_preview_advanced_job']['state_columns'])) {
                             $data .= str_pad(isset($row[$setup_data['paychex_preview_advanced_job']['state_columns']]) ? $row[$setup_data['paychex_preview_advanced_job']['state_columns']] : NULL, 2, ' ', STR_PAD_LEFT);
                             //State
                         }
                         $data .= "\n";
                     }
                 }
             }
             break;
         case 'paychex_preview':
             //Paychex Preview export format.
             //Add an advanced PayChex Preview format that supports rates perhaps?
             //http://kb.idb-sys.com/KnowledgebaseArticle10013.aspx
             if (!isset($setup_data['paychex_preview']['client_number'])) {
                 $setup_data['paychex_preview']['client_number'] = '0000';
             }
             $file_name = $setup_data['paychex_preview']['client_number'] . '_TA.txt';
             ksort($setup_data['paychex_preview']['columns']);
             $setup_data['paychex_preview']['columns'] = Misc::trimSortPrefix($setup_data['paychex_preview']['columns']);
             $data = NULL;
             foreach ($rows as $row) {
                 foreach ($setup_data['paychex_preview']['columns'] as $column_id => $column_data) {
                     if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                         $data .= str_pad($row['employee_number'], 6, ' ', STR_PAD_LEFT);
                         $data .= str_pad('E' . str_pad(trim($column_data['hour_code']), 2, ' ', STR_PAD_RIGHT), 47, ' ', STR_PAD_LEFT);
                         $data .= str_pad(str_pad(TTDate::getTimeUnit($row[$column_id], 20), 8, 0, STR_PAD_LEFT), 17, ' ', STR_PAD_LEFT) . "\n";
                     }
                 }
             }
             break;
         case 'paychex_online':
             //Paychex Online Payroll CSV
             ksort($setup_data['paychex_online']['columns']);
             $setup_data['paychex_online']['columns'] = Misc::trimSortPrefix($setup_data['paychex_online']['columns']);
             $earnings = array();
             //Find all the hours codes
             foreach ($setup_data['paychex_online']['columns'] as $column_id => $column_data) {
                 $hour_code = $column_data['hour_code'];
                 $earnings[] = $hour_code;
             }
             $export_column_map['employee_number'] = '';
             foreach ($earnings as $key => $value) {
                 $export_column_map[$value] = '';
             }
             $i = 0;
             foreach ($rows as $row) {
                 if ($i == 0) {
                     //Include header.
                     $tmp_row['employee_number'] = 'Employee Number';
                     foreach ($earnings as $key => $value) {
                         $tmp_row[$value] = $value . ' Hours';
                     }
                     $tmp_rows[] = $tmp_row;
                     unset($tmp_row);
                 }
                 //Combine all hours from the same code together.
                 foreach ($setup_data['paychex_online']['columns'] as $column_id => $column_data) {
                     $hour_code = trim($column_data['hour_code']);
                     if (isset($row[$column_id]) and $hour_code != '') {
                         if (!isset($tmp_hour_codes[$hour_code])) {
                             $tmp_hour_codes[$hour_code] = 0;
                         }
                         $tmp_hour_codes[$hour_code] = bcadd($tmp_hour_codes[$column_data['hour_code']], $row[$column_id]);
                         //Use seconds for math here.
                     }
                 }
                 if (isset($tmp_hour_codes)) {
                     $tmp_row['employee_number'] = $row['employee_number'];
                     foreach ($tmp_hour_codes as $hour_code => $hours) {
                         $tmp_row[$hour_code] = TTDate::getTimeUnit($hours, 20);
                     }
                     $tmp_rows[] = $tmp_row;
                     unset($tmp_hour_codes, $hour_code, $hours, $tmp_row);
                 }
                 $i++;
             }
             if (isset($tmp_rows)) {
                 $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE, FALSE);
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         case 'millenium':
             //Millenium export format. Also used by Qqest.
             ksort($setup_data['millenium']['columns']);
             $setup_data['millenium']['columns'] = Misc::trimSortPrefix($setup_data['millenium']['columns']);
             $export_column_map = array('employee_number' => '', 'transaction_code' => '', 'hour_code' => '', 'hours' => '');
             foreach ($rows as $row) {
                 foreach ($setup_data['millenium']['columns'] as $column_id => $column_data) {
                     if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                         $tmp_rows[] = array('employee_number' => $row['employee_number'], 'transaction_code' => 'E', 'hour_code' => trim($column_data['hour_code']), 'hours' => TTDate::getTimeUnit($row[$column_id], 20));
                     }
                 }
             }
             if (isset($tmp_rows)) {
                 $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE, FALSE);
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         case 'ceridian_insync':
             //Ceridian InSync export format. Needs to be .IMP to import? DOS line endings?
             if (!isset($setup_data['ceridian_insync']['employer_number']) or $setup_data['ceridian_insync']['employer_number'] == '') {
                 $setup_data['ceridian_insync']['employer_number'] = '0001';
             }
             $file_name = strtolower(trim($setup_data['export_type'])) . '_' . $setup_data['ceridian_insync']['employer_number'] . '_' . date('Y_m_d') . '.imp';
             ksort($setup_data['ceridian_insync']['columns']);
             $setup_data['ceridian_insync']['columns'] = Misc::trimSortPrefix($setup_data['ceridian_insync']['columns']);
             $export_column_map = array('employer_number' => '', 'import_type_id' => '', 'employee_number' => '', 'check_type' => '', 'hour_code' => '', 'value' => '', 'distribution' => '', 'rate' => '', 'premium' => '', 'day' => '', 'pay_period' => '');
             foreach ($rows as $row) {
                 foreach ($setup_data['ceridian_insync']['columns'] as $column_id => $column_data) {
                     if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                         $tmp_rows[] = array('employer_number' => $setup_data['ceridian_insync']['employer_number'], 'import_type_id' => 'COSTING', 'employee_number' => str_pad($row['employee_number'], 9, '0', STR_PAD_LEFT), 'check_type' => 'REG', 'hour_code' => trim($column_data['hour_code']), 'value' => TTDate::getTimeUnit($row[$column_id], 20), 'distribution' => NULL, 'rate' => NULL, 'premium' => NULL, 'day' => NULL, 'pay_period' => NULL);
                     }
                 }
             }
             if (isset($tmp_rows)) {
                 $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE, FALSE, "\r\n");
                 //Use DOS line endings only.
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         case 'quickbooks':
             //Quickbooks Pro export format.
         //Quickbooks Pro export format.
         case 'quickbooks_advanced':
             //Quickbooks Pro export format.
             $file_name = 'payroll_export.iif';
             ksort($setup_data['quickbooks']['columns']);
             $setup_data['quickbooks']['columns'] = Misc::trimSortPrefix($setup_data['quickbooks']['columns']);
             //
             // Quickbooks header
             //
             /*
             	Company Create Time can be found by first running an Timer Activity export in QuickBooks and viewing the output.
             
             	PITEM field needs to be populated, as that is the PAYROLL ITEM in quickbooks. It can be the same as the ITEM field.
             	ITEM is the service item, can be mapped to department/task?
             	PROJ could be mapped to the default department/branch?
             */
             $data = "!TIMERHDR\tVER\tREL\tCOMPANYNAME\tIMPORTEDBEFORE\tFROMTIMER\tCOMPANYCREATETIME\n";
             $data .= "TIMERHDR\t8\t0\t" . trim($setup_data['quickbooks']['company_name']) . "\tN\tY\t" . trim($setup_data['quickbooks']['company_created_date']) . "\n";
             $data .= "!TIMEACT\tDATE\tJOB\tEMP\tITEM\tPITEM\tDURATION\tPROJ\tNOTE\tXFERTOPAYROLL\tBILLINGSTATUS\n";
             foreach ($rows as $row) {
                 foreach ($setup_data['quickbooks']['columns'] as $column_id => $column_data) {
                     if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                         //Make sure employee name is in format: LastName, FirstName MiddleInitial
                         $tmp_employee_name = $row['last_name'] . ', ' . $row['first_name'];
                         if (isset($row['middle_name']) and strlen($row['middle_name']) > 0) {
                             $tmp_employee_name .= ' ' . substr(trim($row['middle_name']), 0, 1);
                         }
                         $proj = NULL;
                         if (isset($row[$setup_data['quickbooks']['proj']])) {
                             $proj = $row[$setup_data['quickbooks']['proj']];
                         }
                         $item = NULL;
                         if (isset($row[$setup_data['quickbooks']['item']])) {
                             $item = $row[$setup_data['quickbooks']['item']];
                         }
                         $job = NULL;
                         if (isset($row[$setup_data['quickbooks']['job']])) {
                             $job = $row[$setup_data['quickbooks']['job']];
                         }
                         $data .= "TIMEACT\t" . date('n/j/y', $row['pay_period_end_date']) . "\t" . $job . "\t" . $tmp_employee_name . "\t" . $item . "\t" . trim($column_data['hour_code']) . "\t" . TTDate::getTimeUnit($row[$column_id], 10) . "\t" . $proj . "\t\tY\t0\n";
                         unset($tmp_employee_name);
                     }
                 }
             }
             break;
         case 'surepayroll':
             //SurePayroll Export format.
             ksort($setup_data['surepayroll']['columns']);
             $setup_data['surepayroll']['columns'] = Misc::trimSortPrefix($setup_data['surepayroll']['columns']);
             //
             //header
             //
             $data = 'TC' . "\n";
             $data .= '00001' . "\n";
             $export_column_map = array('pay_period_end_date' => 'Entry Date', 'employee_number' => 'Employee Number', 'last_name' => 'Last Name', 'first_name' => 'First Name', 'hour_code' => 'Payroll Code', 'value' => 'Hours');
             foreach ($rows as $row) {
                 foreach ($setup_data['surepayroll']['columns'] as $column_id => $column_data) {
                     if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                         //Debug::Arr($column_data,'Output2', __FILE__, __LINE__, __METHOD__,10);
                         $tmp_rows[] = array('pay_period_end_date' => date('m/d/Y', $row['pay_period_end_date']), 'employee_number' => $row['employee_number'], 'last_name' => $row['last_name'], 'first_name' => $row['first_name'], 'hour_code' => trim($column_data['hour_code']), 'value' => TTDate::getTimeUnit($row[$column_id], 20));
                     }
                 }
             }
             if (isset($tmp_rows)) {
                 $data .= Misc::Array2CSV($tmp_rows, $export_column_map, FALSE, FALSE);
                 $data = str_replace('"', '', $data);
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         case 'chris21':
             //Chris21 Export format.
             //Columns required: Employee_number (2), Date (10), ADJUSTMENT_CODE (12), HOURS (13), SIGNED_HOURS(15)[?]
             //Use SIGNED_HOURS only, as it provides more space?
             //When using absences a leave start/end date must be specified other it won't be imported.
             ksort($setup_data['chris21']['columns']);
             $setup_data['chris21']['columns'] = Misc::trimSortPrefix($setup_data['chris21']['columns']);
             $data = '';
             foreach ($rows as $row) {
                 foreach ($setup_data['chris21']['columns'] as $column_id => $column_data) {
                     if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                         //Debug::Arr($column_data,'Output2: ID: '. $column_id, __FILE__, __LINE__, __METHOD__,10);
                         $data .= str_repeat(' ', 8);
                         //8 digits Blank
                         $data .= str_pad(substr($row['employee_number'], 0, 7), 7, ' ', STR_PAD_RIGHT);
                         //7 digits
                         $data .= str_repeat(' ', 11);
                         //14 digits Blank
                         $data .= date('dmy', $row['pay_period_end_date']);
                         //4 digits Date
                         $data .= str_repeat(' ', 4);
                         //4 digits Blank
                         $data .= str_pad(substr(trim($column_data['hour_code']), 0, 4), 4, ' ', STR_PAD_RIGHT);
                         //4 digits
                         $data .= '0000';
                         //4 digits HOURS field, always be 0, use SIGNED_HOURS instead.
                         $data .= str_repeat(' ', 4);
                         //CC_CODE: 4 digits Blank
                         $data .= str_pad(str_replace('.', '', TTDate::getTimeUnit($row[$column_id], 20)), 6, 0, STR_PAD_LEFT) . '+';
                         //SIGNED_HOURS: Hours without decimal padded to 6 digits, with '+' on the end.
                         //$data .= '+000000000'; 																	//Filler: Redefintion of SIGNED_HOURS.
                         $data .= '000000000';
                         //RATE: 9 chars
                         $data .= str_repeat(' ', 20);
                         //ACCT_NO: 20 chars
                         $data .= str_repeat(' ', 16);
                         //JOB_NUMBER: 16 chars
                         if (strpos($column_id, 'absence') !== FALSE) {
                             //Absence column, include LEAVE dates.
                             $data .= date('dmy', $row['pay_period_end_date']);
                             //LEAVE Start Date: 6 digits
                             $data .= date('dmy', $row['pay_period_end_date']);
                             //LEAVE End Date: 6 digits
                         }
                         $data .= "\n";
                     }
                 }
             }
             unset($tmp_rows, $column_id, $column_data, $rows, $row);
             break;
         case 'csv':
             //Generic CSV.
             $file_name = strtolower(trim($setup_data['export_type'])) . '_' . date('Y_m_d') . '.csv';
             //If this needs to be customized, they can just export any regular report. This could probably be removed completely except for the Hour Code mapping...
             ksort($setup_data['csv']['columns']);
             $setup_data['csv']['columns'] = Misc::trimSortPrefix($setup_data['csv']['columns']);
             $export_column_map = array('employee' => '', 'employee_number' => '', 'default_branch' => '', 'default_department' => '', 'pay_period' => '', 'branch_name' => '', 'department_name' => '', 'hour_code' => '', 'hours' => '');
             $i = 0;
             foreach ($rows as $row) {
                 if ($i == 0) {
                     //Include header.
                     $tmp_rows[] = array('employee' => 'Employee', 'employee_number' => 'Employee Number', 'default_branch' => 'Default Branch', 'default_department' => 'Default Department', 'pay_period' => 'Pay Period', 'branch_name' => 'Branch', 'department_name' => 'Department', 'hour_code' => 'Hours Code', 'hours' => 'Hours');
                 }
                 //Combine all hours from the same code together.
                 foreach ($setup_data['csv']['columns'] as $column_id => $column_data) {
                     $hour_code = trim($column_data['hour_code']);
                     if (isset($row[$column_id]) and $hour_code != '') {
                         if (!isset($tmp_hour_codes[$hour_code])) {
                             $tmp_hour_codes[$hour_code] = 0;
                         }
                         $tmp_hour_codes[$hour_code] = bcadd($tmp_hour_codes[$column_data['hour_code']], $row[$column_id]);
                         //Use seconds for math here.
                     }
                 }
                 if (isset($tmp_hour_codes)) {
                     foreach ($tmp_hour_codes as $hour_code => $hours) {
                         $tmp_rows[] = array('employee' => isset($row['full_name']) ? $row['full_name'] : NULL, 'employee_number' => isset($row['employee_number']) ? $row['employee_number'] : NULL, 'default_branch' => isset($row['default_branch']) ? $row['default_branch'] : NULL, 'default_department' => isset($row['default_department']) ? $row['default_department'] : NULL, 'pay_period' => isset($row['pay_period']['display']) ? $row['pay_period']['display'] : NULL, 'branch_name' => isset($row['branch_name']) ? $row['branch_name'] : NULL, 'department_name' => isset($row['department_name']) ? $row['department_name'] : NULL, 'hour_code' => $hour_code, 'hours' => TTDate::getTimeUnit($hours, 20));
                     }
                     unset($tmp_hour_codes, $hour_code, $hours);
                 }
                 $i++;
             }
             if (isset($tmp_rows)) {
                 $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE, FALSE);
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         case 'csv_advanced':
             //Generic CSV.
             unset($rows);
             //Ignore any existing timesheet summary data, we will be using our own job data below.
             //If this needs to be customized, they can just export any regular report. This could probably be removed completely except for the Hour Code mapping...
             if (!isset($setup_data['csv_advanced']['export_columns']) or isset($setup_data['csv_advanced']['export_columns']) and !is_array($setup_data['csv_advanced']['export_columns'])) {
                 $setup_data['csv_advanced']['export_columns'] = array('full_name', 'employee_number', 'default_branch', 'default_department', 'pay_period', 'date_stamp');
             }
             if (isset($setup_data['csv_advanced']['export_columns']) and is_array($setup_data['csv_advanced']['export_columns'])) {
                 //Debug::Arr($setup_data['csv_advanced']['export_columns'], 'Custom Columns defined: ', __FILE__, __LINE__, __METHOD__,10);
                 $config['columns'] = $config['group'] = $setup_data['csv_advanced']['export_columns'];
                 //Force sorting...
                 foreach ($setup_data['csv_advanced']['export_columns'] as $export_column) {
                     $config['sort'][] = array($export_column => 'asc');
                 }
                 $config['columns'] += array_keys(Misc::trimSortPrefix($this->getOptions('dynamic_columns')));
             }
             Debug::Arr($config, 'Job Detail Report Config: ', __FILE__, __LINE__, __METHOD__, 10);
             //Get job data...
             if (is_object($this->getUserObject()) and is_object($this->getUserObject()->getCompanyObject()) and $this->getUserObject()->getCompanyObject()->getProductEdition() >= TT_PRODUCT_CORPORATE) {
                 Debug::Text('Using Job Detail Report...', __FILE__, __LINE__, __METHOD__, 10);
                 $jar = TTNew('JobDetailReport');
             } else {
                 Debug::Text('Using TimeSheet Detail Report...', __FILE__, __LINE__, __METHOD__, 10);
                 $jar = TTNew('TimesheetDetailReport');
             }
             $jar->setAMFMessageID($this->getAMFMessageID());
             $jar->setUserObject($this->getUserObject());
             $jar->setPermissionObject($this->getPermissionObject());
             $jar->setConfig($config);
             $jar->setFilterConfig($this->getFilterConfig());
             $jar->setSortConfig($config['sort']);
             $jar->_getData();
             $jar->_preProcess();
             $jar->group();
             $jar->sort();
             $columns = Misc::trimSortPrefix($jar->getOptions('columns'));
             $rows = $jar->data;
             //Debug::Arr($rows, 'Raw Rows: ', __FILE__, __LINE__, __METHOD__,10);
             $file_name = strtolower(trim($setup_data['export_type'])) . '_' . date('Y_m_d') . '.csv';
             //If this needs to be customized, they can just export any regular report. This could probably be removed completely except for the Hour Code mapping...
             ksort($setup_data['csv_advanced']['columns']);
             $setup_data['csv_advanced']['columns'] = Misc::trimSortPrefix($setup_data['csv_advanced']['columns']);
             foreach ($setup_data['csv_advanced']['export_columns'] as $export_column) {
                 $export_column_map[$export_column] = '';
             }
             $export_column_map['hour_code'] = '';
             $export_column_map['hours'] = '';
             $i = 0;
             foreach ($rows as $row) {
                 if ($i == 0) {
                     //Include header.
                     foreach ($setup_data['csv_advanced']['export_columns'] as $export_column) {
                         Debug::Text('Header Row: ' . $export_column, __FILE__, __LINE__, __METHOD__, 10);
                         $tmp_rows[$i][$export_column] = isset($columns[$export_column]) ? $columns[$export_column] : NULL;
                     }
                     $tmp_rows[$i]['hour_code'] = 'Hours Code';
                     $tmp_rows[$i]['hours'] = 'Hours';
                     $i++;
                 }
                 //Combine all hours from the same code together.
                 foreach ($setup_data['csv_advanced']['columns'] as $column_id => $column_data) {
                     $hour_code = trim($column_data['hour_code']);
                     if (isset($row[$column_id]) and $hour_code != '') {
                         if (!isset($tmp_hour_codes[$hour_code])) {
                             $tmp_hour_codes[$hour_code] = 0;
                         }
                         $tmp_hour_codes[$hour_code] = bcadd($tmp_hour_codes[$column_data['hour_code']], $row[$column_id]);
                         //Use seconds for math here.
                     }
                 }
                 if (isset($tmp_hour_codes)) {
                     foreach ($tmp_hour_codes as $hour_code => $hours) {
                         foreach ($setup_data['csv_advanced']['export_columns'] as $export_column) {
                             $tmp_rows[$i][$export_column] = isset($row[$export_column]) ? isset($row[$export_column]['display']) ? $row[$export_column]['display'] : $row[$export_column] : NULL;
                             $tmp_rows[$i]['hour_code'] = $hour_code;
                             $tmp_rows[$i]['hours'] = TTDate::getTimeUnit($hours, 20);
                         }
                     }
                     unset($tmp_hour_codes, $hour_code, $hours);
                 }
                 $i++;
             }
             //Debug::Arr($tmp_rows, 'Tmp Rows: ', __FILE__, __LINE__, __METHOD__,10);
             if (isset($tmp_rows)) {
                 $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE, FALSE);
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         default:
             //Send raw data so plugin can capture it and change it if needed.
             $data = $this->data;
             break;
     }
     //Debug::Arr($data, 'Export Data: ', __FILE__, __LINE__, __METHOD__,10);
     return array('file_name' => $file_name, 'mime_type' => $mime_type, 'data' => $data);
 }
 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;
 }
Пример #24
0
 function UserDefaults()
 {
     if (is_object($this->getCompanyObject())) {
         //User Default settings, always do this last.
         if (is_object($this->getCompanyObject()->getUserDefaultObject())) {
             $udf = $this->getCompanyObject()->getUserDefaultObject();
         } else {
             $udf = TTnew('UserDefaultFactory');
         }
         $udf->setCompany($this->getCompanyObject()->getID());
         $udf->setCity($this->getCompanyObject()->getCity());
         $udf->setCountry($this->getCompanyObject()->getCountry());
         $udf->setProvince($this->getCompanyObject()->getProvince());
         $udf->setWorkPhone($this->getCompanyObject()->getWorkPhone());
         $udf->setLanguage('en');
         $udf->setItemsPerPage(50);
         //Get currently logged in user preferences and create defaults from those.
         if (is_object($this->getUserObject()) and is_object($this->getUserObject()->getUserPreferenceObject())) {
             $udf->setDateFormat($this->getUserObject()->getUserPreferenceObject()->getDateFormat());
             $udf->setTimeFormat($this->getUserObject()->getUserPreferenceObject()->getTimeFormat());
             $udf->setTimeUnitFormat($this->getUserObject()->getUserPreferenceObject()->getTimeUnitFormat());
             $udf->setStartWeekDay($this->getUserObject()->getUserPreferenceObject()->getStartWeekDay());
         } else {
             $udf->setDateFormat('d-M-y');
             $udf->setTimeFormat('g:i A');
             $udf->setTimeUnitFormat(10);
             $udf->setStartWeekDay(0);
         }
         //Get Pay Period Schedule
         $ppslf = TTNew('PayPeriodScheduleListFactory');
         $ppslf->getByCompanyId($this->getCompanyObject()->getID());
         if ($ppslf->getRecordCount() > 0) {
             $udf->setPayPeriodSchedule($ppslf->getCurrent()->getID());
         }
         //Get Policy Group
         $pglf = TTNew('PolicyGroupListFactory');
         $pglf->getByCompanyId($this->getCompanyObject()->getID());
         if ($pglf->getRecordCount() > 0) {
             $udf->setPolicyGroup($pglf->getCurrent()->getID());
         }
         //Permissions
         $pclf = TTnew('PermissionControlListFactory');
         $pclf->getByCompanyIdAndLevel($this->getCompanyObject()->getID(), 1);
         if ($pclf->getRecordCount() > 0) {
             $udf->setPermissionControl($pclf->getCurrent()->getID());
         }
         //Currency
         $clf = TTNew('CurrencyListFactory');
         $clf->getByCompanyIdAndDefault($this->getCompany(), TRUE);
         if ($clf->getRecordCount() > 0) {
             $udf->setCurrency($clf->getCurrent()->getID());
         }
         $upf = TTnew('UserPreferenceFactory');
         $udf->setTimeZone($upf->getLocationTimeZone($this->getCompanyObject()->getCountry(), $this->getCompanyObject()->getProvince(), $this->getCompanyObject()->getWorkPhone()));
         Debug::text('Time Zone: ' . $udf->getTimeZone(), __FILE__, __LINE__, __METHOD__, 9);
         $udf->setEnableEmailNotificationException(TRUE);
         $udf->setEnableEmailNotificationMessage(TRUE);
         $udf->setEnableEmailNotificationHome(TRUE);
         if ($udf->isValid()) {
             Debug::text('Adding User Default settings...', __FILE__, __LINE__, __METHOD__, 9);
             return $udf->Save();
         }
     }
     return FALSE;
 }
Пример #25
0
 function filterPresetPermissions($preset, $filter_sections = FALSE, $filter_permissions = FALSE)
 {
     $pf = TTNew('PermissionFactory');
     return $this->returnHandler($pf->filterPresetPermissions($preset, $filter_sections, $filter_permissions));
 }
Пример #26
0
 function testTimeBasedPartialPremiumPolicyF3()
 {
     global $dd;
     TTDate::setTimeZone('PST8PDT');
     $policy_ids['premium'][] = $this->createPremiumPolicy($this->company_id, 125);
     //Create Policy Group
     $dd->createPolicyGroup($this->company_id, NULL, NULL, NULL, NULL, $policy_ids['premium'], NULL, array($this->user_id));
     $date_epoch = $this->pay_period_objs[0]->getStartDate() + 86400 * 6;
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     //Test punching in before the premium start time, and out after the premium end time.
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 5: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'], 15 * 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'], 15 * 3600);
     //Premium Time1
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 40);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 12 * 3600);
     //Make sure no other hours
     $this->assertEquals(count($udt_arr[$date_epoch]), 3);
     $udlf = TTNew('UserDateListFactory');
     $udlf->getByID($udt_arr[$date_epoch][0]['user_date_id']);
     unset($udt_arr);
     $user_date_id = $udlf->getCurrent()->getId();
     TTDate::setTimeZone('EST5EDT');
     $recalc_result = UserDateTotalFactory::reCalculateDay($user_date_id, TRUE);
     TTDate::setTimeZone('PST8PDT');
     $date_epoch = $this->pay_period_objs[0]->getStartDate() + 86400 * 6;
     $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'], 15 * 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'], 15 * 3600);
     //Premium Time1
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 40);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 12 * 3600);
     //Make sure no other hours
     $this->assertEquals(count($udt_arr[$date_epoch]), 3);
     return TRUE;
 }
Пример #27
0
 function getPayPeriodScheduleOptions()
 {
     //Get job titles
     $ppslf = TTNew('PayPeriodScheduleListFactory');
     $ppslf->getByCompanyId($this->company_id);
     $this->pay_period_schedule_options = (array) $ppslf->getArrayByListFactory($ppslf, FALSE, TRUE);
     unset($ppslf);
     return TRUE;
 }
 function forceClosePreviousPayPeriods($date = NULL)
 {
     if ($date == '') {
         $date = time();
     }
     //Start with 7 days initially, then cut back to 5 days eventually.
     $date = $date - 86400 * 5;
     //Give a 5 days grace period after the transaction date to start with.
     $pplf = TTNew('PayPeriodListFactory');
     $pplf->getByCompanyIDAndPayPeriodScheduleIdAndStatusAndStartTransactionDateAndEndTransactionDate($this->getCompany(), $this->getID(), 10, 1, $date);
     Debug::text('Closing Pay Periods: ' . $pplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($pplf->getRecordCount() > 0) {
         foreach ($pplf as $pp_obj) {
             if (is_object($pp_obj->getPayPeriodScheduleObject()) and $pp_obj->getPayPeriodScheduleObject()->getCreatedDate() < $date - 86400 * 45) {
                 Debug::text('Closing Pay Period ID: ' . $pp_obj->getID(), __FILE__, __LINE__, __METHOD__, 10);
                 $pp_obj->setStatus(20);
                 //Closed
                 if ($pp_obj->isValid()) {
                     //Make log entry as person who last updated the pay period schedule so they can see it in the audit log at least.
                     TTLog::addEntry($pp_obj->getId(), 500, TTi18n::getText('Force closing pay period') . ': ' . TTDate::getDate('DATE', $pp_obj->getStartDate()) . ' -> ' . TTDate::getDate('DATE', $pp_obj->getEndDate()), $pp_obj->getPayPeriodScheduleObject()->getUpdatedBy(), $pp_obj->getTable());
                     $pp_obj->Save();
                 }
             }
         }
     }
     return TRUE;
 }
Пример #29
0
 /**
  * Check if username is unique or not.
  * @param string $user_name user name
  * @return bool
  */
 function isUniqueUserName($user_name)
 {
     Debug::Text('Checking for unique user name: ' . $user_name, __FILE__, __LINE__, __METHOD__, 10);
     $uf = TTNew('UserFactory');
     $retval = $uf->isUniqueUserName($user_name);
     return $this->returnHandler($retval);
 }
Пример #30
0
 function getUserIdentificationColumns()
 {
     $uf = TTNew('UserFactory');
     $retval = Misc::arrayIntersectByKey(array('user_name', 'employee_number', 'sin'), Misc::trimSortPrefix($uf->getOptions('columns')));
     return $retval;
 }