From 0fd6fa0c3fd604613351867fa6bf812b5dc8e09e Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 6 Jul 2023 01:16:05 +0800 Subject: [PATCH] accounting mapping - export invoice --- .../ListShippingPortalTransactions.php | 38 +++++ .../Services/ExportsInvoiceTransactions.php | 133 ++++++++++++++++++ .../ExportCustomersToExcelController.php | 9 +- .../sections/TransactionsMappingComponent.vue | 6 +- routes/web.php | 1 + 5 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 app/Classes/Modules/Accounting/Processors/ListShippingPortalTransactions.php create mode 100644 app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php diff --git a/app/Classes/Modules/Accounting/Processors/ListShippingPortalTransactions.php b/app/Classes/Modules/Accounting/Processors/ListShippingPortalTransactions.php new file mode 100644 index 00000000..7bc0e29d --- /dev/null +++ b/app/Classes/Modules/Accounting/Processors/ListShippingPortalTransactions.php @@ -0,0 +1,38 @@ + false]); + $response = $client->request('GET', $url . '?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters=' . json_encode($filters)); + $body = $response->getBody(); + $data = json_decode($body, true); + $payload = $data['payload']; + return $data['payload']['data']; + + // return $payload['data']; + // $return_data = Collection::hydrate($payload['data']); + // return $return_data; + + } catch (\Exception $exception) { + dd($exception->getMessage()); +// preg_match('/\{.*\}/s', $exception->getMessage(), $matches); +// $jsonError = json_decode($matches[0]); + // Retrieved Transactions failed +// throw new MalformedRequestException($jsonError->title); + } + + // if not found + throw new MalformedRequestException('Bill Number Not Found.'); + } +} diff --git a/app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php b/app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php new file mode 100644 index 00000000..dab0a00b --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsInvoiceTransactions.php @@ -0,0 +1,133 @@ +request = $request; + } + + public function headings(): array + { + return [ + 'DocNo', + 'DocDate', + 'DebtorCode', + 'Ref', + 'DebtorName', + 'CurrencyCode', + 'ShipInfo', + 'ItemCode', + 'DetailDescription', + 'FurtherDescription', + 'Qty', + 'UnitPrice', + 'AccNo', + 'DeptNo' + ]; + } + + /** + * @return \Illuminate\Support\Collection|mixed + */ + public function query() + { + $query = StatementTransactionOwner::whereNull('invoice_reference') + ->whereIn('type', [StatementTransactionOwnerType::SALES, StatementTransactionOwnerType::WALLET_TOP_UP]) + ->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED]); + + return $query; + } + + /** + * @param Transaction $transaction + * + * @return array + */ + public function map($transaction): array + { + $row = null; + + if($transaction->system == 'EXCHANGE') { + $row = (App()->make($transaction->owner_type))::where('id', $transaction->owner_id)->first(); + $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]; + + return [ + '<>', + $row->updated_at->format('m/d/Y H:m'), + $company->debtor, + '', + 'MYR', + $transaction->bill_no, + 'W1', + 'CREDIT SALES', + '', + 1, + round($transaction->amount, 2), + '500-0000', + 'WALLET' + ]; + } + + + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index 1f7594f8..74384157 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -9,8 +9,8 @@ use App\Classes\Modules\Exports\Services\ExportsBookingTransactions; use App\Classes\Modules\Exports\Services\ExportsLeadsTransactions; use App\Classes\Modules\Exports\Services\ExportsNullDebtors; use App\Classes\Modules\Exports\Services\ExportsPaymentTransactions; - use App\Classes\Modules\Exports\Services\ExportsWalletTransactions; +use App\Classes\Modules\Exports\Services\ExportsInvoiceTransactions; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -57,6 +57,13 @@ class ExportCustomersToExcelController return $response; } + public function invoiceTransactions(Request $request){ + $exportsTransactions = new ExportsInvoiceTransactions($request); + $response = $exportsTransactions->download('invoice-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } + public function bookingTransactions(ExportsBookingTransactions $exportsBookingTransactions, Request $request){ $response = $exportsBookingTransactions->download('bookingTransactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); ob_end_clean(); diff --git a/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue b/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue index 6e9e7982..7bbf87aa 100644 --- a/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue +++ b/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue @@ -102,7 +102,8 @@
-
Export Invoices To AutoCount
+
Export Invoices To AutoCount
+
Nest Step

@@ -209,6 +210,9 @@ export default { }; this.submit(this.route('api.import_receipts.upload'), 'post', this.section, true, false); }, + exportInvoiceToAutoCount(){ + window.open(this.route('invoiceTransactions.export'), '_blank'); + }, successHandler(){ this.step += 1; diff --git a/routes/web.php b/routes/web.php index 09ee5274..7042b498 100644 --- a/routes/web.php +++ b/routes/web.php @@ -228,6 +228,7 @@ Route::get('/export/null-debtor/f614e339d7058904a831aad742e24d55', 'Exports\Expo Route::get('/export/payment-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@paymentTransactions')->name('paymentTransactions.export'); Route::get('/export/wallet-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@walletTransactions')->name('walletTransactions.export'); Route::get('/export/booking-transactions', 'Exports\ExportCustomersToExcelController@bookingTransactions')->name('export.transactions.booking'); +Route::get('/export/invoice-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@invoiceTransactions')->name('invoiceTransactions.export'); Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) { $bookings = Booking::where(function($query){