From 81c81e3b48ac9d7cbaf4c8cfff916622bebc9b23 Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Fri, 15 Mar 2024 10:34:21 +0800 Subject: [PATCH] -show remark and categorized in export refund booking -make refund function available for internal only, not for customer --- .../CreateBookingRefundLogic.php | 4 ++ .../CalculatesBookingRefundAmount.php | 2 +- .../forms/PurchaseOrderFormComponent.vue | 10 ++--- .../views/pages/dashboards/admin.blade.php | 14 ++++++- routes/web.php | 39 +++++++++++++++---- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 75ad76a1..062db191 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -73,6 +73,10 @@ 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; diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php index 239545af..8792aaa6 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php @@ -9,7 +9,7 @@ class CalculatesBookingRefundAmount { public function execute(Booking $booking, int $type, ?string $payment_reference = null): float { - $refundAmounts = $booking->transactions()->payments()->get()->map(function ($payment) use ($type) { + $refundAmounts = $booking->transactions()->payments()->complete()->get()->map(function ($payment) use ($type) { return $this->calculateRefundAmount($payment, $type); }); diff --git a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue index 8df6cfe3..3e0c9ca6 100644 --- a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue +++ b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue @@ -117,7 +117,7 @@
-
+
-
{{(Math.round(( poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3)}}/{{(Math.round((data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}} {{data.fixed_currency.short_code}}
+
{{(Math.round(( poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3)}}/{{(Math.round((data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}} {{data.fixed_currency.short_code}}
- +
-
+
** you purchase order will be saved but wont be approved until your purchase order's total matches your transfer order's total.
@@ -285,7 +285,7 @@ this.submit(route('api.transaction.po.import', this.data.id), 'post', this.section, true, true); }, successHandler(){ - if((Math.round((this.poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) === (Math.round((this.data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)){ + if((Math.round((this.poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) === (Math.round((this.data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)){ this.submitted = true; } this.updateList() diff --git a/resources/views/pages/dashboards/admin.blade.php b/resources/views/pages/dashboards/admin.blade.php index 25a2500e..ac41424c 100644 --- a/resources/views/pages/dashboards/admin.blade.php +++ b/resources/views/pages/dashboards/admin.blade.php @@ -105,7 +105,7 @@ Fully Refund
@@ -123,6 +123,11 @@
Partial Refund
+
@@ -142,7 +147,7 @@ Fully Refund
@@ -160,6 +165,11 @@
Partial Refund
+
diff --git a/routes/web.php b/routes/web.php index 2370a7fc..ade589a5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -433,13 +433,27 @@ Route::get('/pending_orders', function(){ echo ''; })->name('orders.pending'); -Route::get('/approve_refunds', function(){ +Route::get('/approve_refunds', function(Request $request){ + $type = $request->query('type'); $payments = Transaction::where('type', TransactionType::PAYMENT)->where('owner_type', Booking::class)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED]) - ->whereHas('transactions', function ($query) { - return $query->where('type', TransactionType::REFUND)->where('status', ApprovalStatus::APPROVED); - }) - ->orderBy('updated_at', 'DESC') - ->get(); + ->whereHas('transactions', function ($query) use ($type) { + $query->where('type', TransactionType::REFUND)->where('status', ApprovalStatus::APPROVED); + if (str_contains($type, 'partial')) { + $query->whereColumn('original_amount', '!=','transactions.original_amount'); + } else { + $query->whereColumn('original_amount', 'transactions.original_amount'); + } + }); + + if (str_contains($type, 'post')) { + $payments->whereHas('transactions', function($query) { + $query->where('type', TransactionType::SUPPLIER_REFUND); + }); + } else { + $payments->whereDoesntHave('transactions', function($query) { + $query->where('type', TransactionType::SUPPLIER_REFUND); + }); + } echo ''; echo ''; @@ -452,12 +466,13 @@ Route::get('/approve_refunds', function(){ echo ''; echo ''; echo ''; + echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; - foreach ($payments as $index => $payment){ + foreach ($payments->orderBy('updated_at', 'DESC')->get() as $index => $payment){ $booking = $payment->owner; $original_refunds = floatval((App()->make(CalculatesBookingRefundAmount::class))->calculateRefundAmount($payment, $booking->fix_currency_id)); $refunds = $original_refunds / $payment->currency_rate; @@ -471,6 +486,15 @@ Route::get('/approve_refunds', function(){ $bankType = str_word_count($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; } + $refundTransaction = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first(); + $remark = $refundTransaction->original_amount === $payment->original_amount ? 'Fully Refund' : 'Partial Refund'; + + if (str_contains($type, 'post')) { + $remark = 'Post ' . $remark; + } else { + $remark = 'Pre ' . $remark; + } + echo ''; echo ''; echo ''; @@ -483,6 +507,7 @@ Route::get('/approve_refunds', function(){ echo ''; echo ''; echo ''; + echo ''; echo ''; echo ''; echo '';
Refunded Original AmountRemarkServiceLast Updated AtBank TypeBank Holder Name
'.($index + 1).'.'.$payment->updated_at->format('d-M-y').''.$payment->original_currency->short_code.''.number_format($original_refunds, 5, '.', '').''.$remark.''.$booking->service->name.''.$payment->updated_at->diffForHumans().''.$bankType.'