From 1c29e45744b497f6cfb781db9232611cc4f9924e Mon Sep 17 00:00:00 2001 From: Steve Ng Date: Sun, 3 Dec 2023 18:58:55 +0800 Subject: [PATCH 1/2] add payment received date in import invoice result and fix structure export receipts to autocount --- .../ExportsImportedInvoiceMappeds.php | 4 +- .../Services/ExportsReceiptTransactions.php | 127 +++++++++++++----- .../ImportStatementInvoiceController.php | 14 +- .../ImportedInvoiceMappedComponent.vue | 3 +- 4 files changed, 112 insertions(+), 36 deletions(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsImportedInvoiceMappeds.php b/app/Classes/Modules/Exports/Services/ExportsImportedInvoiceMappeds.php index 71363b52..e629675f 100644 --- a/app/Classes/Modules/Exports/Services/ExportsImportedInvoiceMappeds.php +++ b/app/Classes/Modules/Exports/Services/ExportsImportedInvoiceMappeds.php @@ -39,7 +39,8 @@ class ExportsImportedInvoiceMappeds implements FromQuery, WithHeadings, WithHead 'Net Total', 'Cancelled', 'Mapped Status', - 'Mapped Reference No' + 'Mapped Reference No', + 'MapPayment Received Date' ]; } @@ -72,6 +73,7 @@ class ExportsImportedInvoiceMappeds implements FromQuery, WithHeadings, WithHead Arr::get($data,'cancelled'), Arr::get($data,'mapped_status'), Arr::get($data,'mapped_result_reference'), + Arr::get($data,'payment_received_date'), ]; } diff --git a/app/Classes/Modules/Exports/Services/ExportsReceiptTransactions.php b/app/Classes/Modules/Exports/Services/ExportsReceiptTransactions.php index 07c5d3c1..bde46225 100644 --- a/app/Classes/Modules/Exports/Services/ExportsReceiptTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsReceiptTransactions.php @@ -15,8 +15,11 @@ use Illuminate\Support\Facades\Log; use App\Classes\General\Eloquent\ApplyFiltersToQuery; use App\Models\StatementTransaction; use App\Models\Company; +use Maatwebsite\Excel\Concerns\WithEvents; +use Maatwebsite\Excel\Concerns\WithCustomStartCell; +use Maatwebsite\Excel\Events\AfterSheet; -class ExportsReceiptTransactions implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize +class ExportsReceiptTransactions implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, WithEvents, WithCustomStartCell { use Exportable; @@ -28,37 +31,101 @@ class ExportsReceiptTransactions implements FromQuery, WithHeadings, WithHeading $this->request = $request; } + public function startCell(): string + { + return 'A2'; + } + + public function registerEvents(): array { + + return [ + AfterSheet::class => function(AfterSheet $event) { + $sheet = $event->sheet; + + $sheet->mergeCells('A1:A1'); + $sheet->setCellValue('A1', '"'); + + $sheet->mergeCells('M1:Y1'); + $sheet->setCellValue('M1', "Payment Detail Column"); + + $sheet->mergeCells('Z1:AB1'); + $sheet->setCellValue('Z1', "Knock Off Detail"); + + $styleArray = [ + 'alignment' => [ + 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + ], + ]; + + $cellRange = 'A1:AB1'; + $event->sheet->getDelegate()->getStyle($cellRange)->applyFromArray($styleArray); + }, + ]; + } + public function headings(): array { $header = [ - 'DocNo', - 'DocDate', - 'DebtorCode', - 'Description', - 'DocNo2', - 'ProjNo', - 'DeptNo', - 'CurrencyCode', - 'ToHomeRate', - 'ToDebtorRate', - 'Note', - 'PaymentMethod', - 'ChequeNo', - 'PaymentAmt', - 'BankCharge', - 'ToBankRate', - 'BankChargeTaxType', - 'BankChargeTaxRefNo', - 'BankChargeProjNo', - 'BankChargeDeptNo', - 'PaymentBy', - 'FloatDay', - 'IsRCHQ', - 'RCHQDate', - 'KnockOffDocType', - 'KnockOffDocNo', - 'KnockOffAmt', - '', + [ + ' ', + '(20 chars)', + '(Date: dd/MM/yyyy)', + '(12 chars)', + '(40 chars)', + '(25 chars)', + '(10 chars)', + '(10 chars)', + '(5 chars)', + '(Number, use System Currency Rate Decimal)', + '(Number, use System Currency Rate Decimal)', + '(Rich Text)', + '(20 chars)', + '(20 chars)', + '(Number, use System Currency Decimal)', + '(Number, use System Currency Decimal)', + '(Number, use System Currency Rate Decimal)', + '(14 chars)', + '(30 chars)', + '(10 chars)', + '(10 chars)', + '(20 chars)', + '(Integer)', + '(Boolean. Indicate T for stock control or F for non stock control)', + '(Returned Cheque Date: dd/MM/yyyy)', + '(2 chars, RI for Invoice, RD for D/N)', + '', + '(Number, use System Currency Decimal)', + ], + [ + 'DocNo', + 'DocDate', + 'DebtorCode', + 'Description', + 'DocNo2', + 'ProjNo', + 'DeptNo', + 'CurrencyCode', + 'ToHomeRate', + 'ToDebtorRate', + 'Note', + 'PaymentMethod', + 'ChequeNo', + 'PaymentAmt', + 'BankCharge', + 'ToBankRate', + 'BankChargeTaxType', + 'BankChargeTaxRefNo', + 'BankChargeProjNo', + 'BankChargeDeptNo', + 'PaymentBy', + 'FloatDay', + 'IsRCHQ', + 'RCHQDate', + 'KnockOffDocType', + 'KnockOffDocNo', + 'KnockOffAmt', + '', + ] ]; return $header; } @@ -102,7 +169,7 @@ class ExportsReceiptTransactions implements FromQuery, WithHeadings, WithHeading '<>', Carbon::parse($transaction->posting_date)->format('d/m/Y'), ($company ? $company->debtor : null), - $transaction->transaction_description, + 'Payment for '.$transaction->transaction_description, '', '', '', diff --git a/app/Http/Controllers/Imports/ImportStatementInvoiceController.php b/app/Http/Controllers/Imports/ImportStatementInvoiceController.php index b6cfd567..da42d25f 100644 --- a/app/Http/Controllers/Imports/ImportStatementInvoiceController.php +++ b/app/Http/Controllers/Imports/ImportStatementInvoiceController.php @@ -42,16 +42,20 @@ class ImportStatementInvoiceController foreach (['exchange','izyim'] as $system) { $returnReference = $this->mappingTopUp($row, $system); if ($returnReference) { + // $row['mapped_result_reference'] = $data['owner_reference']; + // $row['payment_received_date'] = date('Y-m-d', strtotime($data['created_at'])); $row['mapped_result_reference'] = $returnReference; + $row['payment_received_date'] = ''; $row['mapped_status'] = 'success'; return $row; } } } - $returnReference = $this->mappingExchange($row); + [$returnReference, $transactionDate] = $this->mappingExchange($row); if ($returnReference) { $row['mapped_result_reference'] = $returnReference; + $row['payment_received_date'] = date('d-m-Y', strtotime($transactionDate)); $row['mapped_status'] = 'success'; return $row; } @@ -88,6 +92,7 @@ class ImportStatementInvoiceController $data = []; foreach ($excelRows as $row) { $row['mapped_result_reference'] = null; + $row['payment_received_date'] = null; $row['mapped_status'] = 'failed'; $row['date'] = in_array(gettype($row['date']), ['integer', 'double']) ? $this->changeExcelDate($row['date']) : date('Y-m-d', strtotime($row['date'])); @@ -144,6 +149,7 @@ class ImportStatementInvoiceController private function mappingTopUp(Array $row, String $system) { try { if ($data = (App()->make(ChecksBillNumber::class))->execute($row['shipping_info'], $system)) { + // if ($system == 'izyim' && isset($data['owner_reference'])) return $data; if ($system == 'izyim' && isset($data['owner_reference'])) return $data['owner_reference']; if ($system == 'exchange') return $this->updateTransactionOwnerReference($data, $row['doc_no']); @@ -168,7 +174,7 @@ class ImportStatementInvoiceController if ($transaction && $transaction->count() > 0) { return $this->updateTransactionOwnerReference($transaction, $row['doc_no']); } - return false; + return [false, false]; } public function updateTransactionOwnerReference($transaction, String $docNo) { @@ -178,9 +184,9 @@ class ImportStatementInvoiceController 'invoice_reference'=>$docNo, 'status'=>ApprovalStatus::COMPLETED ]); - return $transactionOwner->owner_reference; + return [$transactionOwner->owner_reference, $transaction->created_at]; } - return false; + return [false, false]; } public function changeExcelDate($date) diff --git a/resources/assets/vue/components/accounting/sections/ImportedInvoiceMappedComponent.vue b/resources/assets/vue/components/accounting/sections/ImportedInvoiceMappedComponent.vue index 9fd29e45..f10f9181 100644 --- a/resources/assets/vue/components/accounting/sections/ImportedInvoiceMappedComponent.vue +++ b/resources/assets/vue/components/accounting/sections/ImportedInvoiceMappedComponent.vue @@ -39,6 +39,7 @@ {{item.cancelled}} {{item.mapped_status}} {{item.mapped_result_reference}} + {{item.payment_received_date}} @@ -101,7 +102,7 @@ }, appendComponentTableHeader() { if (this.section == 'importInvoiceMapping') { - this.tableHeaders = ['No','Doc No','Date','Debtor Code','Debtor Name','Shipping Info','Net Total','Cancelled','Mapped Status','Mapped Reference No']; + this.tableHeaders = ['No','Doc No','Date','Debtor Code','Debtor Name','Shipping Info','Net Total','Cancelled','Mapped Status','Mapped Reference No','Payment Received Date']; } else { this.tableHeaders = ['No','OR No','Date','Creditor Code','Creditor Name','Shipping Info','Net Total','Cancelled','Mapped Status','Mapped Reference No']; } From a1e5d1173999a2bfffad6bf8ba0afa676893f8c4 Mon Sep 17 00:00:00 2001 From: Steve Ng Date: Wed, 6 Dec 2023 21:52:09 +0800 Subject: [PATCH 2/2] fix bug in import invoice --- .../Imports/ImportStatementInvoiceController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Imports/ImportStatementInvoiceController.php b/app/Http/Controllers/Imports/ImportStatementInvoiceController.php index da42d25f..75953f2b 100644 --- a/app/Http/Controllers/Imports/ImportStatementInvoiceController.php +++ b/app/Http/Controllers/Imports/ImportStatementInvoiceController.php @@ -40,12 +40,12 @@ class ImportStatementInvoiceController if (str_starts_with($row['shipping_info'], 'TOPUP')) { // find in exchange first, if cannont then find in izyim foreach (['exchange','izyim'] as $system) { - $returnReference = $this->mappingTopUp($row, $system); + [$returnReference, $transactionDate] = $this->mappingTopUp($row, $system); if ($returnReference) { // $row['mapped_result_reference'] = $data['owner_reference']; // $row['payment_received_date'] = date('Y-m-d', strtotime($data['created_at'])); $row['mapped_result_reference'] = $returnReference; - $row['payment_received_date'] = ''; + $row['payment_received_date'] = $transactionDate ? date('d-m-Y', strtotime($transactionDate)) : null; $row['mapped_status'] = 'success'; return $row; } @@ -150,7 +150,7 @@ class ImportStatementInvoiceController try { if ($data = (App()->make(ChecksBillNumber::class))->execute($row['shipping_info'], $system)) { // if ($system == 'izyim' && isset($data['owner_reference'])) return $data; - if ($system == 'izyim' && isset($data['owner_reference'])) return $data['owner_reference']; + if ($system == 'izyim' && isset($data['owner_reference'])) return [$data['owner_reference'], null]; if ($system == 'exchange') return $this->updateTransactionOwnerReference($data, $row['doc_no']); }