From 58ae950a719f0b0dab9a4259a0342e345d33b6fa Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Fri, 8 Sep 2023 14:49:39 +0800 Subject: [PATCH 01/55] bulk download invoices --- .../BulkDownloadCustomerInvoicesLogic.php | 55 +++++++++++++++++++ ...BulkDownloadCustomerInvoicesController.php | 20 +++++++ .../customer_invoices_bulk_download.blade.php | 35 ++++++++++++ routes/web.php | 6 ++ 4 files changed, 116 insertions(+) create mode 100644 app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php create mode 100644 app/Http/Controllers/Companies/BulkDownloadCustomerInvoicesController.php create mode 100644 resources/views/pages/customer_invoices_bulk_download.blade.php diff --git a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php new file mode 100644 index 00000000..25821b03 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php @@ -0,0 +1,55 @@ +input('marking'))->first(); + + $startDate = $request->input('startDate'); + $endDate = $request->input('endDate'); + if ($company) { + $invoicebookings = $company->bookings()->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->whereHas('transactions', function ($query) { + $query->where('transactions.type', TransactionType::INVOICE) + ->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + })->orderBy('created_at')->get(); + + + $zip_file = "invoices_{$startDate}_to_{$endDate}_{$company->reference}.zip"; + + $zip = new ZipArchive(); + if ($zip->open($zip_file, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { + foreach($invoicebookings as $booking) { + $invoice_file = $booking->documents()->where('document_type', DocumentType::INVOICE)->whereNull('deleted_at')->first()->files()->first(); + $zip->addFile(Storage::disk('documents')->path($invoice_file->file->file_info->original->file), 'invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + } + + $zip->close(); + while (ob_get_level()) { + ob_end_clean(); + } + + return response()->download($zip_file); + } + } + } +} diff --git a/app/Http/Controllers/Companies/BulkDownloadCustomerInvoicesController.php b/app/Http/Controllers/Companies/BulkDownloadCustomerInvoicesController.php new file mode 100644 index 00000000..4d6944d4 --- /dev/null +++ b/app/Http/Controllers/Companies/BulkDownloadCustomerInvoicesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/resources/views/pages/customer_invoices_bulk_download.blade.php b/resources/views/pages/customer_invoices_bulk_download.blade.php new file mode 100644 index 00000000..faae46a5 --- /dev/null +++ b/resources/views/pages/customer_invoices_bulk_download.blade.php @@ -0,0 +1,35 @@ +@extends('layouts.base_portal') +@section('inner_content') +
+
+
+
+
+ @csrf +
+
+ + +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+
+
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php index a9e51a50..3a541f2d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -141,6 +141,12 @@ Route::get('/purchase_orders', function () { return view('pages.purchase_orders'); })->name('purchase_orders'); +Route::get('/customers/invoices', function () { + return view('pages.customer_invoices_bulk_download'); +})->name('customers.invoices'); + +Route::post('/customers/invoices', 'Companies\BulkDownloadCustomerInvoicesController@download')->name('customers.invoices'); + Route::get('/support', function () { return view('pages.customer_support', [ 'marking' => null, From be2e00297b1dc379bf0adb105097a0f6f4f0d85f Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Mon, 11 Sep 2023 20:43:21 +0800 Subject: [PATCH 02/55] fix if customer or no invoices found --- .../BulkDownloadCustomerInvoicesLogic.php | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php index 25821b03..1c9caddb 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php @@ -34,22 +34,28 @@ class BulkDownloadCustomerInvoicesLogic })->orderBy('created_at')->get(); - $zip_file = "invoices_{$startDate}_to_{$endDate}_{$company->reference}.zip"; - - $zip = new ZipArchive(); - if ($zip->open($zip_file, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { - foreach($invoicebookings as $booking) { - $invoice_file = $booking->documents()->where('document_type', DocumentType::INVOICE)->whereNull('deleted_at')->first()->files()->first(); - $zip->addFile(Storage::disk('documents')->path($invoice_file->file->file_info->original->file), 'invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); - } - - $zip->close(); - while (ob_get_level()) { - ob_end_clean(); - } + if (count($invoicebookings) > 0) { + $zip_file = "invoices_{$startDate}_to_{$endDate}_{$company->reference}.zip"; - return response()->download($zip_file); + $zip = new ZipArchive(); + if ($zip->open($zip_file, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { + foreach($invoicebookings as $booking) { + $invoice_file = $booking->documents()->where('document_type', DocumentType::INVOICE)->whereNull('deleted_at')->first()->files()->first(); + $zip->addFile(Storage::disk('documents')->path($invoice_file->file->file_info->original->file), 'invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + } + + $zip->close(); + while (ob_get_level()) { + ob_end_clean(); + } + + return response()->download($zip_file); + } + } else { + return response("No invoices found for this customer in the given date range."); } + } else { + return response("Customer not found"); } } } From 40d9fc15d93ce4c1a924a90f2124ddc5ff9f4862 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 16 Sep 2023 15:25:20 +0800 Subject: [PATCH 03/55] update wallet transaction history page title --- .../elements/CustomerTransactionHistorySectionComponent.vue | 2 +- .../elements/CustomerTransactionPreciseSectionComponent.vue | 2 +- .../wallets/elements/CustomerTransactionSectionComponent.vue | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue index 026a76c5..d1448193 100644 --- a/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue +++ b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue @@ -6,7 +6,7 @@
-
Transaction History
+
Account Statement - Transaction History
diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue index 85868a2b..2b7e3886 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue @@ -7,7 +7,7 @@
-
Transaction History
+
Precise Wallet Transaction History
diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue index fcfba752..3eae3ab7 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue @@ -6,7 +6,7 @@
-
Transaction History
+
Wallet Transaction History
From 823556b9b5063c6a8d22b2172b1d52420b31ece1 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 16 Sep 2023 16:36:32 +0800 Subject: [PATCH 04/55] download wallet transaction history --- ...portsCustomersWalletTransactionHistory.php | 105 ++++++++++++++++++ ...mersWalletTransactionToExcelController.php | 32 ++++++ .../CustomerTransactionSectionComponent.vue | 6 + routes/web.php | 2 + 4 files changed, 145 insertions(+) create mode 100644 app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php create mode 100644 app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php diff --git a/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php b/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php new file mode 100644 index 00000000..e38ce8ac --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php @@ -0,0 +1,105 @@ +request = $request; + } + + public function headings(): array + { + return [ + 'Date', + 'Description', + 'Incoming', + 'Outgoing', + 'Balance', + ]; + } + + /** + * @return \Illuminate\Support\Collection|mixed + */ + public function query() + { + $company = Company::where('reference', $this->request->route('marking'))->first(); + $transactions = $company->wallets()->first()->transactions()->whereIn('transactions.status', [2, 3])->orderBy('id'); + // dd($transactions->get()->toArray()); + + return $transactions; + } + + /** + * @param Transaction $transaction + * + * @return array + */ + public function map($transaction): array + { + // dd($transaction); + + $description = ''; + switch ((int) $transaction->type) { + case 5: + $description = (float) $transaction->amount . ' Credit Top up'; + break; + case 9: + $description = 'Credit Voucher for ' . $transaction->payment_reference; + break; + case 1: + $booking = Transaction::where('payment_reference', $transaction->bill_no)->first()->owner; + + if (!$booking) { + $description = 'Payment for unknown booking, please contact tech support.'; + break; + } + + $marking = $booking->marking; + $description = 'Payment For booking refs' . $marking; + break; + case 11: + $description = 'Debit Voucher for ' . $transaction->payment_reference; + break; + } + + $incoming = $outgoing = ''; + + if (in_array($transaction->type, [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE])) { + $incoming = number_format($transaction->amount, 2, '.', ','); + $this->runningBalance += $transaction->amount; + } + + if (in_array($transaction->type, [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])) { + $outgoing = number_format($transaction->amount, 2, '.', ','); + $this->runningBalance -= $transaction->amount; + } + + return [ + Carbon::parse($transaction->created_at)->format('d-m-Y h:i:s A'), + $description, + $incoming, + $outgoing, + number_format($this->runningBalance, 2, '.', ',') + ]; + } +} diff --git a/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php new file mode 100644 index 00000000..fd49d5b0 --- /dev/null +++ b/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php @@ -0,0 +1,32 @@ +headers->set('Authorization', 'Bearer '.$token); + } + + public function export(Request $request){ + $exportsTransactions = new ExportsCustomersWalletTransactionHistory($request); + $response = $exportsTransactions->download('wallet-transaction-history.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } +} \ No newline at end of file diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue index 3eae3ab7..7ef65ee3 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue @@ -9,6 +9,12 @@
Wallet Transaction History
+
diff --git a/routes/web.php b/routes/web.php index e2357c00..6ec39626 100644 --- a/routes/web.php +++ b/routes/web.php @@ -236,6 +236,8 @@ Route::get('/wallet/{marking}/details-precise', function ($marking) { return view('pages.wallet.precise', ['id' => $id]); })->name('wallet.details-precise'); +Route::get('/wallet/{marking}/export', 'Exports\ExportCustomersWalletTransactionToExcelController@export')->name('wallet.details-export'); + Route::get('/wallets', function () { return view('pages.wallet.wallets'); })->name('wallet.wallets'); From 6542710ba9ceefe3a1c4fb7a905d365a8246c5f3 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 16 Sep 2023 18:09:11 +0800 Subject: [PATCH 05/55] update ui for export Wallet Transaction History --- ...portsCustomersWalletTransactionHistory.php | 8 +- ...mersWalletTransactionToExcelController.php | 12 +- .../elements/CustomerTransactionComponent.vue | 83 +++++++++ ...omerTransactionPreciseSectionComponent.vue | 174 ------------------ .../CustomerTransactionSectionComponent.vue | 61 +----- routes/web.php | 7 +- 6 files changed, 102 insertions(+), 243 deletions(-) create mode 100644 resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue delete mode 100644 resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue diff --git a/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php b/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php index e38ce8ac..745539f5 100644 --- a/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php +++ b/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php @@ -58,6 +58,8 @@ class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeading { // dd($transaction); + $decimals = $this->request->route('is_precise') == 'true' ? 5 : 2; + $description = ''; switch ((int) $transaction->type) { case 5: @@ -85,12 +87,12 @@ class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeading $incoming = $outgoing = ''; if (in_array($transaction->type, [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE])) { - $incoming = number_format($transaction->amount, 2, '.', ','); + $incoming = number_format($transaction->amount, $decimals, '.', ','); $this->runningBalance += $transaction->amount; } if (in_array($transaction->type, [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])) { - $outgoing = number_format($transaction->amount, 2, '.', ','); + $outgoing = number_format($transaction->amount, $decimals, '.', ','); $this->runningBalance -= $transaction->amount; } @@ -99,7 +101,7 @@ class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeading $description, $incoming, $outgoing, - number_format($this->runningBalance, 2, '.', ',') + number_format($this->runningBalance, $decimals, '.', ',') ]; } } diff --git a/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php index fd49d5b0..c4457565 100644 --- a/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php @@ -2,8 +2,6 @@ namespace App\Http\Controllers\Exports; - -use App\Classes\Modules\Exports\Services\ExportsCustomers; use App\Classes\Modules\Exports\Services\ExportsCustomersWalletTransactionHistory; use App\Models\User; use Illuminate\Http\Request; @@ -20,13 +18,15 @@ class ExportCustomersWalletTransactionToExcelController public function __construct(Request $request) { $token = Auth::fromUser(User::find(1)); - $request->headers->set('Authorization', 'Bearer '.$token); + $request->headers->set('Authorization', 'Bearer ' . $token); } - public function export(Request $request){ + public function export(Request $request) + { $exportsTransactions = new ExportsCustomersWalletTransactionHistory($request); - $response = $exportsTransactions->download('wallet-transaction-history.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + $filename = $request->route('marking') . '-wallet-' . ($request->route('is_precise') == 'true' ? 'precise-' : '') . 'transaction-history.xls'; + $response = $exportsTransactions->download($filename, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); ob_end_clean(); return $response; } -} \ No newline at end of file +} diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue new file mode 100644 index 00000000..4d25f91b --- /dev/null +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue @@ -0,0 +1,83 @@ + + diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue deleted file mode 100644 index 2b7e3886..00000000 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionPreciseSectionComponent.vue +++ /dev/null @@ -1,174 +0,0 @@ - - diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue index 7ef65ee3..706bc95a 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue @@ -11,50 +11,15 @@
- Download - View Precise Wallet Transaction + {{ showingPreciseAmount ? 'Showing Precise Wallet Transaction' : 'Show Precise Wallet Transaction'}} + {{ showingPreciseAmount ? 'Download Precise Transaction' : 'Download Transaction'}}
-
-
-
-
Date
-
Description
-
Incoming
-
Outgoing
-
Balance
-
- -
-
{{item.created_at}}
-
-
{{[5, 9].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}
-
{{[1, 11].includes(parseFloat(item.type)) ? '- ' + (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}
-
{{remainingBalance(index)}}
-
-
+
+
- -
-
-
-
-
-
-
-
-
-

Nothing To Show Here

-
-
-
-
- There is no results found, Try adjusting your filters to find what you are looking for. -
-
-
-
-
+
+
@@ -112,6 +77,7 @@ export default { section: 'customerTransactionSection', isLoading: true, company: null, + showingPreciseAmount: false, attention: false } }, @@ -135,19 +101,6 @@ export default { this.isLoading = true; this.submit(route('api.company.show', this.id), 'get', this.section, false, false) }, - remainingBalance(index) { - let tempBalance = 0; - - if(this.company.wallet){ - let transactions = this.company.wallet.transactions.slice().reverse(); - transactions.slice(0, transactions.length - index).map(function(transaction) { - [1, 11].includes(transaction.type) ? tempBalance -= (transaction.amount) : tempBalance += (transaction.amount); - return tempBalance - }, 0); - } - - return (Math.round((tempBalance + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); - }, successHandler(response){ this.isLoading = false; this.company = response.payload.data; diff --git a/routes/web.php b/routes/web.php index 6ec39626..4c4fc328 100644 --- a/routes/web.php +++ b/routes/web.php @@ -231,12 +231,7 @@ Route::get('/wallet/{marking}/details', function ($marking) { return view('pages.wallet.index', ['id' => $id]); })->name('wallet.details'); -Route::get('/wallet/{marking}/details-precise', function ($marking) { - $id = \App\Models\Company::where('reference', '=', $marking)->first()->id; - return view('pages.wallet.precise', ['id' => $id]); -})->name('wallet.details-precise'); - -Route::get('/wallet/{marking}/export', 'Exports\ExportCustomersWalletTransactionToExcelController@export')->name('wallet.details-export'); +Route::get('/wallet/{marking}/{is_precise}/export', 'Exports\ExportCustomersWalletTransactionToExcelController@export')->name('wallet.details-export'); Route::get('/wallets', function () { return view('pages.wallet.wallets'); From cc1229a27f327e8d2d454d11e143a8900d57674e Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Tue, 19 Sep 2023 00:09:09 +0800 Subject: [PATCH 06/55] company wallet transaction pagination --- .../ListWalletTransactionsLogic.php | 22 +++++++ app/Http/Resources/WalletResource.php | 2 +- .../Resources/WalletTransactionResource.php | 6 ++ .../elements/CustomerTransactionComponent.vue | 62 ++++++++++--------- .../CustomerTransactionSectionComponent.vue | 8 ++- .../CustomerWalletTransactionComponent.vue | 35 +++++++++++ .../views/pages/wallet/transactions.blade.php | 2 +- routes/web.php | 6 +- 8 files changed, 107 insertions(+), 36 deletions(-) create mode 100644 resources/assets/vue/components/wallets/elements/CustomerWalletTransactionComponent.vue diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php index 1ae97d45..0b70b484 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php @@ -5,8 +5,12 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transactions\Services\ListsTransactions; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\TransactionType; use App\Http\Resources\BookingResource; use App\Http\Resources\WalletTransactionResource ; +use App\Models\Transaction; +use App\Models\Wallet; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -39,6 +43,24 @@ class ListWalletTransactionsLogic extends AbstractControllerLogic $query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters'))); + if (str_contains($request->input('filters'), "owner_id") && $query->count() > 0) { + $currentWalletBalance = Wallet::find($query->first()->owner_id)->amount; + $incoming = Transaction::where('owner_type', $query->first()->owner_type) + ->where('owner_id', $query->first()->owner_id) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE]) + ->where('id', '>', $query->first()->id) + ->sum('amount'); + $outgoing = Transaction::where('owner_type', $query->first()->owner_type) + ->where('owner_id', $query->first()->owner_id) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->whereIn('type', [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE]) + ->where('id', '>', $query->first()->id) + ->sum('amount'); + $runningBalanceInReverse = $currentWalletBalance - $incoming + $outgoing; + $request['running_balance'] = $runningBalanceInReverse; + } + return $this->collectionResponse(WalletTransactionResource::collection($query)); } diff --git a/app/Http/Resources/WalletResource.php b/app/Http/Resources/WalletResource.php index 4fa484ad..d1c6b941 100644 --- a/app/Http/Resources/WalletResource.php +++ b/app/Http/Resources/WalletResource.php @@ -21,7 +21,7 @@ class WalletResource extends JsonResource 'currency_id' => $this->currency_id, 'amount' => (double) $this->amount, 'company_id' => (int) $this->owner->id, - 'transactions' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereIn('status', [2, 3])->orderBy('id', 'DESC')->get()), []), + // 'transactions' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereIn('status', [2, 3])->orderBy('id', 'DESC')->get()), []), 'top_up_records' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereNotIn('status', [0])->where('type', TransactionType::TOP_UP)->orderBy('id', 'DESC')->get()), []), ]; } diff --git a/app/Http/Resources/WalletTransactionResource.php b/app/Http/Resources/WalletTransactionResource.php index a0e1a930..ef3091fa 100644 --- a/app/Http/Resources/WalletTransactionResource.php +++ b/app/Http/Resources/WalletTransactionResource.php @@ -20,12 +20,15 @@ class WalletTransactionResource extends JsonResource public function toArray($request) { $description = ''; + $current_running_balance = $request['running_balance']; switch((int) $this->type){ case 5: $description = (double) $this->amount.' Credit Top up'; + $request['running_balance'] = bcsub($request['running_balance'], $this->amount, 5); break; case 9: $description = 'Credit Voucher for '.$this->payment_reference; + $request['running_balance'] = bcsub($request['running_balance'], $this->amount, 5); break; case 1: $booking = Transaction::where('payment_reference', $this->bill_no)->first()->owner; @@ -35,11 +38,13 @@ class WalletTransactionResource extends JsonResource break; } + $request['running_balance'] = bcadd($request['running_balance'], $this->amount, 5); $marking = $booking->marking; $description = 'Payment For booking refs.'.''.$marking.''; break; case 11: $description = 'Debit Voucher for '.$this->payment_reference; + $request['running_balance'] = bcadd($request['running_balance'], $this->amount, 5); break; } @@ -53,6 +58,7 @@ class WalletTransactionResource extends JsonResource 'payment_method' => (float) $this->payment_method, 'issuer_name' => $this->issuerCompany->name, 'amount' => (double) $this->amount, + 'running_balance' => (double) $current_running_balance, 'service_charge' => (double) $this->service_charge, 'tax' => (double) $this->tax, 'status' => (int) $this->status, diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue index 4d25f91b..a453a4d8 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue @@ -1,7 +1,7 @@ diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue index 706bc95a..f0f37429 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue @@ -16,10 +16,10 @@
- +
- +
@@ -70,6 +70,10 @@ export default { id: { type: Number, required: true + }, + wallet_id: { + type: Number, + required: true } }, data(){ diff --git a/resources/assets/vue/components/wallets/elements/CustomerWalletTransactionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerWalletTransactionComponent.vue new file mode 100644 index 00000000..bf9864e1 --- /dev/null +++ b/resources/assets/vue/components/wallets/elements/CustomerWalletTransactionComponent.vue @@ -0,0 +1,35 @@ + + \ No newline at end of file diff --git a/resources/views/pages/wallet/transactions.blade.php b/resources/views/pages/wallet/transactions.blade.php index ce31dec6..af89c443 100644 --- a/resources/views/pages/wallet/transactions.blade.php +++ b/resources/views/pages/wallet/transactions.blade.php @@ -1,5 +1,5 @@
- +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 4c4fc328..093de5ff 100644 --- a/routes/web.php +++ b/routes/web.php @@ -227,8 +227,10 @@ Route::get('/fix_bills', function () { })->name('products.random'); Route::get('/wallet/{marking}/details', function ($marking) { - $id = \App\Models\Company::where('reference', '=', $marking)->first()->id; - return view('pages.wallet.index', ['id' => $id]); + $company = \App\Models\Company::where('reference', '=', $marking)->first(); + $id = $company->id; + $wallet_id = $company->wallets()->first()->id; + return view('pages.wallet.index', ['id' => $id, 'wallet_id' => $wallet_id]); })->name('wallet.details'); Route::get('/wallet/{marking}/{is_precise}/export', 'Exports\ExportCustomersWalletTransactionToExcelController@export')->name('wallet.details-export'); From 0c2aa95bd4fe98cc3a15d1347031abb52283bc88 Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Thu, 21 Sep 2023 17:37:57 +0800 Subject: [PATCH 07/55] fix mapping fail when more than one file is import --- ...ankStatementTransactionOwnersProcessor.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php b/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php index 164546c3..ccc70032 100644 --- a/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php +++ b/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php @@ -26,7 +26,7 @@ class CreateBankStatementTransactionOwnersProcessor public function execute() { $transactions = StatementTransaction::whereDoesntHave('owners', function($query){ - return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); })->orderBy('posting_date')->get(); // $transactions = StatementTransaction::whereDoesntHave('owners')->where('amount', '<', 0)->get(); @@ -39,12 +39,13 @@ class CreateBankStatementTransactionOwnersProcessor // Exchange Sales $creditTransactions = $this->getTransactions($transaction->posting_date, $transaction->amount, TransactionType::PAYMENT, Booking::class, PaymentMethodType::WALLET, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED], $keywords); foreach ($creditTransactions as $creditTransaction) { + $isArray = is_array($creditTransaction); $transaction->owners()->firstOrCreate([ 'type' => StatementTransactionOwnerType::SALES, 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, - 'owner_id'=> $creditTransaction->id, - 'owner_reference'=> $creditTransaction->owner->marking, + 'owner_id'=> $isArray ? $creditTransaction['owner_id'] : $creditTransaction->id, + 'owner_reference'=> $isArray ? $creditTransaction['owner_reference'] : $creditTransaction->owner->marking, ]); } @@ -65,12 +66,13 @@ class CreateBankStatementTransactionOwnersProcessor // Exchange Wallet Top Up $creditTransactions = $this->getTransactions($transaction->posting_date, $transaction->amount, TransactionType::TOP_UP, Wallet::class, null, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED], $keywords); foreach ($creditTransactions as $creditTransaction) { + $isArray = is_array($creditTransaction); $transaction->owners()->firstOrCreate([ 'type' => StatementTransactionOwnerType::WALLET_TOP_UP, 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, - 'owner_id'=> $creditTransaction->id, - 'owner_reference'=> $creditTransaction->owner->owner->reference, + 'owner_id'=> $isArray ? $creditTransaction['owner_id'] : $creditTransaction->id, + 'owner_reference'=> $isArray ? $creditTransaction['owner_reference'] : $creditTransaction->owner->owner->reference, ]); } @@ -136,12 +138,13 @@ class CreateBankStatementTransactionOwnersProcessor // Exchange Wallet Withdrawal $debitTransactions = $this->getTransactions($transaction->posting_date, $transaction->amount, TransactionType::DEBIT_NOTE, Wallet::class, null, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED], $keywords); foreach ($debitTransactions as $debitTransaction) { + $isArray = is_array($creditTransaction); $transaction->owners()->firstOrCreate([ 'type' => StatementTransactionOwnerType::WALLET_WITHDRAWAL, 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, - 'owner_id'=> $debitTransaction->id, - 'owner_reference'=> $debitTransaction->owner->owner->marking, + 'owner_id'=> $isArray ? $debitTransaction['owner_id'] : $debitTransaction->id, + 'owner_reference'=> $isArray ? $debitTransaction['owner_reference'] : $debitTransaction->owner->owner->marking, ]); } @@ -271,10 +274,8 @@ class CreateBankStatementTransactionOwnersProcessor return $query->get(); } else { $result = $this->getTransactionsFromExchange($amount, $dateRange, $type, $ownerType, $paymentMethod); - $transactionsId = Arr::pluck($result, 'owner_id'); - $query = $model::whereIn('id', $transactionsId); - return $query->get(); + return $result; } } From 0f37ca56fa96f2f6869514027893e47852ccc387 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 27 Sep 2023 00:12:22 +0800 Subject: [PATCH 08/55] add rows limit --- .../elements/CustomerTransactionComponent.vue | 61 +++----------- .../CustomerTransactionSectionComponent.vue | 80 +++++++++++-------- 2 files changed, 60 insertions(+), 81 deletions(-) diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue index a453a4d8..1250432b 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionComponent.vue @@ -11,75 +11,40 @@
Balance
- +
- -
diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue index f0f37429..698b35be 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue @@ -1,56 +1,65 @@