fix fully refund booking with outstanding

This commit is contained in:
Jia Sheng
2024-08-12 21:18:48 +08:00
parent 08e56acc24
commit 7f40c3d718
@@ -108,30 +108,35 @@ 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;
$bookingAmountBeforeCurrentRefund = $booking->fix_amount - $refundInPending;
$bookingAmountAfterRefunded = $booking->fix_amount - $refundInPending - $request->input('amount');
$bookingAmountAfterRefunded = $booking->fix_amount - $refundInPending - $request->input('amount');
$isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount;
$isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount;
$voucherCode = null;
$voucherCode = null;
if ($transaction->voucherRedemption) {
$voucherCode = $transaction->voucherRedemption->voucher->code;
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;