function exportPayStubAmendment($psalf = NULL, $export_type = NULL) { global $current_company; if (!is_object($psalf) and $this->getId() != '') { $psalf = TTnew('PayStubAmendmentListFactory'); $psalf->getById($this->getId()); } if (get_class($psalf) !== 'PayStubAmendmentListFactory') { return FALSE; } if ($export_type == '') { return FALSE; } if ($psalf->getRecordCount() > 0) { Debug::Text('aExporting...', __FILE__, __LINE__, __METHOD__, 10); switch (strtolower($export_type)) { case 'eft_hsbc': case 'eft_1464': case 'eft_105': case 'eft_ach': case 'eft_beanstream': //Get file creation number $ugdlf = TTnew('UserGenericDataListFactory'); $ugdlf->getByCompanyIdAndScriptAndDefault($current_company->getId(), 'PayStubFactory', TRUE); if ($ugdlf->getRecordCount() > 0) { $ugd_obj = $ugdlf->getCurrent(); $setup_data = $ugd_obj->getData(); } else { $ugd_obj = TTnew('UserGenericDataFactory'); } Debug::Text('bExporting...', __FILE__, __LINE__, __METHOD__, 10); //get User Bank account info $balf = TTnew('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->setScript('PayStubFactory'); $ugd_obj->setName('PayStubFactory'); $ugd_obj->setData($setup_data); $ugd_obj->setDefault(TRUE); if ($ugd_obj->isValid()) { $ugd_obj->Save(); } $eft = new EFT(); $eft->setFileFormat(str_replace('eft_', '', $export_type)); $eft->setBusinessNumber($current_company->getBusinessNumber()); //ACH $eft->setOriginatorID($current_company->getOriginatorID()); $eft->setFileCreationNumber($setup_data['file_creation_number']); $eft->setInitialEntryNumber($current_company->getOtherID5()); //ACH $eft->setDataCenter($current_company->getDataCenterID()); $eft->setDataCenterName($current_company->getOtherID4()); //ACH $eft->setOriginatorShortName($current_company->getShortName()); foreach ($psalf as $key => $psa_obj) { //Can only export fixed amount PS amendemnts? if ($psa_obj->getType() == 10) { Debug::Text('Looping over Pay Stub Amendment... ID: ' . $psa_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //Get User information $ulf = TTnew('UserListFactory'); $user_obj = $ulf->getById($psa_obj->getUser())->getCurrent(); //Get company information $clf = TTnew('CompanyListFactory'); $company_obj = $clf->getById($user_obj->getCompany())->getCurrent(); //get User Bank account info $balf = TTnew('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; } $amount = $psa_obj->getAmount(); if ($amount > 0) { $record = new EFT_Record(); $record->setType('C'); $record->setCPACode(200); $record->setAmount($amount); $record->setDueDate(TTDate::getBeginDayEpoch($psa_obj->getEffectiveDate())); $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('PSA' . $psa_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); } unset($amount); $this->getProgressBarObject()->set(NULL, $key); } else { Debug::Text('Skipping percent PS amendment... ID: ' . $psa_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); } } $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': //Wait until Cheque class is created first. $cheque_form_obj = $this->getChequeFormsObject(str_replace('cheque_', '', $export_type)); $psealf = TTnew('PayStubEntryAccountListFactory'); $i = 0; foreach ($psalf as $key => $psa_obj) { //Can only export fixed amount PS amendemnts? if ($psa_obj->getType() == 10) { //Get User information $ulf = TTnew('UserListFactory'); $user_obj = $ulf->getById($psa_obj->getUser())->getCurrent(); //Get company information $clf = TTnew('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_amendment = array('id' => $psa_obj->getId(), 'display_id' => str_pad($psa_obj->getId(), 15, 0, STR_PAD_LEFT), 'user_id' => $psa_obj->getUser(), 'status' => $psa_obj->getStatus(), 'amount' => $psa_obj->getAmount(), 'date' => TTDate::getTime(), 'full_name' => $user_obj->getFullName(), 'address1' => $user_obj->getAddress1(), 'address2' => $user_obj->getAddress2(), 'city' => $user_obj->getCity(), 'province' => $user_obj->getProvince(), 'postal_code' => $user_obj->getPostalCode(), 'country' => $user_obj->getCountry(), 'company_name' => $company_obj->getName(), 'symbol' => $psa_obj->getUserObject()->getCurrencyObject()->getSymbol(), 'created_date' => $psa_obj->getCreatedDate(), 'created_by' => $psa_obj->getCreatedBy(), 'updated_date' => $psa_obj->getUpdatedDate(), 'updated_by' => $psa_obj->getUpdatedBy(), 'deleted_date' => $psa_obj->getDeletedDate(), 'deleted_by' => $psa_obj->getDeletedBy()); $cheque_form_obj->addRecord($pay_stub_amendment); $this->getFormObject()->addForm($cheque_form_obj); $this->getProgressBarObject()->set(NULL, $key); } else { Debug::Text('Skipping percent PS amendment... ID: ' . $psa_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); } $this->getProgressBarObject()->set(NULL, $i); $i++; } if (stristr($export_type, 'cheque')) { $output_format = 'PDF'; } $output = $this->getFormObject()->output($output_format); break; } } if (isset($output)) { return $output; } return FALSE; }
function exportPayStub($pslf = NULL, $export_type = NULL, $company_obj = NULL) { if (is_object($company_obj)) { $current_company = $company_obj; } else { global $current_company; } if (!is_object($pslf) and $this->getId() != '') { $pslf = TTnew('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 'eft_hsbc': case 'eft_1464': case 'eft_105': case 'eft_ach': case 'eft_beanstream': //Get file creation number $ugdlf = TTnew('UserGenericDataListFactory'); $ugdlf->getByCompanyIdAndScriptAndDefault($current_company->getId(), 'PayStubFactory', TRUE); if ($ugdlf->getRecordCount() > 0) { $ugd_obj = $ugdlf->getCurrent(); $setup_data = $ugd_obj->getData(); } else { $ugd_obj = TTnew('UserGenericDataFactory'); } Debug::Text('bExporting...', __FILE__, __LINE__, __METHOD__, 10); //get User Bank account info $balf = TTnew('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->setScript('PayStubFactory'); $ugd_obj->setName('PayStubFactory'); $ugd_obj->setData($setup_data); $ugd_obj->setDefault(TRUE); if ($ugd_obj->isValid()) { $ugd_obj->Save(); } $eft = new EFT(); $eft->setFileFormat(str_replace('eft_', '', $export_type)); $eft->setBusinessNumber($current_company->getBusinessNumber()); //ACH $eft->setOriginatorID($current_company->getOriginatorID()); $eft->setFileCreationNumber($setup_data['file_creation_number']); $eft->setInitialEntryNumber($current_company->getOtherID5()); //ACH $eft->setDataCenter($current_company->getDataCenterID()); $eft->setDataCenterName($current_company->getOtherID4()); //ACH $eft->setOriginatorShortName($current_company->getShortName()); $psealf = TTnew('PayStubEntryAccountListFactory'); foreach ($pslf as $key => $pay_stub_obj) { Debug::Text('Looping over Pay Stub... ID: ' . $pay_stub_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //Get pay stub entries. $pself = TTnew('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 = 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(); //get User Bank account info $balf = TTnew('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; } if (isset($pay_stub['entries'][40][0]['amount'])) { $amount = $pay_stub['entries'][40][0]['amount']; } else { $amount = 0; } if ($amount > 0) { $record = new EFT_Record(); $record->setType('C'); $record->setCPACode(200); $record->setAmount($amount); $record->setDueDate(TTDate::getBeginDayEpoch($pay_stub_obj->getTransactionDate())); $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); } unset($amount); $this->getProgressBarObject()->set(NULL, $key); } } $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': $cheque_form_obj = $this->getChequeFormsObject(str_replace('cheque_', '', $export_type)); $psealf = TTnew('PayStubEntryAccountListFactory'); $numbers_words = new Numbers_Words(); $i = 0; foreach ($pslf as $pay_stub_obj) { //Get pay stub entries. $pself = TTnew('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(TTi18n::formatNumber($pay_stub_entry->getAmount(), TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), 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 = 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(); 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); if (isset($pay_stub['entries'][40][0]['amount']) and $pay_stub['entries'][40][0]['amount'] > 0) { //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(); $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 = TTnew('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()); $ps_data = array('date' => $pay_stub_obj->getTransactionDate(), 'amount' => $pay_stub['entries'][40][0]['amount'], 'stub_left_column' => $user_obj->getFullName() . "\n" . TTi18n::gettext("Identification #: ") . $pay_stub['display_id'] . "\n" . TTi18n::gettext("Net Pay: ") . $pay_stub_obj->getCurrencyObject()->getSymbol() . TTi18n::formatNumber($pay_stub['entries'][40][0]['amount'], TRUE, $pay_stub_obj->getCurrencyObject()->getRoundDecimalPlaces()), 'stub_right_column' => TTi18n::gettext('Pay Start Date: ') . TTDate::getDate('DATE', $pay_stub['start_date']) . "\n" . TTi18n::gettext('Pay End Date: ') . TTDate::getDate('DATE', $pay_stub['end_date']) . "\n" . TTi18n::gettext('Payment Date: ') . TTDate::getDate('DATE', $pay_stub['transaction_date']), 'start_date' => $pay_stub['start_date'], 'end_date' => $pay_stub['end_date'], 'full_name' => $user_obj->getFullName(), 'address1' => $user_obj->getAddress1(), 'address2' => $user_obj->getAddress2(), 'city' => $user_obj->getCity(), 'province' => $user_obj->getProvince(), 'postal_code' => $user_obj->getPostalCode(), 'country' => $user_obj->getCountry(), 'company_name' => $company_obj->getName(), 'symbol' => $pay_stub_obj->getCurrencyObject()->getSymbol()); $cheque_form_obj->addRecord($ps_data); $this->getFormObject()->addForm($cheque_form_obj); } $this->getProgressBarObject()->set(NULL, $i); $i++; } if (stristr($export_type, 'cheque')) { $output_format = 'PDF'; } $output = $this->getFormObject()->output($output_format); break; } } if (isset($output)) { return $output; } return FALSE; }