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; }
} } } $lines_arr[$quarter_id]['p1_3'] = $lines_arr[$quarter_id]['p1_1'] - $lines_arr[$quarter_id]['p1_2'] - $lines_arr[$quarter_id]['p3_under_cutoff']; $lines_arr[$quarter_id]['p1_4'] = $lines_arr[$quarter_id]['p1_2'] + $lines_arr[$quarter_id]['p1_3']; $lines_arr[$quarter_id]['p1_5'] = $lines_arr[$quarter_id]['p1_1'] - $lines_arr[$quarter_id]['p1_4']; $lines_arr[$quarter_id]['p1_6'] = bcmul($lines_arr[$quarter_id]['p1_5'], 0.008); } unset($user_id); //var_dump($user_ps_entries); } unset($pay_period_ids, $ps_entries); } //Calc Part 1, Line 3 here. if (isset($lines_arr)) { $lines_arr['total'] = Misc::ArrayAssocSum($lines_arr, NULL, 6); Debug::Arr($lines_arr, 'Lines Array: ', __FILE__, __LINE__, __METHOD__, 10); //Line 8 $p1_line8 = $lines_arr['total']['p1_6'] - 0; } $border = 0; $pdf = new fpdi(); //Import original Gov't supplied PDF. if ($show_background == TRUE) { $pagecount = $pdf->setSourceFile(Environment::getBasePath() . 'interface' . DIRECTORY_SEPARATOR . 'forms' . DIRECTORY_SEPARATOR . 'us' . DIRECTORY_SEPARATOR . 'tax' . DIRECTORY_SEPARATOR . 'f940ez.pdf'); $tplidx = $pdf->ImportPage(1); } $pdf->setMargins(0, 0, 0, 0); $pdf->SetAutoPageBreak(FALSE); $pdf->SetFont('freeserif', '', 10); $pdf->AddPage();
$rows = Misc::ArrayGroupBy($rows, array(Misc::trimSortPrefix($filter_data['primary_group_by']), Misc::trimSortPrefix($filter_data['secondary_group_by'])), Misc::trimSortPrefix($ignore_elements)); } if (isset($rows)) { foreach ($rows as $row) { $tmp_rows[] = $row; } //var_dump($tmp_rows); $special_sort_columns = array('pay_period'); if (in_array(Misc::trimSortPrefix($filter_data['primary_sort']), $special_sort_columns)) { $filter_data['primary_sort'] = $filter_data['primary_sort'] . '_order'; } if (in_array(Misc::trimSortPrefix($filter_data['secondary_sort']), $special_sort_columns)) { $filter_data['secondary_sort'] = $filter_data['secondary_sort'] . '_order'; } $rows = Sort::Multisort($tmp_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); $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); //Convert units $tmp_rows = $rows; unset($rows); $trimmed_static_columns = array_keys(Misc::trimSortPrefix($static_columns)); foreach ($tmp_rows as $row) { foreach ($row as $column => $column_data) { if (!strstr($column, 'wage') and !strstr($column, 'worked_days') and !in_array($column, $trimmed_static_columns)) { $column_data = TTDate::getTimeUnit($column_data); }
function sumRecords() { $this->records_total = Misc::ArrayAssocSum($this->records); return TRUE; }
function _outputPDFForm($format = NULL) { $show_background = TRUE; if ($format == 'pdf_form_print' or $format == 'pdf_form_print_government' or $format == 'efile') { $show_background = FALSE; } Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10); $setup_data = $this->getFormConfig(); $filter_data = $this->getFilterConfig(); //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10); $current_company = $this->getUserObject()->getCompanyObject(); if (!is_object($current_company)) { Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $current_user = $this->getUserObject(); if (!is_object($current_user)) { Debug::Text('Invalid user object...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if ($format == 'efile_xml') { $return1040 = $this->getRETURN1040Object(); // Ceate the all needed data for Return1040.xsd at here. $return1040->return_created_timestamp = TTDate::getDBTimeStamp(TTDate::getTime(), FALSE); $return1040->year = TTDate::getYear($filter_data['end_date']); $return1040->tax_period_begin_date = TTDate::getDate('Y-m-d', TTDate::getBeginDayEpoch($filter_data['start_date'])); $return1040->tax_period_end__date = TTDate::getDate('Y-m-d', TTDate::getEndDayEpoch($filter_data['end_date'])); $return1040->software_id = ''; $return1040->originator_efin = ''; $return1040->originator_type_code = ''; $return1040->pin_type_code = ''; $return1040->jurat_disclosure_code = ''; $return1040->pin_entered_by = ''; $return1040->signature_date = TTDate::getDate('Y-m-d', TTDate::getTime()); $return1040->return_type = ''; $return1040->ssn = ''; $return1040->name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName(); $return1040->name_control = ''; $return1040->address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2(); $return1040->city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity(); $return1040->state = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince(); $return1040->zip_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode(); $return1040->ip_address = ''; $return1040->ip_date = TTDate::getDate('Y-m-d', TTDate::getTime()); $return1040->ip_time = TTDate::getDate('H:i:s', TTDate::getTime()); $return1040->timezone = TTDate::getTimeZone(); $this->getFormObject()->addForm($return1040); } $this->sortFormData(); //Make sure forms are sorted. $fw2 = $this->getFW2Object(); $fw2->setDebug(FALSE); //if ( $format == 'efile' ) { // $fw2->setDebug(TRUE); //} $fw2->setShowBackground($show_background); if (stristr($format, 'government')) { $form_type = 'government'; } else { $form_type = 'employee'; } Debug::Text('Form Type: ' . $form_type, __FILE__, __LINE__, __METHOD__, 10); $fw2->setType($form_type); $fw2->year = TTDate::getYear($filter_data['end_date']); //Add support for the user to manually set this data in the setup_data. That way they can use multiple tax IDs for different employees, all beit manually. $fw2->ein = (isset($setup_data['ein']) and $setup_data['ein'] != '') ? $setup_data['ein'] : $current_company->getBusinessNumber(); $fw2->name = (isset($setup_data['name']) and $setup_data['name'] != '') ? $setup_data['name'] : $this->getUserObject()->getFullName(); $fw2->trade_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName(); $fw2->company_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2(); $fw2->company_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity(); $fw2->company_state = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince(); $fw2->company_zip_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode(); $fw2->efile_user_id = (isset($setup_data['efile_user_id']) and $setup_data['efile_user_id'] != '') ? $setup_data['efile_user_id'] : NULL; $fw2->efile_state = (isset($setup_data['efile_state']) and $setup_data['efile_state'] != '') ? $setup_data['efile_state'] : 0; $fw2->contact_name = $current_user->getFullName(); $fw2->contact_phone = $current_user->getWorkPhone(); $fw2->contact_phone_ext = $current_user->getWorkPhoneExt(); $fw2->contact_email = $current_user->getWorkEmail(); if (isset($this->form_data) and count($this->form_data) > 0) { $i = 0; $n = 1; foreach ((array) $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(); $ee_data = array('control_number' => $n, '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(), 'state' => $user_obj->getProvince(), 'employment_province' => $user_obj->getProvince(), 'zip_code' => $user_obj->getPostalCode(), 'ssn' => $user_obj->getSIN(), 'employee_number' => $user_obj->getEmployeeNumber(), 'l1' => $row['l1'], 'l2' => $row['l2'], 'l3' => $row['l3'], 'l4' => $row['l4'], 'l5' => $row['l5'], 'l6' => $row['l6'], 'l7' => $row['l7'], 'l8' => $row['l8'], 'l10' => $row['l10'], 'l11' => $row['l11'], 'l12a_code' => NULL, 'l12a' => NULL, 'l12b_code' => NULL, 'l12b' => NULL, 'l12c_code' => NULL, 'l12c' => NULL, 'l12d_code' => NULL, 'l12d' => NULL, 'l14a_name' => NULL, 'l14a' => NULL, 'l14b_name' => NULL, 'l14b' => NULL, 'l14c_name' => NULL, 'l14c' => NULL, 'l14d_name' => NULL, 'l14d' => NULL); if ($row['l12a'] > 0 and isset($setup_data['l12a_code']) and $setup_data['l12a_code'] != '') { $ee_data['l12a_code'] = $setup_data['l12a_code']; $ee_data['l12a'] = $row['l12a']; } if ($row['l12b'] > 0 and isset($setup_data['l12b_code']) and $setup_data['l12b_code'] != '') { $ee_data['l12b_code'] = $setup_data['l12b_code']; $ee_data['l12b'] = $row['l12b']; } if ($row['l12c'] > 0 and isset($setup_data['l12c_code']) and $setup_data['l12c_code'] != '') { $ee_data['l12c_code'] = $setup_data['l12c_code']; $ee_data['l12c'] = $row['l12c']; } if ($row['l12d'] > 0 and isset($setup_data['l12d_code']) and $setup_data['l12d_code'] != '') { $ee_data['l12d_code'] = $setup_data['l12d_code']; $ee_data['l12d'] = $row['l12d']; } if ($row['l14a'] > 0 and isset($setup_data['l14a_name']) and $setup_data['l14a_name'] != '') { $ee_data['l14a_name'] = $setup_data['l14a_name']; $ee_data['l14a'] = $row['l14a']; } if ($row['l14b'] > 0 and isset($setup_data['l14b_name']) and $setup_data['l14b_name'] != '') { $ee_data['l14b_name'] = $setup_data['l14b_name']; $ee_data['l14b'] = $row['l14b']; } if ($row['l14c'] > 0 and isset($setup_data['l14c_name']) and $setup_data['l14c_name'] != '') { $ee_data['l14c_name'] = $setup_data['l14c_name']; $ee_data['l14c'] = $row['l14c']; } if ($row['l14d'] > 0 and isset($setup_data['l14d_name']) and $setup_data['l14d_name'] != '') { $ee_data['l14d_name'] = $setup_data['l14d_name']; $ee_data['l14d'] = $row['l14d']; } foreach (range('a', 'z') as $z) { //State income tax if (isset($row['l16' . $z])) { if (isset($setup_data['state'][$row['l15' . $z . '_state']])) { $ee_data['l15' . $z . '_state_id'] = $setup_data['state'][$row['l15' . $z . '_state']]['state_id']; } $ee_data['l15' . $z . '_state'] = $row['l15' . $z . '_state']; $ee_data['l16' . $z] = $row['l16' . $z]; $ee_data['l17' . $z] = $row['l17' . $z]; } else { $ee_data['l15' . $z . '_state_id'] = NULL; $ee_data['l15' . $z . '_state'] = NULL; $ee_data['l16' . $z] = NULL; $ee_data['l17' . $z] = NULL; } //District income tax if (isset($row['l18' . $z])) { $ee_data['l18' . $z] = $row['l18' . $z]; $ee_data['l19' . $z] = $row['l19' . $z]; $ee_data['l20' . $z] = $row['l20' . $z]; } else { $ee_data['l18' . $z] = NULL; $ee_data['l19' . $z] = NULL; $ee_data['l20' . $z] = NULL; } } $fw2->addRecord($ee_data); unset($ee_data); $i++; $n++; } } } $this->getFormObject()->addForm($fw2); if ($form_type == 'government') { //Handle W3 $fw3 = $this->getFW3Object(); $fw3->setShowBackground($show_background); $fw3->year = $fw2->year; $fw3->ein = $fw2->ein; $fw3->name = $fw2->name; $fw3->trade_name = $fw2->trade_name; $fw3->company_address1 = $fw2->company_address1; $fw3->company_address2 = $fw2->company_address2; $fw3->company_city = $fw2->company_city; $fw3->company_state = $fw2->company_state; $fw3->company_zip_code = $fw2->company_zip_code; $fw3->contact_name = $current_user->getFullName(); $fw3->contact_phone = $current_user->getWorkPhoneExt() != '' ? $current_user->getWorkPhone() . 'x' . $current_user->getWorkPhoneExt() : $current_user->getWorkPhone(); $fw3->contact_email = $current_user->getWorkEmail(); $fw3->kind_of_payer = '941'; $fw3->kind_of_employer = 'none'; //$fw3->third_party_sick_pay = TRUE; if (isset($setup_data['state'][$fw2->company_state]) and isset($setup_data['state'][$fw2->company_state]['state_id']) and $setup_data['state'][$fw2->company_state]['state_id'] != '') { $fw3->state_id1 = $setup_data['state'][$fw2->company_state]['state_id']; } $fw3->lc = count($this->form_data); $fw3->control_number = $fw3->lc + 1; //$fw3->ld = '1234568'; $total_row = Misc::ArrayAssocSum($this->form_data); //Debug::Arr($total_row, 'Total Row Data: ', __FILE__, __LINE__, __METHOD__,10); if (is_array($total_row)) { $fw3->l1 = $total_row['l1']; $fw3->l2 = $total_row['l2']; $fw3->l3 = $total_row['l3']; $fw3->l4 = $total_row['l4']; $fw3->l5 = $total_row['l5']; $fw3->l6 = $total_row['l6']; $fw3->l7 = $total_row['l7']; $fw3->l8 = $total_row['l8']; $fw3->l10 = $total_row['l10']; $fw3->l11 = $total_row['l11']; foreach (range('a', 'z') as $z) { //State income tax if (isset($total_row['l16' . $z])) { $fw3->l16 += $total_row['l16' . $z]; $fw3->l17 += $total_row['l17' . $z]; } //District income tax if (isset($total_row['l18' . $z])) { $fw3->l18 += $total_row['l18' . $z]; $fw3->l19 += $total_row['l19' . $z]; } } } $this->getFormObject()->addForm($fw3); } if ($format == 'efile') { $output_format = 'EFILE'; if ($fw2->getDebug() == TRUE) { $file_name = 'w2_efile_' . date('Y_m_d') . '.csv'; } else { $file_name = 'w2_efile_' . date('Y_m_d') . '.txt'; } $mime_type = 'applications/octet-stream'; //Force file to download. } elseif ($format == 'efile_xml') { $output_format = 'XML'; $file_name = 'w2_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 _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 _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); }
} $x = 0; foreach ($data_b as $date_stamp => $data_c) { $sub_rows[$x]['date_stamp'] = $date_stamp; foreach ($data_c as $column => $total_time) { $sub_rows[$x][$column] = $total_time; } $x++; } if (isset($sub_rows)) { foreach ($sub_rows as $sub_row) { $tmp_sub_rows[] = $sub_row; } $sub_rows = Sort::Multisort($tmp_sub_rows, Misc::trimSortPrefix($filter_data['primary_sort']), Misc::trimSortPrefix($filter_data['secondary_sort']), $filter_data['primary_sort_dir'], $filter_data['secondary_sort_dir']); if ($action != 'display_timesheet' and $action != 'display_detailed_timesheet') { $total_sub_row = Misc::ArrayAssocSum($sub_rows, NULL, 2); $last_sub_row = count($sub_rows); $sub_rows[$last_sub_row] = $total_sub_row; //$static_columns['epoch'] = 'epoch'; foreach ($static_columns as $static_column_key => $static_column_val) { $sub_rows[$last_sub_row][Misc::trimSortPrefix($static_column_key)] = NULL; } unset($static_column_key, $static_column_val); } //Convert units $tmp_sub_rows = $sub_rows; unset($sub_rows); $trimmed_static_columns = array_keys(Misc::trimSortPrefix($static_columns)); foreach ($tmp_sub_rows as $sub_row) { foreach ($sub_row as $column => $column_data) { if ($action != 'display_timesheet' and $action != 'display_detailed_timesheet') {
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; }
Debug::text(' User Name: ' . $user_obj->getFullName(), __FILE__, __LINE__, __METHOD__, 10); $user_percent = $user_total_time_obj->getColumn('branch_total_time') / $totals['users'][$user_total_time_obj->getColumn('user_id')]; if (isset($pay_stub_rows[$user_total_time_obj->getColumn('user_id')])) { $user_gross_pay = $pay_stub_rows[$user_total_time_obj->getColumn('user_id')]['entries']['gross_pay'] * $user_percent; } else { $user_gross_pay = 0; } $user_entries[$user_total_time_obj->getColumn('branch_id')][] = array('user_id' => $user_total_time_obj->getColumn('user_id'), 'branch_id' => $user_total_time_obj->getColumn('branch_id'), 'full_name' => $user_obj->getFullName(), 'total_time' => $user_total_time_obj->getColumn('branch_total_time'), 'percent' => $user_percent, 'percent_display' => round($user_percent * 100, 2), 'gross_pay' => number_format($user_gross_pay, 2, '.', '')); unset($user_percent, $user_gross_pay); } if (isset($branch_ids)) { foreach ($branch_ids as $branch_id) { Debug::text(' Branch Done! Branch ID: ' . $branch_id, __FILE__, __LINE__, __METHOD__, 10); $branch_obj = $blf->getById($branch_id)->getCurrent(); $branch_percent = $totals['branches'][$branch_id] / $totals['branches']['total']; $user_totals = Misc::ArrayAssocSum($user_entries[$branch_id], NULL, 2); $user_entries[$branch_id][] = array('full_name' => 'Total', 'total_time' => $totals['branches'][$branch_id], 'percent' => $branch_percent * 100, 'percent_display' => round($branch_percent * 100, 2), 'gross_pay' => number_format($user_totals['gross_pay'], 2, '.', '')); $rows[] = array('id' => $branch_id, 'name' => $branch_obj->getName(), 'percent' => $branch_percent, 'percent_display' => round($branch_percent * 100, 2), 'users' => $user_entries[$branch_id]); unset($branch_obj, $branch_percent, $user_totals); } } unset($branch_ids); //var_dump($rows); /* if ( isset($tmp_rows) ) { foreach($tmp_rows as $row) { $rows[] = $row; } $rows = Sort::Multisort($rows, 'last_name'); //var_dump($rows);