From 14947865f8e302a15f856608772f3e5c450365aa Mon Sep 17 00:00:00 2001 From: glovetleong Date: Wed, 6 Apr 2022 22:52:39 +0800 Subject: [PATCH 01/30] wallet pay cash back --- .../Bookings/ControllersLogic/CreateBookingPaymentLogic.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php index fdd786e6..cf95ca2f 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php @@ -139,8 +139,6 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic $paymentReference = $billNumber; $this->updatesWalletBalance->execute($wallet, ($amount * -1)); - - $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction); } $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); @@ -153,6 +151,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic /** @var Transaction $transaction */ $transaction = $this->createsTransaction->execute($booking, $object); + $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction); if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::WALLET){ $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED); From 17f6333030d222a585ab276379822dda77d02040 Mon Sep 17 00:00:00 2001 From: glovetleong Date: Sun, 10 Apr 2022 00:23:23 +0800 Subject: [PATCH 02/30] refund bug --- app/Http/Resources/TransactionResource.php | 8 ++++---- .../bookings/elements/PaymentHistoryComponent.vue | 4 ++-- .../bookings/elements/RefundVerificationComponent.vue | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 30ba223c..4bec5255 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -19,7 +19,7 @@ class TransactionResource extends JsonResource { $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; - $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); + // $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ 'id' => $this->id, @@ -28,7 +28,7 @@ class TransactionResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + // 'recipient_bank_account' => new BankResource($booking->bank), 'issuer_name' => $this->issuerCompany->name, 'amount' => (double) $this->amount, 'original_amount' => (double) $this->original_amount, @@ -45,8 +45,8 @@ class TransactionResource extends JsonResource 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'), 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), 'interval' => [ - 'value' => $days->gt(Carbon::now()) ? '+' : '-', - 'duration' => $days->diff(Carbon::now())->format('%d'), + // 'value' => $days->gt(Carbon::now()) ? '+' : '-', + // 'duration' => $days->diff(Carbon::now())->format('%d'), ] ]; } diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index 51352679..bd45c392 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -123,7 +123,7 @@
Requested Refund Amount
-
{{item.original_currency.short_code}} {{(Math.round((totalRequestedRefund + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
+
{{item.currency.short_code}} {{(Math.round((totalRequestedRefund + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
@@ -220,7 +220,7 @@
-
+
diff --git a/resources/assets/vue/components/bookings/elements/RefundVerificationComponent.vue b/resources/assets/vue/components/bookings/elements/RefundVerificationComponent.vue index e78a14f6..42d5682e 100644 --- a/resources/assets/vue/components/bookings/elements/RefundVerificationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/RefundVerificationComponent.vue @@ -28,7 +28,7 @@
Amount
- {{(Math.round((data.amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}} + {{(Math.round((data.original_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
From eee77325f71eaa961955cf94bd46f7d32cb03c0e Mon Sep 17 00:00:00 2001 From: glovetleong Date: Sun, 10 Apr 2022 00:24:22 +0800 Subject: [PATCH 03/30] back --- app/Http/Resources/TransactionResource.php | 8 ++++---- .../bookings/elements/PaymentHistoryComponent.vue | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 4bec5255..30ba223c 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -19,7 +19,7 @@ class TransactionResource extends JsonResource { $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; - // $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); + $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ 'id' => $this->id, @@ -28,7 +28,7 @@ class TransactionResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - // 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new BankResource($booking->bank), 'issuer_name' => $this->issuerCompany->name, 'amount' => (double) $this->amount, 'original_amount' => (double) $this->original_amount, @@ -45,8 +45,8 @@ class TransactionResource extends JsonResource 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'), 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), 'interval' => [ - // 'value' => $days->gt(Carbon::now()) ? '+' : '-', - // 'duration' => $days->diff(Carbon::now())->format('%d'), + 'value' => $days->gt(Carbon::now()) ? '+' : '-', + 'duration' => $days->diff(Carbon::now())->format('%d'), ] ]; } diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index bd45c392..b73081b9 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -220,7 +220,7 @@
-
+
From 5647957e9fff932c8fd9f54ca2a99118eac9818d Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sun, 10 Apr 2022 21:31:20 +0800 Subject: [PATCH 04/30] delete group transaction --- .../CreateSupplierTransactionLogic.php | 2 +- .../ControllersLogic/DeleteGroupLogic.php | 72 +++++++++++++++ .../ControllersLogic/ListGroupsLogic.php | 42 +++++++++ .../Transactions/Services/FetchesGroup.php | 31 +++++++ .../Transactions/Services/ListsGroups.php | 31 +++++++ .../Transactions/DeleteGroupController.php | 20 ++++ .../Transactions/ListGroupsController.php | 21 +++++ app/Http/Resources/GroupResource.php | 29 ++++++ app/Models/Group.php | 21 ++++- app/Models/GroupTransaction.php | 19 +++- ...170641_create_group_transactions_table.php | 5 +- .../elements/CurrencyOrderComponent.vue | 2 +- .../elements/TransactionGroupComponent.vue | 92 +++++++++++++++++++ resources/views/pages/payments.blade.php | 16 ++++ routes/transaction.php | 3 + 15 files changed, 399 insertions(+), 7 deletions(-) create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php create mode 100644 app/Classes/Modules/Transactions/Services/FetchesGroup.php create mode 100644 app/Classes/Modules/Transactions/Services/ListsGroups.php create mode 100644 app/Http/Controllers/Transactions/DeleteGroupController.php create mode 100644 app/Http/Controllers/Transactions/ListGroupsController.php create mode 100644 app/Http/Resources/GroupResource.php create mode 100644 resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 3dde2e45..0aa0fb7f 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -87,7 +87,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $service_charge = 0; foreach ($this->createSupplierTransactionProcessor->getBills() as $key => $row) { - $group->transaction()->sync($row->id, false); + $group->transactions()->sync($row->id, false); $issuer = $row->issuer; $receiver = $row->receiver; $amount += $row->amount; diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php new file mode 100644 index 00000000..b19a7159 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php @@ -0,0 +1,72 @@ + 'Delete Group Transaction', + 'message' => 'You have successfully deleted this Group Transaction' + ]; + } + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var DeletesTransaction */ + private $deletesTransaction; + + public function __construct( + UpdatesTransactionStatus $updatesTransactionStatus, + FetchesGroup $fetchesGroup, + DeletesTransaction $deletesTransaction + ) + { + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->fetchesGroup = $fetchesGroup; + $this->deletesTransaction = $deletesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $items = $group->transactions()->get(); + + foreach($items as $item) { + $bill = $item; + $payment = $bill->owner; + $group->transactions()->detach($bill->id); + $this->updatesTransactionStatus->execute($payment, ApprovalStatus::APPROVED); + $this->deletesTransaction->execute($bill); + } + + $group->delete(); + + return $this->resourceResponse(new GroupResource($group)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php new file mode 100644 index 00000000..5cf99bbe --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php @@ -0,0 +1,42 @@ +listsGroups = $listsGroups; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Retrieved Groups', + 'message' => 'You have successfully retrieved a list of groups' + ]; + } + + /** @var ListsGroups */ + private $listsGroups; + + public function logic(Request $request) : JsonResponse + { + $query = $this->listsGroups->execute($this->listsGroups->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(GroupResource::collection($query)); + } + +} diff --git a/app/Classes/Modules/Transactions/Services/FetchesGroup.php b/app/Classes/Modules/Transactions/Services/FetchesGroup.php new file mode 100644 index 00000000..6533664b --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/FetchesGroup.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Transactions/Services/ListsGroups.php b/app/Classes/Modules/Transactions/Services/ListsGroups.php new file mode 100644 index 00000000..f9126739 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ListsGroups.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Http/Controllers/Transactions/DeleteGroupController.php b/app/Http/Controllers/Transactions/DeleteGroupController.php new file mode 100644 index 00000000..14ba54f9 --- /dev/null +++ b/app/Http/Controllers/Transactions/DeleteGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/ListGroupsController.php b/app/Http/Controllers/Transactions/ListGroupsController.php new file mode 100644 index 00000000..730633e9 --- /dev/null +++ b/app/Http/Controllers/Transactions/ListGroupsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Resources/GroupResource.php b/app/Http/Resources/GroupResource.php new file mode 100644 index 00000000..2d628d19 --- /dev/null +++ b/app/Http/Resources/GroupResource.php @@ -0,0 +1,29 @@ + $this->id, + 'original_amount' => (double) $this->original_amount, + 'original_currency' => new CurrencyResource($this->original_currency), + 'amount' => (double) $this->amount, + 'currency' => new CurrencyResource($this->currency), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), + 'currency_rate' => (float) $this->currency_rate, + 'transactions' => TransactionResource::collection($this->transactions()->get()), + ]; + } +} diff --git a/app/Models/Group.php b/app/Models/Group.php index eff309e2..6e785faa 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -3,11 +3,28 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Group extends Model { - public function transaction() + public function transactions() { - return $this->belongsToMany('App\Models\Transaction', 'group_transaction'); + return $this->belongsToMany(Transaction::class, GroupTransaction::class); + } + + /** + * @return BelongsTo + */ + public function currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'currency_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function original_currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); } } diff --git a/app/Models/GroupTransaction.php b/app/Models/GroupTransaction.php index c8622ef9..9ab72d18 100644 --- a/app/Models/GroupTransaction.php +++ b/app/Models/GroupTransaction.php @@ -3,8 +3,25 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class GroupTransaction extends Model { - // + protected $table = 'group_transactions'; + + /** + * @return BelongsTo + */ + public function group(): BelongsTo + { + return $this->BelongsTo(Group::class, 'group_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function transaction(): BelongsTo + { + return $this->BelongsTo(Transaction::class, 'transaction_id', 'id'); + } } diff --git a/database/migrations/2022_03_20_170641_create_group_transactions_table.php b/database/migrations/2022_03_20_170641_create_group_transactions_table.php index 6ce7cedc..53f33356 100644 --- a/database/migrations/2022_03_20_170641_create_group_transactions_table.php +++ b/database/migrations/2022_03_20_170641_create_group_transactions_table.php @@ -13,7 +13,8 @@ class CreateGroupTransactionsTable extends Migration */ public function up() { - Schema::create('group_transaction', function (Blueprint $table) { + Schema::create('group_transactions', function (Blueprint $table) { + $table->id(); $table->foreignId('group_id')->unsigned(); $table->foreignId('transaction_id')->unsigned(); }); @@ -26,6 +27,6 @@ class CreateGroupTransactionsTable extends Migration */ public function down() { - Schema::dropIfExists('group_transaction'); + Schema::dropIfExists('group_transactions'); } } diff --git a/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue b/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue index ad4c3e42..a88fd5a9 100644 --- a/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue +++ b/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue @@ -40,7 +40,7 @@
Currency Order Placed
-
Are you sure you that the currency order has been placed with the supplier?
+
Are you sure that the currency order has been placed with the supplier?
diff --git a/resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue b/resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue new file mode 100644 index 00000000..515e56aa --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue @@ -0,0 +1,92 @@ + + + diff --git a/resources/views/pages/payments.blade.php b/resources/views/pages/payments.blade.php index 12604a91..8dec0f8f 100644 --- a/resources/views/pages/payments.blade.php +++ b/resources/views/pages/payments.blade.php @@ -40,6 +40,22 @@
+
+
+
+ Transaction Groups +
+
+
+
+ + + +
+
+
diff --git a/routes/transaction.php b/routes/transaction.php index c3402b47..cbff706d 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -22,4 +22,7 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::get('/company/{id}/account/balance', 'FetchCompanyAccountBalanceController@fetch')->name('company.account.balance'); Route::get('/bank/{id}/account/balance', 'FetchBankAccountBalanceController@fetch')->name('bank.account.balance'); + + Route::get('/groups/list', 'ListGroupsController@list')->name('group.list'); + Route::delete('/groups/{id}/delete', 'DeleteGroupController@delete')->name('group.delete'); }); \ No newline at end of file From 0bf3b1b3539a03e83182480efe4d16ba8cbd04fa Mon Sep 17 00:00:00 2001 From: glovetleong Date: Mon, 11 Apr 2022 23:50:15 +0800 Subject: [PATCH 05/30] refund bug --- .../ControllersLogic/CreateBookingRefundLogic.php | 6 ++++-- app/Http/Resources/BookingResource.php | 1 + .../bookings/elements/PaymentHistoryComponent.vue | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 74e92fa6..d31ee2ce 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -84,12 +84,14 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); - $refund = $transaction->transactions()->refunds()->sum('amount'); if($refund + $request->input('amount') > $transaction->original_amount) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.'); - $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount')); + $amount = $transaction->booking->fix_currency_id == 1 ? $request->input('amount') : $request->input('amount') / $transaction->currency_rate; + + + $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $amount); $transactionRefundCalculationObject->init(); $object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id, diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index 0eeb9670..0adfa65d 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -31,6 +31,7 @@ class BookingResource extends JsonResource 'service' => new ServiceTypeResource($this->service), 'marking' => $this->marking, 'amount' => $this->fix_amount, + 'amount' => $this->fix_amount, 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), 'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index b73081b9..de39dfb0 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -219,7 +219,7 @@ -
+
@@ -249,12 +249,25 @@ }, computed: { totalRequestedRefund() { + let vm = this; var TotalRequestedRefund = 0; this.data.transaction_refunds.forEach(function(refunds) { TotalRequestedRefund += refunds.status === 1 ? refunds.original_amount : 0; }); + return TotalRequestedRefund; }, + totalRequestedConvertRefund() { + let vm = this; + var TotalRequestedRefund = 0; + this.data.transaction_refunds.forEach(function(refunds) { + TotalRequestedRefund += refunds.status === 1 ? refunds.original_amount : 0; + }); + if (vm.data.booking.fixed_currency.id != 1 && this.data.transaction_refunds[0]) { + TotalRequestedRefund = (TotalRequestedRefund * this.data.transaction_refunds[0].currency_rate); + } + return ((Math.round((TotalRequestedRefund + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); + }, totalRefunds() { var TotalRequestedRefund = 0; this.data.transaction_refunds.forEach(function(refunds) { From 29b1f87966ce2f540b9ac877cc0a9a369d520083 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 16 Apr 2022 23:53:12 +0800 Subject: [PATCH 06/30] move notification API and UI from shipping portal --- app/Classes/General/Interfaces/Notifiable.php | 15 +++ .../ApproveIdentificationDocumentLogic.php | 24 ++++- .../ListNotificationsLogic.php | 61 +++++++++++ .../NotificationObject.php | 101 ++++++++++++++++++ .../CreateNotificationProcessor.php | 27 +++++ .../Services/CreatesNotification.php | 30 ++++++ .../Services/ListsNotification.php | 33 ++++++ .../ListNotificationsController.php | 19 ++++ app/Http/Resources/NotificationResource.php | 30 ++++++ app/Models/AbstractModel.php | 28 ++++- app/Models/Notification.php | 18 ++++ ...4_15_211421_create_notifications_table.php | 40 +++++++ .../assets/sass/modules/_typography.scss | 6 ++ .../IdentificationVerificationComponent.vue | 23 +--- ...dentificationVerificationFormComponent.vue | 78 ++++++++++++++ .../elements/NotificationSectionComponent.vue | 82 ++++++++++++++ resources/views/partials/header.blade.php | 10 +- routes/web.php | 4 +- 18 files changed, 597 insertions(+), 32 deletions(-) create mode 100644 app/Classes/General/Interfaces/Notifiable.php create mode 100644 app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php create mode 100644 app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php create mode 100644 app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php create mode 100644 app/Classes/Modules/Notifications/Services/CreatesNotification.php create mode 100644 app/Classes/Modules/Notifications/Services/ListsNotification.php create mode 100644 app/Http/Controllers/Notifications/ListNotificationsController.php create mode 100644 app/Http/Resources/NotificationResource.php create mode 100644 app/Models/Notification.php create mode 100644 database/migrations/2022_04_15_211421_create_notifications_table.php create mode 100644 resources/assets/vue/components/companies/elements/RejectIdentificationVerificationFormComponent.vue create mode 100644 resources/assets/vue/components/general/elements/NotificationSectionComponent.vue diff --git a/app/Classes/General/Interfaces/Notifiable.php b/app/Classes/General/Interfaces/Notifiable.php new file mode 100644 index 00000000..e9d8f22d --- /dev/null +++ b/app/Classes/General/Interfaces/Notifiable.php @@ -0,0 +1,15 @@ +canApproveDocument = $canApproveDocument; $this->approvesDocument = $approvesDocument; $this->rejectsDocument = $rejectsDocument; $this->fetchesDocument = $fetchesDocument; $this->updatesCompanyStatus = $updatesCompanyStatus; + $this->createNotificationProcessor = $createNotificationProcessor; } /** @@ -84,6 +92,20 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic $this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + $object = new NotificationObject( + 'ID Verification ' . ( $status === 'approve' ? 'Approved' : 'Rejected' ), + ( $status === 'approve' ? 'Dear user, congratulations that your ' : 'Dear user, we are sorry to inform you that your ' ) . ( $document->type === 'IDENTITY_CARD' ? 'IC' : 'SSM' ) . ( $status === 'approve' ? ' has been approved. Start your first order now!' : ' has been rejected due to ' . ( $request->input('rejectRemark') ?? '' ) . ', please resubmit it for further action.' ), + $document->owner, + $document->owner->employees()->first(), + $document, + ); + + $this->createNotificationProcessor->execute($object); + + if($status === 'approve'){ + $orders = $this->updatesOrdersStatus->execute($document->owner, ApprovalStatus::APPROVED); + } + return $this->resourceResponse(new DocumentResource($document)); } diff --git a/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php b/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php new file mode 100644 index 00000000..0fdbf6f9 --- /dev/null +++ b/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php @@ -0,0 +1,61 @@ + 'Retrieve Notifications', + 'message' => 'You have successfully retrieved a list of Notifications' + ]; + } + + /** @var ListsNotification */ + private $listsNotification; + + /** + * ListNotificationsLogic constructor. + * @param ListsNotification $listsNotification + */ + public function __construct( + ListsNotification $listsNotification + ) + { + $this->listsNotification = $listsNotification; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $filters = [ + // 'target_id'=>auth()->user()->id, + // 'per_page'=>$request->route('per_page') + ]; + + $notifications = $this->listsNotification->execute($filters); + + return $this->collectionResponse(NotificationResource::collection($notifications)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php b/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php new file mode 100644 index 00000000..40dc4f3c --- /dev/null +++ b/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php @@ -0,0 +1,101 @@ +title = $title; + $this->description = $description; + $this->subject = $subject; + $this->target = $target; + $this->causer = $causer; + $this->status = $status; + } + + /** + * @return int + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return int + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return Notifiable + */ + public function getSubject(): Notifiable + { + return $this->subject; + } + + /** + * @return Notifiable + */ + public function getTarget(): Notifiable + { + return $this->target; + } + + /** + * @return Notifiable + */ + public function getCauser(): Notifiable + { + return $this->causer; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + + +} diff --git a/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php new file mode 100644 index 00000000..d6b077f8 --- /dev/null +++ b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php @@ -0,0 +1,27 @@ +createsNotification = $createsNotification; + } + + public function execute(NotificationObject $object) + { + $notification = $this->createsNotification->execute($object); + return $notification; + } +} diff --git a/app/Classes/Modules/Notifications/Services/CreatesNotification.php b/app/Classes/Modules/Notifications/Services/CreatesNotification.php new file mode 100644 index 00000000..4f5ca5fd --- /dev/null +++ b/app/Classes/Modules/Notifications/Services/CreatesNotification.php @@ -0,0 +1,30 @@ +title = $object->getTitle(); + $model->description = $object->getDescription(); + $model->status = $object->getStatus(); + $model->subject_type = get_class($object->getSubject()); + $model->subject_id = $object->getSubject()->id; + $model->target_type = get_class($object->getTarget()); + $model->target_id = $object->getTarget()->id; + $model->causer_type = get_class($object->getCauser()); + $model->causer_id = $object->getCauser()->id; + $model->save(); + + return $model; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/Services/ListsNotification.php b/app/Classes/Modules/Notifications/Services/ListsNotification.php new file mode 100644 index 00000000..707e7ae8 --- /dev/null +++ b/app/Classes/Modules/Notifications/Services/ListsNotification.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Notifications/ListNotificationsController.php b/app/Http/Controllers/Notifications/ListNotificationsController.php new file mode 100644 index 00000000..58455fc2 --- /dev/null +++ b/app/Http/Controllers/Notifications/ListNotificationsController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Resources/NotificationResource.php b/app/Http/Resources/NotificationResource.php new file mode 100644 index 00000000..564b7b31 --- /dev/null +++ b/app/Http/Resources/NotificationResource.php @@ -0,0 +1,30 @@ + $this->id, + 'title' => $this->title, + 'description' => $this->description, + 'long_ago' => $this->created_at->diffForHumans(), + 'created_at' => $this->created_at->format('d-m-Y') + ]; + + } +} diff --git a/app/Models/AbstractModel.php b/app/Models/AbstractModel.php index 7a7c9c06..47d8754b 100644 --- a/app/Models/AbstractModel.php +++ b/app/Models/AbstractModel.php @@ -3,11 +3,37 @@ namespace App\Models; +use App\Classes\General\Interfaces\Notifiable; use Illuminate\Database\Eloquent\Model; use Spatie\Activitylog\Traits\LogsActivity; +use Illuminate\Database\Eloquent\Relations\MorphTo; -class AbstractModel extends Model +class AbstractModel extends Model implements Notifiable { use LogsActivity; protected static $logFillable = true; + + /** + * @return MorphTo + */ + public function subject(): MorphTo + { + return $this->MorphTo('subject'); + } + + /** + * @return MorphTo + */ + public function target(): MorphTo + { + return $this->MorphTo('target'); + } + + /** + * @return MorphTo + */ + public function causer(): MorphTo + { + return $this->MorphTo('causer'); + } } \ No newline at end of file diff --git a/app/Models/Notification.php b/app/Models/Notification.php new file mode 100644 index 00000000..06bd6024 --- /dev/null +++ b/app/Models/Notification.php @@ -0,0 +1,18 @@ +BelongsTo(Package::class, 'package_id', 'id'); + } +} diff --git a/database/migrations/2022_04_15_211421_create_notifications_table.php b/database/migrations/2022_04_15_211421_create_notifications_table.php new file mode 100644 index 00000000..d14cdc89 --- /dev/null +++ b/database/migrations/2022_04_15_211421_create_notifications_table.php @@ -0,0 +1,40 @@ +id(); + $table->string('title'); + $table->text('description'); + $table->morphs('subject'); + $table->morphs('target'); + $table->morphs('causer'); + $table->integer('status')->default(ApprovalStatus::APPROVED); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('notifications'); + } +} diff --git a/resources/assets/sass/modules/_typography.scss b/resources/assets/sass/modules/_typography.scss index 605b8e7c..aa4506a9 100644 --- a/resources/assets/sass/modules/_typography.scss +++ b/resources/assets/sass/modules/_typography.scss @@ -316,6 +316,12 @@ hr{ background-color: $color-primary-lighter !important; } +.bg-primary-lighter-hover { + &:hover { + background-color: $color-primary-lighter !important; + } +} + /* Complete ------------------------------------ */ diff --git a/resources/assets/vue/components/companies/elements/IdentificationVerificationComponent.vue b/resources/assets/vue/components/companies/elements/IdentificationVerificationComponent.vue index 64fc74e2..838764a3 100644 --- a/resources/assets/vue/components/companies/elements/IdentificationVerificationComponent.vue +++ b/resources/assets/vue/components/companies/elements/IdentificationVerificationComponent.vue @@ -123,28 +123,7 @@
-
-
-
-
-
-
-
Reject Document
-
Are you sure you want to reject this customer's identification?
-
-
-
-
-
Cancel
-
-
-
Reject
-
-
-
-
-
-
+
-
-
-
- -
-
-
@@ -86,6 +79,9 @@
+
+ +
diff --git a/routes/web.php b/routes/web.php index 99e07dd3..52a308d0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -184,4 +184,6 @@ Route::get('purchase/sensitive/', function(Request $request){ } }); -Route::get('/transactions/supplier/{id}/mock_up', 'Transactions\DownloadMockUpWhiteFormPdfController@download')->name('whiteForm.mockUp'); \ No newline at end of file +Route::get('/transactions/supplier/{id}/mock_up', 'Transactions\DownloadMockUpWhiteFormPdfController@download')->name('whiteForm.mockUp'); + +Route::get('/notifications/list', 'Notifications\ListNotificationsController@list')->name('notifications.list'); From 779f7643fbdbefa1f1285b9c7b45993f3544e4f4 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sun, 17 Apr 2022 00:49:33 +0800 Subject: [PATCH 07/30] update responsive notification ui --- .../elements/NotificationSectionComponent.vue | 60 ++++++++++--------- resources/views/partials/header.blade.php | 9 +-- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/resources/assets/vue/components/general/elements/NotificationSectionComponent.vue b/resources/assets/vue/components/general/elements/NotificationSectionComponent.vue index cce6f6c0..468ed7a7 100644 --- a/resources/assets/vue/components/general/elements/NotificationSectionComponent.vue +++ b/resources/assets/vue/components/general/elements/NotificationSectionComponent.vue @@ -2,44 +2,47 @@
-