From 43530352ee848799ca548f2ab15d4c00c4b33a0c Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 28 Aug 2021 11:40:04 +0800 Subject: [PATCH 1/2] Add credit note controller and logic --- .../Bookings/ControllersLogic/CreateBookingRefundLogic.php | 4 ++-- routes/booking.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 0ec53d9b..843ecb88 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -75,6 +75,8 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $booking = Booking::find($request->route('id')); $transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED); $paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company); @@ -87,8 +89,6 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $transaction->tax, $transaction->service_charge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION); $transaction = $this->createsTransaction->execute($booking, $object); - - $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED); return $this->resourceResponse(new TransactionResource($transaction)); } diff --git a/routes/booking.php b/routes/booking.php index e7f3d7d4..c2805443 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -20,6 +20,7 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::group(['prefix' => '{id}/refund', 'as' => 'refund.'], function () { Route::post('{payment_id}/create', 'CreateBookingRefundController@create')->name('create'); + Route::post('{payment_id}/credit_note/create', 'CreateBookingRefundCreditNoteController@create')->name('credit_note.create'); }); Route::post('{id}/purchase_order/verification', 'ApprovePurchaseOrderController@approve')->name('po.approval'); From 410c55e2bf010f21db2eea37763fe3188b6ac8f1 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sun, 29 Aug 2021 20:52:43 +0800 Subject: [PATCH 2/2] Add credit note controller and logic --- .../CreateBookingRefundCreditNoteLogic.php | 97 +++++++++++++++++++ ...reateBookingRefundCreditNoteController.php | 20 ++++ 2 files changed, 117 insertions(+) create mode 100644 app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php create mode 100644 app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php new file mode 100644 index 00000000..9c66abc5 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php @@ -0,0 +1,97 @@ + 'Create Refund Booking', + 'message' => 'You have successfully created a refund booking' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var FetchesCompanyPaymentAttemptLimit */ + private $fetchesCompanyPaymentAttemptLimit; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** + * CreateBookingPaymentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + */ + public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $booking = Booking::find($request->route('id')); + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED); + + $paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company); + + $billNumber = $this->generatesTransactionBillNumber->execute('CDTN-'); + + $object = new TransactionObject($billNumber, TransactionType::CREDIT_NOTE, 1, $booking->company->id, + $booking->bank_id, $transaction->payment_method, + $transaction->amount, $transaction->original_amount, 1, + $transaction->original_currency_id, $transaction->currency_rate, + $transaction->tax, $transaction->service_charge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION); + + $transaction = $this->createsTransaction->execute($booking, $object); + + return $this->resourceResponse(new TransactionResource($transaction)); + } + + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php b/app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php new file mode 100644 index 00000000..4e54678a --- /dev/null +++ b/app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file