$user_data = $ulf->getCurrent();
 if (is_object($user_data->getCurrencyObject())) {
     $wage_data['currency_symbol'] = $user_data->getCurrencyObject()->getSymbol();
     $wage_data['iso_code'] = $user_data->getCurrencyObject()->getISOCode();
 }
 //Get pay period boundary dates for this user.
 //Include user hire date in the list.
 $pay_period_boundary_dates[TTDate::getDate('DATE', $user_data->getHireDate())] = TTi18n::gettext('(Hire Date)') . ' ' . TTDate::getDate('DATE', $user_data->getHireDate());
 $pay_period_boundary_dates = Misc::prependArray(array(-1 => TTi18n::gettext('(Choose Date)')), $pay_period_boundary_dates);
 $ppslf = new PayPeriodScheduleListFactory();
 $ppslf->getByUserId($user_id);
 if ($ppslf->getRecordCount() > 0) {
     $pay_period_schedule_id = $ppslf->getCurrent()->getId();
     $pay_period_schedule_name = $ppslf->getCurrent()->getName();
     Debug::Text('Pay Period Schedule ID: ' . $pay_period_schedule_id, __FILE__, __LINE__, __METHOD__, 10);
     $pplf = new PayPeriodListFactory();
     $pplf->getByPayPeriodScheduleId($pay_period_schedule_id, 10, NULL, NULL, array('transaction_date' => 'desc'));
     $pay_period_dates = NULL;
     foreach ($pplf as $pay_period_obj) {
         //$pay_period_boundary_dates[TTDate::getDate('DATE', $pay_period_obj->getEndDate() )] = '('. $pay_period_schedule_name .') '.TTDate::getDate('DATE', $pay_period_obj->getEndDate() );
         if (!isset($pay_period_boundary_dates[TTDate::getDate('DATE', $pay_period_obj->getStartDate())])) {
             $pay_period_boundary_dates[TTDate::getDate('DATE', $pay_period_obj->getStartDate())] = '(' . $pay_period_schedule_name . ') ' . TTDate::getDate('DATE', $pay_period_obj->getStartDate());
         }
     }
 } else {
     $smarty->assign('pay_period_schedule', FALSE);
     $uwf->Validator->isTrue('employee', FALSE, TTi18n::getText('Employee is not currently assigned to a pay period schedule.') . ' <a href="' . URLBuilder::getURL(NULL, '../payperiod/PayPeriodScheduleList.php') . '">' . TTi18n::getText('Click here</a> to assign'));
 }
 $smarty->assign_by_ref('user_data', $user_data);
 $smarty->assign_by_ref('wage_data', $wage_data);
 $smarty->assign_by_ref('tmp_effective_date', $tmp_effective_date);
 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;
 }
