require_once '../../includes/global.inc.php'; //Debug::setVerbosity(11); $skip_message_check = TRUE; require_once Environment::getBasePath() . 'includes/Interface.inc.php'; if (!$permission->Check('schedule', 'enabled') or !($permission->Check('schedule', 'edit') or $permission->Check('schedule', 'edit_own') or $permission->Check('schedule', 'edit_child'))) { $permission->Redirect(FALSE); //Redirect } $smarty->assign('title', TTi18n::gettext($title = 'Mass Schedule')); // See index.php BreadCrumb::setCrumb($title); /* * Get FORM variables */ extract(FormVariables::GetVariables(array('action', 'id', 'data', 'filter_user_id'))); $data = Misc::preSetArrayValues($data, array('start_date_stamp', 'end_date_stamp', 'start_time', 'end_time'), NULL); if (isset($data)) { if ($data['start_date_stamp'] != '' and !is_numeric($data['start_date_stamp']) and $data['end_date_stamp'] != '' and !is_numeric($data['end_date_stamp']) and $data['start_time'] != '' and !is_numeric($data['end_time']) and $data['end_time'] != '' and !is_numeric($data['end_time'])) { $data['start_full_time_stamp'] = TTDate::parseDateTime($data['start_date_stamp'] . ' ' . $data['start_time']); $data['end_full_time_stamp'] = TTDate::parseDateTime($data['end_date_stamp'] . ' ' . $data['end_time']); } else { $data['start_full_time_stamp'] = NULL; $data['end_full_time_stamp'] = NULL; } if ($data['start_date_stamp'] != '') { $data['start_date_stamp'] = TTDate::parseDateTime($data['start_date_stamp']); } if ($data['end_date_stamp'] != '') { $data['end_date_stamp'] = TTDate::parseDateTime($data['end_date_stamp']); } if ($data['start_time'] != '') {
$filter_data['user_title_ids'] = array(-1); $filter_data['pay_period_ids'] = array('-0000-' . array_shift(array_keys($pay_period_options))); $filter_data['start_date'] = $default_start_date; $filter_data['end_date'] = $default_end_date; $filter_data['group_ids'] = array(-1); //$filter_data['user_ids'] = array_keys( UserListFactory::getByCompanyIdArray( $current_company->getId(), FALSE, FALSE ) ); if (!isset($filter_data['column_ids'])) { $filter_data['column_ids'] = array(); } $filter_data['column_ids'] = array_merge($filter_data['column_ids'], array('-1000-full_name', '-1065-pay_period', '-1090-worked_time', '-1130-paid_time', '-1140-regular_time')); $filter_data['primary_sort'] = '-1000-full_name'; $filter_data['secondary_sort'] = '-1065-pay_period'; $filter_data['secondary_sort_dir'] = '-1'; } } $filter_data = Misc::preSetArrayValues($filter_data, array('include_user_ids', 'exclude_user_ids', 'user_status_ids', 'group_ids', 'branch_ids', 'department_ids', 'punch_branch_ids', 'punch_department_ids', 'user_title_ids', 'pay_period_ids', 'column_ids'), NULL); $ulf = TTnew('UserListFactory'); $all_array_option = array('-1' => TTi18n::gettext('-- All --')); //Get include employee list. $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), array('permission_children_ids' => $permission_children_ids)); $user_options = $ulf->getArrayByListFactory($ulf, FALSE, TRUE); $filter_data['src_include_user_options'] = Misc::arrayDiffByKey((array) $filter_data['include_user_ids'], $user_options); $filter_data['selected_include_user_options'] = Misc::arrayIntersectByKey((array) $filter_data['include_user_ids'], $user_options); //Get exclude employee list $exclude_user_options = Misc::prependArray($all_array_option, $ulf->getArrayByListFactory($ulf, FALSE, TRUE)); $filter_data['src_exclude_user_options'] = Misc::arrayDiffByKey((array) $filter_data['exclude_user_ids'], $user_options); $filter_data['selected_exclude_user_options'] = Misc::arrayIntersectByKey((array) $filter_data['exclude_user_ids'], $user_options); //Get employee status list. $user_status_options = Misc::prependArray($all_array_option, $ulf->getOptions('status')); $filter_data['src_user_status_options'] = Misc::arrayDiffByKey((array) $filter_data['user_status_ids'], $user_status_options); $filter_data['selected_user_status_options'] = Misc::arrayIntersectByKey((array) $filter_data['user_status_ids'], $user_status_options);
break; } } $ppf->FailTransaction(); default: if (isset($id)) { BreadCrumb::setCrumb($title); $pplf = TTnew('PremiumPolicyListFactory'); $pplf->getByIdAndCompanyID($id, $current_company->getID()); foreach ($pplf as $pp_obj) { $data = array('id' => $pp_obj->getId(), 'name' => $pp_obj->getName(), 'type_id' => $pp_obj->getType(), 'pay_type_id' => $pp_obj->getPayType(), 'start_date' => $pp_obj->getStartDate(), 'end_date' => $pp_obj->getEndDate(), 'start_time' => $pp_obj->getStartTime(), 'end_time' => $pp_obj->getEndTime(), 'daily_trigger_time' => $pp_obj->getDailyTriggerTime(), 'maximum_daily_trigger_time' => $pp_obj->getMaximumDailyTriggerTime(), 'weekly_trigger_time' => $pp_obj->getWeeklyTriggerTime(), 'maximum_weekly_trigger_time' => $pp_obj->getMaximumWeeklyTriggerTime(), 'sun' => $pp_obj->getSun(), 'mon' => $pp_obj->getMon(), 'tue' => $pp_obj->getTue(), 'wed' => $pp_obj->getWed(), 'thu' => $pp_obj->getThu(), 'fri' => $pp_obj->getFri(), 'sat' => $pp_obj->getSat(), 'include_holiday_type_id' => $pp_obj->getIncludeHolidayType(), 'include_partial_punch' => $pp_obj->getIncludePartialPunch(), 'maximum_no_break_time' => $pp_obj->getMaximumNoBreakTime(), 'minimum_break_time' => $pp_obj->getMinimumBreakTime(), 'minimum_time_between_shift' => $pp_obj->getMinimumTimeBetweenShift(), 'minimum_first_shift_time' => $pp_obj->getMinimumFirstShiftTime(), 'minimum_shift_time' => $pp_obj->getMinimumShiftTime(), 'minimum_time' => $pp_obj->getMinimumTime(), 'maximum_time' => $pp_obj->getMaximumTime(), 'include_meal_policy' => $pp_obj->getIncludeMealPolicy(), 'include_break_policy' => $pp_obj->getIncludeBreakPolicy(), 'wage_group_id' => $pp_obj->getWageGroup(), 'rate' => Misc::removeTrailingZeros($pp_obj->getRate()), 'accrual_rate' => Misc::removeTrailingZeros($pp_obj->getAccrualRate()), 'accrual_policy_id' => $pp_obj->getAccrualPolicyID(), 'pay_stub_entry_account_id' => $pp_obj->getPayStubEntryAccountId(), 'branch_selection_type_id' => $pp_obj->getBranchSelectionType(), 'exclude_default_branch' => $pp_obj->getExcludeDefaultBranch(), 'branch_ids' => $pp_obj->getBranch(), 'department_selection_type_id' => $pp_obj->getDepartmentSelectionType(), 'exclude_default_department' => $pp_obj->getExcludeDefaultDepartment(), 'department_ids' => $pp_obj->getDepartment(), 'job_group_selection_type_id' => $pp_obj->getJobGroupSelectionType(), 'job_group_ids' => $pp_obj->getJobGroup(), 'job_selection_type_id' => $pp_obj->getJobSelectionType(), 'job_ids' => $pp_obj->getJob(), 'job_item_group_selection_type_id' => $pp_obj->getJobItemGroupSelectionType(), 'job_item_group_ids' => $pp_obj->getJobItemGroup(), 'job_item_selection_type_id' => $pp_obj->getJobItemSelectionType(), 'job_item_ids' => $pp_obj->getJobItem(), 'created_date' => $pp_obj->getCreatedDate(), 'created_by' => $pp_obj->getCreatedBy(), 'updated_date' => $pp_obj->getUpdatedDate(), 'updated_by' => $pp_obj->getUpdatedBy(), 'deleted_date' => $pp_obj->getDeletedDate(), 'deleted_by' => $pp_obj->getDeletedBy()); } } elseif ($action != 'submit') { $data = array('start_time' => NULL, 'end_time' => NULL, 'sun' => TRUE, 'mon' => TRUE, 'tue' => TRUE, 'wed' => TRUE, 'thu' => TRUE, 'fri' => TRUE, 'sat' => TRUE, 'wage_group_id' => 0, 'rate' => '1.00', 'accrual_rate' => '1.00', 'daily_trigger_time' => 0, 'maximum_daily_trigger_time' => 0, 'weekly_trigger_time' => 0, 'maximum_weekly_trigger_time' => 0, 'maximum_no_break_time' => 0, 'minimum_break_time' => 0, 'minimum_time_between_shift' => 0, 'minimum_first_shift_time' => 0, 'minimum_shift_time' => 0, 'minimum_time' => 0, 'maximum_time' => 0, 'include_meal_policy' => TRUE, 'include_break_policy' => TRUE, 'include_holiday_type_id' => 10); } $data = Misc::preSetArrayValues($data, array('branch_ids', 'department_ids', 'job_group_ids', 'job_ids', 'job_item_group_ids', 'job_item_ids'), NULL); $aplf = TTnew('AccrualPolicyListFactory'); $accrual_options = $aplf->getByCompanyIDArray($current_company->getId(), TRUE); $psealf = TTnew('PayStubEntryAccountListFactory'); $pay_stub_entry_options = $psealf->getByCompanyIdAndStatusIdAndTypeIdArray($current_company->getId(), 10, array(10, 20, 30, 50)); //Get branches $blf = TTnew('BranchListFactory'); $blf->getByCompanyId($current_company->getId()); $branch_options = $blf->getArrayByListFactory($blf, FALSE, TRUE); $data['src_branch_options'] = Misc::arrayDiffByKey((array) $data['branch_ids'], $branch_options); $data['selected_branch_options'] = Misc::arrayIntersectByKey((array) $data['branch_ids'], $branch_options); //Get departments $dlf = TTnew('DepartmentListFactory'); $dlf->getByCompanyId($current_company->getId()); $department_options = $dlf->getArrayByListFactory($dlf, FALSE, TRUE); $data['src_department_options'] = Misc::arrayDiffByKey((array) $data['department_ids'], $department_options);
$filter_data['user_title_ids'] = array(-1); $filter_data['job_group_ids'] = array(-1); $filter_data['include_job_ids'] = array(); $filter_data['exclude_job_ids'] = array(); $filter_data['job_item_ids'] = array(-1); $filter_data['group_ids'] = array(-1); //$filter_data['user_ids'] = array_keys( UserListFactory::getByCompanyIdArray( $current_company->getId(), FALSE, FALSE ) ); if (!isset($filter_data['column_ids'])) { $filter_data['column_ids'] = array(); } $filter_data['column_ids'] = array_merge($filter_data['column_ids'], array('-1000-full_name', '-1160-branch', '-1170-department', '-1200-date_stamp', '-1210-status', '-1230-start_time', '-1240-end_time', '-1430-total_time')); $filter_data['primary_sort'] = '-1000-full_name'; $filter_data['secondary_sort'] = '-1095-start_time'; } } $filter_data = Misc::preSetArrayValues($filter_data, array('include_user_ids', 'exclude_user_ids', 'user_status_ids', 'group_ids', 'branch_ids', 'department_ids', 'schedule_status_ids', 'schedule_branch_ids', 'schedule_department_ids', 'user_title_ids', 'pay_period_ids', 'include_job_ids', 'exclude_job_ids', 'job_branch_ids', 'job_department_ids', 'job_group_ids', 'client_ids', 'job_item_ids', 'job_item_group_ids', 'column_ids'), NULL); $ulf = TTnew('UserListFactory'); $slf = TTnew('ScheduleListFactory'); $all_array_option = array('-1' => TTi18n::gettext('-- All --')); //Get include employee list. $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), array('permission_children_ids' => $permission_children_ids)); $user_options = $ulf->getArrayByListFactory($ulf, FALSE, TRUE); $filter_data['src_include_user_options'] = Misc::arrayDiffByKey((array) $filter_data['include_user_ids'], $user_options); $filter_data['selected_include_user_options'] = Misc::arrayIntersectByKey((array) $filter_data['include_user_ids'], $user_options); //Get exclude employee list $exclude_user_options = Misc::prependArray($all_array_option, $ulf->getArrayByListFactory($ulf, FALSE, TRUE)); $filter_data['src_exclude_user_options'] = Misc::arrayDiffByKey((array) $filter_data['exclude_user_ids'], $user_options); $filter_data['selected_exclude_user_options'] = Misc::arrayIntersectByKey((array) $filter_data['exclude_user_ids'], $user_options); //Get employee status list. $user_status_options = Misc::prependArray($all_array_option, $ulf->getOptions('status')); $filter_data['src_user_status_options'] = Misc::arrayDiffByKey((array) $filter_data['user_status_ids'], $user_status_options);
function _getData($format = NULL) { $this->tmp_data = array('pay_stub_entry' => array(), 'user_total' => array()); $columns = $this->getColumnDataConfig(); $filter_data = $this->getFilterConfig(); $form_data = $this->formatFormConfig(); $setup_data = $this->getFormConfig(); $pself = TTnew('PayStubEntryListFactory'); $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data, NULL, NULL, NULL, array('user_id' => 'asc', 'pay_stub_transaction_date' => 'asc')); if ($pself->getRecordCount() > 0) { foreach ($pself as $pse_obj) { $user_id = $this->user_ids[] = $pse_obj->getColumn('user_id'); $date_stamp = $this->date_stamps[] = TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date')); $branch = $pse_obj->getColumn('default_branch'); $department = $pse_obj->getColumn('default_department'); $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId(); if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_period_transaction_date' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')), 'pay_period' => strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); } if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id], $pse_obj->getColumn('amount')); } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount'); } } if (isset($this->tmp_data['pay_stub_entry']) and is_array($this->tmp_data['pay_stub_entry'])) { $payments_over_cutoff = $this->getF940Object()->payment_cutoff_amount; //Need to get this from the government form. $before_adjustment_tax_rate = $this->getF940Object()->futa_tax_before_adjustment_rate; $tax_rate = $this->getF940Object()->futa_tax_rate; if ($setup_data['line_10'] > 0) { //Because they had to fill out a separate worksheet which we don't deal with,just average the excluded wages over each loop iteration. $excluded_wage_divisor = 0; foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) { foreach ($data_a as $date_stamp => $data_b) { $excluded_wage_divisor++; } } $excluded_wage_avg = bcdiv($setup_data['line_10'], $excluded_wage_divisor); Debug::Text(' Excluded Wage Avg: ' . $excluded_wage_avg . ' Divisor: ' . $excluded_wage_divisor, __FILE__, __LINE__, __METHOD__, 10); unset($user_id, $data_a, $data_b, $date_stamp); } foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) { foreach ($data_a as $date_stamp => $data_b) { $quarter_month = TTDate::getYearQuarterMonth($date_stamp); //Debug::Text(' Quarter Month: '. $quarter_month .' Date: '. TTDate::getDate('DATE+TIME', $date_stamp ), __FILE__, __LINE__, __METHOD__,10); if (!isset($this->tmp_data['user_total'][$user_id])) { $this->tmp_data['user_total'][$user_id]['net_payments'] = 0; $this->tmp_data['user_total'][$user_id]['excess_payments'] = 0; } $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['total_payments']['include_pay_stub_entry_account'], $form_data['total_payments']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['exempt_payments']['include_pay_stub_entry_account'], $form_data['exempt_payments']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['net_payments'] = bcsub($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'] = 0; //Need to total up payments for each employee so we know when we exceed the limit. $this->tmp_data['user_total'][$user_id]['net_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['net_payments']; if ($this->tmp_data['user_total'][$user_id]['excess_payments'] == 0) { if ($this->tmp_data['user_total'][$user_id]['net_payments'] > $payments_over_cutoff) { Debug::Text(' First time over cutoff for User: '******'pay_stub_entry'][$user_id][$date_stamp]['excess_payments'] = $this->tmp_data['user_total'][$user_id]['net_payments'] - $payments_over_cutoff; $this->tmp_data['user_total'][$user_id]['excess_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments']; } } else { Debug::Text(' Next time over cutoff for User: '******' Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['net_payments']); } $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages'] = bcsub($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments'], bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'])); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['before_adjustment_tax'] = bcmul($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages'], $before_adjustment_tax_rate); if ($setup_data['line_10'] > 0) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'], $excluded_wage_avg); } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'] = bcmul($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages'], $tax_rate); } $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['after_adjustment_tax'] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['before_adjustment_tax'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax']); //Separate data used for reporting, grouping, sorting, from data specific used for the Form. if (!isset($this->form_data['pay_period'][$quarter_month][$date_stamp])) { $this->form_data['pay_period'][$quarter_month][$date_stamp] = Misc::preSetArrayValues(array(), array('total_payments', 'exempt_payments', 'excess_payments', 'taxable_wages', 'before_adjustment_tax', 'adjustment_tax', 'after_adjustment_tax'), 0); } $this->form_data['pay_period'][$quarter_month][$date_stamp]['total_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['exempt_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['excess_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['taxable_wages'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['before_adjustment_tax'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['before_adjustment_tax']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['adjustment_tax'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['after_adjustment_tax'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['after_adjustment_tax']; } } //Total all pay periods by quarter if (isset($this->form_data['pay_period'])) { foreach ($this->form_data['pay_period'] as $month_id => $pp_data) { $this->form_data['quarter'][$month_id] = Misc::ArrayAssocSum($pp_data, NULL, 8); } //Total all quarters. if (isset($this->form_data['quarter'])) { $this->form_data['total'] = Misc::ArrayAssocSum($this->form_data['quarter'], NULL, 6); } } } } $this->user_ids = array_unique($this->user_ids); //Used to get the total number of employees. //Debug::Arr($this->user_ids, 'User IDs: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($this->form_data, 'Form Raw Data: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($this->tmp_data, 'Tmp Raw Data: ', __FILE__, __LINE__, __METHOD__,10); //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()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig()); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10); return TRUE; }
function _getData($format = NULL) { $this->tmp_data = array('pay_stub_entry' => array()); $columns = $this->getColumnDataConfig(); $filter_data = $this->getFilterConfig(); $form_data = $this->formatFormConfig(); require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php'; $pd_obj = new PayrollDeduction('US', 'WA'); //State doesn't matter. $pd_obj->setDate($filter_data['end_date']); $social_security_wage_limit = $pd_obj->getSocialSecurityMaximumEarnings(); $medicare_additional_threshold_limit = $pd_obj->getMedicareAdditionalEmployerThreshold(); Debug::Text('Social Security Wage Limit: ' . $social_security_wage_limit . ' Medicare Threshold: ' . $medicare_additional_threshold_limit . ' Date: ' . TTDate::getDate('DATE', $filter_data['end_date']), __FILE__, __LINE__, __METHOD__, 10); //Need to get totals up to the beginning of this quarter so we can determine if any employees have exceeded the social security limit. $pself = TTnew('PayStubEntryListFactory'); $ytd_filter_data = $filter_data; $ytd_filter_data['end_date'] = $ytd_filter_data['start_date'] - 1; $ytd_filter_data['start_date'] = TTDate::getBeginYearEpoch($ytd_filter_data['start_date']); $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $ytd_filter_data); //Debug::Arr($ytd_filter_data, 'YTD Filter Data: Row Count: '. $pself->getRecordCount(), __FILE__, __LINE__, __METHOD__,10); if ($pself->getRecordCount() > 0) { foreach ($pself as $pse_obj) { $user_id = $pse_obj->getColumn('user_id'); //Make sure we don't add this to the unique user_id list. //Always use middle day epoch, otherwise multiple entries could exist for the same day. $date_stamp = TTDate::getMiddleDayEpoch(TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); $branch = $pse_obj->getColumn('default_branch'); $department = $pse_obj->getColumn('default_department'); $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId(); if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_period_transaction_date' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')), 'pay_period' => strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); } if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id], $pse_obj->getColumn('amount')); } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount'); } } if (isset($this->tmp_data['pay_stub_entry']) and is_array($this->tmp_data['pay_stub_entry'])) { foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) { foreach ($data_a as $date_stamp => $data_b) { if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] = 0; } $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_wages']['include_pay_stub_entry_account'], $form_data['social_security_wages']['exclude_pay_stub_entry_account']); //Include tips in this amount as well. $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_tips']['include_pay_stub_entry_account'], $form_data['social_security_tips']['exclude_pay_stub_entry_account']); //Handle additional medicare wages in excess of 200,000 if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] = 0; } $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] += Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['medicare_wages']['include_pay_stub_entry_account'], $form_data['medicare_wages']['exclude_pay_stub_entry_account']); } } } //Debug::Arr($this->tmp_data['ytd_pay_stub_entry'], 'YTD Tmp Raw Data: ', __FILE__, __LINE__, __METHOD__,10); } unset($pse_obj, $user_id, $date_stamp, $branch, $department, $pay_stub_entry_name_id, $this->tmp_data['pay_stub_entry']); //Get just the data for the quarter now. $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data); if ($pself->getRecordCount() > 0) { foreach ($pself as $pse_obj) { $user_id = $this->user_ids[] = $pse_obj->getColumn('user_id'); //Always use middle day epoch, otherwise multiple entries could exist for the same day. $date_stamp = TTDate::getMiddleDayEpoch(TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); $branch = $pse_obj->getColumn('default_branch'); $department = $pse_obj->getColumn('default_department'); $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId(); if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_period_transaction_date' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')), 'pay_period' => strtotime($pse_obj->getColumn('pay_stub_transaction_date'))); } if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id])) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id], $pse_obj->getColumn('amount')); } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount'); } } if (isset($this->tmp_data['pay_stub_entry']) and is_array($this->tmp_data['pay_stub_entry'])) { foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) { foreach ($data_a as $date_stamp => $data_b) { $quarter_month = TTDate::getYearQuarterMonthNumber($date_stamp); //Debug::Text('Quarter Month: '. $quarter_month .' Epoch: '. TTDate::getDate('DATE', $date_stamp), __FILE__, __LINE__, __METHOD__,10); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['wages']['include_pay_stub_entry_account'], $form_data['wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['income_tax'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['income_tax']['include_pay_stub_entry_account'], $form_data['income_tax']['exclude_pay_stub_entry_account']); //FIXME: If employees are excluded from Social Security, it will still include total wages //resulting in the 941 form being incorrect in its calculation. //Add Form Setup tab field to select the Social Security tax/deductions? //However there can often be two of them, is just the employee one enough? We could use the employees and include/exclude accounts from that at least then. $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_wages']['include_pay_stub_entry_account'], $form_data['social_security_wages']['exclude_pay_stub_entry_account']); //Handle social security wage limit. if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] = 0; } if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] < $social_security_wage_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_wages']['include_pay_stub_entry_account'], $form_data['social_security_wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['social_security_tips']['include_pay_stub_entry_account'], $form_data['social_security_tips']['exclude_pay_stub_entry_account']); if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] > $social_security_wage_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] - ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] - $social_security_wage_limit); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] = 0; $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] = $social_security_wage_limit; } else { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages']; $this->tmp_data['ytd_pay_stub_entry'][$user_id]['social_security_wages'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips']; } } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages'] = 0; $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips'] = 0; } $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['medicare_wages']['include_pay_stub_entry_account'], $form_data['medicare_wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = 0; //Handle medicare additional wage limit, only consider wages earned above the threshold to be "medicare_additional_wages" if (!isset($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'])) { $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] = 0; } if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] > $medicare_additional_threshold_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages']; } else { if ($this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages'] > $medicare_additional_threshold_limit) { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages'] - $medicare_additional_threshold_limit; } else { $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'] = 0; } } //Debug::Text('User ID: '. $user_id .' DateStamp: '. $date_stamp .' YTD Medicare Additional Wages: '. $this->tmp_data['ytd_pay_stub_entry'][$user_id]['medicare_wages'] .' This Pay Stub: '. $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages'], __FILE__, __LINE__, __METHOD__,10); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['sick_wages'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['sick_wages']['include_pay_stub_entry_account'], $form_data['sick_wages']['exclude_pay_stub_entry_account']); $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['eic'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['eic']['include_pay_stub_entry_account'], $form_data['eic']['exclude_pay_stub_entry_account']); //Separate data used for reporting, grouping, sorting, from data specific used for the Form. if (!isset($this->form_data['pay_period'][$quarter_month][$date_stamp])) { $this->form_data['pay_period'][$quarter_month][$date_stamp] = Misc::preSetArrayValues(array(), array('l2', 'l3', 'l5a', 'l5b', 'l5c', 'l5d', 'l7', 'l9', 'l5a2', 'l5b2', 'l5c2', 'l5d', 'l8', 'l10'), 0); } $this->form_data['pay_period'][$quarter_month][$date_stamp]['l2'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['wages']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l3'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['income_tax']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_wages']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['social_security_tips']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_wages']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['medicare_additional_wages']; //$this->form_data['pay_period'][$quarter_month][$date_stamp]['l9'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['eic']; $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5f'] = 0; //Not implemented currently. //Calculated fields, make sure we don't use += on these. $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a'], $this->getF941Object()->social_security_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b'], $this->getF941Object()->social_security_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c'], $this->getF941Object()->medicare_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d2'] = bcmul($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d'], $this->getF941Object()->medicare_additional_rate); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5e'] = bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5a2'], bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5b2'], bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5c2'], $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5d2']))); $this->form_data['pay_period'][$quarter_month][$date_stamp]['l6'] = bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l3'], bcadd($this->form_data['pay_period'][$quarter_month][$date_stamp]['l5e'], $this->form_data['pay_period'][$quarter_month][$date_stamp]['l5f'])); //Calculate amounts for Schedule B. $this->form_data['pay_period'][$quarter_month][$date_stamp]['l10'] = $this->form_data['pay_period'][$quarter_month][$date_stamp]['l6']; //Add L6 -> L9 if they are implemented later. } } //Total all pay periods by month_id if (isset($this->form_data['pay_period'])) { foreach ($this->form_data['pay_period'] as $month_id => $pp_data) { $this->form_data['quarter'][$month_id] = Misc::ArrayAssocSum($pp_data, NULL, 8); } //Total all quarters. if (isset($this->form_data['quarter'])) { $this->form_data['total'] = Misc::ArrayAssocSum($this->form_data['quarter'], NULL, 6); } } } } $this->user_ids = array_unique($this->user_ids); //Used to get the total number of employees. //Debug::Arr($this->user_ids, 'User IDs: ', __FILE__, __LINE__, __METHOD__,10); Debug::Arr($this->form_data, 'Form Raw Data: ', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($this->tmp_data, 'Tmp Raw Data: ', __FILE__, __LINE__, __METHOD__,10); //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()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig()); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10); return TRUE; }
function returnHandler($retval = TRUE, $code = FALSE, $description = FALSE, $details = FALSE, $validator_stats = FALSE, $user_generic_status_batch_id = FALSE, $request_data = FALSE) { if ($this->getProtocolVersion() == 1) { if ($retval === FALSE or $retval === TRUE and $code !== FALSE or $user_generic_status_batch_id !== FALSE) { if ($retval === FALSE) { if ($code == '') { $code = 'GENERAL'; } if ($description == '') { $description = 'Insufficient data to carry out action'; } } elseif ($retval === TRUE) { if ($code == '') { $code = 'SUCCESS'; } } $validator_stats = Misc::preSetArrayValues($validator_stats, array('total_records', 'valid_records', 'invalids_records'), 0); $retarr = array('api_retval' => $retval, 'api_details' => array('code' => $code, 'description' => $description, 'record_details' => array('total' => $validator_stats['total_records'], 'valid' => $validator_stats['valid_records'], 'invalid' => $validator_stats['total_records'] - $validator_stats['valid_records']), 'user_generic_status_batch_id' => $user_generic_status_batch_id, 'details' => $details)); if ($retval === FALSE) { Debug::Arr($retarr, 'returnHandler ERROR: ' . (int) $retval, __FILE__, __LINE__, __METHOD__, 10); } return $retarr; } //No errors, or additional information, return unmodified data. return $retval; } else { if ($retval === FALSE) { if ($code == '') { $code = 'GENERAL'; } if ($description == '') { $description = 'Insufficient data to carry out action'; } } elseif ($retval === TRUE) { if ($code == '') { $code = 'SUCCESS'; } } $validator_stats = Misc::preSetArrayValues($validator_stats, array('total_records', 'valid_records', 'invalids_records'), 0); $retarr = array('api_retval' => $retval, 'api_details' => array('code' => $code, 'description' => $description, 'record_details' => array('total' => $validator_stats['total_records'], 'valid' => $validator_stats['valid_records'], 'invalid' => $validator_stats['total_records'] - $validator_stats['valid_records']), 'user_generic_status_batch_id' => $user_generic_status_batch_id, 'request' => $request_data, 'pager' => $this->getPagerData(), 'details' => $details)); if ($retval === FALSE) { Debug::Arr($retarr, 'returnHandler ERROR: ' . (int) $retval, __FILE__, __LINE__, __METHOD__, 10); } //Debug::Arr($retarr, 'returnHandler: '. (int)$retval, __FILE__, __LINE__, __METHOD__, 10); return $retarr; } }
function _outputPDFTimesheet($format) { Debug::Text(' Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10); $border = 0; $current_company = $this->getUserObject()->getCompanyObject(); if (!is_object($current_company)) { Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $pdf_created_date = time(); $adjust_x = 10; $adjust_y = 10; //Debug::Arr($this->form_data, 'Form Data: ', __FILE__, __LINE__, __METHOD__,10); if (isset($this->form_data) and count($this->form_data) > 0) { //Make sure we sort the form data for printable timesheets. $this->form_data['user_date_total'] = Sort::arrayMultiSort($this->form_data['user_date_total'], $this->getSortConfig()); //Get pay period schedule data for each pay period. $this->pdf = new TTPDF($this->config['other']['page_orientation'], 'mm', $this->config['other']['page_format'], $this->getUserObject()->getCompanyObject()->getEncoding()); $this->pdf->SetAuthor(APPLICATION_NAME); $this->pdf->SetTitle($this->title); $this->pdf->SetSubject(APPLICATION_NAME . ' ' . TTi18n::getText('Report')); $this->pdf->setMargins($this->config['other']['left_margin'], $this->config['other']['top_margin'], $this->config['other']['right_margin']); //Debug::Arr($this->config['other'], 'Margins: ', __FILE__, __LINE__, __METHOD__,10); $this->pdf->SetAutoPageBreak(FALSE); $this->pdf->SetFont($this->config['other']['default_font'], '', $this->_pdf_fontSize(10)); //Debug::Arr($this->form_data, 'zabUser Raw Data: ', __FILE__, __LINE__, __METHOD__,10); $filter_data = $this->getFilterConfig(); $columns = Misc::trimSortPrefix($this->getOptions('columns')); $this->getProgressBarObject()->start($this->getAMFMessageID(), 2, NULL, TTi18n::getText('Querying Database...')); //Iterations need to be 2, otherwise progress bar is not created. $this->getProgressBarObject()->set($this->getAMFMessageID(), 2); if ($format == 'pdf_timesheet_detail') { $plf = TTnew('PunchListFactory'); $plf->getSearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data); Debug::Text('Got punch data... Total Rows: ' . $plf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); $this->getProgressBarObject()->start($this->getAMFMessageID(), $plf->getRecordCount(), NULL, TTi18n::getText('Retrieving Punch Data...')); if ($plf->getRecordCount() > 0) { foreach ($plf as $key => $p_obj) { $this->form_data['user_date_total'][$p_obj->getColumn('user_id')]['punch_rows'][$p_obj->getColumn('pay_period_id')][TTDate::strtotime($p_obj->getColumn('date_stamp'))][$p_obj->getPunchControlID()][$p_obj->getStatus()] = array('status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType(), 'type_code' => $p_obj->getTypeCode(), 'time_stamp' => $p_obj->getTimeStamp()); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } } unset($plf, $p_obj); } Debug::Text('Drawing timesheets...', __FILE__, __LINE__, __METHOD__, 10); $this->getProgressBarObject()->start($this->getAMFMessageID(), count($this->form_data['user_date_total']), NULL, TTi18n::getText('Generating TimeSheets...')); $key = 0; foreach ($this->form_data['user_date_total'] as $user_data) { if ($this->_pdf_checkMaximumPageLimit() == FALSE) { Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10); //Exceeded maximum pages, stop processing. $this->_pdf_displayMaximumPageLimitError(); break; } if (isset($user_data['first_name']) and isset($user_data['last_name']) and isset($user_data['employee_number'])) { $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter'); $this->timesheetHeader($user_data); //Start displaying dates/times here. Start with header. $column_widths = array('line' => 5, 'date_stamp' => 20, 'dow' => 10, 'in_punch_time_stamp' => 20, 'out_punch_time_stamp' => 20, 'worked_time' => 20, 'regular_time' => 20, 'over_time' => 40.6, 'absence_time' => 45); if (isset($user_data['data']) and is_array($user_data['data'])) { $user_data['data'] = Sort::arrayMultiSort($user_data['data'], array('time_stamp' => SORT_ASC)); $this->timesheet_week_totals = Misc::preSetArrayValues(NULL, array('worked_time', 'absence_time', 'regular_time', 'over_time'), 0); $this->timesheet_totals = array(); $this->timesheet_totals = Misc::preSetArrayValues($this->timesheet_totals, array('worked_time', 'absence_time', 'regular_time', 'over_time'), 0); $this->counter_i = 1; //Overall row counter. $this->counter_x = 1; //Row counter, starts over each week. $this->counter_y = 1; //Week counter. $this->max_i = count($user_data['data']); $prev_data = FALSE; foreach ($user_data['data'] as $data) { if ($this->_pdf_checkMaximumPageLimit() == FALSE) { Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10); //Exceeded maximum pages, stop processing. $this->_pdf_displayMaximumPageLimitError(); break 2; } if (isset($this->form_data['pay_period'][$data['pay_period_id']])) { //Debug::Arr( $data, 'Data: i: '. $this->counter_i .' x: '. $this->counter_x .' Max I: '. $this->max_i, __FILE__, __LINE__, __METHOD__,10); $data = Misc::preSetArrayValues($data, array('time_stamp', 'in_punch_time_stamp', 'out_punch_time_stamp', 'worked_time', 'absence_time', 'regular_time', 'over_time'), '--'); $data['start_week_day'] = $this->form_data['pay_period'][$data['pay_period_id']]['start_week_day']; $row_date_gap = $prev_data !== FALSE ? TTDate::getMiddleDayEpoch($data['time_stamp']) - TTDate::getMiddleDayEpoch($prev_data['time_stamp']) : 0; //Take into account DST by using mid-day epochs. //Debug::Text('Row Gap: '. $row_date_gap, __FILE__, __LINE__, __METHOD__,10); if ($prev_data !== FALSE and $row_date_gap > 86400) { //Handle gaps between individual days with hours. $prev_data = $this->timesheetHandleDayGaps($prev_data['time_stamp'] + 86400, $data['time_stamp'], $format, $columns, $column_widths, $user_data, $data, $prev_data); } elseif ($this->counter_i == 1 and TTDate::getMiddleDayEpoch($data['time_stamp']) - TTDate::getMiddleDayEpoch($data['pay_period_start_date']) >= 86400) { //Always fill gaps between the pay period start date and the date with time, even if not filtering by pay period. //Handle gaps before the first date with hours is displayed, only when filtering by pay period though. $prev_data = $this->timesheetHandleDayGaps($data['pay_period_start_date'], $data['time_stamp'], $format, $columns, $column_widths, $user_data, $data, $prev_data); } //Check for gaps at the end of the date range and before the end of the pay period. //If we find one we have to increase $max_i by one so the last timesheetDayRow doesn't display the week totals. if ($this->counter_i == $this->max_i and TTDate::getMiddleDayEpoch($data['pay_period_end_date']) - TTDate::getMiddleDayEpoch($data['time_stamp']) >= 86400) { $this->max_i++; } $this->timesheetDayRow($format, $columns, $column_widths, $user_data, $data, $prev_data); $prev_data = $data; } else { Debug::Text('Pay Period does not exist, skipping... ID: ' . $data['pay_period_id'], __FILE__, __LINE__, __METHOD__, 10); } } //Check for gaps at the end of the date range and before the end of the pay period so we can fill them in. Only when filtering by pay period though. //as filtering by start/end date can result in a lot of data if they want show time for the last year but an employee was just hired. if (isset($data['pay_period_end_date']) and TTDate::getMiddleDayEpoch($data['pay_period_end_date']) - TTDate::getMiddleDayEpoch($data['time_stamp']) >= 86400) { //Handle gaps between the last day with hours and the end of the pay period. //Always fill gaps between the pay period end date and the current date with time, even if not filtering by pay period. $this->timesheetHandleDayGaps($data['time_stamp'] + 86400, $data['pay_period_end_date'], $format, $columns, $column_widths, $user_data, $data, $prev_data); } if (isset($this->timesheet_totals) and is_array($this->timesheet_totals)) { //Display overall totals. $this->timesheetTotal($column_widths, $this->timesheet_totals); unset($totals); } $this->timesheetSignature($user_data, $data); unset($data, $prev_data); } else { $this->timesheetNoData(); } $this->timesheetFooter($pdf_created_date, $adjust_x, $adjust_y); } $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); if ($key % 25 == 0 and $this->isSystemLoadValid() == FALSE) { return FALSE; } $key++; } $output = $this->pdf->Output('', 'S'); return $output; } Debug::Text('No data to return...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
unset($s_obj, $slf); $smarty->assign_by_ref('time_clock_command_result', $result_str); } default: if (isset($id)) { BreadCrumb::setCrumb($title); $slf = new StationListFactory(); $slf->GetByIdAndCompanyId($id, $current_company->getId()); foreach ($slf as $s_obj) { //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10); $data = array('id' => $s_obj->getId(), 'status' => $s_obj->getStatus(), 'type' => $s_obj->getType(), 'station' => $s_obj->getStation(), 'source' => $s_obj->getSource(), 'description' => $s_obj->getDescription(), 'port' => $s_obj->getPort(), 'user_name' => $s_obj->getUserName(), 'password' => $s_obj->getPassword(), 'poll_frequency' => $s_obj->getPollFrequency(), 'push_frequency' => $s_obj->getPushFrequency(), 'partial_push_frequency' => $s_obj->getPartialPushFrequency(), 'enable_auto_punch_status' => $s_obj->getEnableAutoPunchStatus(), 'mode_flag' => $s_obj->getModeFlag(), 'last_punch_time_stamp' => $s_obj->getLastPunchTimeStamp(), 'last_poll_date' => $s_obj->getLastPollDate(), 'last_push_date' => $s_obj->getLastPushDate(), 'last_partial_push_date' => $s_obj->getLastPartialPushDate(), 'branch_id' => $s_obj->getDefaultBranch(), 'department_id' => $s_obj->getDefaultDepartment(), 'job_id' => $s_obj->getDefaultJob(), 'job_item_id' => $s_obj->getDefaultJobItem(), 'time_zone_id' => $s_obj->getTimeZone(), 'group_selection_type_id' => $s_obj->getGroupSelectionType(), 'group_ids' => $s_obj->getGroup(), 'branch_selection_type_id' => $s_obj->getBranchSelectionType(), 'branch_ids' => $s_obj->getBranch(), 'department_selection_type_id' => $s_obj->getDepartmentSelectionType(), 'department_ids' => $s_obj->getDepartment(), 'include_user_ids' => $s_obj->getIncludeUser(), 'exclude_user_ids' => $s_obj->getExcludeUser(), 'created_date' => $s_obj->getCreatedDate(), 'created_by' => $s_obj->getCreatedBy(), 'updated_date' => $s_obj->getUpdatedDate(), 'updated_by' => $s_obj->getUpdatedBy(), 'deleted_date' => $s_obj->getDeletedDate(), 'deleted_by' => $s_obj->getDeletedBy()); } } elseif ($action != 'submit' and $action != 'time_clock_command') { $data = array('status' => 20, 'port' => 80, 'password' => 0, 'poll_frequency' => 600, 'push_frequency' => 86400, 'partial_push_frequency' => 3600); } $data = Misc::preSetArrayValues($data, array('branch_ids', 'department_ids', 'group_ids', 'include_user_ids', 'exclude_user_ids'), NULL); //Select box options; $data['status_options'] = $sf->getOptions('status'); $data['type_options'] = $sf->getOptions('type'); $data['poll_frequency_options'] = $sf->getOptions('poll_frequency'); $data['push_frequency_options'] = $sf->getOptions('push_frequency'); $data['time_clock_command_options'] = $sf->getOptions('time_clock_command'); $data['mode_flag_options'] = $sf->getOptions('mode_flag'); if ($current_company->getProductEdition() == 20) { $jlf = new JobListFactory(); $jlf->getByCompanyId($current_company->getId()); $data['job_options'] = Misc::prependArray(array(0 => '-- None --'), $jlf->getArrayByListFactory($jlf, FALSE, TRUE)); $jilf = new JobItemListFactory(); $jilf->getByCompanyIdAndStatus($current_company->getId(), 10); $data['job_item_options'] = Misc::prependArray(array(0 => '-- None --'), $jilf->getArrayByListFactory($jilf, TRUE, FALSE)); }