From 1dab99cc49f0789f4e10f7bc56df196d11472118 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Fri, 7 Jul 2023 01:18:58 +0800 Subject: [PATCH] accounting mapping - export invoice --- .../Services/ExportsInvoiceTransactions.php | 80 ++++++++----------- .../Constants/ShippingTransactionType.php | 39 +++++++++ 2 files changed, 74 insertions(+), 45 deletions(-) create mode 100644 app/Classes/ValueObjects/Constants/ShippingTransactionType.php diff --git a/app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php b/app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php index dab0a00b..c9237880 100644 --- a/app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php @@ -15,6 +15,7 @@ use Maatwebsite\Excel\Concerns\WithMapping; use Illuminate\Http\Request; use Carbon\Carbon; use App\Classes\Modules\Accounting\Processors\ListShippingPortalTransactions; +use App\Classes\ValueObjects\Constants\ShippingTransactionType; use App\Classes\ValueObjects\Constants\TransactionType; class ExportsInvoiceTransactions implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize @@ -70,64 +71,53 @@ class ExportsInvoiceTransactions implements FromQuery, WithHeadings, WithHeading $row = null; if($transaction->system == 'EXCHANGE') { - $row = (App()->make($transaction->owner_type))::where('id', $transaction->owner_id)->first(); - $company = $row->owner->owner; + $row = (App()->make($transaction->owner_type))->where('id', $transaction->owner_id)->first(); + $company = $row->type === TransactionType::PAYMENT ? $row->owner->company : $row->owner->owner; - return [ - '<>', - $transaction->updated_at->format('m/d/Y H:m'), - $company->debtor, - $transaction->type === TransactionType::PAYMENT ? $row->owner->marking : $company->reference, - '', - 'MYR', - $booking->marking, - '', - 'PLEASE REFER TO THE ATTACHED APPENDIX REF ' . $booking->marking, - '', - 1, - round($transaction->amount, 2), - '500-0000', - 'CIEF' - ]; - - // return [ - // '<>', - // $row->updated_at->format('m/d/Y H:m'), - // $company->debtor, - // $transaction->type === TransactionType::PAYMENT ? $row->owner->marking : null, - // 'MYR', - // $transaction->bill_no, - // 'W1', - // 'CREDIT SALES', - // '', - // 1, - // round($transaction->amount, 2), - // '500-0000', - // 'WALLET' - // ]; - } - else { - $row = (App()->make(ListShippingPortalTransactions::class))->execute([ - 'id' => $transaction->owner_id, - ])[0]; + $booking = $row->owner; return [ '<>', $row->updated_at->format('m/d/Y H:m'), $company->debtor, + $row->type === TransactionType::PAYMENT ? $booking->marking : $company->reference, '', 'MYR', - $transaction->bill_no, - 'W1', - 'CREDIT SALES', + $row->type === TransactionType::PAYMENT ? $booking->marking : $row->bill_no, + $row->type === TransactionType::PAYMENT ? '' : 'W1', + $row->type === TransactionType::PAYMENT ? 'PLEASE REFER TO THE ATTACHED APPENDIX REF ' . $booking->marking : 'CREDIT SALES', '', 1, - round($transaction->amount, 2), + round($row->amount, 2), '500-0000', - 'WALLET' + 'CIEF' ]; } + else { + $row = (App()->make(ListShippingPortalTransactions::class))->execute([ + 'id' => $transaction->owner_id, + 'with_company' => true, + ])[0]; - + $order = $row['order']; + $company_module = $order['company_module']; + + return [ + '<>', + $row['updated_at'], + $company_module['debtor'], + $row['type'] === ShippingTransactionType::PAYMENT ? $order['reference'] : $company_module['marking'], + '', + 'MYR', + $row['type'] === ShippingTransactionType::PAYMENT ? $order['reference'] : $row['bill_no'], + $row['type'] === ShippingTransactionType::PAYMENT ? '' : 'W1', + $row['type'] === ShippingTransactionType::PAYMENT ? 'PLEASE REFER TO THE ATTACHED APPENDIX REF `' . $order['reference'] : 'CREDIT SALES', + '', + 1, + round($row['amount'], 2), + '500-0000', + 'CIEF' + ]; + } } } \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/ShippingTransactionType.php b/app/Classes/ValueObjects/Constants/ShippingTransactionType.php new file mode 100644 index 00000000..0668e8ca --- /dev/null +++ b/app/Classes/ValueObjects/Constants/ShippingTransactionType.php @@ -0,0 +1,39 @@ +