Exemple #3
0
 foreach ($ulf as $u_obj) {
     $filter_data['user_ids'][] = $u_obj->getId();
 }
 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');
 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 getAmountSumByUserIdAndEntryNameIdAndStartDateAndEndDate($id, $entry_name_id, $start_date = NULL, $end_date = NULL, $exclude_id = NULL, $where = NULL, $order = NULL)
    {
        if ($id == '') {
            return FALSE;
        }
        if ($entry_name_id == '') {
            return FALSE;
        }
        if ($start_date == '') {
            $start_date = 0;
        }
        if ($end_date == '') {
            $end_date = TTDate::getTime();
        }
        $pplf = new PayPeriodListFactory();
        $pslf = new PayStubListFactory();
        $ph = array('start_date' => $this->db->BindTimeStamp($start_date), 'end_date' => $this->db->BindTimeStamp($end_date), 'user_id' => $id, 'exclude_id' => (int) $exclude_id);
        $query = '
					select 	sum(amount) as amount, sum(units) as units
					from	' . $this->getTable() . ' as a,
							' . $pslf->getTable() . ' as b
					where	a.pay_stub_id = b.id
						AND b.pay_period_id in (select id from ' . $pplf->getTable() . ' as y
													where y.pay_period_schedule_id = ( select pay_period_schedule_id from ' . $pplf->getTable() . ' as z where z.id = b.pay_period_id ) AND y.start_date >= ? AND y.start_date < ? and y.deleted =0)
						AND b.user_id = ?
						AND a.id != ?
						AND	a.pay_stub_entry_name_id in (' . $this->getListSQL($entry_name_id, $ph) . ')
						AND a.deleted = 0
						AND b.deleted=0
				';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order);
        Debug::Text('Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10);
        $row = $this->db->GetRow($query, $ph);
        if ($row['amount'] === NULL) {
            $row['amount'] = 0;
        }
        if ($row['units'] === NULL) {
            $row['units'] = 0;
        }
        Debug::text('Over All Sum for ' . $entry_name_id . ': Amount ' . $row['amount'] . ' Units: ' . $row['units'], __FILE__, __LINE__, __METHOD__, 10);
        return $row;
    }
 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 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;
     }
 }
 	$pplf = new PayPeriodListFactory();
 	$pplf->getByIdAndCompanyId($pay_period_id, $current_company->getId() );
 	foreach ($pplf as $pay_period_obj) {
 		$pay_period_obj->setStatus(20);
 		$pay_period_obj->save();
 	}
 
 	Redirect::Page( URLBuilder::getURL( array('pay_period_id' => $pay_period_id), 'ViewPayPeriod') );
 
 	break;
 */
 default:
     if (isset($pay_period_id)) {
         BreadCrumb::setCrumb($title);
         $status_options = $ppf->getOptions('status');
         $pplf = new PayPeriodListFactory();
         $pplf->getByIdAndCompanyId($pay_period_id, $current_company->getId());
         foreach ($pplf as $pay_period_obj) {
             //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
             $pay_period_data = array('id' => $pay_period_obj->getId(), 'company_id' => $pay_period_obj->getCompany(), 'pay_period_schedule_id' => $pay_period_obj->getPayPeriodSchedule(), 'pay_period_schedule_type' => $pay_period_obj->getPayPeriodScheduleObject()->getType(), 'status_id' => $pay_period_obj->getStatus(), 'status' => $status_options[$pay_period_obj->getStatus()], 'start_date' => $pay_period_obj->getStartDate(), 'end_date' => $pay_period_obj->getEndDate(), 'transaction_date' => $pay_period_obj->getTransactionDate(), 'is_primary' => $pay_period_obj->getPrimary(), 'deleted' => $pay_period_obj->getDeleted(), 'tainted' => $pay_period_obj->getTainted(), 'tainted_date' => $pay_period_obj->getTaintedDate(), 'tainted_by' => $pay_period_obj->getTaintedBy(), 'created_date' => $pay_period_obj->getCreatedDate(), 'created_by' => $pay_period_obj->getCreatedBy(), 'updated_date' => $pay_period_obj->getUpdatedDate(), 'updated_by' => $pay_period_obj->getUpdatedBy(), 'deleted_date' => $pay_period_obj->getDeletedDate(), 'deleted_by' => $pay_period_obj->getDeletedBy());
         }
         Debug::Text('Current Pay Period Status: ' . $pay_period_obj->getStatus(), __FILE__, __LINE__, __METHOD__, 10);
         $status_options = $pay_period_obj->getOptions('status');
         if ($pay_period_obj->getStatus() == 20 or $pay_period_obj->getStatus() == 30) {
             //Once pay period is closed, do not allow it to re-open.
             $status_filter_arr = array(20, 30);
         } else {
             //Only allow to close pay period if AFTER end date.
             if (TTDate::getTime() >= $pay_period_obj->getEndDate()) {
                 $status_filter_arr = array(10, 12, $pay_period_obj->getStatus(), 20);
             } else {
    function getByCompanyIdAndPayPeriodId($company_id, $pay_period_id, $limit = NULL, $page = NULL, $where = NULL, $order = NULL)
    {
        if ($company_id == '') {
            return FALSE;
        }
        if ($pay_period_id == '') {
            return FALSE;
        }
        $strict_order = TRUE;
        if ($order == NULL or !is_array($order)) {
            $order = array('a.transaction_date' => 'desc', 'a.advance' => 'asc', 'b.last_name' => 'asc');
            $strict_order = FALSE;
        }
        $ulf = new UserListFactory();
        $pplf = new PayPeriodListFactory();
        $ph = array('company_id' => $company_id);
        $query = '
					select 	a.*
					from	' . $this->getTable() . ' as a,
							' . $ulf->getTable() . ' as b,
							' . $pplf->getTable() . ' as c
					where	a.user_id = b.id
						AND a.pay_period_id = c.id
						AND b.company_id = ?
						AND a.pay_period_id in (' . $this->getListSQL($pay_period_id, $ph) . ')
						AND a.deleted = 0';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order, $strict_order);
        if ($limit == NULL) {
            $this->rs = $this->db->Execute($query, $ph);
        } else {
            $this->rs = $this->db->PageExecute($query, $limit, $page, $ph);
        }
        //$this->rs = $this->db->Execute($query, $ph);
        return $this;
    }
 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('&nbsp;&nbsp;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('&nbsp;&nbsp;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('&nbsp;&nbsp;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('&nbsp;&nbsp;User not in Apply Frequency Window: ', __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                         }
                                     } else {
                                         Debug::Text('&nbsp;&nbsp; No Pay Period Found.', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } elseif ($this->inApplyFrequencyWindow($epoch, $offset) == TRUE) {
                                     Debug::Text('&nbsp;&nbsp;User IS in NON-PayPeriod Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10);
                                     $in_apply_frequency_window = TRUE;
                                 } else {
                                     Debug::Text('&nbsp;&nbsp;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('&nbsp;&nbsp;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('&nbsp;&nbsp; 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('&nbsp;&nbsp; Found duplicate accrual entry, skipping...', __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                             unset($accrual_amount, $accrual_balance, $new_accrual_balance);
                                         } else {
                                             Debug::Text('&nbsp;&nbsp; Accrual Amount is 0...', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     } else {
                                         Debug::Text('&nbsp;&nbsp; Accrual Balance is outside Milestone Range. Skipping...', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     Debug::Text('&nbsp;&nbsp;DID NOT Find Matching Milestone.', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                                 unset($milestone_obj);
                             }
                         } else {
                             Debug::Text('&nbsp;&nbsp;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;
 }
                 }
                 $pay_period_obj->Save();
             }
         }
     }
     $pplf->CommitTransaction();
     Redirect::Page(URLBuilder::getURL(NULL, 'ClosePayPeriod.php'));
     break;
 case 'generate_pay_stubs':
     Debug::Text('Generate Pay Stubs ', __FILE__, __LINE__, __METHOD__, 10);
     //var_dump($pay_stub_pay_period_ids);
     Redirect::Page(URLBuilder::getURL(array('action' => 'generate_paystubs', 'pay_period_ids' => $pay_stub_pay_period_ids, 'next_page' => '../payperiod/ClosePayPeriod.php'), '../progress_bar/ProgressBarControl.php'));
     break;
 default:
     //Step 1, get all open pay periods that have ended and are before the transaction date.
     $pplf = new PayPeriodListFactory();
     $ppslf = new PayPeriodScheduleListFactory();
     $open_pay_periods = FALSE;
     //$pplf->getByCompanyIdAndTransactionDate( $current_company->getId(), TTDate::getTime() );
     $pplf->getByCompanyIdAndStatus($current_company->getId(), array(10, 12, 15));
     if ($pplf->getRecordCount() > 0) {
         foreach ($pplf as $pay_period_obj) {
             $pay_period_schedule = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
             if ($pay_period_schedule != FALSE and $pay_period_obj->getEndDate() < TTDate::getTime()) {
                 $elf = new ExceptionListFactory();
                 $elf->getSumExceptionsByPayPeriodIdAndBeforeDate($pay_period_obj->getId(), $pay_period_obj->getEndDate());
                 $low_severity_exceptions = 0;
                 $med_severity_exceptions = 0;
                 $high_severity_exceptions = 0;
                 if ($elf->getRecordCount() > 0) {
                     Debug::Text(' Found Exceptions: ' . $elf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     unset($tmp_pay_period_obj);
 }
 //var_dump($pay_period_locked_rows);
 /*
 	Get TimeSheet verification
 */
 if (isset($pay_period_obj) and is_object($pay_period_obj)) {
     $pptsvlf = new PayPeriodTimeSheetVerifyListFactory();
     $pptsvlf->getByPayPeriodIdAndUserId($pay_period_obj->getId(), $user_id);
     if ($pptsvlf->getRecordCount() > 0) {
         $pptsv_obj = $pptsvlf->getCurrent();
         $time_sheet_verify = array('id' => $pptsv_obj->getId(), 'status_id' => $pptsv_obj->getStatus(), 'status' => Option::getByKey($pptsv_obj->getStatus(), $pptsv_obj->getOptions('status')), 'pay_period_id' => $pptsv_obj->getPayPeriod(), 'user_id' => $pptsv_obj->getUser(), 'created_date' => $pptsv_obj->getCreatedDate(), 'created_by' => $pptsv_obj->getCreatedBy(), 'updated_date' => $pptsv_obj->getUpdatedDate(), 'updated_by' => $pptsv_obj->getUpdatedBy(), 'deleted_date' => $pptsv_obj->getDeletedDate(), 'deleted_by' => $pptsv_obj->getDeletedBy());
     }
     //Check if previous pay period was verified or not
     $is_previous_time_sheet_verified = FALSE;
     $pplf = new PayPeriodListFactory();
     $pplf->getPreviousPayPeriodById($pay_period_obj->getId());
     if ($pplf->getRecordCount() > 0) {
         $previous_pay_period_obj = $pplf->getCurrent();
         if ($previous_pay_period_obj->getStatus() == 20) {
             $is_previous_time_sheet_verified = TRUE;
         } else {
             $pptsvlf = new PayPeriodTimeSheetVerifyListFactory();
             $pptsvlf->getByPayPeriodIdAndUserId($previous_pay_period_obj->getId(), $user_id);
             if ($pptsvlf->getRecordCount() > 0) {
                 $pptsv_obj = $pptsvlf->getCurrent();
                 if ($pptsv_obj->getAuthorized() == TRUE) {
                     $is_previous_time_sheet_verified = TRUE;
                 }
             }
         }
 function getPayStub($pslf = NULL, $hide_employer_rows = TRUE)
 {
     if (!is_object($pslf) and $this->getId() != '') {
         $pslf = new PayStubListFactory();
         $pslf->getById($this->getId());
     }
     if (get_class($pslf) !== 'PayStubListFactory') {
         return FALSE;
     }
     $border = 0;
     if ($pslf->getRecordCount() > 0) {
         $pdf = new TTPDF('P', 'mm', 'Letter');
         $pdf->setMargins(0, 0);
         //$pdf->SetAutoPageBreak(TRUE, 30);
         $pdf->SetAutoPageBreak(FALSE);
         $pdf->SetFont('freeserif', '', 10);
         //$pdf->SetFont('FreeSans','',10);
         $i = 0;
         foreach ($pslf as $pay_stub_obj) {
             $psealf = new PayStubEntryAccountListFactory();
             Debug::text($i . '. Pay Stub Transaction Date: ' . $pay_stub_obj->getTransactionDate(), __FILE__, __LINE__, __METHOD__, 10);
             //Get Pay Period information
             $pplf = new PayPeriodListFactory();
             $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
             //Use Pay Stub dates, not Pay Period dates.
             $pp_start_date = $pay_stub_obj->getStartDate();
             $pp_end_date = $pay_stub_obj->getEndDate();
             $pp_transaction_date = $pay_stub_obj->getTransactionDate();
             //Get pay period numbers
             $ppslf = new PayPeriodScheduleListFactory();
             $pay_period_schedule_obj = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
             //Get User information
             $ulf = new UserListFactory();
             $user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
             //Get company information
             $clf = new CompanyListFactory();
             $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
             //Change locale to users own locale.
             TTi18n::setCountry($user_obj->getCountry());
             TTi18n::setLanguage($user_obj->getUserPreferenceObject()->getLanguage());
             TTi18n::setLocale();
             //
             // Pay Stub Header
             //
             $pdf->AddPage();
             $adjust_x = 20;
             $adjust_y = 10;
             //Logo
             $pdf->Image($company_obj->getLogoFileName(), Misc::AdjustXY(0, $adjust_x + 0), Misc::AdjustXY(1, $adjust_y + 0), 50, 12, '', '', '', FALSE, 300, '', FALSE, FALSE, 0, TRUE);
             //Company name/address
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getName(), $border, 0, 'C');
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getAddress1() . ' ' . $company_obj->getAddress2(), $border, 0, 'C');
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getCity() . ', ' . $company_obj->getProvince() . ' ' . strtoupper($company_obj->getPostalCode()), $border, 0, 'C');
             //Pay Period info
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Pay Start Date:') . ' ', $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Pay End Date:') . ' ', $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Payment Date:') . ' ', $border, 0, 'R');
             $pdf->SetFont('', 'B', 10);
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_start_date), $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_end_date), $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_transaction_date), $border, 0, 'R');
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(17, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY(17, $adjust_y));
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(19, $adjust_y));
             $pdf->Cell(175, 5, TTi18n::gettext('STATEMENT OF EARNINGS AND DEDUCTIONS'), $border, 0, 'C', 0);
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(27, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY(27, $adjust_y));
             $pdf->setLineWidth(0.25);
             //Get pay stub entries.
             $pself = new PayStubEntryListFactory();
             $pself->getByPayStubId($pay_stub_obj->getId());
             Debug::text('Pay Stub Entries: ' . $pself->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             $prev_type = NULL;
             $description_subscript_counter = 1;
             foreach ($pself as $pay_stub_entry) {
                 Debug::text('Pay Stub Entry Account ID: ' . $pay_stub_entry->getPayStubEntryNameId(), __FILE__, __LINE__, __METHOD__, 10);
                 $description_subscript = NULL;
                 $pay_stub_entry_name_obj = $psealf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
                 //Use this to put the total for each type at the end of the array.
                 if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                     $type = $pay_stub_entry_name_obj->getType();
                 }
                 //Debug::text('Pay Stub Entry Name ID: '. $pay_stub_entry_name_obj->getId() .' Type ID: '. $pay_stub_entry_name_obj->getType() .' Type: '. $type, __FILE__, __LINE__, __METHOD__,10);
                 if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE and strlen($pay_stub_entry->getDescription()) > 0) {
                     $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                     $description_subscript = $description_subscript_counter;
                     $description_subscript_counter++;
                 }
                 //If type if 40 (a total) and the amount is 0, skip it.
                 //This if the employee has no deductions at all, it won't be displayed
                 //on the pay stub.
                 if ($type != 40 or $type == 40 and $pay_stub_entry->getAmount() != 0) {
                     $pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getName(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
                 }
                 $prev_type = $pay_stub_entry_name_obj->getType();
             }
             //There should always be pay stub entries for a pay stub.
             if (!isset($pay_stub_entries)) {
                 continue;
             }
             //Debug::Arr($pay_stub_entries, 'Pay Stub Entries...', __FILE__, __LINE__, __METHOD__,10);
             //$pay_period_number = $pay_period_schedule_obj->getCurrentPayPeriodNumber( $pay_period_obj->getTransactionDate(), $pay_period_obj->getEndDate() );
             $block_adjust_y = 30;
             //
             //Earnings
             //
             if (isset($pay_stub_entries[10])) {
                 //Earnings Header
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(90, 5, TTi18n::gettext('Earnings'), $border, 0, 'L');
                 $pdf->Cell(17, 5, TTi18n::gettext('Rate'), $border, 0, 'R');
                 $pdf->Cell(23, 5, TTi18n::gettext('Hrs/Units'), $border, 0, 'R');
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($pay_stub_entries[10] as $pay_stub_entry) {
                     if ($pay_stub_entry['type'] == 10) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(88, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         $pdf->Cell(17, 5, TTi18n::formatNumber($pay_stub_entry['rate'], TRUE), $border, 0, 'R');
                         $pdf->Cell(23, 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(110, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(131, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(90, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(17, 5, '', $border, 0, 'R');
                         $pdf->Cell(23, 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             // Deductions
             //
             if (isset($pay_stub_entries[20])) {
                 $max_deductions = count($pay_stub_entries[20]);
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                     $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                     $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                 } else {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(130, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                 }
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $tmp_block_adjust_y = $top_block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 $x = 0;
                 $max_block_adjust_y = 0;
                 foreach ($pay_stub_entries[20] as $pay_stub_entry) {
                     //Start with the right side.
                     if ($x < floor($max_deductions / 2)) {
                         $tmp_adjust_x = 90;
                     } else {
                         if ($tmp_block_adjust_y != 0) {
                             $block_adjust_y = $tmp_block_adjust_y;
                             $tmp_block_adjust_y = 0;
                         }
                         $tmp_adjust_x = 0;
                     }
                     if ($pay_stub_entry['type'] == 20) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         if ($max_deductions > 2) {
                             $pdf->setXY(Misc::AdjustXY(2, $tmp_adjust_x + $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         }
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(130, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                     if ($block_adjust_y > $max_block_adjust_y) {
                         $max_block_adjust_y = $block_adjust_y;
                     }
                     $x++;
                 }
                 //Draw line to separate the two columns
                 if ($max_deductions > 2) {
                     $pdf->Line(Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($top_block_adjust_y - 5, $adjust_y), Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($max_block_adjust_y - 5, $adjust_y));
                 }
                 unset($x, $max_deductions, $tmp_adjust_x, $max_block_adjust_y, $tmp_block_adjust_y, $top_block_adjust_y);
             }
             if (isset($pay_stub_entries[40][0])) {
                 $block_adjust_y = $block_adjust_y + 5;
                 //Net Pay entry
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(130, 5, $pay_stub_entries[40][0]['name'], $border, 0, 'L');
                 $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entries[40][0]['amount']), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entries[40][0]['ytd_amount']), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
             }
             //
             //Employer Contributions
             //
             //echo "Employee Ded: <br>\n";
             if (isset($pay_stub_entries[30]) and $hide_employer_rows != TRUE) {
                 $max_deductions = count($pay_stub_entries[30]);
                 //echo "Max Employee Ded: ". $max_deductions ."<br>\n";
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                     $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                     $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                 } else {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(130, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                 }
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $tmp_block_adjust_y = $top_block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 $x = 0;
                 $max_block_adjust_y = 0;
                 foreach ($pay_stub_entries[30] as $pay_stub_entry) {
                     //Start with the right side.
                     if ($x < floor($max_deductions / 2)) {
                         $tmp_adjust_x = 90;
                     } else {
                         if ($tmp_block_adjust_y != 0) {
                             $block_adjust_y = $tmp_block_adjust_y;
                             $tmp_block_adjust_y = 0;
                         }
                         $tmp_adjust_x = 0;
                     }
                     if ($pay_stub_entry['type'] == 30) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         if ($max_deductions > 2) {
                             $pdf->setXY(Misc::AdjustXY(2, $tmp_adjust_x + $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         }
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(130, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                     if ($block_adjust_y > $max_block_adjust_y) {
                         $max_block_adjust_y = $block_adjust_y;
                     }
                     $x++;
                 }
                 //Draw line to separate the two columns
                 if ($max_deductions > 2) {
                     $pdf->Line(Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($top_block_adjust_y - 5, $adjust_y), Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($max_block_adjust_y - 5, $adjust_y));
                 }
                 unset($x, $max_deductions, $tmp_adjust_x, $max_block_adjust_y, $tmp_block_adjust_y, $top_block_adjust_y);
             }
             //
             //Accruals PS accounts
             //
             if (isset($pay_stub_entries[50])) {
                 //Accrual Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(130, 5, TTi18n::gettext('Accruals'), $border, 0, 'L');
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('Balance'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($pay_stub_entries[50] as $pay_stub_entry) {
                     if ($pay_stub_entry['type'] == 50) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             //Accrual Policy Balances
             //
             $ablf = new AccrualBalanceListFactory();
             $ablf->getByUserIdAndCompanyIdAndEnablePayStubBalanceDisplay($user_obj->getId(), $user_obj->getCompany(), TRUE);
             if ($ablf->getRecordCount() > 0) {
                 //Accrual Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(40, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $accrual_time_header_start_x = $pdf->getX();
                 $accrual_time_header_start_y = $pdf->getY();
                 $pdf->Cell(70, 5, TTi18n::gettext('Accrual Time Balances as of ') . TTDate::getDate('DATE', time()), $border, 0, 'L');
                 $pdf->Cell(25, 5, TTi18n::gettext('Balance (hrs)'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $box_height = 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($ablf as $ab_obj) {
                     $balance = $ab_obj->getBalance();
                     if (!is_numeric($balance)) {
                         $balance = 0;
                     }
                     $pdf->setXY(Misc::AdjustXY(40, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(70, 5, $ab_obj->getColumn('name'), $border, 0, 'L');
                     $pdf->Cell(25, 5, TTi18n::formatNumber(TTDate::getHours($balance)), $border, 0, 'R');
                     $block_adjust_y = $block_adjust_y + 5;
                     $box_height = $box_height + 5;
                     unset($balance);
                 }
                 $pdf->Rect($accrual_time_header_start_x, $accrual_time_header_start_y, 95, $box_height);
                 unset($accrual_time_header_start_x, $accrual_time_header_start_y, $box_height);
             }
             //
             //Descriptions
             //
             if (isset($pay_stub_entry_descriptions) and count($pay_stub_entry_descriptions) > 0) {
                 //Description Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(175, 5, TTi18n::gettext('Notes'), $border, 0, 'L');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 8);
                 $x = 0;
                 foreach ($pay_stub_entry_descriptions as $pay_stub_entry_description) {
                     if ($x % 2 == 0) {
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     } else {
                         $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     }
                     //$pdf->Cell(173,5, '['.$pay_stub_entry_description['subscript'].'] '.$pay_stub_entry_description['description'], $border, 0, 'L');
                     $pdf->Cell(85, 5, '[' . $pay_stub_entry_description['subscript'] . '] ' . $pay_stub_entry_description['description'], $border, 0, 'L');
                     if ($x % 2 != 0) {
                         $block_adjust_y = $block_adjust_y + 5;
                     }
                     $x++;
                 }
             }
             unset($x, $pay_stub_entry_descriptions, $pay_stub_entry_description);
             //
             // Pay Stub Footer
             //
             $block_adjust_y = 215;
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY($block_adjust_y, $adjust_y));
             //Non Negotiable
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 3, $adjust_y));
             $pdf->Cell(175, 5, TTi18n::gettext('NON NEGOTIABLE'), $border, 0, 'C', 0);
             //Employee Address
             $pdf->SetFont('', 'B', 12);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 9, $adjust_y));
             $pdf->Cell(60, 5, TTi18n::gettext('CONFIDENTIAL'), $border, 0, 'C', 0);
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 14, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getFullName(), $border, 0, 'C', 0);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 19, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getAddress1(), $border, 0, 'C', 0);
             $address2_adjust_y = 0;
             if ($user_obj->getAddress2() != '') {
                 $address2_adjust_y = 5;
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 24, $adjust_y));
                 $pdf->Cell(60, 5, $user_obj->getAddress2(), $border, 0, 'C', 0);
             }
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 24 + $address2_adjust_y, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 1, 'C', 0);
             //Pay Period - Balance - ID
             $net_pay_amount = 0;
             if (isset($pay_stub_entries[40][0])) {
                 $net_pay_amount = $pay_stub_entries[40][0]['amount'];
             }
             if (isset($pay_stub_entries[65]) and count($pay_stub_entries[65]) > 0) {
                 $net_pay_label = TTi18n::gettext('Balance');
             } else {
                 $net_pay_label = TTi18n::gettext('Net Pay');
             }
             /*
             if ( $pay_period_schedule_obj->getType() != 5 AND $pay_period_number > 0 AND $pay_period_schedule_obj->getAnnualPayPeriods() > 0 ) {
             	$pdf->setXY( Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y+10, $adjust_y) );
             	$pdf->Cell(50, 5, TTi18n::gettext('Pay Period').' '. $pay_period_number .' '. TTi18n::gettext('of') .' '. $pay_period_schedule_obj->getAnnualPayPeriods(), $border, 1, 'L', 0);
             }
             */
             $pdf->SetFont('', 'B', 12);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y + 17, $adjust_y));
             $pdf->Cell(50, 5, $net_pay_label . ': ' . $pay_stub_obj->getCurrencyObject()->getSymbol() . $net_pay_amount . ' ' . $pay_stub_obj->getCurrencyObject()->getISOCode(), $border, 1, 'L', 0);
             if ($pay_stub_obj->getTainted() == TRUE) {
                 $tainted_flag = 'T';
             } else {
                 $tainted_flag = '';
             }
             $pdf->SetFont('', '', 8);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y + 30, $adjust_y));
             $pdf->Cell(50, 5, TTi18n::gettext('Identification #:') . ' ' . str_pad($pay_stub_obj->getId(), 12, 0, STR_PAD_LEFT) . $tainted_flag, $border, 1, 'L', 0);
             unset($net_pay_amount, $tainted_flag);
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 35, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY($block_adjust_y + 35, $adjust_y));
             $pdf->SetFont('', '', 6);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 38, $adjust_y));
             $pdf->Cell(175, 1, TTi18n::gettext('Pay Stub Generated by') . ' ' . APPLICATION_NAME, $border, 0, 'C', 0);
             unset($pay_period_schedule_obj, $pay_stub_entries, $pay_period_number);
             $i++;
         }
         $output = $pdf->Output('', 'S');
     }
     TTi18n::setMasterLocale();
     if (isset($output)) {
         return $output;
     }
     return FALSE;
 }
//Get all pay periods
$pplf = new PayPeriodListFactory();
$pplf->getPayPeriodsWithPayStubsByCompanyId($current_company->getId());
$pay_period_options = array();
if ($pplf->getRecordCount() > 0) {
    $pp = 0;
    foreach ($pplf as $pay_period_obj) {
        $pay_period_ids[] = $pay_period_obj->getId();
        $pay_period_end_dates[$pay_period_obj->getId()] = $pay_period_obj->getEndDate();
        if ($pp == 0) {
            $default_transaction_start_date = $pay_period_obj->getEndDate();
            $default_transaction_end_date = $pay_period_obj->getTransactionDate() + 86400;
        }
        $pp++;
    }
    $pplf = new PayPeriodListFactory();
    $pay_period_options = $pplf->getByIdListArray($pay_period_ids, NULL, array('start_date' => 'desc'));
}
if (isset($filter_data['transaction_start_date'])) {
    $filter_data['transaction_start_date'] = TTDate::getBeginDayEpoch(TTDate::parseDateTime($filter_data['transaction_start_date']));
}
if (isset($filter_data['transaction_end_date'])) {
    $filter_data['transaction_end_date'] = TTDate::getEndDayEpoch(TTDate::parseDateTime($filter_data['transaction_end_date']));
}
$filter_data = Misc::preSetArrayValues($filter_data, array('include_user_ids', 'exclude_user_ids', 'user_status_ids', 'group_ids', 'branch_ids', 'department_ids', 'user_title_ids', 'currency_ids', 'pay_period_ids', 'column_ids'), array());
//Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
$permission_children_ids = array();
if ($permission->Check('pay_stub', 'view') == FALSE) {
    $hlf = new HierarchyListFactory();
    $permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($current_company->getId(), $current_user->getId());
    Debug::Arr($permission_children_ids, 'Permission Children Ids:', __FILE__, __LINE__, __METHOD__, 10);
 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 getData()
 {
     $psenlf = new PayStubEntryNameListFactory();
     $pslf = new PayStubListFactory();
     //$pslf->getByIdAndUserId($id, $current_user->getId(), $current_user_prefs->getItemsPerPage(), $page, NULL, array($sort_column => $sort_order) );
     $pslf->getById($this->pay_stub_id);
     $pager = new Pager($pslf);
     foreach ($pslf as $pay_stub_obj) {
         //Get pay stub entries.
         $pself = new PayStubEntryListFactory();
         $pself->getByPayStubId($pay_stub_obj->getId());
         $prev_type = NULL;
         $description_subscript_counter = 1;
         foreach ($pself as $pay_stub_entry) {
             $description_subscript = NULL;
             $pay_stub_entry_name_obj = $psenlf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
             if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                 $type = $pay_stub_entry_name_obj->getType();
             }
             if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE) {
                 $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                 $description_subscript = $description_subscript_counter;
                 $description_subscript_counter++;
             }
             $this->pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getDescription(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
             $prev_type = $pay_stub_entry_name_obj->getType();
         }
         //'entries' => $pay_stub_entries,
         $this->pay_stub = array('id' => $pay_stub_obj->getId(), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'advance' => $pay_stub_obj->getAdvance(), 'status' => $pay_stub_obj->getStatus(), 'created_date' => $pay_stub_obj->getCreatedDate(), 'created_by' => $pay_stub_obj->getCreatedBy(), 'updated_date' => $pay_stub_obj->getUpdatedDate(), 'updated_by' => $pay_stub_obj->getUpdatedBy(), 'deleted_date' => $pay_stub_obj->getDeletedDate(), 'deleted_by' => $pay_stub_obj->getDeletedBy());
         //Get Pay Period information
         $pplf = new PayPeriodListFactory();
         $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
         if ($pay_stub_obj->getAdvance() == TRUE) {
             $pp_start_date = $pay_period_obj->getStartDate();
             $pp_end_date = $pay_period_obj->getAdvanceEndDate();
             $pp_transaction_date = $pay_period_obj->getAdvanceTransactionDate();
         } else {
             $pp_start_date = $pay_period_obj->getStartDate();
             $pp_end_date = $pay_period_obj->getEndDate();
             $pp_transaction_date = $pay_period_obj->getTransactionDate();
         }
         $this->pay_period = array('start_date' => TTDate::getDate('DATE', $pp_start_date), 'end_date' => TTDate::getDate('DATE', $pp_end_date), 'transaction_date' => TTDate::getDate('DATE', $pp_transaction_date));
         //Get User information
         $ulf = new UserListFactory();
         $this->user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
         //Get company information
         $clf = new CompanyListFactory();
         $this->company_obj = $clf->getById($this->user_obj->getCompany())->getCurrent();
     }
 }
         $description_subscript_counter++;
     }
     $pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getName(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
     //Only for net pay, make a total YTD of Advance plus Net.
     /*
     if ( $type == 40 ) {
     	$pay_stub_entries[$type][0]['ytd_net_plus_advance'] =
     }
     */
     $prev_type = $pay_stub_entry_name_obj->getType();
 }
 $pay_stub = array('id' => $pay_stub_obj->getId(), 'display_id' => str_pad($pay_stub_obj->getId(), 12, 0, STR_PAD_LEFT), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'start_date' => $pay_stub_obj->getStartDate(), 'end_date' => $pay_stub_obj->getEndDate(), 'transaction_date' => $pay_stub_obj->getTransactionDate(), 'advance' => $pay_stub_obj->getAdvance(), 'status' => $pay_stub_obj->getStatus(), 'entries' => $pay_stub_entries, 'tainted' => $pay_stub_obj->getTainted(), 'created_date' => $pay_stub_obj->getCreatedDate(), 'created_by' => $pay_stub_obj->getCreatedBy(), 'updated_date' => $pay_stub_obj->getUpdatedDate(), 'updated_by' => $pay_stub_obj->getUpdatedBy(), 'deleted_date' => $pay_stub_obj->getDeletedDate(), 'deleted_by' => $pay_stub_obj->getDeletedBy());
 unset($pay_stub_entries);
 Debug::text($i . '. Pay Stub Transaction Date: ' . $pay_stub_obj->getTransactionDate(), __FILE__, __LINE__, __METHOD__, 10);
 //Get Pay Period information
 $pplf = new PayPeriodListFactory();
 $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
 if ($pay_stub_obj->getAdvance() == TRUE) {
     $pp_start_date = $pay_period_obj->getStartDate();
     $pp_end_date = $pay_period_obj->getAdvanceEndDate();
     $pp_transaction_date = $pay_period_obj->getAdvanceTransactionDate();
 } else {
     $pp_start_date = $pay_period_obj->getStartDate();
     $pp_end_date = $pay_period_obj->getEndDate();
     $pp_transaction_date = $pay_period_obj->getTransactionDate();
 }
 //Get pay period numbers
 $ppslf = new PayPeriodScheduleListFactory();
 $pay_period_schedule_obj = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
 $pay_period_data = array('advance' => $pay_stub_obj->getAdvance(), 'start_date' => TTDate::getDate('DATE', $pp_start_date), 'end_date' => TTDate::getDate('DATE', $pp_end_date), 'transaction_date' => TTDate::getDate('DATE', $pp_transaction_date), 'annual_pay_periods' => $pay_period_schedule_obj->getAnnualPayPeriods());
 //Get User information
 function reCalculate()
 {
     //Re-generate final pay stub
     //get current pay period based off their last day of work
     $pplf = new PayPeriodListFactory();
     $pay_period_id = $pplf->getByUserIdAndEndDate($this->getUser(), $this->getLastDate())->getCurrent()->getId();
     Debug::Text('Pay Period ID: ' . $pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
     if (is_numeric($pay_period_id) == FALSE) {
         UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Pay Stub'), 10, TTi18n::gettext('Pay Period is invalid!'), NULL);
         return FALSE;
     }
     if ($this->getEnableGeneratePayStub() == TRUE) {
         //Find out if a pay stub is already generated for the pay period we are currently in.
         //If it is, delete it so we can start from fresh
         $pslf = new PayStubListFactory();
         $pslf->getByUserIdAndPayPeriodId($this->getUser(), $pay_period_id);
         foreach ($pslf as $pay_stub) {
             Debug::Text('Found Pay Stub ID: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10);
             //Do not delete PAID pay stubs!
             if ($pay_stub->getStatus() == 10) {
                 Debug::Text('Last Pay Stub Exists: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 $pay_stub->setDeleted(TRUE);
                 $pay_stub->Save();
             }
         }
         //FIXME: Make sure user isn't already in-active! Otherwise pay stub won't generate.
         //Check if pay stub is already generated as well, if it is, and marked paid, then
         //we can't re-generate it, we need to skip this step.
         Debug::Text('Calculating Pay Stub...', __FILE__, __LINE__, __METHOD__, 10);
         $cps = new CalculatePayStub();
         $cps->setUser($this->getUser());
         $cps->setPayPeriod($pay_period_id);
         $cps->calculate();
         Debug::Text('Done Calculating Pay Stub', __FILE__, __LINE__, __METHOD__, 10);
     } else {
         UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE), 20, TTi18n::gettext('Not generating final pay stub!'), NULL);
     }
     //FIXME: Alert the user if they don't have enough information in TimeTrex to get accurate values.
     //Get insurable hours, earnings, and vacation pay now that the final pay stub is generated
     $ugdlf = new UserGenericDataListFactory();
     $ugdlf->getByCompanyIdAndScriptAndDefault($this->getUserObject()->getCompany(), $this->getTable());
     if ($ugdlf->getRecordCount() > 0) {
         Debug::Text('Found Company Form Setup!', __FILE__, __LINE__, __METHOD__, 10);
         $ugd_obj = $ugdlf->getCurrent();
         $setup_data = $ugd_obj->getData();
     }
     unset($ugd_obj);
     if (isset($setup_data)) {
         //var_dump($setup_data);
         if (isset($setup_data['insurable_earnings_psea_ids'])) {
             $insurable_earnings_psea_ids = $setup_data['insurable_earnings_psea_ids'];
         } else {
             //Fall back to Total Gross.
             $insurable_earnings_psea_ids = $this->getPayStubEntryAccountLinkObject()->getTotalGross();
         }
     }
     //Find out the date of how far back we have to go to get insurable values.
     //Insurable Hours
     $insurable_hours_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableHoursReportPayPeriods());
     //Insurable hours dont include stats!Just get total signed in hours.
     //If someone has just a negative bank time balance, those are NOT insurable.
     $udtlf = new UserDateTotalListFactory();
     $worked_total_time = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($this->getUser(), $insurable_hours_start_date, $this->getLastDate());
     Debug::text('Worked Total Time: ' . $worked_total_time, __FILE__, __LINE__, __METHOD__, 10);
     $total_hours = Misc::MoneyFormat(TTDate::getHours($worked_total_time), FALSE);
     Debug::Text('Total Insurable Hours: ' . $total_hours, __FILE__, __LINE__, __METHOD__, 10);
     $insurable_earnings_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableEarningsReportPayPeriods());
     $pself = new PayStubEntryListFactory();
     $total_earnings = $this->getTotalInsurableEarnings();
     //$total_earnings = $pself->getAmountSumByUserIdAndEntryNameIdAndStartDateAndEndDate( $this->getUser(), $insurable_earnings_psea_ids, $insurable_earnings_start_date, $this->getLastDate(), 0 );
     //$total_earnings = $total_earnings['amount'];
     //Note, this includes the current pay stub we just generated
     Debug::Text('Total Insurable Earnings: ' . $total_earnings, __FILE__, __LINE__, __METHOD__, 10);
     UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Record of Employment'), 30, TTi18n::gettext('Insurable Hours:') . ' ' . $total_hours . ' ' . TTi18n::gettext('Insurable Earnings:') . ' ' . $total_earnings, NULL);
     //ReSave these
     if ($this->getId() != '') {
         $rlf = new ROEListFactory();
         $rlf->getById($this->getId());
         if ($rlf->getRecordCount() > 0) {
             $roe_obj = $rlf->getCurrent();
             $roe_obj->setInsurableHours($total_hours);
             $roe_obj->setInsurableEarnings($total_earnings);
             if ($roe_obj->isValid()) {
                 $roe_obj->Save();
             }
         }
     }
     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;
 }
     echo "Pay Period Date not specified, assuming: Last\n";
 }
 if (isset($argv[$last_arg]) and $argv[$last_arg] != '') {
     if (!file_exists($argv[$last_arg]) or !is_writable($argv[$last_arg])) {
         echo "Output Directory: " . $argv[$last_arg] . " does not exists or is not writable!\n";
         exit;
     } else {
         $output_directory = $argv[$last_arg];
     }
 }
 if ($date_type != 'last') {
     echo "Searching for Pay Period " . ucfirst($date_type) . " Date: " . TTDate::getDate('DATE', $pay_period_date) . "...\n";
 } else {
     echo "Searching for Last Pay Period...\n";
 }
 $pplf = new PayPeriodListFactory();
 $pplf->getPayPeriodsWithPayStubsByCompanyId($company_id, NULL, array('a.start_date' => 'desc'));
 if ($pplf->getRecordCount() > 0) {
     $x = 0;
     $found_pay_period = FALSE;
     foreach ($pplf as $pp_obj) {
         if ($date_type == 'start' and TTDate::getBeginDayEpoch($pp_obj->getStartDate()) == $pay_period_date) {
             $found_pay_period = TRUE;
         } elseif ($date_type == 'end' and TTDate::getBeginDayEpoch($pp_obj->getEndDate()) == $pay_period_date) {
             $found_pay_period = TRUE;
         } elseif ($date_type == 'transaction' and TTDate::getBeginDayEpoch($pp_obj->getTransactionDate()) == $pay_period_date) {
             $found_pay_period = TRUE;
         } elseif ($date_type == 'last') {
             //Last pay period
             $found_pay_period = TRUE;
         }
Exemple #23
0
 }
 URLBuilder::setURL($_SERVER['SCRIPT_NAME'], array('sort_column' => Misc::trimSortPrefix($sort_column), 'sort_order' => $sort_order, 'saved_search_id' => $saved_search_id, 'page' => $page));
 $ulf = new UserListFactory();
 $plf = new PunchListFactory();
 $hlf = new HierarchyListFactory();
 $permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($current_company->getId(), $current_user->getId());
 //Debug::Arr($permission_children_ids,'Permission Children Ids:', __FILE__, __LINE__, __METHOD__,10);
 if ($permission->Check('punch', 'view') == FALSE) {
     if ($permission->Check('punch', 'view_child')) {
         $filter_data['permission_children_ids'] = $permission_children_ids;
     }
     if ($permission->Check('punch', 'view_own')) {
         $filter_data['permission_children_ids'][] = $current_user->getId();
     }
 }
 $pplf = new PayPeriodListFactory();
 $pplf->getByCompanyId($current_company->getId());
 $pay_period_options = $pplf->getArrayByListFactory($pplf, FALSE, FALSE);
 $pay_period_ids = array_keys((array) $pay_period_options);
 if (isset($pay_period_ids[0]) and (!isset($filter_data['pay_period_ids']) or $filter_data['pay_period_ids'] == '')) {
     $filter_data['pay_period_ids'] = '-1';
 }
 //Order In punches before Out punches.
 $sort_array = Misc::prependArray($sort_array, array('c.pay_period_id' => 'asc', 'c.user_id' => 'asc', 'a.time_stamp' => 'asc', 'a.punch_control_id' => 'asc', 'a.status_id' => 'desc'));
 $plf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
 $pager = new Pager($plf);
 $punch_status_options = $plf->getOptions('status');
 $punch_type_options = $plf->getOptions('type');
 $utlf = new UserTitleListFactory();
 $utlf->getByCompanyId($current_company->getId());
 $title_options = $utlf->getArrayByListFactory($utlf, FALSE, TRUE);
Exemple #24
0
 }
 if (isset($filter_data['user_ids']) and isset($filter_data['year'])) {
     if (isset($filter_data['year'])) {
         $year_epoch = mktime(0, 0, 0, 1, 1, $filter_data['year']);
         Debug::Text(' Year: ' . TTDate::getDate('DATE+TIME', $year_epoch), __FILE__, __LINE__, __METHOD__, 10);
     }
     $pseallf = new PayStubEntryAccountLinkListFactory();
     $pseallf->getByCompanyId($current_company->getId());
     if ($pseallf->getRecordCount() > 0) {
         $pseal_obj = $pseallf->getCurrent();
     }
     //
     //Get all data for the form.
     //
     //Get Pay Periods in date range.
     $pplf = new PayPeriodListFactory();
     $pplf->getByCompanyIdAndTransactionStartDateAndTransactionEndDate($current_company->getId(), TTDate::getBeginYearEpoch($year_epoch), TTDate::getEndYearEpoch($year_epoch));
     if ($pplf->getRecordCount() > 0) {
         foreach ($pplf as $pp_obj) {
             $pay_period_ids[] = $pp_obj->getID();
         }
     }
     $report_columns = $static_columns;
     $pself = new PayStubEntryListFactory();
     $pself->getReportByCompanyIdAndUserIdAndPayPeriodId($current_company->getId(), $filter_data['user_ids'], $pay_period_ids);
     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');
         $raw_rows[$user_id][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount');
     }
     //var_dump($raw_rows);
Exemple #25
0
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'setup_data', 'generic_data', 'filter_data')));
URLBuilder::setURL($_SERVER['SCRIPT_NAME'], array('filter_data' => $filter_data));
$static_columns = array('-1000-full_name' => TTi18n::gettext('Full Name'), '-1010-title' => TTi18n::gettext('Title'), '-1020-province' => TTi18n::gettext('Province'), '-1030-country' => TTi18n::gettext('Country'), '-1039-group' => TTi18n::gettext('Group'), '-1040-default_branch' => TTi18n::gettext('Default Branch'), '-1050-default_department' => TTi18n::gettext('Default Department'), '-1060-sin' => TTi18n::gettext('SIN'));
$non_static_columns = array('-1100-income' => TTi18n::gettext('Income (14)'), '-1110-income_tax' => TTi18n::gettext('Income Tax (22)'), '-1120-employee_cpp' => TTi18n::gettext('Employee CPP (16)'), '-1125-ei_earnings' => TTi18n::gettext('EI Insurable Earnings (24)'), '-1126-cpp_earnings' => TTi18n::gettext('CPP Pensionable Earnings (26)'), '-1130-employee_ei' => TTi18n::gettext('Employee EI (18)'), '-1140-union_dues' => TTi18n::gettext('Union Dues (44)'), '-1150-employer_cpp' => TTi18n::gettext('Employer CPP'), '-1160-employer_ei' => TTi18n::gettext('Employer EI'), '-1170-rpp' => TTi18n::gettext('RPP Contributions (20)'), '-1180-charity' => TTi18n::gettext('Charity Donations (46)'), '-1190-pension_adjustment' => TTi18n::gettext('Pension Adjustment (52)'), '-1200-other_box_0' => TTi18n::gettext('Other Box 1'), '-1210-other_box_1' => TTi18n::gettext('Other Box 2'), '-1220-other_box_2' => TTi18n::gettext('Other Box 3'), '-1220-other_box_3' => TTi18n::gettext('Other Box 4'), '-1220-other_box_4' => TTi18n::gettext('Other Box 5'), '-1220-other_box_5' => TTi18n::gettext('Other Box 6'));
$pseallf = new PayStubEntryAccountLinkListFactory();
$pseallf->getByCompanyId($current_company->getId());
if ($pseallf->getRecordCount() > 0) {
    $pseal_obj = $pseallf->getCurrent();
}
$column_ps_entry_name_map = array('income' => @$setup_data['income_psea_ids'], 'income_tax' => @$setup_data['tax_psea_ids'], 'employee_cpp' => @$setup_data['employee_cpp_psea_id'], 'employee_ei' => @$setup_data['employee_ei_psea_id'], 'ei_earnings' => @$setup_data['ei_earnings_psea_ids'], 'cpp_earnings' => @$setup_data['cpp_earnings_psea_ids'], 'union_dues' => @$setup_data['union_dues_psea_id'], 'employer_cpp' => @$setup_data['employer_cpp_psea_id'], 'employer_ei' => @$setup_data['employer_ei_psea_id'], 'rpp' => @$setup_data['rpp_psea_ids'], 'charity' => @$setup_data['charity_psea_ids'], 'pension_adjustment' => @$setup_data['pension_adjustment_psea_ids'], 'other_box_0' => @$setup_data['other_box'][0]['psea_ids'], 'other_box_1' => @$setup_data['other_box'][1]['psea_ids'], 'other_box_2' => @$setup_data['other_box'][2]['psea_ids'], 'other_box_3' => @$setup_data['other_box'][3]['psea_ids'], 'other_box_4' => @$setup_data['other_box'][4]['psea_ids'], 'other_box_5' => @$setup_data['other_box'][5]['psea_ids']);
$columns = Misc::prependArray($static_columns, $non_static_columns);
$pplf = new PayPeriodListFactory();
$year_options = $pplf->getYearsArrayByCompanyId($current_company->getId());
$ugdlf = new UserGenericDataListFactory();
$ugdf = new UserGenericDataFactory();
$filter_data = Misc::preSetArrayValues($filter_data, array('include_user_ids', 'exclude_user_ids', 'user_status_ids', 'group_ids', 'branch_ids', 'department_ids', 'user_title_ids', 'pay_period_ids', 'column_ids'), array());
$action = Misc::findSubmitButton();
Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10);
switch ($action) {
    case 'display_t4s':
    case 'display_report':
        //Debug::setVerbosity(11);
        Debug::Text('Submit!: ' . $action, __FILE__, __LINE__, __METHOD__, 10);
        //Debug::Arr($filter_data, 'aFilter Data', __FILE__, __LINE__, __METHOD__,10);
        //Save report setup data
        $ugdlf->getByCompanyIdAndScriptAndDefault($current_company->getId(), $_SERVER['SCRIPT_NAME']);
        if ($ugdlf->getRecordCount() > 0) {
 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;
 }
 $filter_data['src_branch_options'] = Misc::arrayDiffByKey((array) $filter_data['branch_ids'], $branch_options);
 $filter_data['selected_branch_options'] = Misc::arrayIntersectByKey((array) $filter_data['branch_ids'], $branch_options);
 //Get departments
 $dlf = new DepartmentListFactory();
 $dlf->getByCompanyId($current_company->getId());
 $department_options = Misc::prependArray($all_array_option, $dlf->getArrayByListFactory($dlf, FALSE, TRUE));
 $filter_data['src_department_options'] = Misc::arrayDiffByKey((array) $filter_data['department_ids'], $department_options);
 $filter_data['selected_department_options'] = Misc::arrayIntersectByKey((array) $filter_data['department_ids'], $department_options);
 //Get employee titles
 $utlf = new UserTitleListFactory();
 $utlf->getByCompanyId($current_company->getId());
 $user_title_options = Misc::prependArray($all_array_option, $utlf->getArrayByListFactory($utlf, FALSE, TRUE));
 $filter_data['src_user_title_options'] = Misc::arrayDiffByKey((array) $filter_data['user_title_ids'], $user_title_options);
 $filter_data['selected_user_title_options'] = Misc::arrayIntersectByKey((array) $filter_data['user_title_ids'], $user_title_options);
 //Get pay periods
 $pplf = new PayPeriodListFactory();
 $pplf->getByCompanyId($current_company->getId());
 $pay_period_options = Misc::prependArray($all_array_option, $pplf->getArrayByListFactory($pplf, FALSE, TRUE));
 $filter_data['src_pay_period_options'] = Misc::arrayDiffByKey((array) $filter_data['pay_period_ids'], $pay_period_options);
 $filter_data['selected_pay_period_options'] = Misc::arrayIntersectByKey((array) $filter_data['pay_period_ids'], $pay_period_options);
 //Get currencies
 $crlf = new CurrencyListFactory();
 $crlf->getByCompanyId($current_company->getId());
 $currency_options = Misc::prependArray($all_array_option, $crlf->getArrayByListFactory($crlf, FALSE, TRUE));
 $filter_data['src_currency_options'] = Misc::arrayDiffByKey((array) $filter_data['currency_ids'], $currency_options);
 $filter_data['selected_currency_options'] = Misc::arrayIntersectByKey((array) $filter_data['currency_ids'], $currency_options);
 //Get column list
 $filter_data['src_column_options'] = Misc::arrayDiffByKey((array) $filter_data['column_ids'], $columns);
 $filter_data['selected_column_options'] = Misc::arrayIntersectByKey((array) $filter_data['column_ids'], $columns);
 //Get primary/secondary order list
 $filter_data['sort_options'] = $columns;
 function setPayPeriod($id = NULL)
 {
     $id = trim($id);
     if ($id == NULL) {
         $id = $this->findPayPeriod();
     }
     $pplf = new PayPeriodListFactory();
     if ($this->Validator->isResultSetWithRows('pay_period', $pplf->getByID($id), TTi18n::gettext('Invalid Pay Period'))) {
         $this->data['pay_period_id'] = $id;
         return TRUE;
     }
     return FALSE;
 }
Exemple #29
0
 * $Id: global.js.php 3143 2009-12-02 17:21:41Z ipso $
 * $Date: 2009-12-02 09:21:41 -0800 (Wed, 02 Dec 2009) $
 */
$disable_cache_control = TRUE;
require_once '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php';
//When going through the installer or using quickpunch the user isnt logged in, so we still
//need to be able to load this file.
if (isset($config_vars['other']['installer_enabled']) and $config_vars['other']['installer_enabled'] == 1 or stristr($_SERVER['HTTP_REFERER'], 'quick_punch')) {
    //FIXME: Remove the authenticate flag from sm_header and installer.
    $authenticate = FALSE;
}
require_once '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'Interface.inc.php';
//Use session created date or login date.
//So this file is updated each time they login.
forceCacheHeaders(NULL, $authentication->getCreatedDate());
$pplf = new PayPeriodListFactory();
$js_calendar_pay_period_dates = $pplf->getJSCalendarPayPeriodArray();
?>
var TTProductEdition = <?php 
if (isset($current_company) and is_object($current_company) and getTTProductEdition() >= $current_company->getProductEdition()) {
    echo (int) $current_company->getProductEdition();
} else {
    echo (int) getTTProductEdition();
}
?>
;

var JSCalendarPayPeriodEndDates = <?php 
echo Misc::getJSArray($js_calendar_pay_period_dates['end_date']) . "\n";
?>
var JSCalendarPayPeriodTransactionDates = <?php 
     $taxable_wages_psea_ids = array();
     $tax_withheld_psea_ids = array();
     Debug::Text('Found Company Deductions...', __FILE__, __LINE__, __METHOD__, 10);
     foreach ($cdlf as $cd_obj) {
         $taxable_wages_psea_ids = array_merge($taxable_wages_psea_ids, (array) $cd_obj->getCombinedIncludeExcludePayStubEntryAccount($cd_obj->getIncludePayStubEntryAccount(), $cd_obj->getExcludePayStubEntryAccount()));
         $tax_withheld_psea_ids[] = $cd_obj->getPayStubEntryAccount();
     }
     $taxable_wages_psea_ids = array_unique($taxable_wages_psea_ids);
     $tax_withheld_psea_ids = array_unique($tax_withheld_psea_ids);
 }
 //var_dump($taxable_wages_psea_ids);
 foreach ($ulf as $u_obj) {
     $filter_data['user_ids'][] = $u_obj->getId();
 }
 //Get all pay periods by transaction start/end date
 $pplf = new PayPeriodListFactory();
 $pplf->getByCompanyIdAndTransactionStartDateAndTransactionEndDate($current_company->getId(), $filter_data['start_date'], $filter_data['end_date']);
 if ($pplf->getRecordCount() > 0) {
     foreach ($pplf as $pp_obj) {
         $pay_period_ids[] = $pp_obj->getId();
     }
 }
 unset($pplf, $pp_obj);
 if (isset($pay_period_ids) and isset($filter_data['user_ids'])) {
     //Get column headers
     /*
     $psealf = new PayStubEntryAccountListFactory();
     $psealf->getByCompanyId( $current_company->getId() );
     foreach($psealf as $psea_obj) {
     	//$report_columns[$psen_obj->getId()] = $psen_obj->getDescription();
     	$report_columns[$psea_obj->getId()] = $psea_obj->getName();