function generateData() { global $current_company, $current_user; TTDate::setTimeZone('PST8PDT'); $current_epoch = time(); $cf = new CompanyFactory(); $cf->StartTransaction(); $company_id = $this->createCompany(); $clf = new CompanyListFactory(); $clf->getById($company_id); $current_company = $clf->getCurrent(); if ($company_id !== FALSE) { Debug::Text('Company Created Successfully!', __FILE__, __LINE__, __METHOD__, 10); $this->createPermissionGroups($company_id); //Create currency $currency_ids[] = $this->createCurrency($company_id, 10); //USD $currency_ids[] = $this->createCurrency($company_id, 20); //CAD //Create branch $branch_ids[] = $this->createBranch($company_id, 10); //NY $branch_ids[] = $this->createBranch($company_id, 20); //WA //Create departments $department_ids[] = $this->createDepartment($company_id, 10); $department_ids[] = $this->createDepartment($company_id, 20); //Create stations $station_id = $this->createStation($company_id); //Create pay stub accounts. $this->createPayStubAccount($company_id); //Link pay stub accounts. $this->createPayStubAccountLink($company_id); //Company Deductions $this->createCompanyDeduction($company_id); //Wage Groups $wage_group_ids[] = $this->createUserWageGroups($company_id); //User Groups $user_group_ids[] = $this->createUserGroup($company_id, 10, 0); $user_group_ids[] = $this->createUserGroup($company_id, 20, $user_group_ids[0]); $user_group_ids[] = $this->createUserGroup($company_id, 30, $user_group_ids[0]); $user_group_ids[] = $this->createUserGroup($company_id, 40, 0); $user_group_ids[] = $this->createUserGroup($company_id, 50, $user_group_ids[3]); //Users $user_ids[] = $this->createUser($company_id, 10, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[0]); $user_ids[] = $this->createUser($company_id, 11, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]); $user_ids[] = $this->createUser($company_id, 12, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]); $user_ids[] = $this->createUser($company_id, 13, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]); $user_ids[] = $this->createUser($company_id, 14, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]); $user_ids[] = $this->createUser($company_id, 15, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[1]); $user_ids[] = $this->createUser($company_id, 16, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]); $user_ids[] = $this->createUser($company_id, 17, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]); $user_ids[] = $this->createUser($company_id, 18, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[2]); $user_ids[] = $this->createUser($company_id, 19, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[2]); $user_ids[] = $this->createUser($company_id, 20, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[2]); $user_ids[] = $this->createUser($company_id, 21, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]); $user_ids[] = $this->createUser($company_id, 22, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]); $user_ids[] = $this->createUser($company_id, 23, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]); $user_ids[] = $this->createUser($company_id, 24, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]); $user_ids[] = $this->createUser($company_id, 25, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]); $user_ids[] = $this->createUser($company_id, 26, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]); $user_ids[] = $this->createUser($company_id, 27, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]); $user_ids[] = $this->createUser($company_id, 28, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]); $user_ids[] = $this->createUser($company_id, 29, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]); $user_ids[] = $this->createUser($company_id, 30, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4]); $user_ids[] = $this->createUser($company_id, 40, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4]); $current_user_id = $user_ids[] = $this->createUser($company_id, 100, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[1]); //Create random users. for ($i = 0; $i <= $this->getMaxRandomUsers(); $i++) { $tmp_user_id = $this->createUser($company_id, 999, 0, $branch_ids[$i % 2], $department_ids[$i % 2], $currency_ids[0], $user_group_ids[$i % 5]); if ($tmp_user_id != FALSE) { $user_ids[] = $tmp_user_id; } } Debug::Arr($user_ids, 'All User IDs:', __FILE__, __LINE__, __METHOD__, 10); $ulf = new UserListFactory(); $ulf->getById($current_user_id); $current_user = $ulf->getCurrent(); unset($current_user_id); //Create policies $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 10); //In $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 20); //Out $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 10); //Bank Time $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 20); //Vacaction $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 30); //Sick $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 10); $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 20, $policy_ids['accrual'][0]); $policy_ids['premium'][] = $this->createPremiumPolicy($company_id, 10); $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 10, $policy_ids['accrual'][1]); $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 20, $policy_ids['accrual'][0]); $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 30, $policy_ids['accrual'][2]); $policy_ids['meal_1'] = $this->createMealPolicy($company_id); $policy_ids['schedule_1'] = $this->createSchedulePolicy($company_id, $policy_ids['meal_1']); $policy_ids['exception_1'] = $this->createExceptionPolicy($company_id); $hierarchy_user_ids = $user_ids; $root_user_id = array_pop($hierarchy_user_ids); unset($hierarchy_user_ids[0], $hierarchy_user_ids[1]); //Create authorization hierarchy $hierarchy_control_id = $this->createAuthorizationHierarchyControl($company_id, $hierarchy_user_ids); if ($root_user_id == FALSE) { Debug::Text('Administrator wasn\'t created! Duplicate username perhaps? Are we appending a random number?', __FILE__, __LINE__, __METHOD__, 10); } //Admin user at the top $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $root_user_id, 1); $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[0], 2); $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[1], 3); unset($hierarchy_user_ids, $root_user_id); //Pay Period Schedule $this->createPayPeriodSchedule($company_id, $user_ids); //Create Policy Group $this->createPolicyGroup($company_id, $policy_ids['meal_1'], $policy_ids['exception_1'], NULL, $policy_ids['overtime'], $policy_ids['premium'], $policy_ids['round'], $user_ids); if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL) { //Task Groups $task_group_ids[] = $this->createTaskGroup($company_id, 10, 0); $task_group_ids[] = $this->createTaskGroup($company_id, 20, $task_group_ids[0]); $task_group_ids[] = $this->createTaskGroup($company_id, 30, $task_group_ids[0]); $task_group_ids[] = $this->createTaskGroup($company_id, 40, 0); $task_group_ids[] = $this->createTaskGroup($company_id, 50, $task_group_ids[3]); $task_group_ids[] = $this->createTaskGroup($company_id, 60, $task_group_ids[3]); //Job Tasks $default_task_id = $this->createTask($company_id, 10, $task_group_ids[2]); $task_ids[] = $this->createTask($company_id, 20, $task_group_ids[1]); $task_ids[] = $this->createTask($company_id, 30, $task_group_ids[1]); $task_ids[] = $this->createTask($company_id, 40, $task_group_ids[2]); $task_ids[] = $this->createTask($company_id, 50, $task_group_ids[4]); $task_ids[] = $this->createTask($company_id, 60, $task_group_ids[4]); $task_ids[] = $this->createTask($company_id, 70, $task_group_ids[5]); //Job Groups $job_group_ids[] = $this->createJobGroup($company_id, 10, 0); $job_group_ids[] = $this->createJobGroup($company_id, 20, $job_group_ids[0]); $job_group_ids[] = $this->createJobGroup($company_id, 30, $job_group_ids[0]); $job_group_ids[] = $this->createJobGroup($company_id, 40, 0); $job_group_ids[] = $this->createJobGroup($company_id, 50, $job_group_ids[3]); $job_group_ids[] = $this->createJobGroup($company_id, 60, $job_group_ids[3]); //Jobs $job_ids[] = $this->createJob($company_id, 10, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 11, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 12, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 13, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 14, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 15, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]); $job_ids[] = $this->createJob($company_id, 16, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]); $job_ids[] = $this->createJob($company_id, 17, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]); $job_ids[] = $this->createJob($company_id, 18, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]); $job_ids[] = $this->createJob($company_id, 19, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]); $job_ids[] = $this->createJob($company_id, 20, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 21, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 22, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]); $job_ids[] = $this->createJob($company_id, 23, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]); $job_ids[] = $this->createJob($company_id, 24, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]); $job_ids[] = $this->createJob($company_id, 25, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]); } else { $task_ids[] = 0; $job_ids[] = 0; } //Create Accrual balances foreach ($user_ids as $user_id) { foreach ($policy_ids['accrual'] as $accrual_policy_id) { $this->createAccrualBalance($user_id, $accrual_policy_id); } unset($accrual_policy_id); } //Create recurring schedule templates $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 10, $policy_ids['schedule_1']); //Morning shift $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 20, $policy_ids['schedule_1']); //Afternoon shift $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 30, $policy_ids['schedule_1']); //Evening shift $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 40); //Split Shift $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 50, $policy_ids['schedule_1']); //Full rotation $recurring_schedule_start_date = TTDate::getBeginWeekEpoch($current_epoch + 86400 * 7.5); $this->createRecurringSchedule($company_id, $recurring_schedule_ids[0], $recurring_schedule_start_date, '', array($user_ids[0], $user_ids[1], $user_ids[2], $user_ids[3], $user_ids[4])); $this->createRecurringSchedule($company_id, $recurring_schedule_ids[1], $recurring_schedule_start_date, '', array($user_ids[5], $user_ids[6], $user_ids[7], $user_ids[8], $user_ids[9])); $this->createRecurringSchedule($company_id, $recurring_schedule_ids[2], $recurring_schedule_start_date, '', array($user_ids[10], $user_ids[11], $user_ids[12], $user_ids[13], $user_ids[14])); //Create schedule for each employee. foreach ($user_ids as $user_id) { //Create schedule starting 6 weeks ago, up to the end of the week. $schedule_options_arr = array('status_id' => 10, 'start_time' => '08:00AM', 'end_time' => '05:00PM', 'schedule_policy_id' => $policy_ids['schedule_1']); //$schedule_date = ($current_epoch-(86400*42)); $schedule_date = $current_epoch - 86400 * 14; $schedule_end_date = TTDate::getEndWeekEpoch($current_epoch); //$schedule_date = ($current_epoch-(86400*14)); //$schedule_end_date = ($current_epoch+(86400*28)); while ($schedule_date <= $schedule_end_date) { //Random departments/branches $schedule_options_arr['branch_id'] = $branch_ids[rand(0, count($branch_ids) - 1)]; $schedule_options_arr['department_id'] = $department_ids[rand(0, count($department_ids) - 1)]; //Skip weekends. if (date('w', $schedule_date) != 0 and date('w', $schedule_date) != 6) { $this->createSchedule($user_id, $schedule_date, $schedule_options_arr); } $schedule_date += 86400; } //break; unset($schedule_options_arr, $schedule_date, $schedule_end_date, $user_id); } //Punch users in/out randomly. foreach ($user_ids as $user_id) { //Pick random jobs/tasks that are used for the entire date range. //So one employee isn't punching into 15 jobs. $user_random_job_ids = array_rand($job_ids, 2); $user_random_task_ids = array_rand($job_ids, 3); //Create punches starting 6 weeks ago, up to the end of the week. //$start_date = $punch_date = ($current_epoch-(86400*42)); $start_date = $punch_date = $current_epoch - 86400 * 14; $end_date = TTDate::getEndWeekEpoch($current_epoch); //$start_date = $punch_date = ($current_epoch-(86400*14)); //$end_date = ($current_epoch+(86400*28)); $i = 0; while ($punch_date <= $end_date) { $date_stamp = TTDate::getDate('DATE', $punch_date); //$punch_full_time_stamp = strtotime($pc_data['date_stamp'].' '.$pc_data['time_stamp']); $exception_cutoff_date = $current_epoch - 86400 * 14; if (date('w', $punch_date) != 0 and date('w', $punch_date) != 6) { if ($punch_date >= $exception_cutoff_date and $i % 4 == 0) { $first_punch_in = rand(7, 8) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'AM'; $last_punch_out = strtotime($date_stamp . ' ' . rand(4, 5) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'PM'); if ($punch_date >= $exception_cutoff_date and rand(0, 20) == 0) { //Create request $this->createRequest(20, $user_id, $date_stamp); } if ($punch_date >= $exception_cutoff_date and rand(0, 16) == 0) { //Create request $this->createRequest(20, $user_id, $date_stamp); } } else { $first_punch_in = '08:00AM'; if ($punch_date >= $exception_cutoff_date and $i % 10 == 0) { //Don't punch out to generate exception. $last_punch_out = NULL; //Forgot to punch out request $this->createRequest(30, $user_id, $date_stamp); } else { $last_punch_out = strtotime($date_stamp . ' 5:00PM'); } } //Weekdays $this->createPunchPair($user_id, strtotime($date_stamp . ' ' . $first_punch_in), strtotime($date_stamp . ' 11:00AM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE); $this->createPunchPair($user_id, strtotime($date_stamp . ' 11:00AM'), strtotime($date_stamp . ' 1:00PM'), array('in_type_id' => 10, 'out_type_id' => 20, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE); //Calc total time on last punch pair only. $this->createPunchPair($user_id, strtotime($date_stamp . ' 2:00PM'), $last_punch_out, array('in_type_id' => 20, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE); } elseif ($punch_date > $exception_cutoff_date and date('w', $punch_date) == 6 and $i % 10 == 0) { //Sat. $this->createPunchPair($user_id, strtotime($date_stamp . ' 10:00AM'), strtotime($date_stamp . ' 2:30PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE); } //Recalculate entire day. Performance optimization. //UserDateTotalFactory::reCalculateRange( $user_id, $start_date, $end_date ); $punch_date += 86400; $i++; } unset($punch_options_arr, $punch_date, $user_id); } //Generate pay stubs for each pay period $pplf = new PayPeriodListFactory(); $pplf->getByCompanyId($company_id); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { foreach ($user_ids as $user_id) { $cps = new CalculatePayStub(); $cps->setUser($user_id); $cps->setPayPeriod($pp_obj->getId()); $cps->calculate(); } } } unset($pplf, $pp_obj, $user_id); } //$cf->FailTransaction(); $cf->CommitTransaction(); return FALSE; }
} if (isset($filter_data['user_ids']) and isset($filter_data['year'])) { $pseallf = new PayStubEntryAccountLinkListFactory(); $pseallf->getByCompanyId($current_company->getId()); if ($pseallf->getRecordCount() > 0) { $pseal_obj = $pseallf->getCurrent(); } // //Get all data for the form. // foreach ($quarter_dates as $quarter_id => $quarter_dates_arr) { //Get Pay Periods in date range. Debug::Text('Start Date: ' . TTDate::getDate('DATE+TIME', $quarter_dates_arr['start']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $quarter_dates_arr['end']), __FILE__, __LINE__, __METHOD__, 10); $pplf = new PayPeriodListFactory(); $pplf->getByCompanyIdAndTransactionStartDateAndTransactionEndDate($current_company->getId(), $quarter_dates_arr['start'], $quarter_dates_arr['end']); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { $pay_period_ids[] = $pp_obj->getID(); } } if (isset($pay_period_ids)) { $payments_over_cutoff = 7000; //PS Account Amounts... //Get employees who have recieved pay stubs. $pself = new PayStubEntryListFactory(); $pself->getReportByCompanyIdAndUserIdAndPayPeriodId($current_company->getId(), $filter_data['user_ids'], $pay_period_ids); if ($pself->getRecordCount() > 0) { foreach ($pself as $pse_obj) { $user_id = $pse_obj->getColumn('user_id'); //$pay_stub_entry_name_id = $pse_obj->getColumn('pay_stub_entry_name_id'); $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId();
function preSave() { $this->StartTransaction(); if ($this->isNew() == TRUE) { $this->setCreateInitialPayPeriods(TRUE); } if ($this->getShiftAssignedDay() == FALSE) { $this->setShiftAssignedDay(10); //Day shifts start on } elseif ($this->getShiftAssignedDay() == 40) { //Split at midnight $this->setNewDayTriggerTime(0); //Minimum Time-off between shifts must be 0 in these cases. } if ($this->getType() != 5) { //If schedule is other then manual, automatically calculate annual pay periods $this->setAnnualPayPeriods($this->calcAnnualPayPeriods()); } if ($this->getDeleted() == TRUE) { //Delete pay periods assigned to this schedule. $pplf = new PayPeriodListFactory(); $pplf->getByPayPeriodScheduleId($this->getId()); if ($pplf->getRecordCount() > 0) { Debug::text('Delete Pay Periods: ' . $pplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($pplf as $pp_obj) { $pp_obj->setDeleted(TRUE); $pp_obj->Save(); } } } return TRUE; }
function getByUserIdAndPayPeriodIdAndEndDate($user_id, $pay_period_id, $end_date = NULL) { if ($user_id == '') { return FALSE; } if ($pay_period_id == '') { return FALSE; } if ($end_date == NULL) { //Get pay period end date. $pplf = new PayPeriodListFactory(); $pplf->getById($pay_period_id); if ($pplf->getRecordCount() > 0) { $pp_obj = $pplf->getCurrent(); $end_date = $pp_obj->getEndDate(); } } $udf = new UserDateFactory(); $uwf = new UserWageFactory(); $otpf = new OverTimePolicyFactory(); $apf = new AbsencePolicyFactory(); $ppf = new PremiumPolicyFactory(); $ph = array('user_id' => $user_id, 'pay_period_id' => $pay_period_id, 'end_date' => $this->db->BindDate($end_date)); /* select a.status_id as status_id, a.type_id as type_id, a.over_time_policy_id as over_time_policy_id, a.absence_policy_id as absence_policy_id, a.premium_policy_id as premium_policy_id, z.id as user_wage_id, z.effective_date as user_wage_effective_date, sum(total_Time) as total_time from '. $this->getTable() .' as a LEFT JOIN '. $udf->getTable() .' as b ON a.user_date_id = b.id LEFT JOIN '. $uwf->getTable() .' as z ON z.id = (select z.id from '. $uwf->getTable() .' as z where z.user_id = b.user_id and z.effective_date <= b.date_stamp and z.deleted = 0 order by z.effective_date desc limit 1) where b.user_id = ? AND b.pay_period_id = ? AND b.date_stamp <= ? AND a.status_id in (10,30) AND ( a.deleted = 0 AND b.deleted = 0) group by user_wage_id, user_wage_effective_date, a.status_id, a.type_id, a.over_time_policy_id, a.absence_policy_id, a.premium_policy_id order by a.status_id desc, a.type_id asc, user_wage_effective_date desc */ //Order dock hours first, so it can be deducted from regular time. //Order newest wage changes first too. This is VERY important for calculating pro-rate amounts. $query = ' select a.status_id as status_id, a.type_id as type_id, a.over_time_policy_id as over_time_policy_id, n.id as over_time_policy_wage_id, n.effective_date as over_time_policy_wage_effective_date, a.absence_policy_id as absence_policy_id, p.id as absence_policy_wage_id, p.effective_date as absence_policy_wage_effective_date, a.premium_policy_id as premium_policy_id, r.id as premium_policy_wage_id, r.effective_date as premium_policy_wage_effective_date, z.id as user_wage_id, z.effective_date as user_wage_effective_date, sum(total_Time) as total_time from ' . $this->getTable() . ' as a LEFT JOIN ' . $udf->getTable() . ' as b ON a.user_date_id = b.id LEFT JOIN ' . $otpf->getTable() . ' as m ON a.over_time_policy_id = m.id LEFT JOIN ' . $uwf->getTable() . ' as n ON n.id = (select n.id from ' . $uwf->getTable() . ' as n where n.user_id = b.user_id and n.wage_group_id = m.wage_group_id and n.effective_date <= b.date_stamp and n.deleted = 0 order by n.effective_date desc limit 1) LEFT JOIN ' . $apf->getTable() . ' as o ON a.absence_policy_id = o.id LEFT JOIN ' . $uwf->getTable() . ' as p ON p.id = (select p.id from ' . $uwf->getTable() . ' as p where p.user_id = b.user_id and p.wage_group_id = o.wage_group_id and p.effective_date <= b.date_stamp and p.deleted = 0 order by p.effective_date desc limit 1) LEFT JOIN ' . $ppf->getTable() . ' as q ON a.premium_policy_id = q.id LEFT JOIN ' . $uwf->getTable() . ' as r ON r.id = (select r.id from ' . $uwf->getTable() . ' as r where r.user_id = b.user_id and r.wage_group_id = q.wage_group_id and r.effective_date <= b.date_stamp and r.deleted = 0 order by r.effective_date desc limit 1) LEFT JOIN ' . $uwf->getTable() . ' as z ON z.id = (select z.id from ' . $uwf->getTable() . ' as z where z.user_id = b.user_id and z.wage_group_id = 0 and z.effective_date <= b.date_stamp and z.deleted = 0 order by z.effective_date desc limit 1) where b.user_id = ? AND b.pay_period_id = ? AND b.date_stamp <= ? AND a.status_id in (10,30) AND ( a.deleted = 0 AND b.deleted = 0) group by user_wage_id, user_wage_effective_date, over_time_policy_wage_id, over_time_policy_wage_effective_date, absence_policy_wage_id, absence_policy_wage_effective_date, premium_policy_wage_id, premium_policy_wage_effective_date, a.status_id, a.type_id, a.over_time_policy_id, a.absence_policy_id, a.premium_policy_id order by a.status_id desc, a.type_id asc, user_wage_effective_date desc, over_time_policy_wage_effective_date desc, absence_policy_wage_effective_date desc, premium_policy_wage_effective_date desc '; $this->ExecuteSQL($query, $ph); return $this; }
function getAllPayPeriods() { $pplf = new PayPeriodListFactory(); //$pplf->getByCompanyId( $this->company_id ); $pplf->getByPayPeriodScheduleId($this->pay_period_schedule_id); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { Debug::text('Pay Period... Start: ' . TTDate::getDate('DATE+TIME', $pp_obj->getStartDate()) . ' End: ' . TTDate::getDate('DATE+TIME', $pp_obj->getEndDate()), __FILE__, __LINE__, __METHOD__, 10); $this->pay_period_objs[] = $pp_obj; } } $this->pay_period_objs = array_reverse($this->pay_period_objs); return TRUE; }
function getJSCalendarPayPeriodArray($include_all_pay_period_schedules = FALSE) { global $current_company, $current_user; if (!is_object($current_company)) { return FALSE; } if ($include_all_pay_period_schedules == TRUE) { $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_0'; } else { $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_' . $current_user->getId(); } if (!is_object($current_company)) { return FALSE; } if (!is_object($current_user)) { return FALSE; } $retarr = $this->getCache($cache_id); if ($retarr === FALSE) { $pplf = new PayPeriodListFactory(); if ($include_all_pay_period_schedules == TRUE) { $pplf->getByCompanyId($current_company->getId(), 13); $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_0'; } else { $pplf->getByUserId($current_user->getId(), 13); $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_' . $current_user->getId(); } $retarr = FALSE; if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { //$retarr['start_date'][] = TTDate::getDate('Ymd', $pp_obj->getStartDate() ); $retarr['end_date'][] = TTDate::getDate('Ymd', $pp_obj->getEndDate()); $retarr['transaction_date'][] = TTDate::getDate('Ymd', $pp_obj->getTransactionDate()); } } $this->saveCache($retarr, $cache_id); } return $retarr; }
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 getPayStubId() { //Find which pay period this effective date belongs too $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($this->getUser(), $this->getEffectiveDate()); if ($pplf->getRecordCount() > 0) { $pp_obj = $pplf->getCurrent(); Debug::text('Found Pay Period ID: ' . $pp_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //Percent PS amendments can't work on advances. $pslf = new PayStubListFactory(); $pslf->getByUserIdAndPayPeriodIdAndAdvance($this->getUser(), $pp_obj->getId(), FALSE); if ($pslf->getRecordCount() > 0) { $ps_obj = $pslf->getCurrent(); Debug::text('Found Pay Stub for this effective date: ' . $ps_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); return $ps_obj->getId(); } } return FALSE; }
function Validate() { //Make sure pay period isn't locked! if ($this->getPayPeriod() !== FALSE) { if ($this->getPayPeriodObject()->getIsLocked() == TRUE) { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Pay Period is Currently Locked')); } } //Make sure this is a UNIQUE user_date row. $this->Validator->isTRUE('date_stamp', $this->isUnique(), TTi18n::gettext('Employee can not have duplicate entries on the same day')); //Make sure the date isn't BEFORE the first pay period. $pplf = new PayPeriodListFactory(); $pplf->getByUserID($this->getUser(), NULL, NULL, NULL, array('a.start_date' => 'asc')); if ($pplf->getRecordCount() > 0) { $first_pp_obj = $pplf->getCurrent(); if ($this->getDateStamp() < $first_pp_obj->getStartDate()) { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Pay Period Missing') . '(b)'); } } else { $this->Validator->isTRUE('pay_period', FALSE, TTi18n::gettext('Pay Period Missing')); } return TRUE; }
$pdf->Cell(60, 4, $user_data['default_branch'], $border, 0, 'L'); $pdf->Ln(); $pdf->Cell(30, 4, TTi18n::gettext('Group:'), $border, 0, 'R'); $pdf->Cell(70, 4, $user_data['group'], $border, 0, 'L'); $pdf->Cell(40, 4, TTi18n::gettext('Department:'), $border, 0, 'R'); $pdf->Cell(60, 4, $user_data['default_department'], $border, 0, 'L'); $pdf->Ln(3); $pdf->SetFont('', '', 10); //Start displaying dates/times here. Start with header. $column_widths = array('line' => 5, 'date_stamp' => 20, 'dow' => 10, 'in_punch_time_stamp' => 20, 'out_punch_time_stamp' => 20, 'worked_time' => 15, 'paid_time' => 15, 'regular_time' => 15, 'over_time' => 37, 'absence_time' => 43); if (isset($user_data['data']) and is_array($user_data['data'])) { if (isset($filter_data['date_type']) and $filter_data['date_type'] == 'pay_period_ids') { //Fill in any missing days, only if they select by pay period. $pplf = new PayPeriodListFactory(); $pplf->getById($user_data['pay_period_id']); if ($pplf->getRecordCount() == 1) { $pp_obj = $pplf->getCurrent(); for ($d = TTDate::getBeginDayEpoch($pp_obj->getStartDate()); $d <= $pp_obj->getEndDate(); $d += 86400) { if (Misc::inArrayByKeyAndValue($user_data['data'], 'date_stamp', TTDate::getBeginDayEpoch($d)) == FALSE) { $user_data['data'][] = array('date_stamp' => TTDate::getBeginDayEpoch($d), 'in_punch_time' => NULL, 'out_punch_time' => NULL, 'worked_time' => NULL, 'regular_time' => NULL, 'over_time' => NULL, 'paid_time' => NULL, 'absence_time' => NULL); } } } } $user_data['data'] = Sort::Multisort($user_data['data'], 'date_stamp', NULL, 'ASC'); $week_totals = Misc::preSetArrayValues(NULL, array('worked_time', 'paid_time', 'absence_time', 'regular_time', 'over_time'), 0); $totals = array(); $totals = Misc::preSetArrayValues($totals, array('worked_time', 'paid_time', 'absence_time', 'regular_time', 'over_time'), 0); $i = 1; $x = 1; $y = 1;
function getPayPeriodObject() { if (is_object($this->pay_period_obj)) { return $this->pay_period_obj; } else { $pplf = new PayPeriodListFactory(); $pplf->getById($this->getPayPeriod()); if ($pplf->getRecordCount() > 0) { $this->pay_period_obj = $pplf->getCurrent(); return $this->pay_period_obj; } return FALSE; } }
function createPayStubAmendments($epoch = NULL) { //Get all recurring pay stub amendments and generate single pay stub amendments if appropriate. if ($epoch == '') { $epoch = TTDate::getTime(); } $ulf = new UserListFactory(); Debug::text('Recurring PS Amendment ID: ' . $this->getId() . ' Frequency: ' . $this->getFrequency(), __FILE__, __LINE__, __METHOD__, 10); $this->StartTransaction(); $tmp_user_ids = $this->getUser(); if ($tmp_user_ids[0] == -1) { $ulf->getByCompanyIdAndStatus($this->getCompany(), 10); foreach ($ulf as $user_obj) { $user_ids[] = $user_obj->getId(); } unset($user_obj); } else { $user_ids = $this->getUser(); } unset($tmp_user_ids); Debug::text('Total User IDs: ' . count($user_ids), __FILE__, __LINE__, __METHOD__, 10); if (is_array($user_ids) and count($user_ids) > 0) { //Make the PS amendment duplicate check start/end date separate //Make the PS amendment effective date separate. switch ($this->getFrequency()) { case 10: //Get all open pay periods $pplf = new PayPeriodListFactory(); //FIXME: Get all non-closed pay periods AFTER the start date. $pplf->getByUserIdListAndNotStatusAndStartDateAndEndDate($user_ids, 20, $this->getStartDate(), $this->getEndDate()); //All non-closed pay periods Debug::text('Found Open Pay Periods: ' . $pplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($pplf as $pay_period_obj) { Debug::text('Working on Pay Period: ' . $pay_period_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //If near the end of a pay period, or a pay period is already ended, add PS amendment if //it does not already exist. if ($epoch >= $pay_period_obj->getEndDate() and $this->checkTimeFrame($epoch)) { Debug::text('After end of pay period.', __FILE__, __LINE__, __METHOD__, 10); $psalf = new PayStubAmendmentListFactory(); //Loop through each user of this Pay Period Schedule adding PS amendments if they don't already exist. $pay_period_schedule_users = $pay_period_obj->getPayPeriodScheduleObject()->getUser(); Debug::text(' Pay Period Schedule Users: ' . count($pay_period_schedule_users), __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_period_schedule_users as $user_id) { //Make sure schedule user is in the PS amendment user list and user is active. Debug::text(' Pay Period Schedule User: '******' Recurring PS Amendment Selected Users: ', __FILE__, __LINE__, __METHOD__,10); if ($ulf->getById($user_id)->getCurrent()->getStatus() == 10 and in_array($user_id, $user_ids)) { //Check to see if the amendment was added already. if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $pay_period_obj->getStartDate(), $pay_period_obj->getEndDate())->getRecordCount() == 0) { //No amendment, good to insert one Debug::text('Inserting Recurring PS Amendment for User: '******'Recurring PS Amendment already inserted for User: '******'Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); //continue; } } } else { Debug::text('Not in TimeFrame, not inserting amendments: Epoch: ' . $epoch . ' Pay Period End Date: ' . $pay_period_obj->getEndDate(), __FILE__, __LINE__, __METHOD__, 10); } } break; case 30: //Weekly //Weekly case 40: //Monthly //Monthly case 70: //Annually switch ($this->getFrequency()) { case 30: $trigger_date = TTDate::getDateOfNextDayOfWeek(TTDate::getBeginWeekEpoch($epoch), $this->getStartDate()); $start_date = TTDate::getBeginWeekEpoch($epoch); $end_date = TTDate::getEndWeekEpoch($epoch); break; case 40: $trigger_date = TTDate::getDateOfNextDayOfMonth(TTDate::getBeginMonthEpoch($epoch), $this->getStartDate()); //$monthly_date = TTDate::getDateOfNextDayOfMonth( TTDate::getBeginMonthEpoch($epoch), $this->getStartDate() ); $start_date = TTDate::getBeginMonthEpoch($epoch); $end_date = TTDate::getEndMonthEpoch($epoch); break; case 70: $trigger_date = TTDate::getDateOfNextYear($this->getStartDate()); $start_date = TTDate::getBeginYearEpoch($epoch); $end_date = TTDate::getEndYearEpoch($epoch); break; } Debug::text('Trigger Date: ' . TTDate::getDate('DATE', $trigger_date), __FILE__, __LINE__, __METHOD__, 10); if ($epoch >= $trigger_date and $this->checkTimeFrame($epoch)) { Debug::text('After end of pay period.', __FILE__, __LINE__, __METHOD__, 10); foreach ($user_ids as $user_id) { //Make sure schedule user is in the PS amendment user list and user is active. if ($ulf->getById($user_id)->getCurrent()->getStatus() != 10 and !in_array($user_id, $user_ids)) { Debug::text('Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); continue; } $psalf = new PayStubAmendmentListFactory(); if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $start_date, $end_date)->getRecordCount() == 0) { //No amendment, good to insert one Debug::text('Inserting Recurring PS Amendment for User: '******'Recurring PS Amendment already inserted for User: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); } } } break; } } //$this->FailTransaction(); $this->CommitTransaction(); return TRUE; }
function addAccrualPolicyTime($epoch = NULL, $offset = 79200, $daily_total_time = NULL) { //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 = new 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 = new UserListFactory(); $ulf->getByIDAndCompanyID($user_id, $this->getCompany()); if ($ulf->getRecordCount() == 1) { $u_obj = $ulf->getCurrent(); Debug::Text('User: '******' Status: ' . $u_obj->getStatus(), __FILE__, __LINE__, __METHOD__, 10); //Make sure only active employees accrue time. Will this negative affect //Employees who may be on leave? if ($u_obj->getStatus() == 10 and ($this->getMinimumEmployedDays() == 0 or TTDate::getDays($epoch - $u_obj->getHireDate()) >= $this->getMinimumEmployedDays())) { Debug::Text(' User is active and has been employed long enough.', __FILE__, __LINE__, __METHOD__, 10); $annual_pay_periods = 0; $in_apply_frequency_window = FALSE; $accrual_balance = 0; $accrual_amount = 0; if ($this->getType() == 30) { Debug::Text(' Accrual policy is hour based, real-time window.', __FILE__, __LINE__, __METHOD__, 10); //Hour based, apply frequency is real-time. $in_apply_frequency_window = TRUE; } else { if ($this->getApplyFrequency() == 10) { //Because of pay period frequencies, and users being assigned to different //pay period schedules we need to get the last pay period of each user individually. //This will return the pay period that just ended in the offset time. $pplf = new PayPeriodListFactory(); $pplf->getByUserIdAndEndDate($user_id, $epoch - $offset); if ($pplf->getRecordCount() > 0) { foreach ($pplf as $pp_obj) { Debug::Text(' Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $pp_obj->getEndDate()), __FILE__, __LINE__, __METHOD__, 10); if ($this->inApplyFrequencyWindow($epoch, $offset, $pp_obj->getEndDate()) == TRUE) { $in_apply_frequency_window = TRUE; $annual_pay_periods = $pp_obj->getPayPeriodScheduleObject()->getAnnualPayPeriods(); break; } else { Debug::Text(' User not in Apply Frequency Window: ', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::Text(' No Pay Period Found.', __FILE__, __LINE__, __METHOD__, 10); } } elseif ($this->inApplyFrequencyWindow($epoch, $offset) == TRUE) { Debug::Text(' User IS in NON-PayPeriod Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10); $in_apply_frequency_window = TRUE; } else { Debug::Text(' User is not in Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10); $in_apply_frequency_window = FALSE; } } if ($in_apply_frequency_window == TRUE) { $milestone_obj = $this->getActiveMilestoneObject($u_obj, $epoch); if (isset($milestone_obj) and is_object($milestone_obj)) { Debug::Text(' Found Matching Milestone, Accrual Rate: (ID: ' . $milestone_obj->getId() . ') ' . $milestone_obj->getAccrualRate() . '/year', __FILE__, __LINE__, __METHOD__, 10); $accrual_balance = $this->getCurrentAccrualBalance($user_id, $this->getId()); if ($accrual_balance < $milestone_obj->getMaximumTime()) { $accrual_amount = $this->calcAccrualAmount($milestone_obj, 0, $annual_pay_periods); if ($accrual_amount > 0) { $new_accrual_balance = bcadd($accrual_balance, $accrual_amount); //If Maximum time is set to 0, make that unlimited. if ($milestone_obj->getMaximumTime() > 0 and $new_accrual_balance > $milestone_obj->getMaximumTime()) { $accrual_amount = bcsub($milestone_obj->getMaximumTime(), $accrual_balance, 0); } Debug::Text(' Min/Max Adjusted Accrual Amount: ' . $accrual_amount . ' Limits: Min: ' . $milestone_obj->getMinimumTime() . ' Max: ' . $milestone_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10); //Check to make sure there isn't an identical entry already made. $alf = new AccrualListFactory(); $alf->getByCompanyIdAndUserIdAndAccrualPolicyIDAndTimeStampAndAmount($u_obj->getCompany(), $user_id, $this->getId(), TTDate::getMiddleDayEpoch($epoch), $accrual_amount); if ($alf->getRecordCount() == 0) { //Round to nearest 1min $af = new AccrualFactory(); $af->setUser($user_id); $af->setType(75); //Accrual Policy $af->setAccrualPolicyID($this->getId()); $af->setAmount($accrual_amount); $af->setTimeStamp(TTDate::getMiddleDayEpoch($epoch)); $af->setEnableCalcBalance(TRUE); if ($af->isValid()) { $af->Save(); } } else { Debug::Text(' Found duplicate accrual entry, skipping...', __FILE__, __LINE__, __METHOD__, 10); } unset($accrual_amount, $accrual_balance, $new_accrual_balance); } else { Debug::Text(' Accrual Amount is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' Accrual Balance is outside Milestone Range. Skipping...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' DID NOT Find Matching Milestone.', __FILE__, __LINE__, __METHOD__, 10); } unset($milestone_obj); } } else { Debug::Text(' User is not active (Status: ' . $u_obj->getStatus() . ') or has only been employed: ' . TTDate::getDays($epoch - $u_obj->getHireDate()) . ' Days, not enough.', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text('No User Found. Company ID: ' . $this->getCompany(), __FILE__, __LINE__, __METHOD__, 10); } } } } } $pglf->CommitTransaction(); return TRUE; }