diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 062db191..7e176363 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -73,14 +73,16 @@ class CreateBookingRefundLogic extends AbstractControllerLogic public function logic(Request $request) : JsonResponse { - if(auth()->user()->type === 3) { - throw new MalformedRequestException('You do not have the permission to refund the order.'); - } - $transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]); $booking = $transaction->owner; + $invoice = $booking->transactions()->where('type', TransactionType::INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first(); + + if(auth()->user()->type === 3 || ($invoice && !(auth()->user()->type === 0 || auth()->user()->type === 1))) { + throw new MalformedRequestException('You do not have the permission to refund the order.'); + } + $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); $refund = $transaction->transactions()->refunds()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->sum('original_amount'); diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php index 25db0f31..615ded20 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; - +use App\Classes\Exceptions\MalformedRequestException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Bookings\ControllersLogic\UpdateBookingAmountLogic; use App\Classes\Modules\Companies\Services\FetchesCompany; @@ -17,6 +17,7 @@ use App\Classes\Modules\Wallets\Processors\CreditWalletProcessor; use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount; use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount; use App\Classes\ValueObjects\Constants\TransactionType; +use Illuminate\Support\Facades\Auth; class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic { @@ -85,6 +86,10 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { + if (!(Auth::user()->type === 0 || Auth::user()->type === 1)) { + throw new MalformedRequestException('Only super admin can update refund status.'); + } + $refundTransaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); $refundTransaction = $this->updatesTransactionStatus->execute($refundTransaction, $request->route('status')); diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index e3be870f..ec0c0d7a 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -290,7 +290,7 @@
-
+
@@ -345,7 +345,7 @@
-
+
-
+