function filterAmount($value) { if (isset($this->symbol)) { $value = ' ' . $this->symbol; } if (isset($this->amount)) { $value .= Misc::MoneyFormat($this->amount); } return $value; }
function getHourlyRate($original_hourly_rate) { Debug::text(' Getting Premium Rate based off Hourly Rate: ' . $original_hourly_rate, __FILE__, __LINE__, __METHOD__, 10); $rate = 0; switch ($this->getPayType()) { case 10: //Pay Factor //Since they are already paid for this time with regular or OT, minus 1 from the rate $rate = $original_hourly_rate * ($this->getRate() - 1); break; case 20: //Pay Plus Premium $rate = $this->getRate(); break; } return Misc::MoneyFormat($rate, FALSE); }
} if (isset($tmp_rows[$user_id][$pay_period_id]['actual_time'])) { $tmp_rows[$user_id][$pay_period_id]['actual_time'] += (int) $udt_obj->getColumn('actual_total_time'); } else { $tmp_rows[$user_id][$pay_period_id]['actual_time'] = (int) $udt_obj->getColumn('actual_total_time'); } $actual_time_diff = $udt_obj->getColumn('actual_total_time') - $udt_obj->getColumn('total_time'); if (isset($tmp_rows[$user_id][$pay_period_id]['actual_time_diff'])) { $tmp_rows[$user_id][$pay_period_id]['actual_time_diff'] += $actual_time_diff; } else { $tmp_rows[$user_id][$pay_period_id]['actual_time_diff'] = $actual_time_diff; } if (isset($user_wage[$user_id])) { $tmp_rows[$user_id][$pay_period_id]['actual_time_diff_wage'] = Misc::MoneyFormat(TTDate::getHours($tmp_rows[$user_id][$pay_period_id]['actual_time_diff']) * $user_wage[$user_id], FALSE); } else { $tmp_rows[$user_id][$pay_period_id]['actual_time_diff_wage'] = Misc::MoneyFormat(0, FALSE); } unset($actual_time_diff); } elseif ($column != NULL) { if (isset($tmp_rows[$user_id][$pay_period_id][$column])) { $tmp_rows[$user_id][$pay_period_id][$column] += $udt_obj->getColumn('total_time'); } else { $tmp_rows[$user_id][$pay_period_id][$column] = $udt_obj->getColumn('total_time'); } } if (isset($schedule_rows[$user_id][$pay_period_id]['working'])) { $tmp_rows[$user_id][$pay_period_id]['schedule_working'] = $schedule_rows[$user_id][$pay_period_id]['working']; } else { $tmp_rows[$user_id][$pay_period_id]['schedule_working'] = NULL; } if (isset($schedule_rows[$user_id][$pay_period_id]['absence'])) {
function getScheduleArray($filter_data, $permission_children_ids = NULL) { global $current_user, $current_user_prefs; //Get all schedule data by general filter criteria. //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__, 10); if (!isset($filter_data['start_date']) or $filter_data['start_date'] == '') { return FALSE; } if (!isset($filter_data['end_date']) or $filter_data['end_date'] == '') { return FALSE; } $filter_data['start_date'] = TTDate::getBeginDayEpoch($filter_data['start_date']); $filter_data['end_date'] = TTDate::getEndDayEpoch($filter_data['end_date']); $schedule_shifts_index = array(); $branch_options = array(); //No longer needed, use SQL instead. $department_options = array(); //No longer needed, use SQL instead. $apf = TTnew('AbsencePolicyFactory'); $absence_policy_paid_type_options = $apf->getOptions('paid_type'); $max_i = 0; $slf = TTnew('ScheduleListFactory'); $slf->getSearchByCompanyIdAndArrayCriteria($current_user->getCompany(), $filter_data); Debug::text('Found Scheduled Rows: ' . $slf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($absence_policy_paid_type_options, 'Paid Absences: ', __FILE__, __LINE__, __METHOD__, 10); if ($slf->getRecordCount() > 0) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $slf->getRecordCount(), NULL, TTi18n::getText('Processing Committed Shifts...')); $i = 0; foreach ($slf as $s_obj) { //Debug::text('Schedule ID: '. $s_obj->getId() .' User ID: '. $s_obj->getColumn('user_id') .' Start Time: '. $s_obj->getStartTime(), __FILE__, __LINE__, __METHOD__, 10); if ($s_obj->getAbsencePolicyID() > 0) { $absence_policy_name = $s_obj->getColumn('absence_policy'); } else { $absence_policy_name = NULL; //Must be NULL for it to appear as "N/A" in legacy interface. } $hourly_rate = Misc::MoneyFormat($s_obj->getColumn('user_wage_hourly_rate'), FALSE); if ($s_obj->getAbsencePolicyID() > 0 and is_object($s_obj->getAbsencePolicyObject()) and in_array($s_obj->getAbsencePolicyObject()->getType(), $absence_policy_paid_type_options) == FALSE) { //UnPaid Absence. $total_time_wage = Misc::MoneyFormat(0); } else { $total_time_wage = Misc::MoneyFormat(bcmul(TTDate::getHours($s_obj->getColumn('total_time')), $hourly_rate), FALSE); } //$iso_date_stamp = TTDate::getISODateStamp($s_obj->getStartTime()); $iso_date_stamp = TTDate::getISODateStamp(strtotime($s_obj->getColumn('date_stamp'))); //$schedule_shifts[$iso_date_stamp][$s_obj->getColumn('user_id').$s_obj->getStartTime()] = array( $schedule_shifts[$iso_date_stamp][$i] = array('id' => (int) $s_obj->getID(), 'pay_period_id' => (int) $s_obj->getColumn('pay_period_id'), 'user_id' => (int) $s_obj->getColumn('user_id'), 'user_created_by' => (int) $s_obj->getColumn('user_created_by'), 'user_full_name' => $s_obj->getColumn('user_id') > 0 ? Misc::getFullName($s_obj->getColumn('first_name'), NULL, $s_obj->getColumn('last_name'), FALSE, FALSE) : TTi18n::getText('OPEN'), 'first_name' => $s_obj->getColumn('user_id') > 0 ? $s_obj->getColumn('first_name') : TTi18n::getText('OPEN'), 'last_name' => $s_obj->getColumn('last_name'), 'title_id' => $s_obj->getColumn('title_id'), 'title' => $s_obj->getColumn('title'), 'group_id' => $s_obj->getColumn('group_id'), 'group' => $s_obj->getColumn('group'), 'default_branch_id' => $s_obj->getColumn('default_branch_id'), 'default_branch' => $s_obj->getColumn('default_branch'), 'default_department_id' => $s_obj->getColumn('default_department_id'), 'default_department' => $s_obj->getColumn('default_department'), 'job_id' => $s_obj->getColumn('job_id'), 'job' => $s_obj->getColumn('job'), 'job_status_id' => $s_obj->getColumn('job_status_id'), 'job_manual_id' => $s_obj->getColumn('job_manual_id'), 'job_branch_id' => $s_obj->getColumn('job_branch_id'), 'job_department_id' => $s_obj->getColumn('job_department_id'), 'job_group_id' => $s_obj->getColumn('job_group_id'), 'job_item_id' => $s_obj->getColumn('job_item_id'), 'job_item' => $s_obj->getColumn('job_item'), 'type_id' => 10, 'status_id' => (int) $s_obj->getStatus(), 'date_stamp' => TTDate::getAPIDate('DATE', strtotime($s_obj->getColumn('date_stamp'))), 'start_date_stamp' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE', $s_obj->getStartTime()) : $s_obj->getStartTime(), 'start_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $s_obj->getStartTime()) : $s_obj->getStartTime(), 'end_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $s_obj->getEndTime()) : $s_obj->getEndTime(), 'start_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $s_obj->getStartTime()) : $s_obj->getStartTime(), 'end_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $s_obj->getEndTime()) : $s_obj->getEndTime(), 'start_time_stamp' => $s_obj->getStartTime(), 'end_time_stamp' => $s_obj->getEndTime(), 'total_time' => $s_obj->getTotalTime(), 'hourly_rate' => $hourly_rate, 'total_time_wage' => $total_time_wage, 'note' => $s_obj->getColumn('note'), 'schedule_policy_id' => (int) $s_obj->getSchedulePolicyID(), 'absence_policy_id' => (int) $s_obj->getAbsencePolicyID(), 'absence_policy' => $absence_policy_name, 'branch_id' => (int) $s_obj->getBranch(), 'branch' => $s_obj->getColumn('branch'), 'department_id' => (int) $s_obj->getDepartment(), 'department' => $s_obj->getColumn('department'), 'created_by_id' => $s_obj->getCreatedBy(), 'created_date' => $s_obj->getCreatedDate(), 'updated_date' => $s_obj->getUpdatedDate()); //Make sure we add in permission columns. $this->getPermissionColumns($schedule_shifts[$iso_date_stamp][$i], (int) $s_obj->getColumn('user_id'), $s_obj->getCreatedBy(), $permission_children_ids); //$schedule_shifts_index[$iso_date_stamp][$s_obj->getColumn('user_id')][] = $s_obj->getColumn('user_id').$s_obj->getStartTime(); $schedule_shifts_index[$iso_date_stamp][$s_obj->getColumn('user_id')][] = $i; unset($absence_policy_name); $this->getProgressBarObject()->set($this->getAMFMessageID(), $slf->getCurrentRow()); $i++; } $max_i = $i; unset($i); $this->getProgressBarObject()->stop($this->getAMFMessageID()); //Debug::Arr($schedule_shifts, 'Committed Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($schedule_shifts_index, 'Committed Schedule Shifts Index: ', __FILE__, __LINE__, __METHOD__, 10); } else { $schedule_shifts = array(); } unset($slf); //Get holidays //FIXME: What if there are two holiday policies, one that defaults to working, and another that defaults to not working, and they are assigned //to two different groups of employees? For that matter what if the holiday policy isn't assigned to a specific user at all. $holiday_data = array(); $hlf = TTnew('HolidayListFactory'); $hlf->getByCompanyIdAndStartDateAndEndDate($current_user->getCompany(), $filter_data['start_date'], $filter_data['end_date']); Debug::text('Found Holiday Rows: ' . $hlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($hlf as $h_obj) { if (is_object($h_obj->getHolidayPolicyObject()) and is_object($h_obj->getHolidayPolicyObject()->getAbsencePolicyObject())) { $holiday_data[TTDate::getISODateStamp($h_obj->getDateStamp())] = array('status_id' => (int) $h_obj->getHolidayPolicyObject()->getDefaultScheduleStatus(), 'absence_policy_id' => $h_obj->getHolidayPolicyObject()->getAbsencePolicyID(), 'type_id' => $h_obj->getHolidayPolicyObject()->getAbsencePolicyObject()->getType(), 'absence_policy' => $h_obj->getHolidayPolicyObject()->getAbsencePolicyObject()->getName()); } else { $holiday_data[TTDate::getISODateStamp($h_obj->getDateStamp())] = array('status_id' => 10); //Working } } unset($hlf); $recurring_schedule_shifts = array(); $open_shift_conflict_index = array(); $rstlf = TTnew('RecurringScheduleTemplateListFactory'); //Order for this is critcal to working with OPEN shifts. OPEN shifts (user_id=0) must come last, so it can find all conflicting shifts that will override it. //Also order by start_time so earlier shifts come first and therefore are the first to be overridden. $rstlf->getSearchByCompanyIdAndArrayCriteria($current_user->getCompany(), $filter_data, NULL, NULL, NULL, array('c.start_date' => 'asc', 'cb.user_id' => 'desc', 'a.week' => 'asc', 'a.start_time' => 'asc')); Debug::text('Found Recurring Schedule Template Rows: ' . $rstlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($rstlf->getRecordCount() > 0) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $rstlf->getRecordCount(), NULL, TTi18n::getText('Processing Recurring Shifts...')); foreach ($rstlf as $rst_obj) { //Debug::text('Recurring Schedule Template ID: '. $rst_obj->getID() , __FILE__, __LINE__, __METHOD__, 10); $rst_obj->getShifts($filter_data['start_date'], $filter_data['end_date'], $holiday_data, $branch_options, $department_options, $max_i, $schedule_shifts, $schedule_shifts_index, $open_shift_conflict_index, $permission_children_ids); $this->getProgressBarObject()->set($this->getAMFMessageID(), $rstlf->getCurrentRow()); } $this->getProgressBarObject()->stop($this->getAMFMessageID()); } else { Debug::text('DID NOT find Recurring Schedule for this time period: ', __FILE__, __LINE__, __METHOD__, 10); } unset($rstlf, $rst_obj, $open_shift_conflict_index); //Debug::Arr($schedule_shifts, 'Schedule Shifts: ', __FILE__, __LINE__, __METHOD__, 10); //Include employees without scheduled shifts. if (isset($filter_data['include_all_users']) and $filter_data['include_all_users'] == TRUE) { if (!isset($filter_data['exclude_id'])) { $filter_data['exclude_id'] = array(); } //If the user is searching for scheduled branch/departments, convert that to default branch/departments when Show All Employees is enabled. if (isset($filter_data['branch_ids']) and !isset($filter_data['default_branch_ids'])) { $filter_data['default_branch_ids'] = $filter_data['branch_ids']; } if (isset($filter_data['department_ids']) and !isset($filter_data['default_department_ids'])) { $filter_data['default_department_ids'] = $filter_data['department_ids']; } //Loop through schedule_shifts_index getting user_ids. foreach ($schedule_shifts_index as $date_stamp => $date_shifts) { $filter_data['exclude_id'] = array_unique(array_merge($filter_data['exclude_id'], array_keys($date_shifts))); } unset($date_stamp, $date_shifts); if (isset($filter_data['exclude_id'])) { //Debug::Arr($filter_data['exclude_id'], 'Including all employees. Excluded User Ids: ', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($filter_data, 'All Filter Data: ', __FILE__, __LINE__, __METHOD__, 10); //Only include active employees without any scheduled shifts. $filter_data['status_id'] = 10; $ulf = TTnew('UserListFactory'); $ulf->getAPISearchByCompanyIdAndArrayCriteria($current_user->getCompany(), $filter_data); Debug::text('Found blank employees: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($ulf->getRecordCount() > 0) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Processing Employees...')); $i = $max_i; foreach ($ulf as $u_obj) { //Create dummy shift arrays with no start/end time. //$schedule_shifts[TTDate::getISODateStamp( $filter_data['start_date'] )][$u_obj->getID().TTDate::getBeginDayEpoch($filter_data['start_date'])] = array( $schedule_shifts[TTDate::getISODateStamp($filter_data['start_date'])][$i] = array('pay_period_id' => FALSE, 'user_id' => (int) $u_obj->getID(), 'user_created_by' => (int) $u_obj->getCreatedBy(), 'user_full_name' => Misc::getFullName($u_obj->getFirstName(), NULL, $u_obj->getLastName(), FALSE, FALSE), 'first_name' => $u_obj->getFirstName(), 'last_name' => $u_obj->getLastName(), 'title_id' => $u_obj->getTitle(), 'title' => $u_obj->getColumn('title'), 'group_id' => $u_obj->getColumn('group_id'), 'group' => $u_obj->getColumn('group'), 'default_branch_id' => $u_obj->getColumn('default_branch_id'), 'default_branch' => $u_obj->getColumn('default_branch'), 'default_department_id' => $u_obj->getColumn('default_department_id'), 'default_department' => $u_obj->getColumn('default_department'), 'branch_id' => (int) $u_obj->getDefaultBranch(), 'branch' => $u_obj->getColumn('default_branch'), 'department_id' => (int) $u_obj->getDefaultDepartment(), 'department' => $u_obj->getColumn('default_department'), 'created_by_id' => $u_obj->getCreatedBy(), 'created_date' => $u_obj->getCreatedDate(), 'updated_date' => $u_obj->getUpdatedDate()); //Make sure we add in permission columns. $this->getPermissionColumns($schedule_shifts[TTDate::getISODateStamp($filter_data['start_date'])][$i], (int) $u_obj->getID(), $u_obj->getCreatedBy(), $permission_children_ids); $this->getProgressBarObject()->set($this->getAMFMessageID(), $ulf->getCurrentRow()); $i++; } $this->getProgressBarObject()->stop($this->getAMFMessageID()); } } //Debug::Arr($schedule_shifts, 'Final Scheduled Shifts: ', __FILE__, __LINE__, __METHOD__, 10); } unset($schedule_shifts_index); if (isset($schedule_shifts)) { return $schedule_shifts; } return FALSE; }
if (isset($ein[0]) and isset($ein[1])) { $pdf->setXY(15, 236); $pdf->Cell(13, 6, $ein[0], $border, 0, 'R'); $pdf->setXY(29, 236); $pdf->Cell(40, 6, $ein[1], $border, 0, 'L'); } $pdf->setXY(82, 244); $pdf->Cell(75, 6, $current_company->getName(), $border, 0, 'L'); $pdf->setXY(82, 253); $pdf->Cell(45, 6, $current_company->getAddress1() . ' ' . $current_company->getAddress2(), $border, 0, 'L'); $pdf->setXY(82, 261); $pdf->Cell(45, 6, $current_company->getCity() . ', ' . $current_company->getProvince() . ' ' . $current_company->getPostalCode(), $border, 0, 'L'); $pdf->setXY(157, 234); $pdf->Cell(35, 6, Misc::getBeforeDecimal(Misc::MoneyFormat($lines_arr['total']['p1_6'], FALSE)), $border, 0, 'R'); $pdf->setXY(193, 234); $pdf->Cell(6, 6, Misc::getAfterDecimal(Misc::MoneyFormat($lines_arr['total']['p1_6'], FALSE)), $border, 0, 'L'); } $output = $pdf->Output('', 'S'); if (Debug::getVerbosity() == 11) { Debug::Display(); } else { Misc::FileDownloadHeader('f940ez.pdf', 'application/pdf', strlen($output)); echo $output; } exit; } } break; case 'delete': case 'save': Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10);
if ($tax_deduction_arr['calculation_id'] == 200 and $tax_deduction_arr['province'] != '') { //State Wages/Taxes //Handle two states here, just check if $tmp_rows[$x]['state_1'] isset, //if it is, move on to state 2. $tmp_rows[$x]['state_1'] = $tax_deduction_arr['province']; $tmp_rows[$x]['state_wage_1'] = Misc::MoneyFormat(Misc::sumMultipleColumns($raw_rows[$user_id], $tax_deduction_arr['include']), FALSE); $tmp_rows[$x]['state_tax_1'] = Misc::MoneyFormat(Misc::sumMultipleColumns($raw_rows[$user_id], array($tax_deduction_arr['pay_stub_entry_account_id'])), FALSE); } elseif ($tax_deduction_arr['calculation_id'] == 300 and ($tax_deduction_arr['district'] != '' or $tax_deduction_arr['company_value1'] != '')) { //District Wages/Taxes if ($tax_deduction_arr['district'] == '' and $tax_deduction_arr['company_value1'] != '') { $tmp_rows[$x]['district_1'] = $tax_deduction_arr['company_value1']; } else { $tmp_rows[$x]['district_1'] = $tax_deduction_arr['district']; } $tmp_rows[$x]['district_wage_1'] = Misc::MoneyFormat(Misc::sumMultipleColumns($raw_rows[$user_id], $tax_deduction_arr['include']), FALSE); $tmp_rows[$x]['district_tax_1'] = Misc::MoneyFormat(Misc::sumMultipleColumns($raw_rows[$user_id], array($tax_deduction_arr['pay_stub_entry_account_id'])), FALSE); } else { //Debug::Text('Not State or Local income tax: '. $tax_deduction_arr['id'] .' Calculation: '. $tax_deduction_arr['calculation_id'] .' District: '. $tax_deduction_arr['district'] .' UserValue5: '.$tax_deduction_arr['user_value5'] .' CompanyValue1: '. $tax_deduction_arr['company_value1'], __FILE__, __LINE__, __METHOD__,10); } } else { Debug::Text('DID NOT Find user in Tax Deduction ID: ' . $tax_deduction_arr['id'], __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::Text('No Tax Deductions...', __FILE__, __LINE__, __METHOD__, 10); } $x++; } } //print_r($tmp_rows); if (isset($tmp_rows)) {
function getShifts($start_date, $end_date, &$holiday_data = array(), &$branch_options = array(), &$department_options = array(), &$n, &$shifts = array(), &$shifts_index = array(), $open_shift_conflict_index = array(), $permission_children_ids = NULL) { //Debug::text('Start Date: '. TTDate::getDate('DATE+TIME', $start_date) .' End Date: '. TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); $recurring_schedule_control_start_date = TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date')); //Debug::text('Recurring Schedule Control Start Date: '. TTDate::getDate('DATE+TIME', $recurring_schedule_control_start_date),__FILE__, __LINE__, __METHOD__, 10); $current_template_week = $this->getColumn('remapped_week'); $max_week = $this->getColumn('max_week'); //Debug::text('Template Week: '. $current_template_week .' Max Week: '. $this->getColumn('max_week') .' ReMapped Week: '. $this->getColumn('remapped_week') ,__FILE__, __LINE__, __METHOD__, 10); if ($recurring_schedule_control_start_date == '') { return FALSE; } //Get week of start_date $start_date_week = TTDate::getBeginWeekEpoch($recurring_schedule_control_start_date, 0); //Start week on Sunday to match Recurring Schedule. //Debug::text('Week of Start Date: '. $start_date_week ,__FILE__, __LINE__, __METHOD__, 10); $apf = TTnew('AbsencePolicyFactory'); $absence_policy_paid_type_options = $apf->getOptions('paid_type'); for ($i = $start_date; $i <= $end_date; $i += 86400 + 43200) { //Handle DST by adding 12hrs to the date to get the mid-day epoch, then forcing it back to the beginning of the day. $i = TTDate::getBeginDayEpoch($i); if ($this->getColumn('hire_date') != '' and $i < $this->getColumn('hire_date') or $this->getColumn('termination_date') != '' and $i > $this->getColumn('termination_date')) { //Debug::text('Skipping due to Hire/Termination date: User ID: '. $this->getColumn('user_id') .' I: '. $i .' Hire Date: '. $this->getColumn('hire_date') .' Termination Date: '. $this->getColumn('termination_date') ,__FILE__, __LINE__, __METHOD__, 10); continue; } //This needs to take into account weeks spanning January 1st of each year. Where the week goes from 53 to 1. //Rather then use the week of the year, calculate the weeks between the recurring schedule start date and now. $current_week = round((TTDate::getBeginWeekEpoch($i, 0) - $start_date_week) / 604800); //Find out which week we are on based on the recurring schedule start date. Use round due to DST the week might be 6.9 or 7.1, so we need to round to the nearest full week. //Debug::text('I: '. $i .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Week: '. $start_date_week,__FILE__, __LINE__, __METHOD__, 10); $template_week = $current_week % $max_week + 1; //Debug::text('Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10); if ($template_week == $current_template_week) { //Debug::text('Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week,__FILE__, __LINE__, __METHOD__, 10); //Debug::text(' Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10); if ($this->isActiveShiftDay($i)) { //Debug::text(' Active Shift on this day...',__FILE__, __LINE__, __METHOD__, 10); $start_time = TTDate::getTimeLockedDate($this->getStartTime(), $i); $end_time = TTDate::getTimeLockedDate($this->getEndTime(), $i); if ($end_time < $start_time) { //Spans the day boundary, add 86400 to end_time $end_time = $end_time + 86400; //Debug::text(' Schedule spans day boundary, bumping endtime to next day: ',__FILE__, __LINE__, __METHOD__, 10); } $iso_date_stamp = TTDate::getISODateStamp(PayPeriodScheduleFactory::getShiftAssignedDate($start_time, $end_time, $this->getColumn('shift_assigned_day_id'))); //$iso_date_stamp = TTDate::getISODateStamp( $i ); $open_shift_multiplier = $this->getColumn('user_id') == 0 ? $this->getOpenShiftMultiplier() : 1; //Debug::text('Open Shift Multiplier: '. $open_shift_multiplier,__FILE__, __LINE__, __METHOD__, 10); for ($x = 0; $x < $open_shift_multiplier; $x++) { //Check all non-OPEN shifts for conflicts. if ($this->getColumn('user_id') > 0 and isset($shifts_index[$iso_date_stamp][$this->getColumn('user_id')])) { //User has previous recurring schedule shifts, check for overlap. //Loop over each employees shift for this day and check for conflicts foreach ($shifts_index[$iso_date_stamp][$this->getColumn('user_id')] as $shift_key) { if (isset($shifts[$iso_date_stamp][$shift_key])) { //Must use parseDateTime() when called from the API due to date formats that strtotime() fails on. if (TTDate::isTimeOverLap(defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['start_date']) : $shifts[$iso_date_stamp][$shift_key]['start_date'], defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['end_date']) : $shifts[$iso_date_stamp][$shift_key]['end_date'], $start_time, $end_time) == TRUE) { //Debug::text(' Found overlapping recurring schedules! User ID: '. $this->getColumn('user_id') .' Start Time: '. $start_time,__FILE__, __LINE__, __METHOD__, 10); continue 2; } } } unset($shift_key); } elseif ($this->getColumn('user_id') == 0 and isset($shifts_index[$iso_date_stamp])) { //Debug::text(' Checking OPEN shift conflicts... Date: '. $iso_date_stamp,__FILE__, __LINE__, __METHOD__, 10); //Check all OPEN shifts for conflicts. //This is special, since there can be multiple open shifts for the same branch,department,job,task, so we need to check if are conflicts with *any* employee. //Do we allow conflicting shifts between committed and recurring OPEN shifts? For example what if there are two open shifts on the same day //6AM-3PM (x2) and they want to override one of those shifts to 7AM-4PM? If we use this check: // ( $shifts[$iso_date_stamp][$shift_key]['user_id'] > 0 OR ( isset($shifts[$iso_date_stamp][$shift_key]['id']) AND $shifts[$iso_date_stamp][$shift_key]['id'] > 0 ) ) //That allows committed OPEN shifts to override recurring open shifts, which is great, but it prevents adding additional open shifts that may //also overlap unless they override all recurring shifts first. I think this is the trade-off we have to make as its more likely that they //will adjust an open shift time rather than add/remove specific shifts. Removing recurring OPEN shifts can be done by making them ABSENT. //This will also affect when recurring OPEN shifts are committed by preventing the shifts from doubling up. foreach ($shifts_index[$iso_date_stamp] as $tmp_index_user_id => $tmp_index_arr) { foreach ($tmp_index_arr as $shift_key) { $tmp_start_date = defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['start_date']) : $shifts[$iso_date_stamp][$shift_key]['start_date']; $tmp_end_date = defined('TIMETREX_API') ? TTDate::parseDateTime($shifts[$iso_date_stamp][$shift_key]['end_date']) : $shifts[$iso_date_stamp][$shift_key]['end_date']; if (($shifts[$iso_date_stamp][$shift_key]['user_id'] > 0 or isset($shifts[$iso_date_stamp][$shift_key]['id']) and $shifts[$iso_date_stamp][$shift_key]['id'] > 0) and (!isset($open_shift_conflict_index['open'][$this->getID()][$shift_key]) and (isset($shifts[$iso_date_stamp][$shift_key]['id']) and !isset($open_shift_conflict_index['scheduled'][$shifts[$iso_date_stamp][$shift_key]['id']]))) and $this->getColumn('schedule_branch_id') == $shifts[$iso_date_stamp][$shift_key]['branch_id'] and $this->getColumn('schedule_department_id') == $shifts[$iso_date_stamp][$shift_key]['department_id'] and $this->getColumn('job_id') == $shifts[$iso_date_stamp][$shift_key]['job_id'] and $this->getColumn('job_item_id') == $shifts[$iso_date_stamp][$shift_key]['job_item_id'] and ($tmp_start_date == $start_time and $tmp_end_date == $end_time)) { //Debug::text(' Found OPEN shift conflict... Skipping...! Shift Key: '. $shift_key,__FILE__, __LINE__, __METHOD__, 10); //We need to track each shift_key that caused a conflict so it can't cause another conflict later on. // Make sure we just track it on a per template basis though, otherwise the same $shift_key from a previous template can affect other templates. // The above issue would show up as OPEN shifts not being overridden. //We also need to track which scheduled shift that caused a conflict so it can't cause another one later on. // This prevents a single scheduled shift from overriding multiple OPEN shifts of different times. //However we need to be smarter about which shifts override which OPEN shifts... // So if there are two open shifts, 10AM-4PM and 3:50PM-9PM, a 10AM-4PM scheduled shift overrides the OPEN shift that best fits it (10AM to 4PM, *not* 3:50-9PM) // For now require an exact match to override an OPEN shift, if we start using partial schedules it gets much more complicated. // Or we could introduce a hardcoded "fudge factor" setting (ie: 5 mins) that is always used instead. $open_shift_conflict_index['open'][$this->getID()][$shift_key] = TRUE; $open_shift_conflict_index['scheduled'][$shifts[$iso_date_stamp][$shift_key]['id']] = TRUE; continue 3; } unset($tmp_start_date, $tmp_end_date); } } unset($tmp_index_user_id, $tmp_index_arr); } //This check has to occurr after the committed schedule check, otherwise no committed schedules will appear. if ($this->getColumn('recurring_schedule_control_start_date') != '' and $i < TTDate::strtotime($this->getColumn('recurring_schedule_control_start_date')) or $this->getColumn('recurring_schedule_control_end_date') != '' and $i > TTDate::strtotime($this->getColumn('recurring_schedule_control_end_date'))) { //Debug::text('Skipping due to Recurring Schedule Start/End date: ID: '. $this->getColumn('id') .' User ID: '. $this->getColumn('user_id') .' I: '. $i .' Start Date: '. $this->getColumn('recurring_schedule_control_start_date') .' ('. TTDate::strtotime( $this->getColumn('recurring_schedule_control_start_date') ) .') End Date: '. $this->getColumn('recurring_schedule_control_end_date') ,__FILE__, __LINE__, __METHOD__, 10); continue; } //Debug::text(' Start Date: '. TTDate::getDate('DATE+TIME', $start_time) .' End Date: '. TTDate::getDate('DATE+TIME', $end_time),__FILE__, __LINE__, __METHOD__, 10); $status_id = $this->getColumn('status_id'); $absence_policy_id = $this->getColumn('absence_policy_id'); $absence_policy_type_id = $this->getColumn('absence_policy_type_id'); $absence_policy = $this->getColumn('absence_policy') != '' ? $this->getColumn('absence_policy') : NULL; //Must be NULL to be converted to N/A if (isset($holiday_data[$iso_date_stamp])) { //We have to assume they are eligible, because we really won't know //if they will have worked enough days or not. We could assume they //work whatever their schedule is, but chances are they will be eligible then anyways. //Debug::text(' Found Holiday on this day...',__FILE__, __LINE__, __METHOD__, 10); $status_id = $holiday_data[$iso_date_stamp]['status_id']; if (isset($holiday_data[$iso_date_stamp]['absence_policy_id'])) { $absence_policy_id = $holiday_data[$iso_date_stamp]['absence_policy_id']; $absence_policy_type_id = $holiday_data[$iso_date_stamp]['type_id']; $absence_policy = $holiday_data[$iso_date_stamp]['absence_policy']; } } $hourly_rate = Misc::MoneyFormat($this->getColumn('user_wage_hourly_rate'), FALSE); if ($absence_policy_id > 0 and in_array($absence_policy_type_id, $absence_policy_paid_type_options) == FALSE) { //UnPaid Absence. $total_time_wage = Misc::MoneyFormat(0); } else { $total_time_wage = Misc::MoneyFormat(bcmul(TTDate::getHours($this->getTotalTime()), $hourly_rate), FALSE); } //Debug::text('I: '. $i .' N: '. $n .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Time: '. TTDate::getDate('DATE+TIME', $start_time ) .' Absence Policy: '. $absence_policy,__FILE__, __LINE__, __METHOD__, 10); //$shifts[$iso_date_stamp][$this->getColumn('user_id').$start_time] = array( $shifts[$iso_date_stamp][$n] = array('pay_period_id' => FALSE, 'user_id' => (int) $this->getColumn('user_id'), 'user_created_by' => $this->getColumn('user_created_by'), 'user_full_name' => $this->getColumn('user_id') > 0 ? Misc::getFullName($this->getColumn('first_name'), NULL, $this->getColumn('last_name'), FALSE, FALSE) : TTi18n::getText('OPEN'), 'first_name' => $this->getColumn('first_name'), 'last_name' => $this->getColumn('last_name'), 'title_id' => $this->getColumn('title_id'), 'title' => $this->getColumn('title'), 'group_id' => $this->getColumn('group_id'), 'group' => $this->getColumn('group'), 'default_branch_id' => $this->getColumn('default_branch_id'), 'default_branch' => $this->getColumn('default_branch'), 'default_department_id' => $this->getColumn('default_department_id'), 'default_department' => $this->getColumn('default_department'), 'job_id' => $this->getJob(), 'job' => $this->getColumn('job'), 'job_status_id' => $this->getColumn('job_status_id'), 'job_manual_id' => $this->getColumn('job_manual_id'), 'job_branch_id' => $this->getColumn('job_branch_id'), 'job_department_id' => $this->getColumn('job_department_id'), 'job_group_id' => $this->getColumn('job_group_id'), 'job_item_id' => $this->getJobItem(), 'job_item' => $this->getColumn('job_item'), 'type_id' => 20, 'status_id' => $status_id, 'date_stamp' => TTDate::getAPIDate('DATE', strtotime($iso_date_stamp)), 'start_date_stamp' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE', $start_time) : $start_time, 'start_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $start_time) : $start_time, 'end_date' => defined('TIMETREX_API') ? TTDate::getAPIDate('DATE+TIME', $end_time) : $end_time, 'start_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $start_time) : $start_time, 'end_time' => defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', $end_time) : $end_time, 'start_time_stamp' => $start_time, 'end_time_stamp' => $end_time, 'total_time' => $this->getTotalTime(), 'hourly_rate' => $hourly_rate, 'total_time_wage' => $total_time_wage, 'note' => FALSE, 'schedule_policy_id' => $this->getSchedulePolicyID(), 'absence_policy_id' => $absence_policy_id, 'absence_policy' => $absence_policy, 'branch_id' => $this->getColumn('schedule_branch_id'), 'branch' => $this->getColumn('schedule_branch'), 'department_id' => $this->getColumn('schedule_department_id'), 'department' => $this->getColumn('schedule_department'), 'created_by_id' => $this->getColumn('recurring_schedule_control_created_by'), 'created_date' => $this->getCreatedDate(), 'updated_date' => $this->getUpdatedDate()); //Make sure we add in permission columns. $this->getPermissionColumns($shifts[$iso_date_stamp][$n], (int) $this->getColumn('user_id'), $this->getColumn('recurring_schedule_control_created_by'), $permission_children_ids); //$shifts_index[$iso_date_stamp][$this->getColumn('user_id')][] = $this->getColumn('user_id').$start_time; $shifts_index[$iso_date_stamp][$this->getColumn('user_id')][] = $n; $n++; } unset($open_shift_multiplier); unset($start_time, $end_time); } else { //Debug::text(' NOT active shift on this day... ID: '. $this->getColumn('id') .' User ID: '. $this->getColumn('user_id') .' Start Time: '. TTDate::getDate('DATE+TIME', $i),__FILE__, __LINE__, __METHOD__, 10); } } } if (isset($shifts)) { //Debug::Arr($shifts, 'Template Shifts: ',__FILE__, __LINE__, __METHOD__, 10); return $shifts; } return FALSE; }
$aplf = TTnew('AbsencePolicyListFactory'); $aplf->getByCompanyId($current_company->getId()); if ($aplf->getRecordCount() > 0) { foreach ($aplf as $ap_obj) { $absence_policy_paid_options[$ap_obj->getID()] = $ap_obj->isPaid(); } } unset($aplf, $ap_obj); $sf = TTnew('ScheduleFactory'); $raw_schedule_shifts = $sf->getScheduleArray($filter_data); if (is_array($raw_schedule_shifts)) { foreach ($raw_schedule_shifts as $iso_date => $data_a) { foreach ($data_a as $shift_key => $data) { //Hide wages if they don't have permission. if ($permission->Check('wage', 'view') == FALSE and !in_array($data['user_id'], $wage_filter_data['permission_children_ids']) == TRUE) { $data['hourly_rate'] = $data['total_time_wage'] = Misc::MoneyFormat(0); } $tmp_rows[$data['pay_period_id']][$data['user_id']][] = $data; } } } unset($raw_schedule_shifts); //var_dump($tmp_rows); $ulf = TTnew('UserListFactory'); $utlf = TTnew('UserTitleListFactory'); $title_options = $utlf->getByCompanyIdArray($current_company->getId()); $uglf = TTnew('UserGroupListFactory'); $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'no_tree_text', TRUE)); $blf = TTnew('BranchListFactory'); $branch_options = $blf->getByCompanyIdArray($current_company->getId()); $dlf = TTnew('DepartmentListFactory');
function _outputPDFForm($format = NULL) { $show_background = TRUE; if ($format == 'pdf_form_print' or $format == 'pdf_form_print_government') { $show_background = FALSE; } Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10); $setup_data = $this->getFormConfig(); $filter_data = $this->getFilterConfig(); //Debug::Arr($setup_data, 'Setup Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($this->data, 'Data: ', __FILE__, __LINE__, __METHOD__,10); //$last_row = count($this->form_data)-1; //$total_row = $last_row+1; $current_company = $this->getUserObject()->getCompanyObject(); if (!is_object($current_company)) { Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $this->sortFormData(); //Make sure forms are sorted. if ($format == 'efile_xml') { $t619 = $this->getT619Object(); $t619->setStatus($setup_data['status_id']); $t619->transmitter_number = isset($setup_data['transmitter_number']) ? $setup_data['transmitter_number'] : NULL; $t619->transmitter_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName(); $t619->transmitter_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1(); $t619->transmitter_address2 = (isset($setup_data['address2']) and $setup_data['address2'] != '') ? $setup_data['address2'] : $current_company->getAddress2(); $t619->transmitter_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity(); $t619->transmitter_province = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince(); $t619->transmitter_postal_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode(); $t619->contact_name = $this->getUserObject()->getFullName(); $t619->contact_phone = $current_company->getWorkPhone(); $t619->contact_email = $this->getUserObject()->getWorkEmail(); $this->getFormObject()->addForm($t619); } $t4a = $this->getT4AObject(); if (isset($setup_data['include_t4a_back']) and $setup_data['include_t4a_back'] == 1) { $t4a->setShowInstructionPage(TRUE); } if (stristr($format, 'government')) { $form_type = 'government'; } else { $form_type = 'employee'; } Debug::Text('Form Type: ' . $form_type, __FILE__, __LINE__, __METHOD__, 10); $t4a->setType($form_type); $t4a->setStatus($setup_data['status_id']); $t4a->year = TTDate::getYear($filter_data['start_date']); $t4a->payroll_account_number = (isset($setup_data['payroll_account_number']) and $setup_data['payroll_account_number'] != '') ? $setup_data['payroll_account_number'] : $current_company->getBusinessNumber(); $t4a->company_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName(); $i = 0; foreach ($this->form_data as $row) { //if ( $i == $last_row ) { // continue; //} if (!isset($row['user_id'])) { Debug::Text('User ID not set!', __FILE__, __LINE__, __METHOD__, 10); continue; } $ulf = TTnew('UserListFactory'); $ulf->getById((int) $row['user_id']); if ($ulf->getRecordCount() == 1) { $user_obj = $ulf->getCurrent(); $ee_data = array('first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'address1' => $user_obj->getAddress1(), 'address2' => $user_obj->getAddress2(), 'city' => $user_obj->getCity(), 'province' => $user_obj->getProvince(), 'employment_province' => $user_obj->getProvince(), 'postal_code' => $user_obj->getPostalCode(), 'sin' => $user_obj->getSIN(), 'employee_number' => $user_obj->getEmployeeNumber(), 'l16' => $row['pension'], 'l22' => $row['income_tax'], 'l18' => $row['lump_sum_payment'], 'l20' => $row['self_employed_commission'], 'l24' => $row['annuities'], 'l48' => $row['service_fees'], 'other_box_0_code' => NULL, 'other_box_0' => NULL, 'other_box_1_code' => NULL, 'other_box_1' => NULL, 'other_box_2_code' => NULL, 'other_box_2' => NULL, 'other_box_3_code' => NULL, 'other_box_3' => NULL, 'other_box_4_code' => NULL, 'other_box_4' => NULL, 'other_box_5_code' => NULL, 'other_box_5' => NULL); if ($row['other_box_0'] > 0 and isset($setup_data['other_box'][0]['box']) and $setup_data['other_box'][0]['box'] != '') { $ee_data['other_box_0_code'] = $setup_data['other_box'][0]['box']; $ee_data['other_box_0'] = $row['other_box_0']; } if ($row['other_box_1'] > 0 and isset($setup_data['other_box'][1]['box']) and $setup_data['other_box'][1]['box'] != '') { $ee_data['other_box_1_code'] = $setup_data['other_box'][1]['box']; $ee_data['other_box_1'] = $row['other_box_1']; } if ($row['other_box_2'] > 0 and isset($setup_data['other_box'][2]['box']) and $setup_data['other_box'][2]['box'] != '') { $ee_data['other_box_2_code'] = $setup_data['other_box'][2]['box']; $ee_data['other_box_2'] = $row['other_box_2']; } if ($row['other_box_3'] > 0 and isset($setup_data['other_box'][3]['box']) and $setup_data['other_box'][3]['box'] != '') { $ee_data['other_box_3_code'] = $setup_data['other_box'][3]['box']; $ee_data['other_box_3'] = $row['other_box_3']; } if ($row['other_box_4'] > 0 and isset($setup_data['other_box'][4]['box']) and $setup_data['other_box'][4]['box'] != '') { $ee_data['other_box_4_code'] = $setup_data['other_box'][4]['box']; $ee_data['other_box_4'] = $row['other_box_4']; } $t4a->addRecord($ee_data); unset($ee_data); $i++; } } $this->getFormObject()->addForm($t4a); //Handle T4ASummary $t4as = $this->getT4ASumObject(); $t4as->setStatus($setup_data['status_id']); $t4as->year = $t4a->year; $t4as->payroll_account_number = $t4a->payroll_account_number; $t4as->company_name = $t4a->company_name; $t4as->company_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1(); $t4as->company_address2 = (isset($setup_data['address2']) and $setup_data['address2'] != '') ? $setup_data['address2'] : $current_company->getAddress2(); $t4as->company_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity(); $t4as->company_province = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince(); $t4as->company_postal_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode(); $t4as->l76 = $this->getUserObject()->getFullName(); //Contact name. $t4as->l78 = $current_company->getWorkPhone(); $total_row = Misc::ArrayAssocSum($this->form_data); $t4as->l88 = count($this->form_data); $t4as->l16 = $total_row['pension']; $t4as->l22 = $total_row['income_tax']; $t4as->l18 = $total_row['lump_sum_payment']; $t4as->l20 = $total_row['self_employed_commission']; $t4as->l24 = $total_row['annuities']; $t4as->l48 = $total_row['service_fees']; if (isset($setup_data['other_box'])) { foreach ($setup_data['other_box'] as $key => $other_box_data) { //Debug::Text('zFound other box total for T4A Sum: '. $key .' Code: '. $other_box_data['box'], __FILE__, __LINE__, __METHOD__,10); if (in_array((int) $other_box_data['box'], array(28, 30, 32, 34, 40, 42))) { //Debug::Text('Found other box total for T4A Sum: '. $key .' Code: '. $other_box_data['box'], __FILE__, __LINE__, __METHOD__,10); $object_var = 'l' . (int) $other_box_data['box']; $t4as->{$object_var} = $total_row['other_box_' . $key]; unset($object_var); } } } unset($other_box_data, $key); $total_other_deductions = Misc::MoneyFormat(Misc::sumMultipleColumns($total_row, array('other_box_0', 'other_box_1', 'other_box_2', 'other_box_3', 'other_box_4')), FALSE); $t4as->l101 = $total_other_deductions; //$total_deductions = Misc::MoneyFormat( Misc::sumMultipleColumns( $total_row, array('pension','income_tax','lump_sum_payment', 'self_employed_commission', 'annuities','service_fees') ), FALSE ); //$t4as->l82 = $total_deductions; $t4as->l82 = $total_row['income_tax']; $this->getFormObject()->addForm($t4as); if ($format == 'efile_xml') { $output_format = 'XML'; $file_name = 't4a_efile_' . date('Y_m_d') . '.xml'; $mime_type = 'applications/octet-stream'; //Force file to download. } else { $output_format = 'PDF'; $file_name = $this->file_name; $mime_type = $this->file_mime_type; } $output = $this->getFormObject()->output($output_format); return array('file_name' => $file_name, 'mime_type' => $mime_type, 'data' => $output); }
function calcHourlyRate($epoch = FALSE, $accurate_calculation = FALSE) { $hourly_wage = 0; if ($this->getType() == 10) { $hourly_wage = $this->getWage(); } else { $hourly_wage = $this->getAnnualHourlyRate($this->getAnnualWage(), $epoch, $accurate_calculation); } return Misc::MoneyFormat($hourly_wage, FALSE); }
function createInvoice($company_id, $client_id, $currency_id, $products, $status_id = 10, $payments = NULL, $user_ids = NULL, $shipping_policy_ids = NULL) { $if = TTnew('InvoiceFactory'); $ilf = TTnew('InvoiceListFactory'); $tf = TTnew('TransactionFactory'); $clf = TTnew('ClientListFactory'); $plf = TTnew('ProductListFactory'); if (isset($client_id) and $client_id != '') { $clf->getByIdAndCompanyId($client_id, $company_id); if ($clf->getRecordCount() > 0) { $c_obj = $clf->getCurrent(); } } $client_billing_contact_obj = $c_obj->getClientContactObject($c_obj->getDefaultBillingContact()); if (is_object($client_billing_contact_obj)) { $default_currency = $client_billing_contact_obj->getCurrency(); } else { $default_currency = $currency_id; } unset($client_billing_contact_obj); //-------------------------------------- $if->StartTransaction(); $if->setClient($client_id); $if->setStatus($status_id); $if->setBillingContact($c_obj->getDefaultBillingContact()); $if->setShippingContact($c_obj->getDefaultShippingContact()); $if->setOtherContact($c_obj->getDefaultOtherContact()); $if->setSalesContact($this->getRandomArrayValue((array) $user_ids)); $if->setCurrency($default_currency); $if->setOrderDate(TTDate::getTime()); $if->setInvoiceDate(TTDate::getTime()); if ($shipping_policy_ids != NULL) { $shipping_policy_id = $this->getRandomArrayValue((array) $shipping_policy_ids); } else { $shipping_policy_id = 0; } $combined_shipping_policy_arr = ShippingPolicyFactory::parseCombinedShippingPolicyServiceId($shipping_policy_id); if (isset($combined_shipping_policy_arr['shipping_policy_id'])) { $shipping_policy_id = $combined_shipping_policy_arr['shipping_policy_id']; } if (isset($combined_shipping_policy_arr['shipping_policy_service_id'])) { $shipping_policy_service_id = $combined_shipping_policy_arr['shipping_policy_service_id']; } else { $shipping_policy_service_id = $this->getRandomArrayValue((array) $shipping_policy_ids); } $if->setShippingPolicy($shipping_policy_id); $if->setShippingPolicyService($shipping_policy_service_id); $if->setPublicNote(''); $if->setPrivateNote(''); if ($if->isValid()) { $invoice_id = $if->Save(FALSE); } if (is_numeric($products)) { $products = (array) $products; } foreach ($products as $key => $product_id) { Debug::Text('Product Id: ' . $product_id, __FILE__, __LINE__, __METHOD__, 10); $plf->getByIdAndCompanyId($product_id, $company_id); if ($plf->getRecordCount() > 0) { foreach ($plf as $pf) { $transactions[$key]['counter'] = $key; $transactions[$key]['type_id'] = 10; $transactions[$key]['product_id'] = $product_id; $transactions[$key]['product_type_id'] = $pf->getType(); $transactions[$key]['product_part_number'] = $pf->getPartNumber(); $transactions[$key]['product_name'] = $pf->getName(); $transactions[$key]['description'] = ''; $transactions[$key]['currency_id'] = $default_currency; $transactions[$key]['unit_price'] = $pf->getUnitPrice(); $transactions[$key]['pro_rate_numerator'] = 1; $transactions[$key]['pro_rate_denominator'] = 1; $transactions[$key]['unit_cost'] = $pf->getUnitCost(); $transactions[$key]['quantity'] = rand(1, 10) * 10; $transactions[$key]['amount'] = bcmul($transactions[$key]['unit_price'], $transactions[$key]['quantity']); } } if (isset($payments)) { $payments[$key]['counter'] = $key; $payments[$key]['payment_type_id'] = 10; $payments[$key]['currency_id'] = $default_currency; $payments[$key]['amount'] = Misc::MoneyFormat($transactions[$key]['amount']); $taxes_arr = $if->calcTaxes(array($transactions[$key])); Debug::Arr($taxes_arr, 'Taxes...: ', __FILE__, __LINE__, __METHOD__, 10); if (is_array($taxes_arr)) { foreach ($taxes_arr as $ptp_data) { $payments[$key]['amount'] = Misc::MoneyFormat(bcadd($payments[$key]['amount'], $ptp_data['amount'])); } } } Debug::Arr($transactions[$key], 'Single Transaction...: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($payments[$key], 'Single Payment...: ', __FILE__, __LINE__, __METHOD__, 10); } Debug::Arr($transactions, 'Transaction...: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($payments, 'Payment...: ', __FILE__, __LINE__, __METHOD__, 10); $is_credit_transaction_valid = TRUE; $is_debit_transaction_valid = TRUE; //Add each transaction now. //Debug::Arr($transactions, 'Transactions: ', __FILE__, __LINE__, __METHOD__,10); if (isset($transactions) and count($transactions) > 0) { Debug::Text('Inserting Transactions: ' . count($transactions), __FILE__, __LINE__, __METHOD__, 10); foreach ($transactions as $transaction_data) { if ($is_debit_transaction_valid == TRUE and $if->setTransaction($transaction_data) == FALSE) { $is_debit_transaction_valid = FALSE; } } } if (isset($payments) and count($payments) > 0) { Debug::Text('Inserting Payments: ' . count($payments), __FILE__, __LINE__, __METHOD__, 10); foreach ($payments as $payment_counter => $payment_data) { $tf->setEffectiveDate(time()); $tf->setClient($client_id); $tf->setInvoice($invoice_id); //$tf->setStatus( 10 ); //Don't set status, let preSave() handle that. $tf->setType(20); //Credit $tf->setPaymentType($payment_data['payment_type_id']); /* if ( $payment_data['payment_type_id'] == 30 OR $payment_data['payment_type_id'] == 35 OR $payment_data['payment_type_id'] == 40 ) { $tf->setClientPayment($payment_data['client_payment_id']); } if ( $payment_data['payment_type_id'] != 10 ) { $tf->setConfirmNumber($payment_data['confirm_number']); } */ $tf->setCurrency($payment_data['currency_id']); $tf->setAmount($payment_data['amount']); if ($is_credit_transaction_valid == TRUE and $tf->isValid() == TRUE) { $save_result = $tf->Save(); if (is_numeric($save_result)) { $payment_transaction_ids[$save_result] = $payment_counter; } } else { $is_credit_transaction_valid = FALSE; } unset($payment_counter, $save_result); } } if ($is_debit_transaction_valid == TRUE and $is_credit_transaction_valid == TRUE) { if ($if->getEnableCalcShipping() == TRUE) { Debug::Text('calculating shipping!!', __FILE__, __LINE__, __METHOD__, 10); $if->insertShippingTransactions($if->calcShipping()); } $if->insertTaxTransactions($if->calcTaxes()); $if->CommitTransaction(); //$if->setStatus( $if->determineStatus() ); if ($if->isValid() == TRUE and $tf->Validator->isValid() == TRUE) { $if->Save(FALSE); return $invoice_id; } } else { $if->FailTransaction(); } return FALSE; }
$x = 0; foreach ($raw_rows as $user_id => $raw_row) { $user_obj = $ulf->getById($user_id)->getCurrent(); $tmp_rows[$x]['user_id'] = $user_id; $tmp_rows[$x]['full_name'] = $user_obj->getFullName(TRUE); //$tmp_rows[$x]['province'] = Option::getByKey($user_obj->getProvince(), $user_obj->getOptions('province') ); //$tmp_rows[$x]['province'] = $user_obj->getProvince(); $tmp_rows[$x]['province'] = $user_obj->getProvince(); $tmp_rows[$x]['country'] = $user_obj->getCountry(); $tmp_rows[$x]['title'] = Option::getByKey($user_obj->getTitle(), $title_options, NULL); $tmp_rows[$x]['group'] = Option::getByKey($user_obj->getGroup(), $group_options); $tmp_rows[$x]['default_branch'] = Option::getByKey($user_obj->getDefaultBranch(), $branch_options, NULL); $tmp_rows[$x]['default_department'] = Option::getByKey($user_obj->getDefaultDepartment(), $department_options, NULL); $tmp_rows[$x]['sin'] = $user_obj->getSIN(); foreach ($column_ps_entry_name_map as $column_key => $ps_entry_map) { $tmp_rows[$x][$column_key] = Misc::MoneyFormat(Misc::sumMultipleColumns($raw_rows[$user_id], $ps_entry_map), FALSE); } $x++; } } //var_dump($tmp_rows); //Skip grouping if they are displaying T4's if ($action != 'display_t4as' and isset($filter_data['primary_group_by']) and $filter_data['primary_group_by'] != '0') { Debug::Text('Primary Grouping Data By: ' . $filter_data['primary_group_by'], __FILE__, __LINE__, __METHOD__, 10); $ignore_elements = array_keys($static_columns); $filter_data['column_ids'] = array_diff($filter_data['column_ids'], $ignore_elements); //Add the group by element back in if (isset($filter_data['secondary_group_by']) and $filter_data['secondary_group_by'] != 0) { array_unshift($filter_data['column_ids'], $filter_data['primary_group_by'], $filter_data['secondary_group_by']); } else { array_unshift($filter_data['column_ids'], $filter_data['primary_group_by']);
function setAmount($value) { $value = trim($value); //Pull out only digits and periods. $value = $this->Validator->stripNonFloat($value); if ($this->Validator->isFloat('amount', $value, TTi18n::gettext('Invalid Amount, Must be a numeric value'))) { $this->data['amount'] = Misc::MoneyFormat($value, FALSE); return TRUE; } return FALSE; }
$filter_data['job_item_ids'] = array(-1); } //$plf->getReportByStartDateAndEndDateAndUserIdListAndBranchIdAndDepartmentIdAndJobIdListAndJobItemIdList( $filter_data['start_date'], $filter_data['end_date'], $filter_data['user_ids'], $filter_data['punch_branch_ids'], $filter_data['punch_department_ids'], $filter_data['job_ids'], $filter_data['job_item_ids'] ); $plf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data); foreach ($plf as $p_obj) { //Debug::Text('User ID: '. $p_obj->getColumn('user_id') .' Status ID: '. $p_obj->getColumn('status_id') .' Time Stamp: '. TTDate::getDate('DATE+TIME', TTDate::strtotime( $p_obj->getColumn('punch_time_stamp') ) ), __FILE__, __LINE__, __METHOD__,10); if (!isset($tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')])) { $hourly_rate = 0; if ($permission->Check('wage', 'view') == TRUE or in_array($p_obj->getColumn('user_id'), $wage_filter_data['permission_children_ids']) == TRUE) { $uw_obj = getUserWageObject($p_obj->getColumn('user_wage_id'), $p_obj->getColumn('user_id')); if (is_object($uw_obj)) { $hourly_rate = $uw_obj->getHourlyRate(); } } $actual_time_diff = (int) $p_obj->getColumn('actual_total_time') - (int) $p_obj->getColumn('total_time'); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')] = array('user_id' => $p_obj->getColumn('user_id'), 'group_id' => $p_obj->getColumn('group_id'), 'branch_id' => $p_obj->getColumn('branch_id'), 'department_id' => $p_obj->getColumn('department_id'), 'job_id' => $p_obj->getColumn('job_id'), 'job_name' => $p_obj->getColumn('job_name'), 'job_status_id' => $p_obj->getColumn('job_status_id'), 'job_manual_id' => $p_obj->getColumn('job_manual_id'), 'job_description' => $p_obj->getColumn('job_description'), 'job_branch_id' => $p_obj->getColumn('job_branch_id'), 'job_department_id' => $p_obj->getColumn('job_department_id'), 'job_group_id' => $p_obj->getColumn('job_group_id'), 'job_item_id' => $p_obj->getColumn('job_item_id'), 'quantity' => $p_obj->getColumn('quantity'), 'bad_quantity' => $p_obj->getColumn('bad_quantity'), 'note' => $p_obj->getColumn('note'), 'total_time' => $p_obj->getColumn('total_time'), 'total_time_wage' => Misc::MoneyFormat(bcmul(TTDate::getHours($p_obj->getColumn('total_time')), $hourly_rate), FALSE), 'actual_total_time' => $p_obj->getColumn('actual_total_time'), 'actual_total_time_diff' => $actual_time_diff, 'actual_total_time_wage' => Misc::MoneyFormat(bcmul(TTDate::getHours($p_obj->getColumn('actual_total_time')), $hourly_rate), FALSE), 'actual_total_time_diff_wage' => Misc::MoneyFormat(bcmul(TTDate::getHours($actual_time_diff), $hourly_rate)), 'other_id1' => $p_obj->getColumn('other_id1'), 'other_id2' => $p_obj->getColumn('other_id2'), 'other_id3' => $p_obj->getColumn('other_id3'), 'other_id4' => $p_obj->getColumn('other_id4'), 'other_id5' => $p_obj->getColumn('other_id5'), 'date_stamp' => TTDate::strtotime($p_obj->getColumn('date_stamp')), 'in_time_stamp' => NULL, 'in_actual_time_stamp' => NULL, 'in_type' => NULL, 'out_time_stamp' => NULL, 'out_actual_time_stamp' => NULL, 'out_type' => NULL, 'user_wage_id' => $p_obj->getColumn('user_wage_id'), 'hourly_rate' => Misc::MoneyFormat($hourly_rate, FALSE), 'in_station_type_id' => NULL, 'in_station_station_id' => NULL, 'in_station_source' => NULL, 'in_station_description' => NULL, 'out_station_type_id' => NULL, 'out_station_station_id' => NULL, 'out_station_source' => NULL, 'out_station_description' => NULL); } if ($p_obj->getColumn('status_id') == 10) { $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['in_time_stamp'] = TTDate::strtotime($p_obj->getColumn('time_stamp')); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['in_type'] = $p_obj->getColumn('type_id'); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['in_actual_time_stamp'] = TTDate::strtotime($p_obj->getColumn('actual_time_stamp')); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['in_station_type_id'] = $p_obj->getColumn('station_type_id'); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['in_station_station_id'] = $p_obj->getColumn('station_station_id'); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['in_station_source'] = $p_obj->getColumn('station_source'); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['in_station_description'] = $p_obj->getColumn('station_description'); } else { $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['out_time_stamp'] = TTDate::strtotime($p_obj->getColumn('time_stamp')); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['out_type'] = $p_obj->getColumn('type_id'); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['out_actual_time_stamp'] = TTDate::strtotime($p_obj->getColumn('actual_time_stamp')); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['out_station_type_id'] = $p_obj->getColumn('station_type_id'); $tmp_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][$p_obj->getColumn('punch_control_id')]['out_station_station_id'] = $p_obj->getColumn('station_station_id');
function _getData($format = NULL) { $this->tmp_data = array('schedule' => array(), 'user' => array(), 'total_shift' => array()); $columns = $this->getColumnDataConfig(); $filter_data = $this->getFilterConfig(); if ($this->getPermissionObject()->Check('schedule', 'view') == FALSE or $this->getPermissionObject()->Check('wage', 'view') == FALSE) { $hlf = TTnew('HierarchyListFactory'); $permission_children_ids = $wage_permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($this->getUserObject()->getCompany(), $this->getUserObject()->getID()); Debug::Arr($permission_children_ids, 'Permission Children Ids:', __FILE__, __LINE__, __METHOD__, 10); } else { //Get Permission Hierarchy Children first, as this can be used for viewing, or editing. $permission_children_ids = array(); $wage_permission_children_ids = array(); } if ($this->getPermissionObject()->Check('schedule', 'view') == FALSE) { if ($this->getPermissionObject()->Check('schedule', 'view_child') == FALSE) { $permission_children_ids = array(); } if ($this->getPermissionObject()->Check('schedule', 'view_own')) { $permission_children_ids[] = $this->getUserObject()->getID(); } $filter_data['permission_children_ids'] = $permission_children_ids; } //Get Wage Permission Hierarchy Children first, as this can be used for viewing, or editing. if ($this->getPermissionObject()->Check('wage', 'view') == TRUE) { $wage_permission_children_ids = TRUE; } elseif ($this->getPermissionObject()->Check('wage', 'view') == FALSE) { if ($this->getPermissionObject()->Check('wage', 'view_child') == FALSE) { $wage_permission_children_ids = array(); } if ($this->getPermissionObject()->Check('wage', 'view_own')) { $wage_permission_children_ids[] = $this->getUserObject()->getID(); } } //Debug::Text(' Permission Children: '. count($permission_children_ids) .' Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($permission_children_ids, 'Permission Children: '. count($permission_children_ids), __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($wage_permission_children_ids, 'Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10); if ($this->getUserObject()->getCompanyObject()->getProductEdition() >= TT_PRODUCT_CORPORATE) { $jlf = TTnew('JobListFactory'); $job_status_options = $jlf->getOptions('status'); } else { $job_status_options = array(); } $pay_period_ids = array(); if (strpos($format, 'schedule') === FALSE) { //Avoid running these queries when printing out the schedule. $slf = TTnew('ScheduleListFactory'); $slf->getScheduleSummaryReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data, NULL, NULL, NULL, array('last_name' => 'asc')); //Sort by last name mainly for the PDF schedule for printing. Debug::Text(' Total Rows: ' . $slf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); $this->getProgressBarObject()->start($this->getAMFMessageID(), $slf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...')); if ($slf->getRecordCount() > 0) { foreach ($slf as $key => $s_obj) { $hourly_rate = 0; if ($wage_permission_children_ids === TRUE or in_array($s_obj->getColumn('user_id'), $wage_permission_children_ids)) { $hourly_rate = $s_obj->getColumn('user_wage_hourly_rate'); } $date_stamp_epoch = TTDate::strtotime($s_obj->getColumn('date_stamp')); $shift_arr = array('user_id' => $s_obj->getColumn('user_id'), 'status_id' => $s_obj->getColumn('status_id'), 'group' => $s_obj->getColumn('group'), 'default_branch' => $s_obj->getColumn('default_branch'), 'default_department' => $s_obj->getColumn('default_department'), 'branch' => $s_obj->getColumn('branch'), 'department' => $s_obj->getColumn('department'), 'job' => $s_obj->getColumn('job'), 'job_status_id' => Option::getByKey($s_obj->getColumn('job_status_id'), $job_status_options, NULL), 'job_manual_id' => $s_obj->getColumn('job_manual_id'), 'job_description' => $s_obj->getColumn('job_description'), 'job_branch' => $s_obj->getColumn('job_branch'), 'job_department' => $s_obj->getColumn('job_department'), 'job_group' => $s_obj->getColumn('job_group'), 'job_item' => $s_obj->getColumn('job_item'), 'quantity' => $s_obj->getColumn('quantity'), 'bad_quantity' => $s_obj->getColumn('bad_quantity'), 'total_time' => $s_obj->getColumn('total_time'), 'total_time_wage' => Misc::MoneyFormat(bcmul(TTDate::getHours($s_obj->getColumn('total_time')), $hourly_rate), FALSE), 'total_time_wage_burden' => Misc::MoneyFormat(bcmul(TTDate::getHours($s_obj->getColumn('total_time')), bcmul($hourly_rate, bcdiv($s_obj->getColumn('user_labor_burden_percent'), 100))), FALSE), 'total_time_wage_with_burden' => Misc::MoneyFormat(bcmul(TTDate::getHours($s_obj->getColumn('total_time')), bcmul($hourly_rate, bcadd(bcdiv($s_obj->getColumn('user_labor_burden_percent'), 100), 1))), FALSE), 'other_id1' => $s_obj->getColumn('other_id1'), 'other_id2' => $s_obj->getColumn('other_id2'), 'other_id3' => $s_obj->getColumn('other_id3'), 'other_id4' => $s_obj->getColumn('other_id4'), 'other_id5' => $s_obj->getColumn('other_id5'), 'date_stamp' => $date_stamp_epoch, 'schedule_policy' => $s_obj->getColumn('schedule_policy'), 'absence_policy' => $s_obj->getColumn('absence_policy'), 'schedule_status' => Option::getByKey($s_obj->getStatus(), $s_obj->getOptions('status'), NULL), 'start_time' => TTDate::strtotime($s_obj->getColumn('start_time')), 'end_time' => TTDate::strtotime($s_obj->getColumn('end_time')), 'user_wage_id' => $s_obj->getColumn('user_wage_id'), 'hourly_rate' => Misc::MoneyFormat($hourly_rate, FALSE), 'pay_period_start_date' => strtotime($s_obj->getColumn('pay_period_start_date')), 'pay_period_end_date' => strtotime($s_obj->getColumn('pay_period_end_date')), 'pay_period_transaction_date' => strtotime($s_obj->getColumn('pay_period_transaction_date')), 'pay_period' => strtotime($s_obj->getColumn('pay_period_transaction_date')), 'pay_period_id' => $s_obj->getColumn('pay_period_id'), 'schedule_note' => $s_obj->getColumn('note'), 'total_shift' => 1); unset($hourly_rate); $this->tmp_data['schedule'][$s_obj->getColumn('user_id')][] = $shift_arr; $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } } //Debug::Arr($this->tmp_data['schedule'], 'Schedule Raw Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($this->form_data, 'Schedule Raw Data: ', __FILE__, __LINE__, __METHOD__,10); } unset($filter_data['status_id']); //This is for schedule status, not user status. //If we're printing the schedule, make sure we include the required columns. if (in_array($format, $this->special_output_format)) { $this->config['columns_data']['first_name'] = TRUE; $this->config['columns_data']['last_name'] = TRUE; } //Get user data for joining. $ulf = TTnew('UserListFactory'); $ulf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data); Debug::Text(' User Total Rows: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...')); foreach ($ulf as $key => $u_obj) { $this->tmp_data['user'][$u_obj->getId()] = $this->form_data['user'][$u_obj->getId()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig()); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } //Add OPEN user to the list so it can printed on schedules. $this->tmp_data['user'][0] = $this->form_data['user'][0] = array('first_name' => TTi18n::getText('OPEN'), 'last_name' => ''); //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10); return TRUE; }
} if (isset($taxable_wages_psea_ids) and is_array($taxable_wages_psea_ids) and in_array($pay_stub_entry_name_id, $taxable_wages_psea_ids)) { //Debug::Text('Total Taxable Wages Amount: '. $amount, __FILE__, __LINE__, __METHOD__,10); $taxable_wages_amount += $amount; } if (isset($tax_withheld_psea_ids) and is_array($tax_withheld_psea_ids) and in_array($pay_stub_entry_name_id, $tax_withheld_psea_ids)) { //Debug::Text('Total Tax Withheld Amount: '. $amount, __FILE__, __LINE__, __METHOD__,10); $tax_withheld_amount += $amount; } //Debug::Text('Total: Gross: '. $total_gross_amount .' Taxable Wages: '. $taxable_wages_amount .' Tax Withheld: '. $tax_withheld_amount .' Amount: '. $amount, __FILE__, __LINE__, __METHOD__,10); //$tmp_rows[$x][$pay_stub_entry_name_id] = $amount; } unset(${$pay_stub_entry_name_id}, $amount); $tmp_rows[$x]['subject_wages'] = Misc::MoneyFormat($total_gross_amount, FALSE); $tmp_rows[$x]['taxable_wages'] = Misc::MoneyFormat($taxable_wages_amount, FALSE); $tmp_rows[$x]['tax_withheld'] = Misc::MoneyFormat($tax_withheld_amount, FALSE); $x++; } } } //var_dump($tmp_rows); if (isset($tmp_rows) and isset($filter_data['primary_group_by']) and $filter_data['primary_group_by'] != '0') { Debug::Text('Primary Grouping Data By: ' . $filter_data['primary_group_by'], __FILE__, __LINE__, __METHOD__, 10); $ignore_elements = array_keys($static_columns); $filter_data['column_ids'] = array_diff($filter_data['column_ids'], $ignore_elements); //Add the group by element back in if (isset($filter_data['secondary_group_by']) and $filter_data['secondary_group_by'] != 0) { array_unshift($filter_data['column_ids'], $filter_data['primary_group_by'], $filter_data['secondary_group_by']); } else { array_unshift($filter_data['column_ids'], $filter_data['primary_group_by']); }
$t4->setCompanyAddress1($company_obj->getAddress1()); $t4->setCompanyAddress2($company_obj->getAddress2()); $t4->setCompanyCity($company_obj->getCity()); $t4->setCompanyProvince($company_obj->getProvince()); $t4->setCompanyPostalCode($company_obj->getPostalCode()); $t4sum = new T4Summary(); $t4sum->setTotalT4s(count($rows) - 1); $t4sum->setEmploymentIncome($rows[$last_row]['income']); $t4sum->setIncomeTax($rows[$last_row]['income_tax']); $t4sum->setEmployeeCPP($rows[$last_row]['employee_cpp']); $t4sum->setEmployeeEI($rows[$last_row]['employee_ei']); $t4sum->setEmployerCPP($rows[$last_row]['employer_cpp']); $t4sum->setEmployerEI($rows[$last_row]['employer_ei']); $t4sum->setEmployeeRPP($rows[$last_row]['rpp']); $t4sum->setPensionAdjustment($rows[$last_row]['pension_adjustment']); $total_deductions = Misc::MoneyFormat($rows[$last_row]['employee_cpp'] + $rows[$last_row]['employer_cpp'] + $rows[$last_row]['employee_ei'] + $rows[$last_row]['employer_ei'] + $rows[$last_row]['income_tax'], FALSE); $t4sum->setTotalDeductions($total_deductions); $t4->addT4Summary($t4sum); $i = 0; foreach ($rows as $row) { if ($i == $last_row) { continue; } $ulf = new UserListFactory(); $user_obj = $ulf->getById($row['user_id'])->getCurrent(); $t4ee = new T4Employee(); $t4ee->setSin($row['sin']); $t4ee->setFirstName($user_obj->getFirstName()); $t4ee->setMiddleName($user_obj->getMiddleName()); $t4ee->setLastName($user_obj->getLastName()); $t4ee->setAddress1($user_obj->getAddress1());
static function CalcDifferences($pay_stub_id1, $pay_stub_id2, $ps_amendment_date = NULL) { //PayStub 1 is new. //PayStub 2 is old. if ($pay_stub_id1 == '') { return FALSE; } if ($pay_stub_id2 == '') { return FALSE; } if ($pay_stub_id1 == $pay_stub_id2) { return FALSE; } Debug::Text('Calculating the differences between Pay Stub: ' . $pay_stub_id1 . ' And: ' . $pay_stub_id2, __FILE__, __LINE__, __METHOD__, 10); $pslf = new PayStubListFactory(); $pslf->StartTransaction(); $pslf->getById($pay_stub_id1); if ($pslf->getRecordCount() > 0) { $pay_stub1_obj = $pslf->getCurrent(); } else { Debug::Text('Pay Stub1 does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $pslf->getById($pay_stub_id2); if ($pslf->getRecordCount() > 0) { $pay_stub2_obj = $pslf->getCurrent(); } else { Debug::Text('Pay Stub2 does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if ($pay_stub1_obj->getUser() != $pay_stub2_obj->getUser()) { Debug::Text('Pay Stubs are from different users!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if ($ps_amendment_date == NULL or $ps_amendment_date == '') { Debug::Text('PS Amendment Date not set, trying to figure it out!', __FILE__, __LINE__, __METHOD__, 10); //Take a guess at the end of the newest open pay period. $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getByUserId($pay_stub2_obj->getUser()); if ($ppslf->getRecordCount() > 0) { Debug::Text('Found Pay Period Schedule', __FILE__, __LINE__, __METHOD__, 10); $pplf = new PayPeriodListFactory(); $pplf->getByPayPeriodScheduleIdAndTransactionDate($ppslf->getCurrent()->getId(), time()); if ($pplf->getRecordCount() > 0) { Debug::Text('Using Pay Period End Date.', __FILE__, __LINE__, __METHOD__, 10); $ps_amendment_date = TTDate::getBeginDayEpoch($pplf->getCurrent()->getEndDate()); } } else { Debug::Text('Using Today.', __FILE__, __LINE__, __METHOD__, 10); $ps_amendment_date = time(); } } Debug::Text('Using Date: ' . TTDate::getDate('DATE+TIME', $ps_amendment_date), __FILE__, __LINE__, __METHOD__, 10); //Only do Earnings for now. //Get all earnings, EE/ER deduction PS entries. $pay_stub1_entry_ids = NULL; $pay_stub1_entries = new PayStubEntryListFactory(); $pay_stub1_entries->getByPayStubIdAndType($pay_stub1_obj->getId(), array(10, 20, 30)); if ($pay_stub1_entries->getRecordCount() > 0) { Debug::Text('Pay Stub1 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_stub1_entries as $pay_stub1_entry_obj) { $pay_stub1_entry_ids[] = $pay_stub1_entry_obj->getPayStubEntryNameId(); } } else { Debug::Text('Pay Stub1 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } Debug::Arr($pay_stub1_entry_ids, 'Pay Stub1 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10); //var_dump($pay_stub1_entry_ids); $pay_stub2_entry_ids = NULL; $pay_stub2_entries = new PayStubEntryListFactory(); $pay_stub2_entries->getByPayStubIdAndType($pay_stub2_obj->getId(), array(10, 20, 30)); if ($pay_stub2_entries->getRecordCount() > 0) { Debug::Text('Pay Stub2 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_stub2_entries as $pay_stub2_entry_obj) { $pay_stub2_entry_ids[] = $pay_stub2_entry_obj->getPayStubEntryNameId(); } } else { Debug::Text('Pay Stub2 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } Debug::Arr($pay_stub1_entry_ids, 'Pay Stub2 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10); $pay_stub_entry_ids = array_unique(array_merge($pay_stub1_entry_ids, $pay_stub2_entry_ids)); Debug::Arr($pay_stub_entry_ids, 'Pay Stub Entry Differences: ', __FILE__, __LINE__, __METHOD__, 10); //var_dump($pay_stub_entry_ids); $pself = new PayStubEntryListFactory(); if (count($pay_stub_entry_ids) > 0) { foreach ($pay_stub_entry_ids as $pay_stub_entry_id) { Debug::Text('Entry ID: ' . $pay_stub_entry_id, __FILE__, __LINE__, __METHOD__, 10); $pay_stub1_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub1_obj->getId(), $pay_stub_entry_id); $pay_stub2_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub2_obj->getId(), $pay_stub_entry_id); Debug::Text('Pay Stub1 Amount: ' . $pay_stub1_entry_arr['amount'] . ' Pay Stub2 Amount: ' . $pay_stub2_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10); if ($pay_stub1_entry_arr['amount'] != $pay_stub2_entry_arr['amount']) { $amount_diff = bcsub($pay_stub1_entry_arr['amount'], $pay_stub2_entry_arr['amount'], 2); $units_diff = abs(bcsub($pay_stub1_entry_arr['units'], $pay_stub2_entry_arr['units'], 2)); Debug::Text('FOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff, __FILE__, __LINE__, __METHOD__, 10); //Generate PS Amendment. $psaf = new PayStubAmendmentFactory(); $psaf->setUser($pay_stub1_obj->getUser()); $psaf->setStatus('ACTIVE'); $psaf->setType(10); $psaf->setPayStubEntryNameId($pay_stub_entry_id); if ($units_diff > 0) { //Re-calculate amount when units are involved, due to rounding issues. $unit_rate = Misc::MoneyFormat(bcdiv($amount_diff, $units_diff)); $amount_diff = Misc::MoneyFormat(bcmul($unit_rate, $units_diff)); Debug::Text('bFOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff . ' Unit Rate: ' . $unit_rate, __FILE__, __LINE__, __METHOD__, 10); $psaf->setRate($unit_rate); $psaf->setUnits($units_diff); $psaf->setAmount($amount_diff); } else { $psaf->setAmount($amount_diff); } $psaf->setDescription('Adjustment from Pay Period Ending: ' . TTDate::getDate('DATE', $pay_stub2_obj->getEndDate())); $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($ps_amendment_date)); if ($psaf->isValid()) { $psaf->Save(); } unset($amount_diff, $units_diff, $unit_rate); } else { Debug::Text('No DIFFERENCE!', __FILE__, __LINE__, __METHOD__, 10); } } } $pslf->CommitTransaction(); return TRUE; }
foreach ($test_data[$country][$province_code]['income'] as $income) { $pd_obj = new PayrollDeduction($country, $province_code); $pd_obj->setDate($effective_date); $pd_obj->setAnnualPayPeriods($pay_periods); $pd_obj->setEnableCPPAndEIDeduction(TRUE); //Deduct CPP/EI. $pd_obj->setFederalTotalClaimAmount($federal_claim); $pd_obj->setProvincialTotalClaimAmount($provincial_claim); $pd_obj->setEIExempt(FALSE); $pd_obj->setCPPExempt(FALSE); $pd_obj->setFederalTaxExempt(FALSE); $pd_obj->setProvincialTaxExempt(FALSE); $pd_obj->setYearToDateCPPContribution(0); $pd_obj->setYearToDateEIContribution(0); $pd_obj->setGrossPayPeriodIncome($income); $retarr[] = array('country' => $country, 'province' => $province_code, 'date' => date('m/d/y', $effective_date), 'pay_periods' => $pay_periods, 'federal_claim' => $pd_obj->getFederalTotalClaimAmount(), 'provincial_claim' => $pd_obj->getProvincialTotalClaimAmount(), 'gross_income' => $income, 'federal_deduction' => Misc::MoneyFormat($pd_obj->getFederalPayPeriodDeductions(), FALSE), 'provincial_deduction' => Misc::MoneyFormat($pd_obj->getProvincialPayPeriodDeductions(), FALSE)); } } } } } //generate column array. $column_keys = array_keys($retarr[0]); foreach ($column_keys as $column_key) { $columns[$column_key] = $column_key; } //var_dump($test_data); //var_dump($retarr); echo Misc::Array2CSV($retarr, $columns, FALSE, $include_header = TRUE); } }
function Validate() { if ($this->getType() == 10) { //If rate and units are set, and not amount, calculate the amount for us. if ($this->getRate() !== NULL and $this->getUnits() !== NULL and $this->getAmount() == NULL) { $this->preSave(); } //Make sure rate * units = amount if ($this->getAmount() === NULL) { Debug::Text('Amount is NULL...', __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTrue('amount', FALSE, TTi18n::gettext('Invalid Amount')); } //Make sure amount is sane given the rate and units. if ($this->getRate() !== NULL and $this->getUnits() !== NULL and $this->getRate() != 0 and $this->getUnits() != 0 and $this->getRate() != '' and $this->getUnits() != '' and Misc::MoneyFormat(bcmul($this->getRate(), $this->getUnits()), FALSE) != Misc::MoneyFormat($this->getAmount(), FALSE)) { Debug::text('Validate: Rate: ' . $this->getRate() . ' Units: ' . $this->getUnits() . ' Amount: ' . $this->getAmount() . ' Calc: Rate: ' . $this->getRate() . ' Units: ' . $this->getUnits() . ' Total: ' . Misc::MoneyFormat(bcmul($this->getRate(), $this->getUnits()), FALSE), __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTrue('amount', FALSE, TTi18n::gettext('Invalid Amount, calculation is incorrect')); } } else { } //FIXME: Make sure effective date isn't in a CLOSED pay period? return TRUE; }
function filterAmountPadded($value) { if (isset($this->amount)) { $value = str_pad(Misc::MoneyFormat($this->amount), 12, '*', STR_PAD_LEFT); } if (get_class($this) === 'ChequeForms_9085') { return ' ' . $this->symbol . $value; } if (get_class($this) === 'ChequeForms_FORM1') { return ' ' . $this->symbol . $value; } if (get_class($this) === 'ChequeForms_FORM2') { return $this->symbol . ' ' . $value; } return $value; }
} $tmp_rows = Misc::ArrayGroupBy($tmp_rows, array(Misc::trimSortPrefix($filter_data['primary_group_by']), Misc::trimSortPrefix($filter_data['secondary_group_by'])), Misc::trimSortPrefix($ignore_elements)); } if (isset($tmp_rows)) { foreach ($tmp_rows as $row) { $rows[] = $row; } if ($filter_data['primary_sort'] == 'hire_date') { $filter_data['primary_sort'] = 'hire_date_order'; } //$rows = Sort::Multisort($rows, $filter_data['primary_sort'], NULL, 'ASC'); $rows = Sort::Multisort($rows, Misc::trimSortPrefix($filter_data['primary_sort']), Misc::trimSortPrefix($filter_data['secondary_sort']), $filter_data['primary_sort_dir'], $filter_data['secondary_sort_dir']); $total_row = Misc::ArrayAssocSum($rows, NULL, 2); //Get values to go directly on the PD7AE (05) form. if (isset($total_row)) { $form_data = array('cpp' => Misc::MoneyFormat($total_row['cpp_total']), 'ei' => Misc::MoneyFormat($total_row['ei_total']), 'tax' => Misc::MoneyFormat($total_row['tax_total']), 'amount_due' => Misc::MoneyFormat($total_row['total']), 'gross_payroll' => Misc::MoneyFormat($total_row[$pseal_obj->getTotalGross()]), 'employees' => $total_employees, 'due_date' => Wage::getRemittanceDueDate($transaction_date, $total_row['total']), 'end_remitting_period' => date('Y-m', $transaction_date)); } //var_dump($form_data); $last_row = count($rows); $rows[$last_row] = $total_row; foreach ($static_columns as $static_column_key => $static_column_val) { $rows[$last_row][Misc::trimSortPrefix($static_column_key)] = NULL; } unset($static_column_key, $static_column_val); } } } foreach ($filter_data['column_ids'] as $column_key) { //$filter_columns[$column_key] = $report_columns[$column_key]; $filter_columns[Misc::trimSortPrefix($column_key)] = $columns[$column_key]; }
$total_je_records[$grouped_je_record['type']] = $grouped_je_record['amount']; } if (isset($total_je_records['debit']) and isset($total_je_records['credit'])) { $total_je_records['diff'] = bcsub($total_je_records['debit'], $total_je_records['credit']); } } $grouped_je_records['total'] = $total_je_records; //var_dump($total_je_records); //var_dump($grouped_je_records); //var_dump($grouped_je_records); foreach ($grouped_je_records as $je_record) { $tmp_arr = array('user_id' => $user_obj->getId(), 'full_name' => $user_obj->getFullName(TRUE), 'transaction_date' => $ps_obj->getTransactionDate(), 'pay_stub_id' => $ps_obj->getId(), 'pay_period_id' => $ps_obj->getPayPeriod(), 'province' => $user_obj->getProvince(), 'country' => $user_obj->getCountry(), 'title' => $title_options[$user_obj->getTitle()], 'default_branch_id' => $user_obj->getDefaultBranch(), 'default_branch' => $branch_options[$user_obj->getDefaultBranch()], 'default_department_id' => $user_obj->getDefaultDepartment(), 'default_department' => $department_options[$user_obj->getDefaultDepartment()], 'type' => $je_record['type'], 'account' => $je_record['account'], 'amount' => $je_record['amount']); if ($je_record['type'] == 'total') { $tmp_arr['total_debits'] = Misc::MoneyFormat($je_record['debit'], FALSE); $tmp_arr['total_credits'] = Misc::MoneyFormat($je_record['credit'], FALSE); $tmp_arr['total_diff'] = Misc::MoneyFormat($je_record['diff'], FALSE); } $tmp_rows[] = $tmp_arr; } //var_dump($tmp_rows); unset($grouped_je_records, $total_je_records); } } } if (isset($tmp_rows) and isset($filter_data['primary_group_by']) and $filter_data['primary_group_by'] != '0') { Debug::Text('Grouping Data By: ' . $filter_data['primary_group_by'], __FILE__, __LINE__, __METHOD__, 10); $ignore_elements = array_keys($static_columns); $tmp_rows = Misc::ArrayGroupBy($tmp_rows, array('transaction_date', 'type', 'account', Misc::trimSortPrefix($filter_data['primary_group_by'])), $ignore_elements); //var_dump($tmp_rows); $final_group_key = Misc::trimSortPrefix($filter_data['primary_group_by']); } else {
static function getAfterDecimal($float, $format_number = TRUE) { if ($format_number == TRUE) { $float = Misc::MoneyFormat($float, FALSE); } $float_array = preg_split('/\\./', $float); if (isset($float_array[1])) { return str_pad($float_array[1], 2, '0'); } return FALSE; }
public function mf($amount) { return Misc::MoneyFormat($amount, FALSE); }
$f941->l17_month3 = $lines_arr['3']['10']; } } elseif (isset($setup_data['deposit_schedule']) and $setup_data['deposit_schedule'] == 20) { $f941sb = $gf->getFormObject('941sb', 'US'); $f941sb->setShowBackground($show_background); $f941sb->year = $filter_data['year']; $f941sb->ein = $current_company->getBusinessNumber(); $f941sb->name = $setup_data['name']; $f941sb->quarter = $filter_data['quarter_id']; for ($i = 1; $i <= 3; $i++) { for ($d = 1; $d <= 31; $d++) { if (isset($pp_lines_arr[$i])) { foreach ($pp_lines_arr[$i] as $pay_period_id => $data) { $dom = TTDate::getDayOfMonth($pay_period_transaction_dates[$pay_period_id]); if ($d == $dom) { $f941sb_data[$i][$d] = Misc::MoneyFormat($data['10'], FALSE); } } } } } if (isset($f941sb_data[1])) { $f941sb->month1 = $f941sb_data[1]; } if (isset($f941sb_data[2])) { $f941sb->month2 = $f941sb_data[2]; } if (isset($f941sb_data[3])) { $f941sb->month3 = $f941sb_data[3]; } unset($i, $d, $f941sb_data);
function getROE($rlf = NULL, $show_background = TRUE) { if (!is_object($rlf) and $this->getId() != '') { $rlf = TTnew('ROEListFactory'); $rlf->getById($this->getId()); } if (get_class($rlf) !== 'ROEListFactory') { return FALSE; } $border = 0; if ($rlf->getRecordCount() > 0) { $ppsf = TTnew('PayPeriodScheduleListFactory'); $pay_period_type_options = $ppsf->getOptions('type'); $pdf = new TTPDF(); $pdf->setMargins(0, 0, 0, 0); $pdf->SetAutoPageBreak(FALSE); foreach ($rlf as $r_obj) { $pdf->SetFont('freesans', '', 12); //Get User information $ulf = TTnew('UserListFactory'); $user_obj = $ulf->getById($r_obj->getUser())->getCurrent(); $ulf = TTnew('UserListFactory'); $created_user_obj = $ulf->getById($r_obj->getCreatedBy())->getCurrent(); //Get company information $clf = TTnew('CompanyListFactory'); $company_obj = $clf->getById($user_obj->getCompany())->getCurrent(); $pdf->AddPage(); if ($show_background == TRUE) { //Use this command to convert PDF to images: convert -density 600x600 -quality 00 $file $pdf->Image(Environment::getImagesPath() . 'roe-template.jpg', 0, 0, 210, 300); } //Serial $pdf->setXY(10, 17); $pdf->Cell(55, 10, $r_obj->getSerial(), $border, 0, 'L'); //Employer Info $pdf->setXY(10, 30); $pdf->Cell(120, 10, $company_obj->getName(), $border, 0, 'L'); $pdf->setXY(10, 40); $pdf->Cell(120, 10, $company_obj->getAddress1() . ' ' . $company_obj->getAddress2(), $border, 0, 'L'); $pdf->setXY(10, 50); $pdf->Cell(90, 10, $company_obj->getCity() . ', ' . $company_obj->getProvince(), $border, 0, 'L'); $postal_code_a = substr($company_obj->getPostalCode(), 0, 3); $postal_code_b = substr($company_obj->getPostalCode(), 3, 6); $pdf->setXY(110, 50); $pdf->Cell(10, 10, $postal_code_a, $border, 0, 'L'); $pdf->setXY(122, 50); $pdf->Cell(10, 10, $postal_code_b, $border, 0, 'L'); //Business Number $pdf->setXY(138, 28); $pdf->Cell(120, 10, $company_obj->getBusinessNumber(), $border, 0, 'L'); //Pay Period Type $pdf->setXY(138, 40); $pdf->Cell(50, 10, $pay_period_type_options[$r_obj->getPayPeriodType()], $border, 0, 'L'); //SIN $pdf->setXY(138, 50); $pdf->Cell(50, 10, $user_obj->getSIN(), $border, 0, 'L'); //Employee info $pdf->SetFontSize(10); $pdf->setXY(10, 75); $pdf->Cell(90, 5, $user_obj->getFullName(), $border, 0, 'L'); $pdf->setXY(10, 80); $pdf->Cell(90, 5, $user_obj->getAddress1() . ' ' . $user_obj->getAddress2(), $border, 0, 'L'); $pdf->setXY(10, 85); $pdf->Cell(90, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 0, 'L'); $pdf->SetFontSize(12); //Employee Title if (is_object($user_obj->getTitleObject())) { $title = $user_obj->getTitleObject()->getName(); } else { $title = NULL; } $pdf->setXY(10, 100); $pdf->Cell(90, 10, $title, $border, 0, 'L'); //First Day Worked $pdf->SetFontSize(10); $first_date = getdate($r_obj->getFirstDate()); $pdf->setXY(175, 64); $pdf->Cell(8, 10, $first_date['mday'], $border, 0, 'C'); $pdf->setXY(185, 64); $pdf->Cell(8, 10, $first_date['mon'], $border, 0, 'C'); $pdf->setXY(196, 64); $pdf->Cell(10, 10, $first_date['year'], $border, 0, 'C'); //Last day paid $last_date = getdate($r_obj->getLastDate()); $pdf->setXY(175, 75); $pdf->Cell(8, 10, $last_date['mday'], $border, 0, 'C'); $pdf->setXY(185, 75); $pdf->Cell(8, 10, $last_date['mon'], $border, 0, 'C'); $pdf->setXY(196, 75); $pdf->Cell(10, 10, $last_date['year'], $border, 0, 'C'); //Pay Period End Date $pay_period_end_date = getdate($r_obj->getPayPeriodEndDate()); $pdf->setXY(175, 86); $pdf->Cell(8, 10, $pay_period_end_date['mday'], $border, 0, 'C'); $pdf->setXY(185, 86); $pdf->Cell(8, 10, $pay_period_end_date['mon'], $border, 0, 'C'); $pdf->setXY(196, 86); $pdf->Cell(10, 10, $pay_period_end_date['year'], $border, 0, 'C'); //Insurable Hours $pdf->SetFontSize(10); $pdf->setXY(75, 113); $pdf->Cell(25, 10, Misc::getBeforeDecimal($r_obj->getInsurableHours()), $border, 0, 'R'); $pdf->setXY(101, 113); $pdf->Cell(10, 10, Misc::getAfterDecimal(Misc::MoneyFormat($r_obj->getInsurableHours(), FALSE)), $border, 0, 'L'); //Enter Code $pdf->setXY(185, 113); $pdf->Cell(10, 10, $r_obj->getCode(), $border, 0, 'C'); //Further Information Contact Name $pdf->setXY(130, 126); $pdf->Cell(75, 5, $created_user_obj->getFullName(), $border, 0, 'R'); $pdf->setXY(130, 132); $pdf->Cell(75, 10, $created_user_obj->getWorkPhone(), $border, 0, 'R'); //Insurable Earnings $pdf->setXY(75, 131); $pdf->Cell(25, 10, Misc::getBeforeDecimal($r_obj->getInsurableEarnings()), $border, 0, 'R'); $pdf->setXY(101, 131); $pdf->Cell(10, 10, Misc::getAfterDecimal(Misc::MoneyFormat($r_obj->getInsurableEarnings(), FALSE)), $border, 0, 'L'); //Check to see if a pay period didn't have earnings. if ($r_obj->isPayPeriodWithNoEarnings() == TRUE) { $pay_period_earnings = $r_obj->getInsurableEarningsByPayPeriod(); if (is_array($pay_period_earnings)) { //Add additional entries for testing alignment purposes. /* for( $y=0; $y < 14; $y++ ) { $pay_period_earnings[] = array('amount' => rand(1,10) ); } */ $top_left_x = $x = Misc::AdjustXY(30, 0); $top_left_y = $y = Misc::AdjustXY(157, 0); $col = 1; $i = 1; foreach ($pay_period_earnings as $pay_period_earning) { Debug::Text('I: ' . $i . ' X: ' . $x . ' Y: ' . $y . ' Col: ' . $col . ' Amount: ' . (double) $pay_period_earning['amount'], __FILE__, __LINE__, __METHOD__, 10); $pdf->setXY($x, $y); $pdf->Cell(6, 6, Misc::MoneyFormat((double) $pay_period_earning['amount'], FALSE), $border, 0, 'R'); if ($i > 0 and $i % 3 == 0) { $x = $top_left_x; $y += 7; } else { $x += 35; } $i++; } } } //Box 17A, Vacation pay in last pay period. $vacation_pay = $r_obj->getLastPayPeriodVacationEarnings(); if ($vacation_pay > 0) { $pdf->setXY(132, 155); $pdf->Cell(10, 10, Misc::getBeforeDecimal(Misc::MoneyFormat($vacation_pay, FALSE)), $border, 0, 'R'); $pdf->Cell(10, 10, Misc::getAfterDecimal(Misc::MoneyFormat($vacation_pay, FALSE)), $border, 0, 'L'); } //Comments $pdf->setXY(115, 212); $pdf->MultiCell(85, 5, $r_obj->getComments(), $border, 'L'); //English $pdf->setXY(8.5, 256.5); $pdf->Cell(10, 10, 'X', $border, 0, 'L'); //ROE creator phone number $pdf->setXY(75, 258); $pdf->Cell(25, 10, $created_user_obj->getWorkPhone(), $border, 0, 'L'); //ROE create name. $pdf->SetFontSize(12); $pdf->setXY(87, 273); $pdf->Cell(75, 10, $created_user_obj->getFullName(), $border, 0, 'C'); //Create Date $created_date = getdate($r_obj->getCreatedDate()); $pdf->SetFontSize(10); $pdf->setXY(175, 273); $pdf->Cell(8, 10, $created_date['mday'], $border, 0, 'C'); $pdf->setXY(185, 273); $pdf->Cell(8, 10, $created_date['mon'], $border, 0, 'C'); $pdf->setXY(195, 273); $pdf->Cell(10, 10, $created_date['year'], $border, 0, 'C'); } $output = $pdf->Output('', 'S'); } if (isset($output)) { return $output; } return FALSE; }
function _outputPDFForm($format = NULL) { // Always display the background. $show_background = TRUE; Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10); $setup_data = $this->getFormConfig(); $filter_data = $this->getFilterConfig(); //Debug::Arr($setup_data, 'Setup Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($this->data, 'Data: ', __FILE__, __LINE__, __METHOD__,10); //$last_row = count($this->form_data)-1; //$total_row = $last_row+1; $current_company = $this->getUserObject()->getCompanyObject(); if (!is_object($current_company)) { Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $roe = $this->getROEObject(); $roe->setShowBackground($show_background); //$roe->setDebug( TRUE ); //$roe->setType( $form_type ); $roe->business_number = $current_company->getBusinessNumber(); $roe->company_name = $current_company->getName(); $roe->company_address1 = $current_company->getAddress1(); $roe->company_address2 = $current_company->getAddress2(); $roe->company_city = $current_company->getCity(); $roe->company_province = $current_company->getProvince(); $roe->company_postal_code = $current_company->getPostalCode(); $roe->company_work_phone = $current_company->getWorkPhone(); $roe->english = TRUE; $i = 0; foreach ($this->form_data as $row) { if (!isset($row['user_id'])) { Debug::Text('User ID not set!', __FILE__, __LINE__, __METHOD__, 10); continue; } $ulf = TTnew('UserListFactory'); $ulf->getById((int) $row['user_id']); if ($ulf->getRecordCount() == 1) { $user_obj = $ulf->getCurrent(); $title_obj = $user_obj->getTitleObject(); $ee_data = array('first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'employee_full_name' => $user_obj->getFullName(FALSE), 'employee_address1' => $user_obj->getAddress1(), 'employee_address2' => $user_obj->getAddress2(), 'employee_city' => $user_obj->getCity(), 'employee_province' => $user_obj->getProvince(), 'employee_postal_code' => $user_obj->getPostalCode(), 'title' => is_object($title_obj) ? $title_obj->getName() : NULL, 'sin' => $user_obj->getSIN(), 'pay_period_type' => $row['pay_period_type'], 'pay_period_type_id' => $row['pay_period_type_id'], 'code_id' => $row['code_id'], 'first_date' => TTDate::parseDateTime($row['first_date']), 'last_date' => TTDate::parseDateTime($row['last_date']), 'pay_period_end_date' => TTDate::parseDateTime($row['pay_period_end_date']), 'recall_date' => TTDate::parseDateTime($row['recall_date']), 'insurable_hours' => $row['insurable_hours'], 'insurable_earnings' => $row['insurable_earnings'], 'vacation_pay' => $row['vacation_pay'], 'serial' => $row['serial'], 'comments' => $row['comments'], 'created_date' => TTDate::parseDateTime($row['created_date'])); } $ulf->getById((int) $row['created_by_id']); if ($ulf->getRecordCount() == 1) { $user_obj = $ulf->getCurrent(); $ee_data['created_user_first_name'] = $user_obj->getFirstName(); $ee_data['created_user_middle_name'] = $user_obj->getMiddleName(); $ee_data['created_user_last_name'] = $user_obj->getLastName(); $ee_data['created_user_full_name'] = $user_obj->getFullName(FALSE); $ee_data['created_user_work_phone'] = $user_obj->getWorkPhone(); } if (isset($row['pay_period_earnings']) and is_array($row['pay_period_earnings'])) { foreach ($row['pay_period_earnings'] as $pay_period_earning) { $ee_data['pay_period_earnings'][] = Misc::MoneyFormat($pay_period_earning['amount'], FALSE); } } $roe->addRecord($ee_data); unset($ee_data); $i++; } $this->getFormObject()->addForm($roe); if ($format == 'efile_xml') { $output_format = 'XML'; $file_name = 'roe_efile_' . date('Y_m_d') . '.blk'; //The filename should actually end in ".blk" instead of ".xml" $mime_type = 'applications/octet-stream'; //Force file to download. } else { $output_format = 'PDF'; $file_name = $this->file_name; $mime_type = $this->file_mime_type; } $output = $this->getFormObject()->output($output_format); return array('file_name' => $file_name, 'mime_type' => $mime_type, 'data' => $output); }
function _outputPDFForm($format = NULL) { $show_background = TRUE; if ($format == 'pdf_form_print' or $format == 'pdf_form_print_government') { $show_background = FALSE; } Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10); $setup_data = $this->getFormConfig(); $filter_data = $this->getFilterConfig(); //Debug::Arr($setup_data, 'Setup Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($this->data, 'Data: ', __FILE__, __LINE__, __METHOD__,10); //$last_row = count($this->form_data)-1; //$total_row = $last_row+1; $current_company = $this->getUserObject()->getCompanyObject(); if (!is_object($current_company)) { Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $this->sortFormData(); //Make sure forms are sorted. if ($format == 'efile_xml') { $t619 = $this->getT619Object(); $t619->setStatus($setup_data['status_id']); $t619->transmitter_number = isset($setup_data['transmitter_number']) ? $setup_data['transmitter_number'] : NULL; $t619->transmitter_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName(); $t619->transmitter_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1(); $t619->transmitter_address2 = (isset($setup_data['address2']) and $setup_data['address2'] != '') ? $setup_data['address2'] : $current_company->getAddress2(); $t619->transmitter_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity(); $t619->transmitter_province = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince(); $t619->transmitter_postal_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode(); $t619->contact_name = $this->getUserObject()->getFullName(); $t619->contact_phone = $current_company->getWorkPhone(); $t619->contact_email = $this->getUserObject()->getWorkEmail(); $this->getFormObject()->addForm($t619); } $t4 = $this->getT4Object(); if (isset($setup_data['include_t4_back']) and $setup_data['include_t4_back'] == 1) { $t4->setShowInstructionPage(TRUE); } if (stristr($format, 'government')) { $form_type = 'government'; } else { $form_type = 'employee'; } Debug::Text('Form Type: ' . $form_type, __FILE__, __LINE__, __METHOD__, 10); $t4->setType($form_type); $t4->setStatus($setup_data['status_id']); $t4->year = TTDate::getYear($filter_data['start_date']); $t4->payroll_account_number = (isset($setup_data['payroll_account_number']) and $setup_data['payroll_account_number'] != '') ? $setup_data['payroll_account_number'] : $current_company->getBusinessNumber(); $t4->company_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName(); $i = 0; if (is_array($this->form_data)) { foreach ($this->form_data as $row) { //if ( $i == $last_row ) { // continue; //} if (!isset($row['user_id'])) { Debug::Text('User ID not set!', __FILE__, __LINE__, __METHOD__, 10); continue; } $ulf = TTnew('UserListFactory'); $ulf->getById((int) $row['user_id']); if ($ulf->getRecordCount() == 1) { $user_obj = $ulf->getCurrent(); $ee_data = array('first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'address1' => $user_obj->getAddress1(), 'address2' => $user_obj->getAddress2(), 'city' => $user_obj->getCity(), 'province' => $user_obj->getProvince(), 'employment_province' => $user_obj->getProvince(), 'postal_code' => $user_obj->getPostalCode(), 'sin' => $user_obj->getSIN(), 'employee_number' => $user_obj->getEmployeeNumber(), 'l14' => $row['income'], 'l22' => $row['tax'], 'l16' => $row['employee_cpp'], 'l24' => $row['ei_earnings'], 'l26' => $row['cpp_earnings'], 'l18' => $row['employee_ei'], 'l44' => $row['union_dues'], 'l20' => $row['rpp'], 'l46' => $row['charity'], 'l52' => $row['pension_adjustment'], 'l50' => $setup_data['rpp_number'], 'cpp_exempt' => FALSE, 'ei_exempt' => FALSE, 'other_box_0_code' => NULL, 'other_box_0' => NULL, 'other_box_1_code' => NULL, 'other_box_1' => NULL, 'other_box_2_code' => NULL, 'other_box_2' => NULL, 'other_box_3_code' => NULL, 'other_box_3' => NULL, 'other_box_4_code' => NULL, 'other_box_4' => NULL, 'other_box_5_code' => NULL, 'other_box_5' => NULL); //Get User Tax / Deductions by Pay Stub Account. $udlf = TTnew('UserDeductionListFactory'); if (isset($setup_data['employee_cpp']['include_pay_stub_entry_account'])) { $udlf->getByUserIdAndPayStubEntryAccountID($user_obj->getId(), $setup_data['employee_cpp']['include_pay_stub_entry_account']); //FIXME: What if they were CPP exempt because of age, so no CPP was taken off, but they are assigned to the Tax/Deduction? //Don't think there is much we can do about this for now. if ($setup_data['employee_cpp']['include_pay_stub_entry_account'] != 0 and $udlf->getRecordCount() == 0 and $row['employee_cpp'] == 0) { //Debug::Text('CPP Exempt!', __FILE__, __LINE__, __METHOD__,10); $ee_data['cpp_exempt'] = TRUE; } } if (isset($setup_data['employee_ei']['include_pay_stub_entry_account'])) { $udlf->getByUserIdAndPayStubEntryAccountID($user_obj->getId(), $setup_data['employee_ei']['include_pay_stub_entry_account']); if ($setup_data['employee_ei']['include_pay_stub_entry_account'] != 0 and $udlf->getRecordCount() == 0 and $row['employee_ei'] == 0) { //Debug::Text('EI Exempt!', __FILE__, __LINE__, __METHOD__,10); $ee_data['ei_exempt'] = TRUE; } } if ($row['other_box_0'] > 0 and isset($setup_data['other_box'][0]['box']) and $setup_data['other_box'][0]['box'] != '') { $ee_data['other_box_0_code'] = $setup_data['other_box'][0]['box']; $ee_data['other_box_0'] = $row['other_box_0']; } if ($row['other_box_1'] > 0 and isset($setup_data['other_box'][1]['box']) and $setup_data['other_box'][1]['box'] != '') { $ee_data['other_box_1_code'] = $setup_data['other_box'][1]['box']; $ee_data['other_box_1'] = $row['other_box_1']; } if ($row['other_box_2'] > 0 and isset($setup_data['other_box'][2]['box']) and $setup_data['other_box'][2]['box'] != '') { $ee_data['other_box_2_code'] = $setup_data['other_box'][2]['box']; $ee_data['other_box_2'] = $row['other_box_2']; } if ($row['other_box_3'] > 0 and isset($setup_data['other_box'][3]['box']) and $setup_data['other_box'][3]['box'] != '') { $ee_data['other_box_3_code'] = $setup_data['other_box'][3]['box']; $ee_data['other_box_3'] = $row['other_box_3']; } if ($row['other_box_4'] > 0 and isset($setup_data['other_box'][4]['box']) and $setup_data['other_box'][4]['box'] != '') { $ee_data['other_box_4_code'] = $setup_data['other_box'][4]['box']; $ee_data['other_box_4'] = $row['other_box_4']; } if ($row['other_box_5'] > 0 and isset($setup_data['other_box'][5]['box']) and $setup_data['other_box'][5]['box'] != '') { $ee_data['other_box_5_code'] = $setup_data['other_box'][5]['box']; $ee_data['other_box_5'] = $row['other_box_5']; } $t4->addRecord($ee_data); unset($ee_data); $i++; } } $this->getFormObject()->addForm($t4); } //Handle T4Summary $t4s = $this->getT4SumObject(); $t4s->setStatus($setup_data['status_id']); $t4s->year = $t4->year; $t4s->payroll_account_number = $t4->payroll_account_number; $t4s->company_name = $t4->company_name; $t4s->company_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1(); $t4s->company_address2 = (isset($setup_data['address2']) and $setup_data['address2'] != '') ? $setup_data['address2'] : $current_company->getAddress2(); $t4s->company_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity(); $t4s->company_province = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince(); $t4s->company_postal_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode(); $t4s->l76 = $this->getUserObject()->getFullName(); //Contact name. $t4s->l78 = $current_company->getWorkPhone(); $total_row = Misc::ArrayAssocSum($this->form_data); $t4s->l88 = count($this->form_data); $t4s->l14 = $total_row['income']; $t4s->l22 = $total_row['tax']; $t4s->l16 = $total_row['employee_cpp']; $t4s->l18 = $total_row['employee_ei']; $t4s->l27 = $total_row['employer_cpp']; $t4s->l19 = $total_row['employer_ei']; $t4s->l20 = $total_row['rpp']; $t4s->l52 = $total_row['pension_adjustment']; $total_deductions = Misc::MoneyFormat(Misc::sumMultipleColumns($total_row, array('tax', 'employee_cpp', 'employee_ei', 'employer_cpp', 'employer_ei')), FALSE); $t4s->l82 = $total_deductions; $this->getFormObject()->addForm($t4s); if ($format == 'efile_xml') { $output_format = 'XML'; $file_name = 't4_efile_' . date('Y_m_d') . '.xml'; $mime_type = 'applications/octet-stream'; //Force file to download. } else { $output_format = 'PDF'; $file_name = $this->file_name . '.pdf'; $mime_type = $this->file_mime_type; } $output = $this->getFormObject()->output($output_format); if (!is_array($output)) { return array('file_name' => $file_name, 'mime_type' => $mime_type, 'data' => $output); } return $output; }
function Validate() { if ($this->validate_only == FALSE and $this->getUser() == FALSE and $this->Validator->hasError('user_id') == FALSE) { $this->Validator->isTrue('user_id', FALSE, TTi18n::gettext('Invalid Employee')); } //Only show this error if it wasn't already triggered earlier. if ($this->validate_only == FALSE and is_object($this->Validator) and $this->Validator->hasError('pay_stub_entry_name_id') == FALSE and $this->getPayStubEntryNameId() == FALSE) { $this->Validator->isTrue('pay_stub_entry_name_id', FALSE, TTi18n::gettext('Invalid Pay Stub Account')); } if ($this->getType() == 10) { //If rate and units are set, and not amount, calculate the amount for us. if ($this->getRate() !== NULL and $this->getUnits() !== NULL and $this->getAmount() == NULL) { $this->preSave(); } //Make sure rate * units = amount if ($this->getAmount() === NULL) { Debug::Text('Amount is NULL...', __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTrue('amount', FALSE, TTi18n::gettext('Invalid Amount')); } //Make sure amount is sane given the rate and units. if ($this->getRate() !== NULL and $this->getUnits() !== NULL and $this->getRate() != 0 and $this->getUnits() != 0 and $this->getRate() != '' and $this->getUnits() != '' and Misc::MoneyFormat($this->calcAmount(), FALSE) != Misc::MoneyFormat($this->getAmount(), FALSE)) { Debug::text('Validate: Rate: ' . $this->getRate() . ' Units: ' . $this->getUnits() . ' Amount: ' . $this->getAmount() . ' Calc: Amount: ' . $this->calcAmount() . ' Raw: ' . bcmul($this->getRate(), $this->getUnits(), 4), __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTrue('amount', FALSE, TTi18n::gettext('Invalid Amount, calculation is incorrect')); } } else { } if ($this->getDeleted() == FALSE) { $this->Validator->isTrue('user_id', $this->isUnique(), TTi18n::gettext('Another Pay Stub Amendment already exists for the same employee, account, effective date and amount')); } //Don't allow these to be deleted in closed pay periods either. //Make sure effective date isn't in a CLOSED pay period? $pplf = TTNew('PayPeriodListFactory'); $pplf->getByUserIdAndEndDate($this->getUser(), $this->getEffectiveDate()); if ($pplf->getRecordCount() == 1) { $pp_obj = $pplf->getCurrent(); //Only check for CLOSED (not locked) pay periods when the //status of the PSA is *not* 52 and 55 if ($pp_obj->getStatus() == 20 and ($this->getStatus() != 52 and $this->getStatus() != 55)) { $this->Validator->isTrue('effective_date', FALSE, TTi18n::gettext('Pay Period that this effective date falls within is currently closed')); } } return TRUE; }