function exportPayStub($pslf = NULL, $export_type = NULL)
 {
     global $current_company;
     if (!is_object($pslf) and $this->getId() != '') {
         $pslf = new PayStubListFactory();
         $pslf->getById($this->getId());
     }
     if (get_class($pslf) !== 'PayStubListFactory') {
         return FALSE;
     }
     if ($export_type == '') {
         return FALSE;
     }
     if ($pslf->getRecordCount() > 0) {
         Debug::Text('aExporting...', __FILE__, __LINE__, __METHOD__, 10);
         switch (strtolower($export_type)) {
             case 'hsbc':
             case '1464':
             case '105':
             case 'ach':
                 //Get file creation number
                 $ugdlf = new UserGenericDataListFactory();
                 $ugdlf->getByCompanyIdAndScriptAndDefault($current_company->getId(), 'PayStubFactory', TRUE);
                 if ($ugdlf->getRecordCount() > 0) {
                     Debug::Text('Found Script Setup Data!', __FILE__, __LINE__, __METHOD__, 10);
                     $ugd_obj = $ugdlf->getCurrent();
                     $setup_data = $ugd_obj->getData();
                 } else {
                     $ugd_obj = new UserGenericDataFactory();
                 }
                 Debug::Text('bExporting...', __FILE__, __LINE__, __METHOD__, 10);
                 //get User Bank account info
                 $balf = new BankAccountListFactory();
                 $balf->getCompanyAccountByCompanyId($current_company->getID());
                 if ($balf->getRecordCount() > 0) {
                     $company_bank_obj = $balf->getCurrent();
                     //Debug::Arr($company_bank_obj,'Company Bank Object', __FILE__, __LINE__, __METHOD__,10);
                 }
                 if (isset($setup_data['file_creation_number'])) {
                     $setup_data['file_creation_number']++;
                 } else {
                     //Start at a high number, in attempt to eliminate conflicts.
                     $setup_data['file_creation_number'] = 500;
                 }
                 Debug::Text('bFile Creation Number: ' . $setup_data['file_creation_number'], __FILE__, __LINE__, __METHOD__, 10);
                 //Increment file creation number in DB
                 if ($ugd_obj->getId() == '') {
                     $ugd_obj->setID($ugd_obj->getId());
                 }
                 $ugd_obj->setCompany($current_company->getId());
                 $ugd_obj->setName('PayStubFactory');
                 $ugd_obj->setScript('PayStubFactory');
                 $ugd_obj->setData($setup_data);
                 $ugd_obj->setDefault(TRUE);
                 if ($ugd_obj->isValid()) {
                     $ugd_obj->Save();
                 }
                 $eft = new EFT();
                 $eft->setFileFormat($export_type);
                 $eft->setOriginatorID($current_company->getOriginatorID());
                 $eft->setFileCreationNumber($setup_data['file_creation_number']);
                 $eft->setDataCenter($current_company->getDataCenterID());
                 $eft->setOriginatorShortName($current_company->getShortName());
                 $psealf = new PayStubEntryAccountListFactory();
                 foreach ($pslf as $pay_stub_obj) {
                     Debug::Text('Looping over Pay Stub... ID: ' . $pay_stub_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                     //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();
                         $pay_stub_entry_name_obj = $psealf->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();
                         }
                         //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) {
                             $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                             $description_subscript = $description_subscript_counter;
                             $description_subscript_counter++;
                         }
                         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();
                     }
                     if (isset($pay_stub_entries)) {
                         $pay_stub = array('id' => $pay_stub_obj->getId(), 'display_id' => str_pad($pay_stub_obj->getId(), 12, 0, STR_PAD_LEFT), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'start_date' => $pay_stub_obj->getStartDate(), 'end_date' => $pay_stub_obj->getEndDate(), 'transaction_date' => $pay_stub_obj->getTransactionDate(), 'status' => $pay_stub_obj->getStatus(), 'entries' => $pay_stub_entries, '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());
                         unset($pay_stub_entries);
                         //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();
                         //get User Bank account info
                         $balf = new BankAccountListFactory();
                         $user_bank_obj = $balf->getUserAccountByCompanyIdAndUserId($user_obj->getCompany(), $user_obj->getId());
                         if ($user_bank_obj->getRecordCount() > 0) {
                             $user_bank_obj = $user_bank_obj->getCurrent();
                         } else {
                             continue;
                         }
                         $record = new EFT_Record();
                         $record->setType('C');
                         $amount = $pay_stub['entries'][40][0]['amount'];
                         $record->setCPACode(200);
                         $record->setAmount($amount);
                         unset($amount);
                         $record->setDueDate(TTDate::getBeginDayEpoch($pay_stub_obj->getTransactionDate()));
                         //$record->setDueDate( strtotime("24-Sep-99") );
                         $record->setInstitution($user_bank_obj->getInstitution());
                         $record->setTransit($user_bank_obj->getTransit());
                         $record->setAccount($user_bank_obj->getAccount());
                         $record->setName($user_obj->getFullName());
                         $record->setOriginatorShortName($company_obj->getShortName());
                         $record->setOriginatorLongName(substr($company_obj->getName(), 0, 30));
                         $record->setOriginatorReferenceNumber('TT' . $pay_stub_obj->getId());
                         if (isset($company_bank_obj) and is_object($company_bank_obj)) {
                             $record->setReturnInstitution($company_bank_obj->getInstitution());
                             $record->setReturnTransit($company_bank_obj->getTransit());
                             $record->setReturnAccount($company_bank_obj->getAccount());
                         }
                         $eft->setRecord($record);
                     }
                 }
                 $eft->compile();
                 $output = $eft->getCompiledData();
                 break;
             case 'cheque_9085':
             case 'cheque_9209p':
             case 'cheque_dlt103':
             case 'cheque_dlt104':
             case 'cheque_cr_standard_form_1':
             case 'cheque_cr_standard_form_2':
                 $border = 0;
                 $show_background = 0;
                 $pdf = new TTPDF();
                 $pdf->setMargins(0, 0, 0, 0);
                 $pdf->SetAutoPageBreak(FALSE);
                 $pdf->SetFont('freeserif', '', 10);
                 $psealf = new PayStubEntryAccountListFactory();
                 $i = 0;
                 foreach ($pslf as $pay_stub_obj) {
                     //Get pay stub entries.
                     $pself = new PayStubEntryListFactory();
                     $pself->getByPayStubId($pay_stub_obj->getId());
                     $pay_stub_entries = NULL;
                     $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();
                         $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) {
                             $pay_stub_entry_descriptions[] = array('subscript' => $description_subscript_counter, 'description' => $pay_stub_entry->getDescription());
                             $description_subscript = $description_subscript_counter;
                             $description_subscript_counter++;
                         }
                         $amount_words = str_pad(ucwords(Numbers_Words::toWords(floor($pay_stub_entry->getAmount()), "en_US")) . ' ', 65, "-", STR_PAD_RIGHT);
                         //echo "Amount: ". floor($pay_stub_entry->getAmount()) ." - Words: ". $amount_words ."<br>\n";
                         //var_dump($amount_words);
                         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(), 'amount_padded' => str_pad($pay_stub_entry->getAmount(), 12, '*', STR_PAD_LEFT), 'amount_words' => $amount_words, 'amount_cents' => Misc::getAfterDecimal($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());
                         }
                         unset($amount_words);
                         //Only for net pay, make a total YTD of Advance plus Net.
                         /*
                         if ( $type == 40 ) {
                         	$pay_stub_entries[$type][0]['ytd_net_plus_advance'] =
                         }
                         */
                         $prev_type = $pay_stub_entry_name_obj->getType();
                     }
                     //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();
                     if ($user_obj->getCountry() == 'CA') {
                         $date_format = 'd/m/Y';
                     } else {
                         $date_format = 'm/d/Y';
                     }
                     $pay_stub = array('id' => $pay_stub_obj->getId(), 'display_id' => str_pad($pay_stub_obj->getId(), 15, 0, STR_PAD_LEFT), 'user_id' => $pay_stub_obj->getUser(), 'pay_period_id' => $pay_stub_obj->getPayPeriod(), 'start_date' => $pay_stub_obj->getStartDate(), 'end_date' => $pay_stub_obj->getEndDate(), 'transaction_date' => $pay_stub_obj->getTransactionDate(), 'transaction_date_display' => date($date_format, $pay_stub_obj->getTransactionDate()), 'status' => $pay_stub_obj->getStatus(), 'entries' => $pay_stub_entries, 'tainted' => $pay_stub_obj->getTainted(), '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());
                     unset($pay_stub_entries);
                     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();
                     $pp_start_date = $pay_period_obj->getStartDate();
                     $pp_end_date = $pay_period_obj->getEndDate();
                     $pp_transaction_date = $pay_period_obj->getTransactionDate();
                     //Get pay period numbers
                     $ppslf = new PayPeriodScheduleListFactory();
                     $pay_period_schedule_obj = $ppslf->getById($pay_period_obj->getPayPeriodSchedule())->getCurrent();
                     $pay_period_data = 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), 'annual_pay_periods' => $pay_period_schedule_obj->getAnnualPayPeriods());
                     $pdf->AddPage();
                     switch ($export_type) {
                         case 'cheque_9085':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9085.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(42, $adjust_y));
                             $pdf->Cell(100, 5, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 5, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(130, $adjust_x), Misc::AdjustXY(50, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub['transaction_date_display'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(175, $adjust_x), Misc::AdjustXY(50, $adjust_y));
                             $pdf->Cell(23, 5, ' ' . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(55, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(60, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getAddress1() . ' ' . $user_obj->getAddress2(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(17, $adjust_x), Misc::AdjustXY(65, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 95;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_9209p':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9209P.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(42, $adjust_y));
                             $pdf->Cell(100, 10, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 10, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(25, $adjust_y));
                             $pdf->Cell(10, 10, TTi18n::gettext('Date:') . ' ', $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(182, $adjust_x), Misc::AdjustXY(25, $adjust_y));
                             $pdf->Cell(25, 10, $pay_stub['transaction_date_display'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(42, $adjust_y));
                             $pdf->Cell(35, 10, $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(57, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(62, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getAddress1() . ' ' . $user_obj->getAddress2(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(67, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getCity() . ', ' . $user_obj->getProvince() . ' ' . $user_obj->getPostalCode(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 100;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_dlt103':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_dlt103.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(54, $adjust_y));
                             $pdf->Cell(100, 10, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 10, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(10, 10, TTi18n::gettext('Date:') . ' ', $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(182, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(25, 10, $pay_stub['transaction_date_display'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(46, $adjust_y));
                             $pdf->Cell(35, 10, $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(46, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 100;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_dlt104':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_dlt104.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(52, $adjust_y));
                             $pdf->Cell(100, 10, $pay_stub['entries'][40][0]['amount_words'], $border, 0, 'L');
                             $pdf->Cell(15, 10, $pay_stub['entries'][40][0]['amount_cents'] . '/100', $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(10, 10, TTi18n::gettext('Date:') . ' ', $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(182, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(25, 10, $pay_stub['transaction_date_display'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(172, $adjust_x), Misc::AdjustXY(43, $adjust_y));
                             $pdf->Cell(35, 10, $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(25, $adjust_x), Misc::AdjustXY(48, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 100;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: ') . $pay_stub_obj->getCurrencyObject()->getSymbol() . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             break;
                         case 'cheque_cr_standard_form_1':
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9085.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(41, $adjust_y));
                             $pdf->Cell(100, 5, $pay_stub['entries'][40][0]['amount_words'] . TTi18n::gettext(' and ') . $pay_stub['entries'][40][0]['amount_cents'] . '/100 *****', $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(100, $adjust_x), Misc::AdjustXY(23, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub['transaction_date_display'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(136, $adjust_x), Misc::AdjustXY(32, $adjust_y));
                             $pdf->Cell(24, 5, '  $' . $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 95;
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, $user_obj->getFullName(), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Identification #:') . ' ' . $pay_stub['display_id'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay Start Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(115 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Pay End Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(160, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(50, 5, TTi18n::gettext('Payment Date:') . ' ' . TTDate::getDate('DATE', $pay_stub['transaction_date']), $border, 0, 'L');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: $') . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(15, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->Cell(40, 5, TTi18n::gettext('Net Pay: $') . $pay_stub['entries'][40][0]['amount'], $border, 0, 'L');
                             //Signature lines
                             $pdf->setXY(Misc::AdjustXY(7, $adjust_x), Misc::AdjustXY(250, $adjust_y));
                             $border = 0;
                             $pdf->Cell(40, 5, TTi18n::gettext('Employee Signature:'), $border, 0, 'L');
                             $pdf->Cell(60, 5, '_____________________________', $border, 0, 'L');
                             $pdf->Cell(40, 5, TTi18n::gettext('Supervisor Signature:'), $border, 0, 'R');
                             $pdf->Cell(60, 5, '_____________________________', $border, 0, 'L');
                             $pdf->Ln();
                             $pdf->Cell(40, 5, '', $border, 0, 'R');
                             $pdf->Cell(60, 5, $user_obj->getFullName(), $border, 0, 'C');
                             $pdf->Ln();
                             $pdf->Cell(147, 5, '', $border, 0, 'R');
                             $pdf->Cell(60, 5, '_____________________________', $border, 0, 'C');
                             $pdf->Ln();
                             $pdf->Cell(140, 5, '', $border, 0, 'R');
                             $pdf->Cell(60, 5, TTi18n::gettext('(print name)'), $border, 0, 'C');
                             break;
                         case 'cheque_cr_standard_form_2':
                             $pdf_created_date = time();
                             $adjust_x = 0;
                             $adjust_y = -5;
                             if ($show_background == 1) {
                                 $pdf->Image(Environment::getBasePath() . 'interface/images/nebs_cheque_9085.jpg', 0, 0, 210, 300);
                             }
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(41, $adjust_y));
                             $pdf->Cell(100, 5, $pay_stub['entries'][40][0]['amount_words'] . TTi18n::gettext(' and ') . $pay_stub['entries'][40][0]['amount_cents'] . '/100 *****', $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(100, $adjust_x), Misc::AdjustXY(23, $adjust_y));
                             $pdf->Cell(38, 5, $pay_stub['transaction_date_display'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(136, $adjust_x), Misc::AdjustXY(32, $adjust_y));
                             $pdf->Cell(24, 5, '$  ' . $pay_stub['entries'][40][0]['amount_padded'], $border, 0, 'L');
                             $pdf->setXY(Misc::AdjustXY(20, $adjust_x), Misc::AdjustXY(33, $adjust_y));
                             $pdf->Cell(100, 5, $user_obj->getFullName(), $border, 0, 'L');
                             //Cheque Stub
                             $stub_2_offset = 110;
                             $pdf->SetFont('', 'U', 14);
                             $pdf->setXY(Misc::AdjustXY(65, $adjust_x), Misc::AdjustXY(100, $adjust_y));
                             $pdf->Cell(75, 5, TTi18n::gettext('Recipient Copy:'), $border, 0, 'C');
                             $pdf->SetFont('', '', 10);
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(110, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Date of Issue:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(130, 5, TTDate::getDate('DATE+TIME', $pdf_created_date), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(110 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Date of Issue:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(130, 5, TTDate::getDate('DATE+TIME', $pdf_created_date), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(120, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Recipient:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(110, 5, $user_obj->getFullName(), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(120 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Recipient:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(130, 5, $user_obj->getFullName(), $border, 0, 'J');
                             //Earnings
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(130, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Amount:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, ' $' . $pay_stub['entries'][40][0]['amount'], $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(130 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Amount:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, ' $' . $pay_stub['entries'][40][0]['amount'], $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(140, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Regarding:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, TTi18n::gettext('Payment from') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']) . ' ' . TTi18n::gettext('to') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'J');
                             $pdf->setXY(Misc::AdjustXY(75, $adjust_x), Misc::AdjustXY(140 + $stub_2_offset, $adjust_y));
                             $pdf->SetFont('', 'B', 10);
                             $pdf->Cell(30, 5, TTi18n::gettext('Regarding:'), $border, 0, 'J');
                             $pdf->SetFont('', '', 10);
                             $pdf->Cell(100, 5, TTi18n::gettext('Payment from') . ' ' . TTDate::getDate('DATE', $pay_stub['start_date']) . ' ' . TTi18n::gettext('to') . ' ' . TTDate::getDate('DATE', $pay_stub['end_date']), $border, 0, 'J');
                             $pdf->SetFont('', 'U', 14);
                             $pdf->setXY(Misc::AdjustXY(65, $adjust_x), Misc::AdjustXY(210, $adjust_y));
                             $pdf->Cell(75, 5, $company_obj->getName() . ' ' . TTi18n::gettext('Copy:'), $border, 0, 'C');
                             $pdf->setXY(Misc::AdjustXY(30, $adjust_x), Misc::AdjustXY(260, $adjust_y));
                             $column_widths = array('generated_by' => 25, 'signed_by' => 25, 'received_by' => 35, 'date' => 35, 'sin_ssn' => 35);
                             $line_h = 4;
                             $cell_h_min = $cell_h_max = $line_h * 4;
                             $pdf->SetFont('', '', 8);
                             $pdf->setFillColor(255, 255, 255);
                             $pdf->MultiCell($column_widths['generated_by'], $line_h, TTi18n::gettext('Generated By') . "\n\n\n ", 1, 'C', 1, 0);
                             $pdf->MultiCell($column_widths['signed_by'], $line_h, TTi18n::gettext('Signed By') . "\n\n\n ", 1, 'C', 1, 0);
                             $pdf->MultiCell($column_widths['received_by'], $line_h, TTi18n::gettext('Received By') . "\n\n\n ", 'T,L,B', 'C', 1, 0);
                             $pdf->MultiCell($column_widths['date'], $line_h, TTi18n::gettext('Date') . "\n\n\n ", 'T,B', 'C', 1, 0);
                             $pdf->MultiCell($column_widths['sin_ssn'], $line_h, TTi18n::gettext('SIN / SSN') . "\n\n\n ", 'T,R,B', 'C', 1, 0);
                             $pdf->Ln();
                             $pdf->SetFont('', '', 10);
                             break;
                     }
                     $i++;
                 }
                 $output = $pdf->Output('', 'S');
                 break;
         }
     }
     if (isset($output)) {
         return $output;
     }
     return FALSE;
 }
 function getSchedule($filter_data, $start_week_day = 0, $group_schedule = FALSE)
 {
     global $current_user, $current_user_prefs;
     //Individual is one schedule per employee, or all on one schedule.
     if (!is_array($filter_data)) {
         return FALSE;
     }
     $current_epoch = time();
     //Debug::Text('Start Date: '. TTDate::getDate('DATE', $start_date) .' End Date: '. TTDate::getDate('DATE', $end_date) , __FILE__, __LINE__, __METHOD__,10);
     Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $filter_data['start_date']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $filter_data['end_date']) . ' Start Week Day: ' . $start_week_day, __FILE__, __LINE__, __METHOD__, 10);
     $pdf = new TTPDF('L', 'pt', 'Letter');
     $left_margin = 20;
     $top_margin = 20;
     $pdf->setMargins($left_margin, $top_margin);
     $pdf->SetAutoPageBreak(TRUE, 30);
     //$pdf->SetAutoPageBreak(FALSE);
     $pdf->SetFont('freesans', '', 10);
     $border = 0;
     $adjust_x = 0;
     $adjust_y = 0;
     if ($group_schedule == FALSE) {
         $valid_schedules = 0;
         $sf = TTnew('ScheduleFactory');
         $tmp_schedule_shifts = $sf->getScheduleArray($filter_data);
         //Re-arrange array by user_id->date
         if (is_array($tmp_schedule_shifts)) {
             foreach ($tmp_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_schedule_shift) {
                     $raw_schedule_shifts[$day_schedule_shift['user_id']][$day_epoch][] = $day_schedule_shift;
                 }
             }
         }
         unset($tmp_schedule_shifts);
         //Debug::Arr($raw_schedule_shifts, 'Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
         if (isset($raw_schedule_shifts) and is_array($raw_schedule_shifts)) {
             foreach ($raw_schedule_shifts as $user_id => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                     foreach ($day_schedule_shifts as $day_schedule_shift) {
                         //Debug::Arr($day_schedule_shift, 'aDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10);
                         $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                         if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) {
                             $schedule_shift_totals[$day_epoch]['total_shifts']++;
                         } else {
                             $schedule_shift_totals[$day_epoch]['total_shifts'] = 1;
                         }
                         //$week_of_year = TTDate::getWeek( strtotime($day_epoch) );
                         $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day);
                         if (!isset($schedule_shift_totals[$day_epoch]['labels'])) {
                             $schedule_shift_totals[$day_epoch]['labels'] = 0;
                         }
                         if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) {
                             $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE;
                             $schedule_shift_totals[$day_epoch]['labels']++;
                         }
                         if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) {
                             $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE;
                             $schedule_shift_totals[$day_epoch]['labels']++;
                         }
                         if (!isset($max_week_data[$week_of_year]['shift'])) {
                             Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10);
                             $max_week_data[$week_of_year]['shift'] = 1;
                             $max_week_data[$week_of_year]['labels'] = 0;
                         }
                         if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) {
                             Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10);
                             $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts'];
                             $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels'];
                         }
                         //Debug::Arr($schedule_shift_totals, ' Schedule Shift Totals: ', __FILE__, __LINE__, __METHOD__,10);
                         //Debug::Arr($max_week_data, ' zMaxWeekData: ', __FILE__, __LINE__, __METHOD__,10);
                     }
                 }
                 if (isset($tmp_schedule_shifts)) {
                     //Sort Branches/Departments first
                     foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                         ksort($day_tmp_schedule_shift);
                         $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                         foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                             ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                         }
                     }
                     //Sort each department by start time.
                     foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                         foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                             foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                                 $department_schedule_shift = Sort::multiSort($department_schedule_shift, 'start_time');
                                 $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift;
                             }
                         }
                     }
                 }
                 unset($day_tmp_schedule_shift, $department_schedule_shifts, $department_schedule_shift, $tmp_schedule_shifts, $branch, $department);
                 $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
                 //var_dump($calendar_array);
                 if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) {
                     continue;
                     //Skip to next user.
                 }
                 $ulf = TTnew('UserListFactory');
                 $ulf->getByIdAndCompanyId($user_id, $current_user->getCompany());
                 if ($ulf->getRecordCount() != 1) {
                     continue;
                 } else {
                     $user_obj = $ulf->getCurrent();
                     $pdf->AddPage();
                     $pdf->setXY(670, $top_margin);
                     $pdf->SetFont('freesans', '', 10);
                     $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R');
                     $pdf->setXY($left_margin, $top_margin);
                     $pdf->SetFont('freesans', 'B', 25);
                     $pdf->Cell(0, 25, $user_obj->getFullName() . ' - ' . TTi18n::getText('Schedule'), $border, 0, 'C');
                     $pdf->Ln();
                 }
                 $pdf->SetFont('freesans', 'B', 16);
                 $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C');
                 //$pdf->Ln();
                 $pdf->Ln();
                 $pdf->Ln();
                 $pdf->SetFont('freesans', '', 8);
                 $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7);
                 $cell_height = 100;
                 $i = 0;
                 $total_days = count($calendar_array) - 1;
                 $boader = 1;
                 foreach ($calendar_array as $calendar) {
                     if ($i == 0) {
                         //Calendar Header
                         $pdf->SetFont('freesans', 'B', 8);
                         $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day);
                         foreach ($calendar_header as $header_name) {
                             $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C');
                         }
                         $pdf->Ln();
                         unset($calendar_header, $header_name);
                     }
                     $month_name = NULL;
                     if ($i == 0 or $calendar['isNewMonth'] == TRUE) {
                         $month_name = $calendar['month_name'];
                     }
                     if ($i > 0 and $i % 7 == 0) {
                         $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day);
                         unset($week_date_stamps);
                     }
                     $pdf->SetFont('freesans', 'B', 8);
                     $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L');
                     $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R');
                     $week_date_stamps[] = $calendar['date_stamp'];
                     $i++;
                 }
                 $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE);
                 $valid_schedules++;
                 unset($this->schedule_shifts, $calendar_array, $week_date_stamps, $max_week_data, $day_epoch, $day_schedule_shifts, $day_schedule_shift, $schedule_shift_totals);
             }
         }
         unset($raw_schedule_shifts);
     } else {
         $valid_schedules = 1;
         $sf = TTnew('ScheduleFactory');
         $raw_schedule_shifts = $sf->getScheduleArray($filter_data);
         if (is_array($raw_schedule_shifts)) {
             foreach ($raw_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_schedule_shift) {
                     //Debug::Arr($day_schedule_shift, 'bDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10);
                     $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                     if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) {
                         $schedule_shift_totals[$day_epoch]['total_shifts']++;
                     } else {
                         $schedule_shift_totals[$day_epoch]['total_shifts'] = 1;
                     }
                     //$week_of_year = TTDate::getWeek( strtotime($day_epoch) );
                     $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day);
                     Debug::text(' Date: ' . TTDate::getDate('DATE', strtotime($day_epoch)) . ' Week: ' . $week_of_year . ' TMP: ' . TTDate::getWeek(strtotime('20070721'), $start_week_day), __FILE__, __LINE__, __METHOD__, 10);
                     if (!isset($schedule_shift_totals[$day_epoch]['labels'])) {
                         $schedule_shift_totals[$day_epoch]['labels'] = 0;
                     }
                     if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) {
                         $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE;
                         $schedule_shift_totals[$day_epoch]['labels']++;
                     }
                     if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) {
                         $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE;
                         $schedule_shift_totals[$day_epoch]['labels']++;
                     }
                     if (!isset($max_week_data[$week_of_year]['shift'])) {
                         Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10);
                         $max_week_data[$week_of_year]['shift'] = 1;
                         $max_week_data[$week_of_year]['labels'] = 0;
                     }
                     if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) {
                         Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10);
                         $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts'];
                         $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels'];
                     }
                 }
             }
         }
         //print_r($tmp_schedule_shifts);
         //print_r($max_week_data);
         if (isset($tmp_schedule_shifts)) {
             //Sort Branches/Departments first
             foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                 ksort($day_tmp_schedule_shift);
                 $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                 foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                     ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                 }
             }
             //Sort each department by start time.
             foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                 foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                     foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                         $department_schedule_shift = Sort::multiSort($department_schedule_shift, 'last_name');
                         $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift;
                     }
                 }
             }
         }
         //Debug::Arr($this->schedule_shifts, 'Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
         $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
         //var_dump($calendar_array);
         if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) {
             return FALSE;
         }
         $pdf->AddPage();
         $pdf->setXY(670, $top_margin);
         $pdf->SetFont('freesans', '', 10);
         $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R');
         $pdf->setXY($left_margin, $top_margin);
         $pdf->SetFont('freesans', 'B', 25);
         $pdf->Cell(0, 25, 'Employee Schedule', $border, 0, 'C');
         $pdf->Ln();
         $pdf->SetFont('freesans', 'B', 10);
         $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C');
         $pdf->Ln();
         $pdf->Ln();
         $pdf->SetFont('freesans', '', 8);
         $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7);
         $cell_height = 100;
         $i = 0;
         $total_days = count($calendar_array) - 1;
         $boader = 1;
         foreach ($calendar_array as $calendar) {
             if ($i == 0) {
                 //Calendar Header
                 $pdf->SetFont('freesans', 'B', 8);
                 $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day);
                 foreach ($calendar_header as $header_name) {
                     $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C');
                 }
                 $pdf->Ln();
                 unset($calendar_header, $header_name);
             }
             $month_name = NULL;
             if ($i == 0 or $calendar['isNewMonth'] == TRUE) {
                 $month_name = $calendar['month_name'];
             }
             if ($i > 0 and $i % 7 == 0) {
                 $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day);
                 unset($week_date_stamps);
             }
             $pdf->SetFont('freesans', 'B', 8);
             $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L');
             $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R');
             $week_date_stamps[] = $calendar['date_stamp'];
             $i++;
         }
         $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE);
     }
     if ($valid_schedules > 0) {
         $output = $pdf->Output('', 'S');
         return $output;
     }
     return FALSE;
 }
 $pdf_created_date = time();
 //Page width: 205mm
 $pdf = new TTPDF('P', 'mm', 'Letter');
 $pdf->setMargins(10, 5);
 $pdf->SetAutoPageBreak(TRUE, 10);
 $pdf->SetFont('freeserif', '', 10);
 $border = 0;
 //Create PDF TimeSheet for each employee.
 foreach ($rows as $user_data) {
     $pdf->AddPage();
     $adjust_x = 10;
     $adjust_y = 10;
     //$pdf->setXY( Misc::AdjustXY(0, $adjust_x), Misc::AdjustXY(0, $adjust_y) );
     $pdf->SetFont('', 'B', 22);
     $pdf->Cell(200, 8, TTi18n::gettext('Detailed Employee TimeSheet'), $border, 0, 'C');
     $pdf->Ln();
     $pdf->SetFont('', 'B', 12);
     $pdf->Cell(200, 5, $current_company->getName(), $border, 0, 'C');
     $pdf->Ln(8);
     $pdf->Rect($pdf->getX(), $pdf->getY() - 1, 200, 14);
     $pdf->SetFont('', '', 10);
     $pdf->Cell(30, 4, TTi18n::gettext('Employee:'), $border, 0, 'R');
     $pdf->SetFont('', 'B', 10);
     $pdf->Cell(70, 4, $user_data['first_name'] . ' ' . $user_data['last_name'] . ' (#' . $user_data['employee_number'] . ')', $border, 0, 'L');
     $pdf->SetFont('', '', 10);
     $pdf->Cell(40, 4, TTi18n::gettext('Pay Period:'), $border, 0, 'R');
     $pdf->SetFont('', 'B', 10);
     $pdf->Cell(60, 4, $user_data['pay_period'], $border, 0, 'L');
     $pdf->Ln();
     $pdf->SetFont('', '', 10);
     $pdf->Cell(30, 4, TTi18n::gettext('Title:'), $border, 0, 'R');