From a36b6f5e57d3c2010b53213c3ad16a9f71fa6ece Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Mon, 12 Aug 2024 10:48:35 +0800 Subject: [PATCH 1/4] Comments on code --- app/Http/Resources/ListTransactionJobResource.php | 2 ++ app/Http/Resources/PaymentTransactionResource.php | 2 ++ app/Http/Resources/TransactionResource.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/app/Http/Resources/ListTransactionJobResource.php b/app/Http/Resources/ListTransactionJobResource.php index b8908ee6..1547c09e 100644 --- a/app/Http/Resources/ListTransactionJobResource.php +++ b/app/Http/Resources/ListTransactionJobResource.php @@ -18,6 +18,7 @@ class ListTransactionJobResource extends JsonResource { $booking = null; //cief todo: 66 $bank = null; + //Check if Transaction of type PAYMENT has an override for recipient bank - starts if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])){ $booking = $this->owner->owner; $bank = $this->owner->bank ?? $booking->bank; @@ -26,6 +27,7 @@ class ListTransactionJobResource extends JsonResource $booking = $this->owner; $bank = $this->bank ?? $booking->bank; } + //Check if Transaction of type PAYMENT has an override for recipient bank - ends $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ diff --git a/app/Http/Resources/PaymentTransactionResource.php b/app/Http/Resources/PaymentTransactionResource.php index d0549c38..01da84b2 100644 --- a/app/Http/Resources/PaymentTransactionResource.php +++ b/app/Http/Resources/PaymentTransactionResource.php @@ -20,6 +20,7 @@ class PaymentTransactionResource extends JsonResource { $booking = null; //cief todo: 66 $bank = null; + //Check if Transaction of type PAYMENT has an override for recipient bank - starts if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])){ $booking = $this->owner->owner; $bank = $this->owner->bank ?? $booking->bank; @@ -28,6 +29,7 @@ class PaymentTransactionResource extends JsonResource $booking = $this->owner; $bank = $this->bank ?? $booking->bank; } + //Check if Transaction of type PAYMENT has an override for recipient bank - ends $booking_marking = ''; switch ($this->owner_type) { diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 595ce443..e14c32c0 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -21,6 +21,7 @@ class TransactionResource extends JsonResource { $booking = null; //cief todo: 66 $bank = null; + //Check if Transaction of type PAYMENT has an override for recipient bank - starts if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND, TransactionType::SUPPLIER_REFUND])){ $booking = $this->owner->owner; $bank = $this->owner->bank ?? $booking->bank; @@ -29,6 +30,7 @@ class TransactionResource extends JsonResource $booking = $this->owner; $bank = $this->bank ?? $booking->bank; } + //Check if Transaction of type PAYMENT has an override for recipient bank - ends $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ From a6174c61bf1399fd22e24a63a2ce8f5ff99962a5 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 12 Aug 2024 14:10:35 +0800 Subject: [PATCH 2/4] revert update on pending_orders --- routes/web.php | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/routes/web.php b/routes/web.php index b2067c6e..32038ed2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -400,27 +400,10 @@ Route::get('/pending_orders', function(){ ->whereDoesntHave('transactions', function ($query) { return $query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]); }) - ->orderBy('updated_at', 'desc') + // ->orderBy('updated_at', 'desc') ->get(); - - echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; - // echo ''; + + echo '
Client Booking DatePayment TypeMarkingCustomer Payment CurrencyCustomer Payment AmountReference No.Booking Amount CurrencyCNYServiceDaysCust Supplier Acc TypeCust Supplier Acc Name
'; $i = 0; foreach ($payments as $payment){ $booking = $payment->owner; @@ -440,17 +423,19 @@ Route::get('/pending_orders', function(){ echo ''; echo ''; - echo ''; echo ''; + echo ''; echo ''; echo ''; echo ''; + echo ''; echo ''; echo ''; + echo ''; echo ''; echo ''; echo ''; - echo ''; + echo ''; echo ''; } echo '
'.$payment->updated_at->format('d-M-y').''.\App\Classes\ValueObjects\Constants\PaymentMethodType::PAYMENT_METHODS_ID[$payment->payment_method].''.$booking->marking.''.\App\Classes\ValueObjects\Constants\PaymentMethodType::PAYMENT_METHODS_ID[$payment->payment_method].''.$payment->currency->short_code.''.number_format(bcsub($payment->amount, $refunds, 7), 5, '.', '').''.$booking->company->reference.''.$payment->original_currency->short_code.''.number_format(bcsub($payment->original_amount, $original_refunds, 7), 5, '.', '').''.$booking->service->name.''.$payment->updated_at->diffForHumans().''.$bankType.''.$bank->holder_name.''.$booking->bank->holder_name.'
'; From 08e56acc2438ad88503df9504a2d82b6cbfe37e7 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 12 Aug 2024 14:17:07 +0800 Subject: [PATCH 3/4] update pending_orders, order by updated_at desc --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 32038ed2..112dee31 100644 --- a/routes/web.php +++ b/routes/web.php @@ -400,7 +400,7 @@ Route::get('/pending_orders', function(){ ->whereDoesntHave('transactions', function ($query) { return $query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]); }) - // ->orderBy('updated_at', 'desc') + ->orderBy('updated_at', 'desc') ->get(); echo ''; From 03472dc6be8969b84750a43ab5e7220a0938ec05 Mon Sep 17 00:00:00 2001 From: Jia Sheng Date: Mon, 12 Aug 2024 21:25:48 +0800 Subject: [PATCH 4/4] fix fully refund oustanding --- .../CreateBookingRefundLogic.php | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 8c492eb1..6c2ab63a 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -108,29 +108,34 @@ class CreateBookingRefundLogic extends AbstractControllerLogic // $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount')); // $transactionRefundCalculationObject->init(); - $refundAmount = bcdiv($request->input('amount'), $transaction->currency_rate, 7); + if ((float)$request->input('amount') === (float)$transaction->original_amount) { + $refundAmount = $transaction->original_amount / $transaction->currency_rate; + $service_charges_to_refund = $transaction->service_charge; + } else { + $refundAmount = bcdiv($request->input('amount'), $transaction->currency_rate, 7); - $bookingAmountBeforeCurrentRefund = $booking->fix_amount - $refundInPending; - - $bookingAmountAfterRefunded = $booking->fix_amount - $refundInPending - $request->input('amount'); - - $isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount; - - $voucherCode = null; - - if ($transaction->voucherRedemption) { - $voucherCode = $transaction->voucherRedemption->voucher->code; + $bookingAmountBeforeCurrentRefund = $booking->fix_amount - $refundInPending; + + $bookingAmountAfterRefunded = $booking->fix_amount - $refundInPending - $request->input('amount'); + + $isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount; + + $voucherCode = null; + + if ($transaction->voucherRedemption) { + $voucherCode = $transaction->voucherRedemption->voucher->code; + } + + $conversionObjectBeforeCurrentRefund = new CurrencyConversionObject($bookingAmountBeforeCurrentRefund, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method); + + $conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $request->input('amount') : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method); + + $quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode); + + $quotationAfterRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectAfterRefund, $voucherCode); + + $service_charges_to_refund = $isFullyRefund ? $quotationBeforeCurrentRefund->getServiceCharge() : $quotationBeforeCurrentRefund->getServiceCharge() - $quotationAfterRefund->getServiceCharge(); } - - $conversionObjectBeforeCurrentRefund = new CurrencyConversionObject($bookingAmountBeforeCurrentRefund, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method); - - $conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $request->input('amount') : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method); - - $quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode); - - $quotationAfterRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectAfterRefund, $voucherCode); - - $service_charges_to_refund = $isFullyRefund ? $quotationBeforeCurrentRefund->getServiceCharge() : $quotationBeforeCurrentRefund->getServiceCharge() - $quotationAfterRefund->getServiceCharge(); // refund service charges if booking is not E2E $refundTotal = $refundAmount;