From 6542710ba9ceefe3a1c4fb7a905d365a8246c5f3 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 16 Sep 2023 18:09:11 +0800 Subject: [PATCH] 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');