function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //New Pay Period Schedule format, update any current schedules.
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     Debug::text('Found Pay Period Schedules: ' . $ppslf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 9);
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             if ($pps_obj->getType() == 10 or $pps_obj->getType() == 20) {
                 $pps_obj->setStartDayOfWeek(TTDate::getDayOfWeek(TTDate::strtotime($pps_obj->getColumn('anchor_date'))));
                 $pps_obj->setTransactionDate(floor((TTDate::strtotime($pps_obj->getColumn('primary_transaction_date')) - TTDate::strtotime($pps_obj->getColumn('primary_date'))) / 86400) + 1);
             } elseif ($pps_obj->getType() == 30) {
                 $pps_obj->setPrimaryDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('anchor_date'))) + 1);
                 if ($pps_obj->getColumn('primary_transaction_date_ldom') == 1) {
                     $pps_obj->setPrimaryTransactionDayOfMonth(-1);
                 } else {
                     $pps_obj->setPrimaryTransactionDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('primary_transaction_date'))));
                 }
                 $pps_obj->setSecondaryDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('primary_date'))));
                 if ($pps_obj->getColumn('secondary_transaction_date_ldom') == 1) {
                     $pps_obj->setSecondaryTransactionDayOfMonth(-1);
                 } else {
                     $pps_obj->setSecondaryTransactionDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('secondary_transaction_date'))));
                 }
             } elseif ($pps_obj->getType() == 50) {
                 $pps_obj->setPrimaryDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('anchor_date'))));
                 if ($pps_obj->getColumn('primary_transaction_date_ldom') == 1) {
                     $pps_obj->setPrimaryTransactionDayOfMonth(-1);
                 } else {
                     $pps_obj->setPrimaryTransactionDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('primary_transaction_date'))));
                 }
             }
             if ($pps_obj->getColumn('transaction_date_bd') == 1 or $pps_obj->getColumn('secondary_transaction_date_bd') == 1) {
                 $pps_obj->setTransactionDateBusinessDay(TRUE);
             }
             if ($pps_obj->isValid()) {
                 $pps_obj->Save();
             }
         }
     }
     return TRUE;
 }
 function getPayPeriodMaximumShiftTime($user_id, $maximum_shift_time = NULL)
 {
     if (!is_numeric($maximum_shift_time)) {
         //Get pay period start/maximum shift time
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($user_id);
         if ($ppslf->getRecordCount() == 1) {
             $pps_obj = $ppslf->getCurrent();
             $maximum_shift_time = $pps_obj->getMaximumShiftTime();
             //Debug::Text(' aPay Period Schedule Maximum Shift Time: '. $maximum_shift_time, __FILE__, __LINE__, __METHOD__,10);
         } else {
             //Debug::Text(' bPay Period Schedule Not Found! Using 4hrs as default', __FILE__, __LINE__, __METHOD__,10);
             $maximum_shift_time = 3600 * 16;
         }
     }
     Debug::Text(' cPay Period Schedule Maximum Shift Time: ' . $maximum_shift_time, __FILE__, __LINE__, __METHOD__, 10);
     return $maximum_shift_time;
 }
 function postInstall()
 {
     global $cache;
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Get all pay period schedules.
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             $user_ids = $pps_obj->getUser();
             if (is_array($user_ids)) {
                 $time_zone_arr = array();
                 foreach ($user_ids as $user_id) {
                     $uplf = new UserPreferenceListFactory();
                     $uplf->getByUserId($user_id);
                     if ($uplf->getRecordCount() > 0) {
                         if (isset($time_zone_arr[$uplf->getCurrent()->getTimeZone()])) {
                             $time_zone_arr[$uplf->getCurrent()->getTimeZone()]++;
                         } else {
                             $time_zone_arr[$uplf->getCurrent()->getTimeZone()] = 1;
                         }
                     }
                 }
                 arsort($time_zone_arr);
                 //Grab the first time zone, as it is most common
                 foreach ($time_zone_arr as $time_zone => $count) {
                     break;
                 }
                 if ($time_zone != '') {
                     //Set pay period timezone to the timezone of the majority of the users are in.
                     $pps_obj->setTimeZone($time_zone);
                     if ($pps_obj->isValid()) {
                         $pps_obj->Save();
                     }
                 }
             }
         }
     }
     Debug::text('l: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     return TRUE;
 }
