From 825b4e7bc38b3817a735815100aefd3ff9952de8 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 30 Aug 2025 12:59:45 +0800 Subject: [PATCH] E-Invoice - Minor code refactor --- .../CreateBookingRefundLogic.php | 13 +++-- .../Rules/CanCreateBookingRefund.php | 46 ++++++++++++++++++ .../UpdateRefundTransactionStatusLogic.php | 14 ++++-- .../CanUpdateRefundTransactionStatus.php | 48 +++++++++++++++++++ 4 files changed, 111 insertions(+), 10 deletions(-) create mode 100644 app/Classes/Modules/Bookings/Standards/Rules/CanCreateBookingRefund.php create mode 100644 app/Classes/Modules/Transactions/Standards/Rules/CanUpdateRefundTransactionStatus.php diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 16d047a8..b7e7123d 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -14,6 +14,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transactions\Services\CreatesTransaction; use App\Classes\Modules\Transactions\Services\FetchesTransaction; use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation; +use App\Classes\Modules\Bookings\Standards\Rules\CanCreateBookingRefund; use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject; use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject; use App\Classes\Modules\Transactions\ControllersLogic\UpdateRefundTransactionStatusLogic; @@ -58,6 +59,9 @@ class CreateBookingRefundLogic extends AbstractControllerLogic /** @var CreateRemarkProcessor */ private $createRemarkProcessor; + /** @var CanCreateBookingRefund */ + private $canCreateBookingRefund; + /** * CreateBookingPaymentLogic constructor. * @param FetchesBookingQuotation $fetchBookingQuotation @@ -67,8 +71,9 @@ class CreateBookingRefundLogic extends AbstractControllerLogic * @param CreatesTransaction $createsTransaction * @param UpdateRefundTransactionStatusLogic $updateRefundTransactionStatusLogic * @param CreateRemarkProcessor $createRemarkProcessor + * @param CanCreateBookingRefund $canCreateBookingRefund */ - public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, UpdateRefundTransactionStatusLogic $updateRefundTransactionStatusLogic, CreateRemarkProcessor $createRemarkProcessor) + public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, UpdateRefundTransactionStatusLogic $updateRefundTransactionStatusLogic, CreateRemarkProcessor $createRemarkProcessor, CanCreateBookingRefund $canCreateBookingRefund) { $this->fetchBookingQuotation = $fetchBookingQuotation; $this->fetchesTransaction = $fetchesTransaction; @@ -77,6 +82,7 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $this->createsTransaction = $createsTransaction; $this->updateRefundTransactionStatusLogic = $updateRefundTransactionStatusLogic; $this->createRemarkProcessor = $createRemarkProcessor; + $this->canCreateBookingRefund = $canCreateBookingRefund; } /** @@ -93,10 +99,7 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $invoice = $booking->transactions()->where('type', TransactionType::INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first(); - //cief todo: 90 - move this into rules - // if(auth()->user()->type === 3) { - // throw new MalformedRequestException('You do not have the permission to refund the order.'); - // } + $this->canCreateBookingRefund->passes(); $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); diff --git a/app/Classes/Modules/Bookings/Standards/Rules/CanCreateBookingRefund.php b/app/Classes/Modules/Bookings/Standards/Rules/CanCreateBookingRefund.php new file mode 100644 index 00000000..bd982018 --- /dev/null +++ b/app/Classes/Modules/Bookings/Standards/Rules/CanCreateBookingRefund.php @@ -0,0 +1,46 @@ +type, RoleTypes::ADMIN_ROLES)) { + return true; + } + return false; + + } + + /** + * @param BookingObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php index a8e6ca69..f35ec0e8 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php @@ -14,8 +14,10 @@ use Illuminate\Http\Request; use App\Classes\Modules\Wallets\Processors\CreditWalletProcessor; use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount; use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount; +use App\Classes\Modules\Transactions\Standards\Rules\CanUpdateRefundTransactionStatus; use App\Classes\ValueObjects\Constants\RemarkRefundReason; use App\Classes\ValueObjects\Constants\TransactionType; +use Illuminate\Support\Facades\Log; class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic { @@ -54,6 +56,9 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic /** @var UpdateBookingAmountLogic */ private $updateBookingAmountLogic; + /** @var CanUpdateRefundTransactionStatus */ + private $canUpdateRefundTransactionStatus; + /** * CreatePaymentVerificationDocumentLogic constructor. * @param FetchesCompany $fetchesCompany @@ -64,8 +69,9 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic * @param CalculatesBookingPayableAmount $calculatesBookingPayableAmount * @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount * @param UpdateBookingAmountLogic $updateBookingAmountLogic + * @param CanUpdateRefundTransactionStatus $canUpdateRefundTransactionStatus */ - public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, DeletesDocument $deletesDocument, CreditWalletProcessor $creditWalletProcessor, CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingRefundAmount $calculatesBookingRefundAmount, UpdateBookingAmountLogic $updateBookingAmountLogic) + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, DeletesDocument $deletesDocument, CreditWalletProcessor $creditWalletProcessor, CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingRefundAmount $calculatesBookingRefundAmount, UpdateBookingAmountLogic $updateBookingAmountLogic, CanUpdateRefundTransactionStatus $canUpdateRefundTransactionStatus) { $this->fetchesCompany = $fetchesCompany; $this->fetchesTransaction = $fetchesTransaction; @@ -75,6 +81,7 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic $this->calculatesBookingPayableAmount = $calculatesBookingPayableAmount; $this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount; $this->updateBookingAmountLogic = $updateBookingAmountLogic; + $this->canUpdateRefundTransactionStatus = $canUpdateRefundTransactionStatus; } /** @@ -84,10 +91,7 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - //cief todo: 90 - move this into rules - // if(auth()->user()->type === 3) { - // throw new MalformedRequestException('You do not have the permission to refund the order.'); - // } + $this->canUpdateRefundTransactionStatus->passes(); $refundTransaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanUpdateRefundTransactionStatus.php b/app/Classes/Modules/Transactions/Standards/Rules/CanUpdateRefundTransactionStatus.php new file mode 100644 index 00000000..41e58004 --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanUpdateRefundTransactionStatus.php @@ -0,0 +1,48 @@ +type, RoleTypes::ADMIN_ROLES)) { + return true; + } + return false; + + } + + /** + * @param BookingObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +}