예제 #1
0
 function getData()
 {
     $psenlf = new PayStubEntryNameListFactory();
     $pslf = new PayStubListFactory();
     //$pslf->getByIdAndUserId($id, $current_user->getId(), $current_user_prefs->getItemsPerPage(), $page, NULL, array($sort_column => $sort_order) );
     $pslf->getById($this->pay_stub_id);
     $pager = new Pager($pslf);
     foreach ($pslf as $pay_stub_obj) {
         //Get pay stub entries.
         $pself = new PayStubEntryListFactory();
         $pself->getByPayStubId($pay_stub_obj->getId());
         $prev_type = NULL;
         $description_subscript_counter = 1;
         foreach ($pself as $pay_stub_entry) {
             $description_subscript = NULL;
             $pay_stub_entry_name_obj = $psenlf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
             if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                 $type = $pay_stub_entry_name_obj->getType();
             }
             if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE) {
                 $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                 $description_subscript = $description_subscript_counter;
                 $description_subscript_counter++;
             }
             $this->pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getDescription(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
             $prev_type = $pay_stub_entry_name_obj->getType();
         }
         //'entries' => $pay_stub_entries,
         $this->pay_stub = array('id' => $pay_stub_obj->getId(), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'advance' => $pay_stub_obj->getAdvance(), 'status' => $pay_stub_obj->getStatus(), 'created_date' => $pay_stub_obj->getCreatedDate(), 'created_by' => $pay_stub_obj->getCreatedBy(), 'updated_date' => $pay_stub_obj->getUpdatedDate(), 'updated_by' => $pay_stub_obj->getUpdatedBy(), 'deleted_date' => $pay_stub_obj->getDeletedDate(), 'deleted_by' => $pay_stub_obj->getDeletedBy());
         //Get Pay Period information
         $pplf = new PayPeriodListFactory();
         $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
         if ($pay_stub_obj->getAdvance() == TRUE) {
             $pp_start_date = $pay_period_obj->getStartDate();
             $pp_end_date = $pay_period_obj->getAdvanceEndDate();
             $pp_transaction_date = $pay_period_obj->getAdvanceTransactionDate();
         } else {
             $pp_start_date = $pay_period_obj->getStartDate();
             $pp_end_date = $pay_period_obj->getEndDate();
             $pp_transaction_date = $pay_period_obj->getTransactionDate();
         }
         $this->pay_period = array('start_date' => TTDate::getDate('DATE', $pp_start_date), 'end_date' => TTDate::getDate('DATE', $pp_end_date), 'transaction_date' => TTDate::getDate('DATE', $pp_transaction_date));
         //Get User information
         $ulf = new UserListFactory();
         $this->user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
         //Get company information
         $clf = new CompanyListFactory();
         $this->company_obj = $clf->getById($this->user_obj->getCompany())->getCurrent();
     }
 }
 $crlf->getByCompanyIdAndBase($current_company->getId(), TRUE);
 if ($crlf->getRecordCount() > 0) {
     $base_currency_obj = $crlf->getCurrent();
 }
 $currency_convert_to_base = FALSE;
 if (in_array('-1', $filter_data['currency_ids']) or count($filter_data['currency_ids']) > 1) {
     Debug::Text('More then one currency selected, converting to base!', __FILE__, __LINE__, __METHOD__, 10);
     $currency_convert_to_base = TRUE;
 }
 foreach ($pslf as $ps_obj) {
     $user_obj = $ulf->getById($ps_obj->getUser())->getCurrent();
     $replace_arr = array($branch_code_map[(int) $user_obj->getDefaultBranch()], $department_code_map[(int) $user_obj->getDefaultDepartment()], $user_obj->getEmployeeNumber());
     $je_records = NULL;
     //Get all PS Entries for this pay stub.
     $pself = new PayStubEntryListFactory();
     $pself->getByPayStubId($ps_obj->getId());
     if ($pself->getRecordCount() > 0) {
         Debug::Text('Found Pay Stub Entries for PS ID:' . $ps_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
         foreach ($pself as $pse_obj) {
             Debug::Text('Pay Stub Entry ID:' . $pse_obj->getId() . ' PSE Account ID: ' . $pse_obj->getPayStubEntryNameId() . ' Currency Rate: ' . $ps_obj->getCurrencyRate() . ' Amount: ' . $pse_obj->getAmount(), __FILE__, __LINE__, __METHOD__, 10);
             if (isset($psea_arr[$pse_obj->getPayStubEntryNameId()])) {
                 if (isset($psea_arr[$pse_obj->getPayStubEntryNameId()]['debit_account']) and $psea_arr[$pse_obj->getPayStubEntryNameId()]['debit_account'] != '') {
                     $debit_accounts = explode(',', $psea_arr[$pse_obj->getPayStubEntryNameId()]['debit_account']);
                     foreach ($debit_accounts as $debit_account) {
                         $debit_account = replaceGLAccountVariables($debit_account, $replace_arr);
                         Debug::Text('Debit Entry: Account: ' . $debit_account . ' Amount: ' . $pse_obj->getAmount(), __FILE__, __LINE__, __METHOD__, 10);
                         //Skip negative amounts completely and Don't include entries that are $0.
                         if ($pse_obj->getAmount() > 0) {
                             $raw_je_records[] = array('type' => 'debit', 'account' => $debit_account, 'amount' => Misc::MoneyFormat($base_currency_obj->getBaseCurrencyAmount($pse_obj->getAmount(), $ps_obj->getCurrencyRate(), $currency_convert_to_base), FALSE));
                         }
                     }
예제 #3
0
     $ids = array($id);
 }
 if (count($ids) > 0) {
     $pslf = new PayStubListFactory();
     if ($permission->Check('pay_stub', 'view')) {
         $pslf->getByCompanyIdAndId($current_company->getId(), $ids);
     } else {
         $pslf->getByUserIdAndId($current_user->getId(), $ids);
     }
     //foreach ($ids as $id) {
     $i = 0;
     foreach ($pslf as $pay_stub_obj) {
         $psealf = new PayStubEntryAccountListFactory();
         //Get pay stub entries.
         $pself = new PayStubEntryListFactory();
         $pself->getByPayStubId($pay_stub_obj->getId());
         Debug::text('Pay Stub Entries: ' . $pself->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
         $prev_type = NULL;
         $description_subscript_counter = 1;
         foreach ($pself as $pay_stub_entry) {
             Debug::text('Pay Stub Entry Account ID: ' . $pay_stub_entry->getPayStubEntryNameId(), __FILE__, __LINE__, __METHOD__, 10);
             $description_subscript = NULL;
             //$pay_stub_entry_name_obj = $psenlf->getById( $pay_stub_entry->getPayStubEntryNameId() ) ->getCurrent();
             $pay_stub_entry_name_obj = $psealf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
             //Use this to put the total for each type at the end of the array.
             if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                 $type = $pay_stub_entry_name_obj->getType();
             }
             //Debug::text('Pay Stub Entry Name ID: '. $pay_stub_entry_name_obj->getId() .' Type ID: '. $pay_stub_entry_name_obj->getType() .' Type: '. $type, __FILE__, __LINE__, __METHOD__,10);
             //var_dump( $pay_stub_entry->getDescription() );
             if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE and strlen($pay_stub_entry->getDescription()) > 0) {
예제 #4
0
 function getPayStubEntryArray($pay_stub_id)
 {
     //Check Pay Stub to make sure it was created correctly.
     $pself = new PayStubEntryListFactory();
     $pself->getByPayStubId($pay_stub_id);
     if ($pself->getRecordCount() > 0) {
         foreach ($pself as $pse_obj) {
             $ps_entry_arr[$pse_obj->getPayStubEntryNameId()][] = array('amount' => $pse_obj->getAmount(), 'ytd_amount' => $pse_obj->getYTDAmount());
         }
     }
     if (isset($ps_entry_arr)) {
         return $ps_entry_arr;
     }
     return FALSE;
 }
 function getPayStub($pslf = NULL, $hide_employer_rows = TRUE)
 {
     if (!is_object($pslf) and $this->getId() != '') {
         $pslf = new PayStubListFactory();
         $pslf->getById($this->getId());
     }
     if (get_class($pslf) !== 'PayStubListFactory') {
         return FALSE;
     }
     $border = 0;
     if ($pslf->getRecordCount() > 0) {
         $pdf = new TTPDF('P', 'mm', 'Letter');
         $pdf->setMargins(0, 0);
         //$pdf->SetAutoPageBreak(TRUE, 30);
         $pdf->SetAutoPageBreak(FALSE);
         $pdf->SetFont('freeserif', '', 10);
         //$pdf->SetFont('FreeSans','',10);
         $i = 0;
         foreach ($pslf as $pay_stub_obj) {
             $psealf = new PayStubEntryAccountListFactory();
             Debug::text($i . '. Pay Stub Transaction Date: ' . $pay_stub_obj->getTransactionDate(), __FILE__, __LINE__, __METHOD__, 10);
             //Get Pay Period information
             $pplf = new PayPeriodListFactory();
             $pay_period_obj = $pplf->getById($pay_stub_obj->getPayPeriod())->getCurrent();
             //Use Pay Stub dates, not Pay Period dates.
             $pp_start_date = $pay_stub_obj->getStartDate();
             $pp_end_date = $pay_stub_obj->getEndDate();
             $pp_transaction_date = $pay_stub_obj->getTransactionDate();
             //Get pay period numbers
             $ppslf = new PayPeriodScheduleListFactory();
             $pay_period_schedule_obj = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
             //Get User information
             $ulf = new UserListFactory();
             $user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
             //Get company information
             $clf = new CompanyListFactory();
             $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
             //Change locale to users own locale.
             TTi18n::setCountry($user_obj->getCountry());
             TTi18n::setLanguage($user_obj->getUserPreferenceObject()->getLanguage());
             TTi18n::setLocale();
             //
             // Pay Stub Header
             //
             $pdf->AddPage();
             $adjust_x = 20;
             $adjust_y = 10;
             //Logo
             $pdf->Image($company_obj->getLogoFileName(), Misc::AdjustXY(0, $adjust_x + 0), Misc::AdjustXY(1, $adjust_y + 0), 50, 12, '', '', '', FALSE, 300, '', FALSE, FALSE, 0, TRUE);
             //Company name/address
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getName(), $border, 0, 'C');
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getAddress1() . ' ' . $company_obj->getAddress2(), $border, 0, 'C');
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getCity() . ', ' . $company_obj->getProvince() . ' ' . strtoupper($company_obj->getPostalCode()), $border, 0, 'C');
             //Pay Period info
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Pay Start Date:') . ' ', $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Pay End Date:') . ' ', $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Payment Date:') . ' ', $border, 0, 'R');
             $pdf->SetFont('', 'B', 10);
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(0, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_start_date), $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_end_date), $border, 0, 'R');
             $pdf->setXY(Misc::AdjustXY(155, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(20, 5, TTDate::getDate('DATE', $pp_transaction_date), $border, 0, 'R');
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(17, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY(17, $adjust_y));
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(19, $adjust_y));
             $pdf->Cell(175, 5, TTi18n::gettext('STATEMENT OF EARNINGS AND DEDUCTIONS'), $border, 0, 'C', 0);
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(27, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY(27, $adjust_y));
             $pdf->setLineWidth(0.25);
             //Get pay stub entries.
             $pself = new PayStubEntryListFactory();
             $pself->getByPayStubId($pay_stub_obj->getId());
             Debug::text('Pay Stub Entries: ' . $pself->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             $prev_type = NULL;
             $description_subscript_counter = 1;
             foreach ($pself as $pay_stub_entry) {
                 Debug::text('Pay Stub Entry Account ID: ' . $pay_stub_entry->getPayStubEntryNameId(), __FILE__, __LINE__, __METHOD__, 10);
                 $description_subscript = NULL;
                 $pay_stub_entry_name_obj = $psealf->getById($pay_stub_entry->getPayStubEntryNameId())->getCurrent();
                 //Use this to put the total for each type at the end of the array.
                 if ($prev_type == 40 or $pay_stub_entry_name_obj->getType() != 40) {
                     $type = $pay_stub_entry_name_obj->getType();
                 }
                 //Debug::text('Pay Stub Entry Name ID: '. $pay_stub_entry_name_obj->getId() .' Type ID: '. $pay_stub_entry_name_obj->getType() .' Type: '. $type, __FILE__, __LINE__, __METHOD__,10);
                 if ($pay_stub_entry->getDescription() !== NULL and $pay_stub_entry->getDescription() !== FALSE and strlen($pay_stub_entry->getDescription()) > 0) {
                     $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                     $description_subscript = $description_subscript_counter;
                     $description_subscript_counter++;
                 }
                 //If type if 40 (a total) and the amount is 0, skip it.
                 //This if the employee has no deductions at all, it won't be displayed
                 //on the pay stub.
                 if ($type != 40 or $type == 40 and $pay_stub_entry->getAmount() != 0) {
                     $pay_stub_entries[$type][] = array('id' => $pay_stub_entry->getId(), 'pay_stub_entry_name_id' => $pay_stub_entry->getPayStubEntryNameId(), 'type' => $pay_stub_entry_name_obj->getType(), 'name' => $pay_stub_entry_name_obj->getName(), 'display_name' => $pay_stub_entry_name_obj->getName(), 'rate' => $pay_stub_entry->getRate(), 'units' => $pay_stub_entry->getUnits(), 'ytd_units' => $pay_stub_entry->getYTDUnits(), 'amount' => $pay_stub_entry->getAmount(), 'ytd_amount' => $pay_stub_entry->getYTDAmount(), 'description' => $pay_stub_entry->getDescription(), 'description_subscript' => $description_subscript, 'created_date' => $pay_stub_entry->getCreatedDate(), 'created_by' => $pay_stub_entry->getCreatedBy(), 'updated_date' => $pay_stub_entry->getUpdatedDate(), 'updated_by' => $pay_stub_entry->getUpdatedBy(), 'deleted_date' => $pay_stub_entry->getDeletedDate(), 'deleted_by' => $pay_stub_entry->getDeletedBy());
                 }
                 $prev_type = $pay_stub_entry_name_obj->getType();
             }
             //There should always be pay stub entries for a pay stub.
             if (!isset($pay_stub_entries)) {
                 continue;
             }
             //Debug::Arr($pay_stub_entries, 'Pay Stub Entries...', __FILE__, __LINE__, __METHOD__,10);
             //$pay_period_number = $pay_period_schedule_obj->getCurrentPayPeriodNumber( $pay_period_obj->getTransactionDate(), $pay_period_obj->getEndDate() );
             $block_adjust_y = 30;
             //
             //Earnings
             //
             if (isset($pay_stub_entries[10])) {
                 //Earnings Header
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(90, 5, TTi18n::gettext('Earnings'), $border, 0, 'L');
                 $pdf->Cell(17, 5, TTi18n::gettext('Rate'), $border, 0, 'R');
                 $pdf->Cell(23, 5, TTi18n::gettext('Hrs/Units'), $border, 0, 'R');
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($pay_stub_entries[10] as $pay_stub_entry) {
                     if ($pay_stub_entry['type'] == 10) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(88, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         $pdf->Cell(17, 5, TTi18n::formatNumber($pay_stub_entry['rate'], TRUE), $border, 0, 'R');
                         $pdf->Cell(23, 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(110, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(131, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(90, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(17, 5, '', $border, 0, 'R');
                         $pdf->Cell(23, 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             // Deductions
             //
             if (isset($pay_stub_entries[20])) {
                 $max_deductions = count($pay_stub_entries[20]);
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                     $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                     $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                 } else {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(130, 5, TTi18n::gettext('Deductions'), $border, 0, 'L');
                 }
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $tmp_block_adjust_y = $top_block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 $x = 0;
                 $max_block_adjust_y = 0;
                 foreach ($pay_stub_entries[20] as $pay_stub_entry) {
                     //Start with the right side.
                     if ($x < floor($max_deductions / 2)) {
                         $tmp_adjust_x = 90;
                     } else {
                         if ($tmp_block_adjust_y != 0) {
                             $block_adjust_y = $tmp_block_adjust_y;
                             $tmp_block_adjust_y = 0;
                         }
                         $tmp_adjust_x = 0;
                     }
                     if ($pay_stub_entry['type'] == 20) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         if ($max_deductions > 2) {
                             $pdf->setXY(Misc::AdjustXY(2, $tmp_adjust_x + $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         }
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(130, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                     if ($block_adjust_y > $max_block_adjust_y) {
                         $max_block_adjust_y = $block_adjust_y;
                     }
                     $x++;
                 }
                 //Draw line to separate the two columns
                 if ($max_deductions > 2) {
                     $pdf->Line(Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($top_block_adjust_y - 5, $adjust_y), Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($max_block_adjust_y - 5, $adjust_y));
                 }
                 unset($x, $max_deductions, $tmp_adjust_x, $max_block_adjust_y, $tmp_block_adjust_y, $top_block_adjust_y);
             }
             if (isset($pay_stub_entries[40][0])) {
                 $block_adjust_y = $block_adjust_y + 5;
                 //Net Pay entry
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(130, 5, $pay_stub_entries[40][0]['name'], $border, 0, 'L');
                 $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entries[40][0]['amount']), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entries[40][0]['ytd_amount']), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
             }
             //
             //Employer Contributions
             //
             //echo "Employee Ded: <br>\n";
             if (isset($pay_stub_entries[30]) and $hide_employer_rows != TRUE) {
                 $max_deductions = count($pay_stub_entries[30]);
                 //echo "Max Employee Ded: ". $max_deductions ."<br>\n";
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                     $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                     $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(40, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                 } else {
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(130, 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L');
                 }
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R');
                 $block_adjust_y = $tmp_block_adjust_y = $top_block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 $x = 0;
                 $max_block_adjust_y = 0;
                 foreach ($pay_stub_entries[30] as $pay_stub_entry) {
                     //Start with the right side.
                     if ($x < floor($max_deductions / 2)) {
                         $tmp_adjust_x = 90;
                     } else {
                         if ($tmp_block_adjust_y != 0) {
                             $block_adjust_y = $tmp_block_adjust_y;
                             $tmp_block_adjust_y = 0;
                         }
                         $tmp_adjust_x = 0;
                     }
                     if ($pay_stub_entry['type'] == 30) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         if ($max_deductions > 2) {
                             $pdf->setXY(Misc::AdjustXY(2, $tmp_adjust_x + $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         }
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(150, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->line(Misc::AdjustXY(151, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(130, 5, $pay_stub_entry['name'], $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                     if ($block_adjust_y > $max_block_adjust_y) {
                         $max_block_adjust_y = $block_adjust_y;
                     }
                     $x++;
                 }
                 //Draw line to separate the two columns
                 if ($max_deductions > 2) {
                     $pdf->Line(Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($top_block_adjust_y - 5, $adjust_y), Misc::AdjustXY(88, $adjust_x), Misc::AdjustXY($max_block_adjust_y - 5, $adjust_y));
                 }
                 unset($x, $max_deductions, $tmp_adjust_x, $max_block_adjust_y, $tmp_block_adjust_y, $top_block_adjust_y);
             }
             //
             //Accruals PS accounts
             //
             if (isset($pay_stub_entries[50])) {
                 //Accrual Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(130, 5, TTi18n::gettext('Accruals'), $border, 0, 'L');
                 $pdf->Cell(20, 5, TTi18n::gettext('Amount'), $border, 0, 'R');
                 $pdf->Cell(25, 5, TTi18n::gettext('Balance'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($pay_stub_entries[50] as $pay_stub_entry) {
                     if ($pay_stub_entry['type'] == 50) {
                         if ($pay_stub_entry['description_subscript'] != '') {
                             $subscript = '[' . $pay_stub_entry['description_subscript'] . ']';
                         } else {
                             $subscript = NULL;
                         }
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(128, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L');
                         $pdf->Cell(20, 5, TTi18n::formatNumber($pay_stub_entry['amount']), $border, 0, 'R');
                         $pdf->Cell(25, 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount']), $border, 0, 'R');
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             //Accrual Policy Balances
             //
             $ablf = new AccrualBalanceListFactory();
             $ablf->getByUserIdAndCompanyIdAndEnablePayStubBalanceDisplay($user_obj->getId(), $user_obj->getCompany(), TRUE);
             if ($ablf->getRecordCount() > 0) {
                 //Accrual Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(40, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $accrual_time_header_start_x = $pdf->getX();
                 $accrual_time_header_start_y = $pdf->getY();
                 $pdf->Cell(70, 5, TTi18n::gettext('Accrual Time Balances as of ') . TTDate::getDate('DATE', time()), $border, 0, 'L');
                 $pdf->Cell(25, 5, TTi18n::gettext('Balance (hrs)'), $border, 0, 'R');
                 $block_adjust_y = $block_adjust_y + 5;
                 $box_height = 5;
                 $pdf->SetFont('', '', 10);
                 foreach ($ablf as $ab_obj) {
                     $balance = $ab_obj->getBalance();
                     if (!is_numeric($balance)) {
                         $balance = 0;
                     }
                     $pdf->setXY(Misc::AdjustXY(40, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell(70, 5, $ab_obj->getColumn('name'), $border, 0, 'L');
                     $pdf->Cell(25, 5, TTi18n::formatNumber(TTDate::getHours($balance)), $border, 0, 'R');
                     $block_adjust_y = $block_adjust_y + 5;
                     $box_height = $box_height + 5;
                     unset($balance);
                 }
                 $pdf->Rect($accrual_time_header_start_x, $accrual_time_header_start_y, 95, $box_height);
                 unset($accrual_time_header_start_x, $accrual_time_header_start_y, $box_height);
             }
             //
             //Descriptions
             //
             if (isset($pay_stub_entry_descriptions) and count($pay_stub_entry_descriptions) > 0) {
                 //Description Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell(175, 5, TTi18n::gettext('Notes'), $border, 0, 'L');
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', '', 8);
                 $x = 0;
                 foreach ($pay_stub_entry_descriptions as $pay_stub_entry_description) {
                     if ($x % 2 == 0) {
                         $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     } else {
                         $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     }
                     //$pdf->Cell(173,5, '['.$pay_stub_entry_description['subscript'].'] '.$pay_stub_entry_description['description'], $border, 0, 'L');
                     $pdf->Cell(85, 5, '[' . $pay_stub_entry_description['subscript'] . '] ' . $pay_stub_entry_description['description'], $border, 0, 'L');
                     if ($x % 2 != 0) {
                         $block_adjust_y = $block_adjust_y + 5;
                     }
                     $x++;
                 }
             }
             unset($x, $pay_stub_entry_descriptions, $pay_stub_entry_description);
             //
             // Pay Stub Footer
             //
             $block_adjust_y = 215;
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY($block_adjust_y, $adjust_y));
             //Non Negotiable
             $pdf->SetFont('', 'B', 14);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 3, $adjust_y));
             $pdf->Cell(175, 5, TTi18n::gettext('NON NEGOTIABLE'), $border, 0, 'C', 0);
             //Employee Address
             $pdf->SetFont('', 'B', 12);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 9, $adjust_y));
             $pdf->Cell(60, 5, TTi18n::gettext('CONFIDENTIAL'), $border, 0, 'C', 0);
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 14, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getFullName(), $border, 0, 'C', 0);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 19, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getAddress1(), $border, 0, 'C', 0);
             $address2_adjust_y = 0;
             if ($user_obj->getAddress2() != '') {
                 $address2_adjust_y = 5;
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 24, $adjust_y));
                 $pdf->Cell(60, 5, $user_obj->getAddress2(), $border, 0, 'C', 0);
             }
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 24 + $address2_adjust_y, $adjust_y));
             $pdf->Cell(60, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 1, 'C', 0);
             //Pay Period - Balance - ID
             $net_pay_amount = 0;
             if (isset($pay_stub_entries[40][0])) {
                 $net_pay_amount = $pay_stub_entries[40][0]['amount'];
             }
             if (isset($pay_stub_entries[65]) and count($pay_stub_entries[65]) > 0) {
                 $net_pay_label = TTi18n::gettext('Balance');
             } else {
                 $net_pay_label = TTi18n::gettext('Net Pay');
             }
             /*
             if ( $pay_period_schedule_obj->getType() != 5 AND $pay_period_number > 0 AND $pay_period_schedule_obj->getAnnualPayPeriods() > 0 ) {
             	$pdf->setXY( Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y+10, $adjust_y) );
             	$pdf->Cell(50, 5, TTi18n::gettext('Pay Period').' '. $pay_period_number .' '. TTi18n::gettext('of') .' '. $pay_period_schedule_obj->getAnnualPayPeriods(), $border, 1, 'L', 0);
             }
             */
             $pdf->SetFont('', 'B', 12);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y + 17, $adjust_y));
             $pdf->Cell(50, 5, $net_pay_label . ': ' . $pay_stub_obj->getCurrencyObject()->getSymbol() . $net_pay_amount . ' ' . $pay_stub_obj->getCurrencyObject()->getISOCode(), $border, 1, 'L', 0);
             if ($pay_stub_obj->getTainted() == TRUE) {
                 $tainted_flag = 'T';
             } else {
                 $tainted_flag = '';
             }
             $pdf->SetFont('', '', 8);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY($block_adjust_y + 30, $adjust_y));
             $pdf->Cell(50, 5, TTi18n::gettext('Identification #:') . ' ' . str_pad($pay_stub_obj->getId(), 12, 0, STR_PAD_LEFT) . $tainted_flag, $border, 1, 'L', 0);
             unset($net_pay_amount, $tainted_flag);
             //Line
             $pdf->setLineWidth(1);
             $pdf->Line(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 35, $adjust_y), Misc::AdjustXY(185, $adjust_y), Misc::AdjustXY($block_adjust_y + 35, $adjust_y));
             $pdf->SetFont('', '', 6);
             $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y + 38, $adjust_y));
             $pdf->Cell(175, 1, TTi18n::gettext('Pay Stub Generated by') . ' ' . APPLICATION_NAME, $border, 0, 'C', 0);
             unset($pay_period_schedule_obj, $pay_stub_entries, $pay_period_number);
             $i++;
         }
         $output = $pdf->Output('', 'S');
     }
     TTi18n::setMasterLocale();
     if (isset($output)) {
         return $output;
     }
     return FALSE;
 }