示例#4
0
 $cjlf->getByName('calcExceptions');
 if ($cjlf->getRecordCount() > 0) {
     foreach ($cjlf as $cj_obj) {
         $tmp_start_date = $cj_obj->getLastRunDate();
         if ($tmp_start_date < $start_date) {
             $start_date = $tmp_start_date;
             Debug::text('  CRON Job hasnt run in more then 48hrs, reducing Start Date to: ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 5);
         }
     }
 }
 unset($cjlf, $cj_obj, $tmp_start_date);
 //Get maximum shift time for each pay period schedule, so we know how far back
 //we have to recalculate days at the minimum.
 $ppslf = new PayPeriodScheduleListFactory();
 $ppslf->getByCompanyId($c_obj->getId());
 if ($ppslf->getRecordCount() > 0) {
     foreach ($ppslf as $pps_obj) {
         $tmp_start_date = TTDate::getMiddleDayEpoch($execution_time) - $pps_obj->getMaximumShiftTime();
         if ($tmp_start_date < $start_date) {
             $start_date = $tmp_start_date;
             Debug::text('  Maximum Shift Time is greater then 48hrs, reducing Start Date to: ' . TTDate::getDate('DATE+TIME', $start_date), __FILE__, __LINE__, __METHOD__, 5);
         }
     }
 }
 unset($ppslf, $pps_obj, $tmp_start_date);
 //Get earliest pre_mature exception in a NON-closed pay period.
 $elf = new ExceptionListFactory();
 $elf->getByCompanyIDAndTypeAndPayPeriodStatus($c_obj->getId(), 5, array(10, 12, 15, 30), 1, NULL, NULL, array('b.date_stamp' => 'asc'));
 //Limit 1
 if ($elf->getRecordCount() > 0) {
     foreach ($elf as $e_obj) {
 function createPayPeriods()
 {
     $max_pay_periods = 29;
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getById($this->pay_period_schedule_id);
     if ($ppslf->getRecordCount() > 0) {
         $pps_obj = $ppslf->getCurrent();
         for ($i = 0; $i < $max_pay_periods; $i++) {
             if ($i == 0) {
                 //$end_date = TTDate::getBeginYearEpoch( strtotime('01-Jan-07') );
                 $end_date = TTDate::getBeginYearEpoch(time());
             } else {
                 $end_date = $end_date + 86400 * 14;
             }
             Debug::Text('I: ' . $i . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
             $pps_obj->createNextPayPeriod($end_date, 86400 * 3600);
         }
     }
     return TRUE;
 }
 static function CalcDifferences($pay_stub_id1, $pay_stub_id2, $ps_amendment_date = NULL)
 {
     //PayStub 1 is new.
     //PayStub 2 is old.
     if ($pay_stub_id1 == '') {
         return FALSE;
     }
     if ($pay_stub_id2 == '') {
         return FALSE;
     }
     if ($pay_stub_id1 == $pay_stub_id2) {
         return FALSE;
     }
     Debug::Text('Calculating the differences between Pay Stub: ' . $pay_stub_id1 . ' And: ' . $pay_stub_id2, __FILE__, __LINE__, __METHOD__, 10);
     $pslf = new PayStubListFactory();
     $pslf->StartTransaction();
     $pslf->getById($pay_stub_id1);
     if ($pslf->getRecordCount() > 0) {
         $pay_stub1_obj = $pslf->getCurrent();
     } else {
         Debug::Text('Pay Stub1 does not exist: ', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $pslf->getById($pay_stub_id2);
     if ($pslf->getRecordCount() > 0) {
         $pay_stub2_obj = $pslf->getCurrent();
     } else {
         Debug::Text('Pay Stub2 does not exist: ', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     if ($pay_stub1_obj->getUser() != $pay_stub2_obj->getUser()) {
         Debug::Text('Pay Stubs are from different users!', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     if ($ps_amendment_date == NULL or $ps_amendment_date == '') {
         Debug::Text('PS Amendment Date not set, trying to figure it out!', __FILE__, __LINE__, __METHOD__, 10);
         //Take a guess at the end of the newest open pay period.
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($pay_stub2_obj->getUser());
         if ($ppslf->getRecordCount() > 0) {
             Debug::Text('Found Pay Period Schedule', __FILE__, __LINE__, __METHOD__, 10);
             $pplf = new PayPeriodListFactory();
             $pplf->getByPayPeriodScheduleIdAndTransactionDate($ppslf->getCurrent()->getId(), time());
             if ($pplf->getRecordCount() > 0) {
                 Debug::Text('Using Pay Period End Date.', __FILE__, __LINE__, __METHOD__, 10);
                 $ps_amendment_date = TTDate::getBeginDayEpoch($pplf->getCurrent()->getEndDate());
             }
         } else {
             Debug::Text('Using Today.', __FILE__, __LINE__, __METHOD__, 10);
             $ps_amendment_date = time();
         }
     }
     Debug::Text('Using Date: ' . TTDate::getDate('DATE+TIME', $ps_amendment_date), __FILE__, __LINE__, __METHOD__, 10);
     //Only do Earnings for now.
     //Get all earnings, EE/ER deduction PS entries.
     $pay_stub1_entry_ids = NULL;
     $pay_stub1_entries = new PayStubEntryListFactory();
     $pay_stub1_entries->getByPayStubIdAndType($pay_stub1_obj->getId(), array(10, 20, 30));
     if ($pay_stub1_entries->getRecordCount() > 0) {
         Debug::Text('Pay Stub1 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($pay_stub1_entries as $pay_stub1_entry_obj) {
             $pay_stub1_entry_ids[] = $pay_stub1_entry_obj->getPayStubEntryNameId();
         }
     } else {
         Debug::Text('Pay Stub1 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     Debug::Arr($pay_stub1_entry_ids, 'Pay Stub1 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10);
     //var_dump($pay_stub1_entry_ids);
     $pay_stub2_entry_ids = NULL;
     $pay_stub2_entries = new PayStubEntryListFactory();
     $pay_stub2_entries->getByPayStubIdAndType($pay_stub2_obj->getId(), array(10, 20, 30));
     if ($pay_stub2_entries->getRecordCount() > 0) {
         Debug::Text('Pay Stub2 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($pay_stub2_entries as $pay_stub2_entry_obj) {
             $pay_stub2_entry_ids[] = $pay_stub2_entry_obj->getPayStubEntryNameId();
         }
     } else {
         Debug::Text('Pay Stub2 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     Debug::Arr($pay_stub1_entry_ids, 'Pay Stub2 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10);
     $pay_stub_entry_ids = array_unique(array_merge($pay_stub1_entry_ids, $pay_stub2_entry_ids));
     Debug::Arr($pay_stub_entry_ids, 'Pay Stub Entry Differences: ', __FILE__, __LINE__, __METHOD__, 10);
     //var_dump($pay_stub_entry_ids);
     $pself = new PayStubEntryListFactory();
     if (count($pay_stub_entry_ids) > 0) {
         foreach ($pay_stub_entry_ids as $pay_stub_entry_id) {
             Debug::Text('Entry ID: ' . $pay_stub_entry_id, __FILE__, __LINE__, __METHOD__, 10);
             $pay_stub1_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub1_obj->getId(), $pay_stub_entry_id);
             $pay_stub2_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub2_obj->getId(), $pay_stub_entry_id);
             Debug::Text('Pay Stub1 Amount: ' . $pay_stub1_entry_arr['amount'] . ' Pay Stub2 Amount: ' . $pay_stub2_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10);
             if ($pay_stub1_entry_arr['amount'] != $pay_stub2_entry_arr['amount']) {
                 $amount_diff = bcsub($pay_stub1_entry_arr['amount'], $pay_stub2_entry_arr['amount'], 2);
                 $units_diff = abs(bcsub($pay_stub1_entry_arr['units'], $pay_stub2_entry_arr['units'], 2));
                 Debug::Text('FOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff, __FILE__, __LINE__, __METHOD__, 10);
                 //Generate PS Amendment.
                 $psaf = new PayStubAmendmentFactory();
                 $psaf->setUser($pay_stub1_obj->getUser());
                 $psaf->setStatus('ACTIVE');
                 $psaf->setType(10);
                 $psaf->setPayStubEntryNameId($pay_stub_entry_id);
                 if ($units_diff > 0) {
                     //Re-calculate amount when units are involved, due to rounding issues.
                     $unit_rate = Misc::MoneyFormat(bcdiv($amount_diff, $units_diff));
                     $amount_diff = Misc::MoneyFormat(bcmul($unit_rate, $units_diff));
                     Debug::Text('bFOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff . ' Unit Rate: ' . $unit_rate, __FILE__, __LINE__, __METHOD__, 10);
                     $psaf->setRate($unit_rate);
                     $psaf->setUnits($units_diff);
                     $psaf->setAmount($amount_diff);
                 } else {
                     $psaf->setAmount($amount_diff);
                 }
                 $psaf->setDescription('Adjustment from Pay Period Ending: ' . TTDate::getDate('DATE', $pay_stub2_obj->getEndDate()));
                 $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($ps_amendment_date));
                 if ($psaf->isValid()) {
                     $psaf->Save();
                 }
                 unset($amount_diff, $units_diff, $unit_rate);
             } else {
                 Debug::Text('No DIFFERENCE!', __FILE__, __LINE__, __METHOD__, 10);
             }
         }
     }
     $pslf->CommitTransaction();
     return TRUE;
 }
 function getPayPeriodScheduleObject()
 {
     if (is_object($this->pay_period_schedule_obj)) {
         return $this->pay_period_schedule_obj;
     } else {
         if ($this->getUser() > 0) {
             $ppslf = new PayPeriodScheduleListFactory();
             $ppslf->getByUserId($this->getUser());
             if ($ppslf->getRecordCount() == 1) {
                 $this->pay_period_schedule_obj = $ppslf->getCurrent();
                 return $this->pay_period_schedule_obj;
             }
         }
         return FALSE;
     }
 }
示例#8
0
 function createPayPeriods($start_date = NULL)
 {
     if ($start_date == '') {
         $start_date = TTDate::getBeginWeekEpoch(TTDate::getBeginYearEpoch(time()) - 86400 * (7 * 6));
     }
     $max_pay_periods = 192;
     //Make a lot of pay periods as we need to test 6 years worth of accruals for different milestones.
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getById($this->pay_period_schedule_id);
     if ($ppslf->getRecordCount() > 0) {
         $pps_obj = $ppslf->getCurrent();
         for ($i = 0; $i < $max_pay_periods; $i++) {
             if ($i == 0) {
                 //$end_date = TTDate::getBeginYearEpoch( strtotime('01-Jan-07') );
                 $end_date = $start_date;
             } else {
                 $end_date = $end_date + 86400 * 14;
             }
             Debug::Text('I: ' . $i . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
             $pps_obj->createNextPayPeriod($end_date, 86400 * 3600);
         }
     }
     return TRUE;
 }
 function postSave()
 {
     $this->removeCache($this->getId());
     if ($this->getDeleted() == FALSE and $this->getPermissionControl() !== FALSE) {
         Debug::text('Permission Group is set...', __FILE__, __LINE__, __METHOD__, 10);
         $pclf = new PermissionControlListFactory();
         $pclf->getByCompanyIdAndUserID($this->getCompany(), $this->getId());
         if ($pclf->getRecordCount() > 0) {
             Debug::text('Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             $pc_obj = $pclf->getCurrent();
             if ($pc_obj->getId() == $this->getPermissionControl()) {
                 $add_permission_control = FALSE;
             } else {
                 Debug::text('Permission Group has changed...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $pulf = new PermissionUserListFactory();
                 $pulf->getByPermissionControlIdAndUserID($pc_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $pulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($pulf->getRecordCount() > 0) {
                     foreach ($pulf as $pu_obj) {
                         Debug::text('Deleteing from Permission Group: ' . $pu_obj->getPermissionControl(), __FILE__, __LINE__, __METHOD__, 10);
                         $pu_obj->Delete();
                     }
                 }
                 $add_permission_control = TRUE;
             }
         } else {
             Debug::text('NOT Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             $add_permission_control = TRUE;
         }
         if ($this->getPermissionControl() !== FALSE and $add_permission_control == TRUE) {
             Debug::text('Adding user to Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             //Add to new permission group
             $puf = new PermissionUserFactory();
             $puf->setPermissionControl($this->getPermissionControl());
             $puf->setUser($this->getID());
             if ($puf->isValid()) {
                 $puf->Save();
                 //Clear permission class for this employee.
                 $pf = new PermissionFactory();
                 $pf->clearCache($this->getID(), $this->getCompany());
             }
         }
         unset($add_permission_control);
     }
     if ($this->getDeleted() == FALSE and $this->getPayPeriodSchedule() !== FALSE) {
         Debug::text('Pay Period Schedule is set...', __FILE__, __LINE__, __METHOD__, 10);
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($this->getId());
         if ($ppslf->getRecordCount() > 0) {
             $pps_obj = $ppslf->getCurrent();
             if ($this->getPayPeriodSchedule() == $pps_obj->getId()) {
                 Debug::text('Already assigned to this Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
                 $add_pay_period_schedule = FALSE;
             } else {
                 Debug::text('Changing Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $ppsulf = new PayPeriodScheduleUserListFactory();
                 $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($ppsulf->getRecordCount() > 0) {
                     foreach ($ppsulf as $ppsu_obj) {
                         Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
                         $ppsu_obj->Delete();
                     }
                 }
                 $add_pay_period_schedule = TRUE;
             }
         } else {
             Debug::text('Not assigned to ANY Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
             $add_pay_period_schedule = TRUE;
         }
         if ($this->getPayPeriodSchedule() !== FALSE and $add_pay_period_schedule == TRUE) {
             //Add to new pay period schedule
             $ppsuf = new PayPeriodScheduleUserFactory();
             $ppsuf->setPayPeriodSchedule($this->getPayPeriodSchedule());
             $ppsuf->setUser($this->getID());
             if ($ppsuf->isValid()) {
                 $ppsuf->Save();
             }
         }
         unset($add_pay_period_schedule);
     }
     if ($this->getDeleted() == FALSE and $this->getPolicyGroup() !== FALSE) {
         Debug::text('Policy Group is set...', __FILE__, __LINE__, __METHOD__, 10);
         $pglf = new PolicyGroupListFactory();
         $pglf->getByUserIds($this->getId());
         if ($pglf->getRecordCount() > 0) {
             $pg_obj = $pglf->getCurrent();
             if ($this->getPolicyGroup() == $pg_obj->getId()) {
                 Debug::text('Already assigned to this Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
                 $add_policy_group = FALSE;
             } else {
                 Debug::text('Changing Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $pgulf = new PolicyGroupUserListFactory();
                 $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($pgulf->getRecordCount() > 0) {
                     foreach ($pgulf as $pgu_obj) {
                         Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10);
                         $pgu_obj->Delete();
                     }
                 }
                 $add_policy_group = TRUE;
             }
         } else {
             Debug::text('Not assigned to ANY Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
             $add_policy_group = TRUE;
         }
         if ($this->getPolicyGroup() !== FALSE and $add_policy_group == TRUE) {
             //Add to new policy group
             $pguf = new PolicyGroupUserFactory();
             $pguf->setPolicyGroup($this->getPolicyGroup());
             $pguf->setUser($this->getID());
             if ($pguf->isValid()) {
                 $pguf->Save();
             }
         }
         unset($add_policy_group);
     }
     if ($this->getDeleted() == FALSE and $this->getHierarchyControl() !== FALSE) {
         Debug::text('Hierarchies are set...', __FILE__, __LINE__, __METHOD__, 10);
         $hierarchy_control_data = array_unique(array_values((array) $this->getHierarchyControl()));
         //Debug::Arr($hierarchy_control_data, 'Setting hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10);
         if (is_array($hierarchy_control_data)) {
             $hclf = new HierarchyControlListFactory();
             $hclf->getObjectTypeAppendedListByCompanyIDAndUserID($this->getCompany(), $this->getID());
             $existing_hierarchy_control_data = array_unique(array_values((array) $hclf->getArrayByListFactory($hclf, FALSE, TRUE, FALSE)));
             //Debug::Arr($existing_hierarchy_control_data, 'Existing hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10);
             $hierarchy_control_delete_diff = array_diff($existing_hierarchy_control_data, $hierarchy_control_data);
             //Debug::Arr($hierarchy_control_delete_diff, 'Hierarchy control delete diff: ', __FILE__, __LINE__, __METHOD__, 10);
             //Remove user from existing hierarchy control
             if (is_array($hierarchy_control_delete_diff)) {
                 foreach ($hierarchy_control_delete_diff as $hierarchy_control_id) {
                     if ($hierarchy_control_id != 0) {
                         $hulf = new HierarchyUserListFactory();
                         $hulf->getByHierarchyControlAndUserID($hierarchy_control_id, $this->getID());
                         if ($hulf->getRecordCount() > 0) {
                             Debug::text('Deleting user from hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10);
                             $hulf->getCurrent()->Delete();
                         }
                     }
                 }
             }
             unset($hierarchy_control_delete_diff, $hulf, $hclf, $hierarchy_control_id);
             $hierarchy_control_add_diff = array_diff($hierarchy_control_data, $existing_hierarchy_control_data);
             //Debug::Arr($hierarchy_control_add_diff, 'Hierarchy control add diff: ', __FILE__, __LINE__, __METHOD__, 10);
             if (is_array($hierarchy_control_add_diff)) {
                 foreach ($hierarchy_control_add_diff as $hierarchy_control_id) {
                     Debug::text('Hierarchy data changed...', __FILE__, __LINE__, __METHOD__, 10);
                     if ($hierarchy_control_id != 0) {
                         $huf = new HierarchyUserFactory();
                         $huf->setHierarchyControl($hierarchy_control_id);
                         $huf->setUser($this->getId());
                         if ($huf->isValid()) {
                             Debug::text('Adding user to hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10);
                             $huf->Save();
                         }
                     }
                 }
             }
             unset($hierarchy_control_add, $huf, $hierarchy_control_id);
         }
     }
     if (isset($this->is_new) and $this->is_new == TRUE) {
         $udlf = new UserDefaultListFactory();
         $udlf->getByCompanyId($this->getCompany());
         if ($udlf->getRecordCount() > 0) {
             Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10);
             $udf_obj = $udlf->getCurrent();
             Debug::text('Inserting Default Deductions...', __FILE__, __LINE__, __METHOD__, 10);
             $company_deduction_ids = $udf_obj->getCompanyDeduction();
             if (is_array($company_deduction_ids) and count($company_deduction_ids) > 0) {
                 foreach ($company_deduction_ids as $company_deduction_id) {
                     $udf = new UserDeductionFactory();
                     $udf->setUser($this->getId());
                     $udf->setCompanyDeduction($company_deduction_id);
                     if ($udf->isValid()) {
                         $udf->Save();
                     }
                 }
             }
             unset($company_deduction_ids, $company_deduction_id, $udf);
             Debug::text('Inserting Default Prefs...', __FILE__, __LINE__, __METHOD__, 10);
             $upf = new UserPreferenceFactory();
             $upf->setUser($this->getId());
             $upf->setLanguage($udf_obj->getLanguage());
             $upf->setDateFormat($udf_obj->getDateFormat());
             $upf->setTimeFormat($udf_obj->getTimeFormat());
             $upf->setTimeUnitFormat($udf_obj->getTimeUnitFormat());
             $upf->setTimeZone($udf_obj->getTimeZone());
             $upf->setItemsPerPage($udf_obj->getItemsPerPage());
             $upf->setStartWeekDay($udf_obj->getStartWeekDay());
             $upf->setEnableEmailNotificationException($udf_obj->getEnableEmailNotificationException());
             $upf->setEnableEmailNotificationMessage($udf_obj->getEnableEmailNotificationMessage());
             $upf->setEnableEmailNotificationHome($udf_obj->getEnableEmailNotificationHome());
             if ($upf->isValid()) {
                 $upf->Save();
             }
         }
     }
     if ($this->getDeleted() == TRUE) {
         //Remove them from the authorization hierarchy, policy group, and pay period schedule.
         //Delete any accruals for them as well.
         //Pay Period Schedule
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($this->getId());
         if ($ppslf->getRecordCount() > 0) {
             $pps_obj = $ppslf->getCurrent();
             //Remove user from current schedule.
             $ppsulf = new PayPeriodScheduleUserListFactory();
             $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId());
             Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             if ($ppsulf->getRecordCount() > 0) {
                 foreach ($ppsulf as $ppsu_obj) {
                     Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
                     $ppsu_obj->Delete();
                 }
             }
         }
         //Policy Group
         $pglf = new PolicyGroupListFactory();
         $pglf->getByUserIds($this->getId());
         if ($pglf->getRecordCount() > 0) {
             $pg_obj = $pglf->getCurrent();
             $pgulf = new PolicyGroupUserListFactory();
             $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId());
             Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             if ($pgulf->getRecordCount() > 0) {
                 foreach ($pgulf as $pgu_obj) {
                     Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10);
                     $pgu_obj->Delete();
                 }
             }
         }
         //Hierarchy
         $hclf = new HierarchyControlListFactory();
         $hclf->getByCompanyId($this->getCompany());
         if ($hclf->getRecordCount() > 0) {
             foreach ($hclf as $hc_obj) {
                 $hf = new HierarchyListFactory();
                 $hf->setUser($this->getID());
                 $hf->setHierarchyControl($hc_obj->getId());
                 $hf->Delete();
             }
             $hf->removeCache(NULL, $hf->getTable(TRUE));
             //On delete we have to delete the entire group.
             unset($hf);
         }
         //Accrual balances
         $alf = new AccrualListFactory();
         $alf->getByUserIdAndCompanyId($this->getId(), $this->getCompany());
         if ($alf->getRecordCount() > 0) {
             foreach ($alf as $a_obj) {
                 $a_obj->setDeleted(TRUE);
                 if ($a_obj->isValid()) {
                     $a_obj->Save();
                 }
             }
         }
     }
     return TRUE;
 }
 function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Go through all pay period schedules and update the annual pay period column
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             $pps_obj->setAnnualPayPeriods($pps_obj->calcAnnualPayPeriods());
             if ($pps_obj->isValid()) {
                 $pps_obj->Save();
             }
         }
     }
     //Go through all employee wages and update HourlyRate to the accurate annual hourly rate.
     //**Handle this in 1034A postInstall() instead, as it needs to handle incorrect effective_dates properly.
     /*
     $uwlf = new UserWageListFactory();
     $uwlf->getAll();
     if ( $uwlf->getRecordCount() > 0 ) {
     	foreach( $uwlf as $uw_obj ) {
     		$uw_obj->setHourlyRate( $uw_obj->calcHourlyRate( time(), TRUE ) );
     		if ( $uw_obj->isValid() ) {
     			$uw_obj->Save();
     		}
     	}
     }
     */
     //Upgrade to new hierarchy format.
     $clf = new CompanyListFactory();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             if ($c_obj->getStatus() != 30) {
                 /*
                 					if ( !($c_obj->getId() == 1052) ) { //$c_obj->getId() == 1009 OR $c_obj->getId() == 1087 OR
                 						continue;
                 					}
                 */
                 $company_id = $c_obj->getId();
                 Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                 $hclf = new HierarchyControlListFactory();
                 $hclf->StartTransaction();
                 $hclf->getByCompanyId($company_id);
                 if ($hclf->getRecordCount() > 0) {
                     foreach ($hclf as $hc_obj) {
                         $paths_to_root = array();
                         $hierarchy_id = $hc_obj->getId();
                         $hlf = new HierarchyListFactory();
                         $hierarchy_users = $hlf->getByCompanyIdAndHierarchyControlId($company_id, $hierarchy_id);
                         if (is_array($hierarchy_users) and count($hierarchy_users) > 0) {
                             $hotlf = new HierarchyObjectTypeListFactory();
                             $hotlf->getByHierarchyControlId($hierarchy_id);
                             if ($hotlf->getRecordCount() > 0) {
                                 foreach ($hotlf as $hot_obj) {
                                     $object_types[$hierarchy_id][] = $hot_obj->getObjectType();
                                 }
                             }
                             foreach ($hierarchy_users as $hierarchy_user_arr) {
                                 Debug::Text(' Checking User ID: ' . $hierarchy_user_arr['id'], __FILE__, __LINE__, __METHOD__, 10);
                                 $id = $hierarchy_user_arr['id'];
                                 $tmp_id = $id;
                                 $i = 0;
                                 do {
                                     Debug::Text(' Iteration...', __FILE__, __LINE__, __METHOD__, 10);
                                     $hlf_b = new HierarchyListFactory();
                                     $parents = $hlf_b->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $tmp_id);
                                     sort($parents);
                                     $level = $hlf_b->getFastTreeObject()->getLevel($tmp_id) - 1;
                                     if (is_array($parents) and count($parents) > 0) {
                                         $parent_users = array();
                                         foreach ($parents as $user_id) {
                                             $parent_users[] = $user_id;
                                             unset($user);
                                         }
                                         $parent_groups[$level] = $parent_users;
                                         unset($parent_users);
                                     }
                                     if (isset($parents[0])) {
                                         $tmp_id = $parents[0];
                                     }
                                     $i++;
                                 } while (is_array($parents) and count($parents) > 0 and $i < 100);
                                 if (isset($parent_groups)) {
                                     $serialized_path = serialize($parent_groups);
                                     $paths_to_root[$serialized_path][] = $id;
                                     unset($serialized_path);
                                 }
                                 unset($parent_groups, $parents);
                             }
                         }
                         Debug::Arr($paths_to_root, ' Paths To Root: ', __FILE__, __LINE__, __METHOD__, 10);
                         //Decode path_to_root array
                         if (isset($paths_to_root) and count($paths_to_root) > 0) {
                             foreach ($paths_to_root as $serialized_path => $children) {
                                 $path_arr = unserialize($serialized_path);
                                 $decoded_paths[] = array('hierarchy_control_id' => $hierarchy_id, 'path' => $path_arr, 'children' => $children);
                             }
                             unset($path_arr, $children);
                             Debug::Arr($decoded_paths, ' Decoded Paths: ', __FILE__, __LINE__, __METHOD__, 10);
                             if (isset($decoded_paths) and is_array($decoded_paths)) {
                                 foreach ($decoded_paths as $decoded_path) {
                                     Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                                     //Create new hierarchy_control
                                     $hcf = new HierarchyControlFactory();
                                     $hcf->setCompany($company_id);
                                     $hcf->setObjectType($object_types[$decoded_path['hierarchy_control_id']]);
                                     //Generate meaningful name
                                     $name = FALSE;
                                     if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                         ksort($decoded_path['path']);
                                         //Sort by level.
                                         foreach ($decoded_path['path'] as $level => $superior_ids) {
                                             foreach ($superior_ids as $superior_id) {
                                                 $ulf = new UserListFactory();
                                                 $ulf->getById($superior_id);
                                                 if ($ulf->getRecordCount() > 0) {
                                                     $name[] = $level . '. ' . $ulf->getCurrent()->getFullName();
                                                 }
                                             }
                                         }
                                         unset($level, $superior_ids, $superior_id);
                                     }
                                     if (isset($name)) {
                                         $name = $hc_obj->getName() . ' ' . implode(', ', $name) . ' (#' . rand(1000, 9999) . ')';
                                     } else {
                                         $name = $hc_obj->getName() . ' (#' . rand(1000, 9999) . ')';
                                     }
                                     $hcf->setName(substr($name, 0, 249));
                                     $hcf->setDescription(TTi18n::getText('Automatically created by TimeTrex'));
                                     if ($hcf->isValid()) {
                                         $hc_id = $hcf->Save(FALSE);
                                         Debug::Text('Hierarchy Control ID: ' . $hc_id, __FILE__, __LINE__, __METHOD__, 10);
                                         $hcf->setUser($decoded_path['children']);
                                         if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                             foreach ($decoded_path['path'] as $level => $superior_ids) {
                                                 foreach ($superior_ids as $superior_id) {
                                                     $hlf = new HierarchyLevelFactory();
                                                     $hlf->setHierarchyControl($hc_id);
                                                     $hlf->setLevel($level);
                                                     $hlf->setUser($superior_id);
                                                     if ($hlf->isValid()) {
                                                         $hlf->Save();
                                                         Debug::Text('Saving Level Row ID... User ID: ' . $superior_id, __FILE__, __LINE__, __METHOD__, 10);
                                                     }
                                                 }
                                             }
                                             unset($level, $superior_ids, $superior_id);
                                         }
                                     }
                                 }
                             }
                             unset($decoded_paths);
                         }
                         //Delete existing hierarchy control.
                         $hc_obj->setDeleted(TRUE);
                         if ($hc_obj->isValid() == TRUE) {
                             $hc_obj->Save();
                         }
                     }
                 }
                 //$hclf->FailTransaction();
                 $hclf->CommitTransaction();
             }
         }
     }
     //Go through each permission group, and enable break policies for anyone who can see meal policies
     $clf = new 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) {
                 $pclf = new PermissionControlListFactory();
                 $pclf->getByCompanyId($c_obj->getId());
                 if ($pclf->getRecordCount() > 0) {
                     foreach ($pclf as $pc_obj) {
                         Debug::text('Permission Group: ' . $pc_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
                         $plf = new PermissionListFactory();
                         $plf->getByCompanyIdAndPermissionControlIdAndSectionAndName($c_obj->getId(), $pc_obj->getId(), 'meal_policy', 'enabled');
                         if ($plf->getRecordCount() > 0) {
                             Debug::text('Found permission group with meal policy enabled: ' . $plf->getCurrent()->getValue(), __FILE__, __LINE__, __METHOD__, 9);
                             $pc_obj->setPermission(array('break_policy' => array('enabled' => TRUE, 'view' => TRUE, 'add' => TRUE, 'edit' => TRUE, 'delete' => TRUE)));
                         } else {
                             Debug::text('Permission group does NOT have meal policy enabled...', __FILE__, __LINE__, __METHOD__, 9);
                         }
                     }
                 }
             }
         }
     }
     //Add MiscDaily cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscDaily');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('*');
     $cjf->setCommand('MiscDaily.php');
     $cjf->Save();
     //Add MiscWeekly cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscWeekly');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('0');
     //Sunday morning.
     $cjf->setCommand('MiscWeekly.php');
     $cjf->Save();
     return TRUE;
 }
 static function smartReCalculate($user_id, $user_date_ids, $enable_exception = TRUE, $enable_premature_exceptions = FALSE, $enable_future_exceptions = TRUE)
 {
     if ($user_id == '') {
         return FALSE;
     }
     //Debug::Arr($user_date_ids, 'aUser Date IDs: ', __FILE__, __LINE__, __METHOD__, 10);
     if (!is_array($user_date_ids) and is_int($user_date_ids)) {
         $user_date_ids = array($user_date_ids);
     }
     if (!is_array($user_date_ids)) {
         return FALSE;
     }
     $user_date_ids = array_unique($user_date_ids);
     //Debug::Arr($user_date_ids, 'bUser Date IDs: ', __FILE__, __LINE__, __METHOD__, 10);
     $start_week_day_id = 0;
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getByUserId($user_id);
     if ($ppslf->getRecordCount() == 1) {
         $pps_obj = $ppslf->getCurrent();
         $start_week_day_id = $pps_obj->getStartWeekDay();
     }
     Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10);
     //Get date stamps for all user_date_ids.
     $udlf = new UserDateListFactory();
     $udlf->getByIds($user_date_ids, NULL, array('date_stamp' => 'asc'));
     //Order by date asc
     if ($udlf->getRecordCount() > 0) {
         //Order them, and get the one or more sets of date ranges that need to be recalculated.
         //Need to consider re-calculating multiple weeks at once.
         $i = 0;
         foreach ($udlf as $ud_obj) {
             $start_week_epoch = TTDate::getBeginWeekEpoch($ud_obj->getDateStamp(), $start_week_day_id);
             $end_week_epoch = TTDate::getEndWeekEpoch($ud_obj->getDateStamp(), $start_week_day_id);
             Debug::text('Current Date: ' . TTDate::getDate('DATE', $ud_obj->getDateStamp()) . ' Start Week: ' . TTDate::getDate('DATE', $start_week_epoch) . ' End Week: ' . TTDate::getDate('DATE', $end_week_epoch), __FILE__, __LINE__, __METHOD__, 10);
             if ($i == 0) {
                 $range_arr[$start_week_epoch] = array('start_date' => $ud_obj->getDateStamp(), 'end_date' => $end_week_epoch);
             } else {
                 //Loop through each range extending it if needed.
                 foreach ($range_arr as $tmp_start_week_epoch => $tmp_range) {
                     if ($ud_obj->getDateStamp() >= $tmp_range['start_date'] and $ud_obj->getDateStamp() <= $tmp_range['end_date']) {
                         //Date falls within already existing range
                         continue;
                     } elseif ($ud_obj->getDateStamp() < $tmp_range['start_date'] and $ud_obj->getDateStamp() >= $tmp_start_week_epoch) {
                         //Date falls within the same week, but before the current start date.
                         $range_arr[$tmp_start_week_epoch]['start_date'] = $ud_obj->getDateStamp();
                         Debug::text('Pushing Start Date back...', __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         //Outside current range. Check to make sure it isn't within another range.
                         if (isset($range_arr[$start_week_epoch])) {
                             //Within another existing week, check to see if we need to extend it.
                             if ($ud_obj->getDateStamp() < $range_arr[$start_week_epoch]['start_date']) {
                                 Debug::text('bPushing Start Date back...', __FILE__, __LINE__, __METHOD__, 10);
                                 $range_arr[$start_week_epoch]['start_date'] = $ud_obj->getDateStamp();
                             }
                         } else {
                             //Not within another existing week
                             Debug::text('Adding new range...', __FILE__, __LINE__, __METHOD__, 10);
                             $range_arr[$start_week_epoch] = array('start_date' => $ud_obj->getDateStamp(), 'end_date' => $end_week_epoch);
                         }
                     }
                 }
                 unset($tmp_range, $tmp_start_week_epoch);
             }
             $i++;
         }
         unset($start_week_epoch, $end_week_epoch, $udlf, $ud_obj);
         if (is_array($range_arr)) {
             ksort($range_arr);
             //Sort range by start week, so recalculating goes in date order.
             //Debug::Arr($range_arr, 'Range Array: ', __FILE__, __LINE__, __METHOD__, 10);
             foreach ($range_arr as $week_range) {
                 $udlf = new UserDateListFactory();
                 $udlf->getByUserIdAndStartDateAndEndDate($user_id, $week_range['start_date'], $week_range['end_date']);
                 if ($udlf->getRecordCount() > 0) {
                     Debug::text('Found days to re-calculate: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                     $udlf->StartTransaction();
                     $z = 1;
                     $z_max = $udlf->getRecordCount();
                     foreach ($udlf as $ud_obj) {
                         //We only need to re-calculate exceptions on the exact days specified by user_date_ids.
                         //This was the case before we Over Weekly Time/Over Scheduled Weekly Time exceptions,
                         //Now we have to enable calculating exceptions for the entire week.
                         /*
                         if ( in_array( $ud_obj->getId(), $user_date_ids ) ) {
                         	//Calculate exceptions
                         	Debug::text('Re-calculating day with exceptions: '. $ud_obj->getId() , __FILE__, __LINE__, __METHOD__, 10);
                         	UserDateTotalFactory::reCalculateDay( $ud_obj->getId(), $enable_exception, $enable_premature_exceptions, $enable_future_exceptions );
                         } else {
                         	//Don't calculate exceptions.
                         	UserDateTotalFactory::reCalculateDay( $ud_obj->getId() );
                         }
                         */
                         Debug::text('Re-calculating day with exceptions: ' . $ud_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                         if ($z == $z_max) {
                             //Enable recalculating holidays at the end of each week.
                             UserDateTotalFactory::reCalculateDay($ud_obj->getId(), $enable_exception, $enable_premature_exceptions, $enable_future_exceptions, TRUE);
                         } else {
                             UserDateTotalFactory::reCalculateDay($ud_obj->getId(), $enable_exception, $enable_premature_exceptions, $enable_future_exceptions);
                         }
                         $z++;
                     }
                     $udlf->CommitTransaction();
                 }
             }
             return TRUE;
         }
     }
     Debug::text('Returning FALSE!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
 function Validate()
 {
     //Make sure there aren't conflicting pay periods.
     //Start date checks that...
     //Make sure End Date is after Start Date, and transaction date is the same or after End Date.
     Debug::text('Start Date: ' . $this->getStartDate() . ' End Date: ' . $this->getEndDate(), __FILE__, __LINE__, __METHOD__, 10);
     if ($this->getEndDate() <= $this->getStartDate()) {
         $this->Validator->isTrue('end_date', FALSE, TTi18n::gettext('Conflicting end date'));
     }
     if ($this->getTransactionDate() < $this->getEndDate()) {
         $this->Validator->isTrue('transaction_date', FALSE, TTi18n::gettext('Conflicting transaction date'));
     }
     //Make sure if this a monthly+advanc pay period, advance dates are set.
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getById($this->getPayPeriodSchedule());
     if ($ppslf->getRecordCount() == 1 and is_object($ppslf) and $ppslf->getCurrent()->getType() == 40) {
         Debug::text('Pay Period Type IS Monthly + Advance: ', __FILE__, __LINE__, __METHOD__, 10);
         if ($this->getAdvanceEndDate() === FALSE) {
             $this->Validator->isTrue('advance_end_date', FALSE, TTi18n::gettext('Advance end date is not set'));
         }
         if ($this->getAdvanceTransactionDate() === FALSE) {
             $this->Validator->isTrue('advance_transaction_date', FALSE, TTi18n::gettext('Advance transaction date is not set'));
         }
         //Make sure advance dates are in the proper range.
         if ($this->getAdvanceEndDate() > $this->getEndDate() or $this->getAdvanceEndDate() < $this->getStartDate()) {
             $this->Validator->isDate('advance_end_date', FALSE, TTi18n::gettext('Incorrect advance end date'));
         }
         if ($this->getAdvanceTransactionDate() > $this->getEndDate() or $this->getAdvanceTransactionDate() < $this->getAdvanceEndDate()) {
             $this->Validator->isDate('advance_transaction_date', FALSE, TTi18n::gettext('Incorrect advance transaction date'));
         }
     } elseif ($ppslf->getRecordCount() == 1 and is_object($ppslf)) {
         Debug::text('Pay Period Type is NOT Monthly + Advance... Advance End Date: ' . $this->getAdvanceEndDate(), __FILE__, __LINE__, __METHOD__, 10);
         if ($this->getAdvanceEndDate() != '') {
             $this->Validator->isTrue('advance_end_date', FALSE, TTi18n::gettext('Advance end date is set'));
         }
         if ($this->getAdvanceTransactionDate() != '') {
             $this->Validator->isTrue('advance_transaction_date', FALSE, TTi18n::gettext('Advance transaction date is set'));
         }
     } else {
         Debug::text('Pay Period Schedule not found: ' . $this->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
         $this->Validator->isTrue('pay_period_schedule', FALSE, TTi18n::gettext('Incorrect Pay Period Schedule'));
     }
     return TRUE;
 }