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;
 }
Пример #2
0
 function getPayStub($pslf = NULL, $hide_employer_rows = TRUE)
 {
     if (!is_object($pslf) and $this->getId() != '') {
         $pslf = TTnew('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);
         $i = 0;
         foreach ($pslf as $pay_stub_obj) {
             $psealf = TTnew('PayStubEntryAccountListFactory');
             //Debug::text($i .'. Pay Stub Transaction Date: '. $pay_stub_obj->getTransactionDate(), __FILE__, __LINE__, __METHOD__,10);
             //Get Pay Period information
             $pplf = TTnew('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 User information
             $ulf = TTnew('UserListFactory');
             $user_obj = $ulf->getById($pay_stub_obj->getUser())->getCurrent();
             //Get company information
             $clf = TTnew('CompanyListFactory');
             $company_obj = $clf->getById($user_obj->getCompany())->getCurrent();
             //Change locale to users own locale.
             TTi18n::setLanguage($user_obj->getUserPreferenceObject()->getLanguage());
             TTi18n::setCountry($user_obj->getCountry());
             TTi18n::setLocale();
             $pdf->SetFont(TTi18n::getPDFDefaultFont($user_obj->getUserPreferenceObject()->getLanguage()), '', 10);
             //
             // Pay Stub Header
             //
             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
             $pdf->AddPage();
             $adjust_x = 20;
             $adjust_y = 10;
             //Logo
             $pdf->Image($company_obj->getLogoFileName(NULL, TRUE, FALSE, 'large'), Misc::AdjustXY(0, $adjust_x + 0), Misc::AdjustXY(1, $adjust_y + 0), $pdf->pixelsToUnits(167), $pdf->pixelsToUnits(42), '', '', '', 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', FALSE, '', 1);
             $pdf->SetFont('', '', 10);
             $pdf->setXY(Misc::AdjustXY(50, $adjust_x), Misc::AdjustXY(6, $adjust_y));
             $pdf->Cell(75, 5, $company_obj->getAddress1() . ' ' . $company_obj->getAddress2(), $border, 0, 'C', FALSE, '', 1);
             $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', FALSE, '', 1);
             //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', FALSE, '', 1);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(5, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Pay End Date:') . ' ', $border, 0, 'R', FALSE, '', 1);
             $pdf->setXY(Misc::AdjustXY(125, $adjust_x), Misc::AdjustXY(10, $adjust_y));
             $pdf->Cell(30, 5, TTi18n::gettext('Payment Date:') . ' ', $border, 0, 'R', FALSE, '', 1);
             $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', FALSE, '', 1);
             $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', FALSE, '', 1);
             $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', FALSE, '', 1);
             //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', FALSE, '', 1);
             //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 = TTnew('PayStubEntryListFactory');
             $pself->getByPayStubId($pay_stub_obj->getId());
             Debug::text('Pay Stub Entries: ' . $pself->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             $max_widths = array('units' => 0, 'rate' => 0, 'amount' => 0, 'ytd_amount' => 0);
             $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 and ($type != 30 or $type == 30 and $hide_employer_rows == FALSE)) {
                     //Make sure PSA descriptions are not shown on employee pay stubs.
                     $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());
                     //Calculate maximum widths of numeric values.
                     $width_units = strlen($pay_stub_entry->getUnits());
                     if ($width_units > $max_widths['units']) {
                         $max_widths['units'] = $width_units;
                     }
                     $width_rate = strlen($pay_stub_entry->getRate());
                     if ($width_rate > $max_widths['rate']) {
                         $max_widths['rate'] = $width_rate;
                     }
                     $width_amount = strlen($pay_stub_entry->getAmount());
                     if ($width_amount > $max_widths['amount']) {
                         $max_widths['amount'] = $width_amount;
                     }
                     $width_ytd_amount = strlen($pay_stub_entry->getYTDAmount());
                     if ($width_amount > $max_widths['ytd_amount']) {
                         $max_widths['ytd_amount'] = $width_ytd_amount;
                     }
                     unset($width_rate, $width_units, $width_amount, $width_ytd_amount);
                 }
                 $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);
             //Debug::Arr($max_widths, 'Maximum Widths: ', __FILE__, __LINE__, __METHOD__,10);
             $block_adjust_y = 30;
             //
             //Earnings
             //
             if (isset($pay_stub_entries[10])) {
                 $column_widths['ytd_amount'] = $max_widths['ytd_amount'] * 2 < 25 ? 25 : $max_widths['ytd_amount'] * 2;
                 $column_widths['amount'] = $max_widths['amount'] * 2 < 20 ? 20 : $max_widths['amount'] * 2;
                 $column_widths['rate'] = $max_widths['rate'] * 2 < 5 ? 5 : $max_widths['rate'] * 2;
                 $column_widths['units'] = $max_widths['units'] * 2 < 17 ? 17 : $max_widths['units'] * 2;
                 $column_widths['name'] = 175 - ($column_widths['ytd_amount'] + $column_widths['amount'] + $column_widths['rate'] + $column_widths['units']);
                 //Debug::Arr($column_widths, 'Column Widths: ', __FILE__, __LINE__, __METHOD__,10);
                 //Earnings Header
                 $pdf->SetFont('', 'B', 10);
                 $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                 $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Earnings'), $border, 0, 'L', FALSE, '', 1);
                 $pdf->Cell($column_widths['rate'], 5, TTi18n::gettext('Rate'), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['units'], 5, TTi18n::gettext('Hrs/Units'), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R', FALSE, '', 1);
                 $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($column_widths['name'] - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                         //68
                         $pdf->Cell($column_widths['rate'], 5, TTi18n::formatNumber($pay_stub_entry['rate'], TRUE), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['units'], 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     } else {
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'] - $column_widths['amount'] - $column_widths['units'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175 - (1 + $column_widths['ytd_amount']) - $column_widths['amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //90
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'] - $column_widths['amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175 - (1 + $column_widths['ytd_amount']), $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //111
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //141
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell($column_widths['name'], 5, $pay_stub_entry['name'], $border, 0, 'L', FALSE, '', 1);
                         $pdf->Cell($column_widths['rate'], 5, '', $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['units'], 5, TTi18n::formatNumber($pay_stub_entry['units'], TRUE), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             // Deductions
             //
             if (isset($pay_stub_entries[20])) {
                 $max_deductions = count($pay_stub_entries[20]);
                 $two_column_threshold = 2;
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > $two_column_threshold) {
                     $column_widths['name'] = 85 - ($column_widths['ytd_amount'] + $column_widths['amount']);
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Deductions'), $border, 0, 'L', FALSE, '', 1);
                     $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                     $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R', FALSE, '', 1);
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Deductions'), $border, 0, 'L', FALSE, '', 1);
                 } else {
                     $column_widths['name'] = 175 - ($column_widths['ytd_amount'] + $column_widths['amount']);
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Deductions'), $border, 0, 'L', FALSE, '', 1);
                 }
                 $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R', FALSE, '', 1);
                 $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 > $two_column_threshold) {
                             $pdf->setXY(Misc::AdjustXY(2, $tmp_adjust_x + $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             //$pdf->Cell( $column_widths['name']-2, 5, Misc::TruncateString( $pay_stub_entry['name'], $column_widths['name']/1.7, 0, TRUE ) . $subscript, $border, 0, 'L', FALSE, '', 1);
                             $pdf->Cell($column_widths['name'] - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell($column_widths['name'] - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                         }
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         //Debug::Text('Y Adjustments: '. $adjust_y .' Block: '. $block_adjust_y, __FILE__, __LINE__, __METHOD__,10);
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'] - $column_widths['amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175 - (1 + $column_widths['ytd_amount']), $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //111
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //141
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(175 - ($column_widths['amount'] + $column_widths['ytd_amount']), 5, $pay_stub_entry['name'], $border, 0, 'L', FALSE, '', 1);
                         //110
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     }
                     $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 > $two_column_threshold) {
                     $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(175 - ($column_widths['amount'] + $column_widths['ytd_amount']), 5, $pay_stub_entries[40][0]['name'], $border, 0, 'L', FALSE, '', 1);
                 $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entries[40][0]['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entries[40][0]['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                 $block_adjust_y = $block_adjust_y + 5;
             }
             //
             //Miscellaneous
             //
             if (isset($pay_stub_entries[80])) {
                 $max_deductions = count($pay_stub_entries[80]);
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $column_widths['name'] = 85 - ($column_widths['ytd_amount'] + $column_widths['amount']);
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Miscellaneous'), $border, 0, 'L', FALSE, '', 1);
                     $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                     $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R', FALSE, '', 1);
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Miscellaneous'), $border, 0, 'L', FALSE, '', 1);
                 } else {
                     $column_widths['name'] = 175 - ($column_widths['ytd_amount'] + $column_widths['amount']);
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Miscellaneous'), $border, 0, 'L', FALSE, '', 1);
                 }
                 $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R', FALSE, '', 1);
                 $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[80] 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'] == 80) {
                         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($column_widths['name'] - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                             //38
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell($column_widths['name'] - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                             //128
                         }
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'] - $column_widths['amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175 - (1 + $column_widths['ytd_amount']), $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //111
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //141
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(175 - ($column_widths['amount'] + $column_widths['ytd_amount']), 5, $pay_stub_entry['name'], $border, 0, 'L', FALSE, '', 1);
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     }
                     $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);
             }
             //
             //Employer Contributions
             //
             if (isset($pay_stub_entries[30]) and $hide_employer_rows != TRUE) {
                 $max_deductions = count($pay_stub_entries[30]);
                 //Deductions Header
                 $block_adjust_y = $block_adjust_y + 5;
                 $pdf->SetFont('', 'B', 10);
                 if ($max_deductions > 2) {
                     $column_widths['name'] = 85 - ($column_widths['ytd_amount'] + $column_widths['amount']);
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L', FALSE, '', 1);
                     $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                     $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R', FALSE, '', 1);
                     $pdf->setXY(Misc::AdjustXY(90, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L', FALSE, '', 1);
                 } else {
                     $column_widths['name'] = 175 - ($column_widths['ytd_amount'] + $column_widths['amount']);
                     $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                     $pdf->Cell($column_widths['name'], 5, TTi18n::gettext('Employer Contributions'), $border, 0, 'L', FALSE, '', 1);
                 }
                 $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('YTD Amount'), $border, 0, 'R', FALSE, '', 1);
                 $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($column_widths['name'] - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                             //38
                         } else {
                             $pdf->setXY(Misc::AdjustXY(2, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                             $pdf->Cell($column_widths['name'] - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                             //128
                         }
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     } else {
                         $block_adjust_y = $max_block_adjust_y + 0;
                         //Total
                         $pdf->SetFont('', 'B', 10);
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'] - $column_widths['amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175 - (1 + $column_widths['ytd_amount']), $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //111
                         $pdf->line(Misc::AdjustXY(175 - $column_widths['ytd_amount'], $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y), Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         //141
                         $pdf->setXY(Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y));
                         $pdf->Cell(175 - ($column_widths['amount'] + $column_widths['ytd_amount']), 5, $pay_stub_entry['name'], $border, 0, 'L', FALSE, '', 1);
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     }
                     $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(175 - ($column_widths['amount'] + $column_widths['ytd_amount']), 5, TTi18n::gettext('Accruals'), $border, 0, 'L', FALSE, '', 1);
                 $pdf->Cell($column_widths['amount'], 5, TTi18n::gettext('Amount'), $border, 0, 'R', FALSE, '', 1);
                 $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::gettext('Balance'), $border, 0, 'R', FALSE, '', 1);
                 $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(175 - ($column_widths['amount'] + $column_widths['ytd_amount']) - 2, 5, $pay_stub_entry['name'] . $subscript, $border, 0, 'L', FALSE, '', 1);
                         $pdf->Cell($column_widths['amount'], 5, TTi18n::formatNumber($pay_stub_entry['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                         $pdf->Cell($column_widths['ytd_amount'], 5, TTi18n::formatNumber($pay_stub_entry['ytd_amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), $border, 0, 'R', FALSE, '', 1);
                     }
                     $block_adjust_y = $block_adjust_y + 5;
                 }
             }
             //
             //Accrual Policy Balances
             //
             $ablf = TTnew('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', FALSE, '', 1);
                 $pdf->Cell(25, 5, TTi18n::gettext('Balance (hrs)'), $border, 0, 'R', FALSE, '', 1);
                 $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', FALSE, '', 1);
                     $pdf->Cell(25, 5, TTi18n::formatNumber(TTDate::getHours($balance)), $border, 0, 'R', FALSE, '', 1);
                     $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', FALSE, '', 1);
                 $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(85, 5, '[' . $pay_stub_entry_description['subscript'] . '] ' . html_entity_decode($pay_stub_entry_description['description']), $border, 0, 'L', FALSE, '', 1);
                     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', FALSE, '', 1);
             //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', FALSE, '', 1);
             $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() . ' (#' . $user_obj->getEmployeeNumber() . ')', $border, 0, 'C', FALSE, '', 1);
             $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', FALSE, '', 1);
             $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', FALSE, '', 1);
             }
             $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', FALSE, '', 1);
             //Pay Period - Balance - ID
             $net_pay_amount = 0;
             if (isset($pay_stub_entries[40][0])) {
                 $net_pay_amount = TTi18n::formatNumber($pay_stub_entries[40][0]['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces());
             }
             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');
             }
             $pdf->SetFont('', 'B', 12);
             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY($block_adjust_y + 17, $adjust_y));
             $pdf->Cell(100, 5, $net_pay_label . ': ' . $pay_stub_obj->getCurrencyObject()->getSymbol() . $net_pay_amount . ' ' . $pay_stub_obj->getCurrencyObject()->getISOCode(), $border, 1, 'R', FALSE, '', 1);
             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, 'R', FALSE, '', 1);
             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 . ' @ ' . TTDate::getDate('DATE+TIME', $pay_stub_obj->getCreatedDate()), $border, 0, 'C', FALSE, '', 1);
             unset($pay_stub_entries, $pay_period_number);
             $this->getProgressBarObject()->set(NULL, $pslf->getCurrentRow());
             $i++;
         }
         Debug::Text('Generating PDF...', __FILE__, __LINE__, __METHOD__, 10);
         $output = $pdf->Output('', 'S');
     }
     TTi18n::setMasterLocale();
     if (isset($output)) {
         return $output;
     }
     return FALSE;
 }