From ed0bcb34c452028892822e8aae66cc847a903268 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 29 Jun 2023 21:24:21 +0800 Subject: [PATCH 1/2] list all customer transactions --- .../FetchCompanyTransactionStatementLogic.php | 61 +++++++++ ...hCompanyTransactionStatementController.php | 21 +++ .../Resources/PaymentTransactionResource.php | 45 +++++++ ...omerTransactionHistorySectionComponent.vue | 120 ++++++++++++++++++ .../pages/transactions/history.blade.php | 8 ++ routes/transaction.php | 1 + routes/web.php | 5 + 7 files changed, 261 insertions(+) create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php create mode 100644 app/Http/Controllers/Transactions/FetchCompanyTransactionStatementController.php create mode 100644 app/Http/Resources/PaymentTransactionResource.php create mode 100644 resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue create mode 100644 resources/views/pages/transactions/history.blade.php diff --git a/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php new file mode 100644 index 00000000..0542e042 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php @@ -0,0 +1,61 @@ + 'Retrieved Company Balance Account', + 'message' => 'You have successfully retrieved company balance account' + ]; + } + + /** + * FetchCompanyAccountBalanceLogic constructor. + */ + public function __construct() + { + } + + public function logic(Request $request): JsonResponse + { + $companyId = $request->route('id'); + + $transactions = Transaction::where(function ($query) use ($companyId) { + $query + ->where('type', TransactionType::PAYMENT) + ->where('owner_type', Booking::class) + ->whereHas('booking', function ($query) use ($companyId) { + $query->where('company_id', $companyId); + }); + }) + ->orWhere(function ($query) use ($companyId) { + $query->whereHas('owner', function ($query) use ($companyId) { + $query->where('owner_id', $companyId); + $query->where('owner_type', Company::class); + }) + ->where('owner_type', Wallet::class) + ->where('type', '!=', TransactionType::PAYMENT); + }) + ->orderBy('created_at', 'desc') + ->get(); + + return $this->collectionResponse(PaymentTransactionResource::collection($transactions)); + } +} diff --git a/app/Http/Controllers/Transactions/FetchCompanyTransactionStatementController.php b/app/Http/Controllers/Transactions/FetchCompanyTransactionStatementController.php new file mode 100644 index 00000000..a1d8c3cb --- /dev/null +++ b/app/Http/Controllers/Transactions/FetchCompanyTransactionStatementController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Resources/PaymentTransactionResource.php b/app/Http/Resources/PaymentTransactionResource.php new file mode 100644 index 00000000..0bdfa86b --- /dev/null +++ b/app/Http/Resources/PaymentTransactionResource.php @@ -0,0 +1,45 @@ +type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + + return [ + 'id' => $this->id, + 'booking_marking' => $booking->marking, + 'type' => (int) $this->type, + 'bill_no' => $this->bill_no, + 'payment_reference' => $this->payment_reference, + 'payment_method' => (float) $this->payment_method, + 'recipient_bank_account' => new BankResource($booking->bank), + 'issuer_name' => $this->issuerCompany->name, + 'issuer_id' => $this->issuerCompany->id, + 'amount' => (double) $this->amount, + 'original_amount' => (double) $this->original_amount, + 'currency' => new CurrencyResource($this->currency), + 'original_currency' => new CurrencyResource($this->original_currency), + 'service_charge' => (double) $this->service_charge, + 'tax' => (double) $this->tax, + 'currency_rate' => (double) $this->currency_rate, + 'status' => (int) $this->status, + 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') + ]; + } +} diff --git a/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue new file mode 100644 index 00000000..9ac3f5b6 --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue @@ -0,0 +1,120 @@ + + diff --git a/resources/views/pages/transactions/history.blade.php b/resources/views/pages/transactions/history.blade.php new file mode 100644 index 00000000..49a8145c --- /dev/null +++ b/resources/views/pages/transactions/history.blade.php @@ -0,0 +1,8 @@ +@extends('layouts.base_portal') +@section('inner_content') +
+
+ +
+
+@endsection \ No newline at end of file diff --git a/routes/transaction.php b/routes/transaction.php index b3dd6434..708c2439 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -22,6 +22,7 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::get('wallet/list', 'ListWalletTransactionsController@list')->name('wallet.list'); Route::get('/company/{id}/account/balance', 'FetchCompanyAccountBalanceController@fetch')->name('company.account.balance'); + Route::get('/company/{id}/transaction/fetch', 'FetchCompanyTransactionStatementController@fetch')->name('company.transaction.fetch'); Route::get('/bank/{id}/account/balance', 'FetchBankAccountBalanceController@fetch')->name('bank.account.balance'); diff --git a/routes/web.php b/routes/web.php index 93a87218..11c727fb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -74,6 +74,11 @@ Route::get('/customer/{marking}', function ($marking) { return view('pages.customers.profile', ['id' => $id]); })->name('customer.profile'); +Route::get('/customer/{marking}/transactions', function ($marking) { + $id = \App\Models\Company::where('reference', '=', $marking)->first()->id; + return view('pages.transactions.history', ['id' => $id]); +})->name('transactions.history'); + Route::get('/payments', function () { return view('pages.payments'); })->name('payments'); From a90c79396b2fbe1c3624c62dc4f62dc1cabcafd5 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 29 Jun 2023 22:00:26 +0800 Subject: [PATCH 2/2] update list all customer transactions --- .../FetchCompanyTransactionStatementLogic.php | 7 +++++-- app/Http/Resources/PaymentTransactionResource.php | 13 ++++++++++++- .../CustomerTransactionHistorySectionComponent.vue | 6 +++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php index 0542e042..c16ac453 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php @@ -6,6 +6,7 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Classes\General\Abstracts\AbstractControllerLogic; +use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; use App\Http\Resources\PaymentTransactionResource; use App\Models\Booking; @@ -21,8 +22,8 @@ class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic protected function notification(): array { return [ - 'title' => 'Retrieved Company Balance Account', - 'message' => 'You have successfully retrieved company balance account' + 'title' => 'Retrieved Company Transaction Statement', + 'message' => 'You have successfully retrieved company transaction statement' ]; } @@ -41,6 +42,7 @@ class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic $query ->where('type', TransactionType::PAYMENT) ->where('owner_type', Booking::class) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) ->whereHas('booking', function ($query) use ($companyId) { $query->where('company_id', $companyId); }); @@ -53,6 +55,7 @@ class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic ->where('owner_type', Wallet::class) ->where('type', '!=', TransactionType::PAYMENT); }) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) ->orderBy('created_at', 'desc') ->get(); diff --git a/app/Http/Resources/PaymentTransactionResource.php b/app/Http/Resources/PaymentTransactionResource.php index 0bdfa86b..456ece3d 100644 --- a/app/Http/Resources/PaymentTransactionResource.php +++ b/app/Http/Resources/PaymentTransactionResource.php @@ -5,6 +5,7 @@ namespace App\Http\Resources; use App\Classes\ValueObjects\Constants\TransactionType; use App\Models\Booking; use Carbon\Carbon; +use App\Models\Wallet; use Illuminate\Http\Resources\Json\JsonResource; class PaymentTransactionResource extends JsonResource @@ -20,9 +21,19 @@ class PaymentTransactionResource extends JsonResource $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + $booking_marking = ''; + switch ($this->owner_type) { + case Booking::class: + $booking_marking = $booking->marking; + break; + case Wallet::class: + $booking_marking = $this->booking->marking; + break; + } + return [ 'id' => $this->id, - 'booking_marking' => $booking->marking, + 'booking_marking' => $booking_marking, 'type' => (int) $this->type, 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, diff --git a/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue index 9ac3f5b6..3d441d53 100644 --- a/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue +++ b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue @@ -14,7 +14,7 @@
Date
Description
-
Type
+
Marking
Incoming
Outgoing
Balance
@@ -22,8 +22,8 @@
{{item.created_at}}
-
{{ item.payment_reference ? item.payment_reference + ' - ' : '' }} {{convertPaymentMethod(item.payment_method)}} - {{item.booking_marking}}
-
{{ convertTransactionType(item.type) }}
+
{{ convertTransactionType(item.type) }} {{ item.payment_reference ? ' - ' + item.payment_reference : '' }}
+
{{[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)}}