mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
fix for multiple payments and discount order
This commit is contained in:
@@ -31,9 +31,20 @@
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->get()
|
||||
->sum(function ($transaction) {
|
||||
return $transaction->amount;
|
||||
return round($transaction->amount, 2);
|
||||
});
|
||||
|
||||
$average_currency_rate = $booking->transactions()
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->get()
|
||||
->sum(function ($transaction) {
|
||||
return $transaction->currency_rate;
|
||||
}) / $booking->transactions()
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->count();
|
||||
|
||||
$refundedAmount = (App()->make(CalculatesBookingRefundAmount::class))->execute($booking, 1);
|
||||
$refundedServiceCharge = (App()->make(CalculatesBookingRefundServiceCharge::class))->execute($booking, 1);
|
||||
|
||||
@@ -42,7 +53,7 @@
|
||||
|
||||
@foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
|
||||
@php
|
||||
$exactUnitPrice = ($currency_id) === 1 ? $transaction_detail->price : bcdiv($transaction_detail->price, $transaction->currency_rate, 7);
|
||||
$exactUnitPrice = ($currency_id) === 1 ? $transaction_detail->price : bcdiv($transaction_detail->price, $average_currency_rate, 7);
|
||||
$displayUnitPrice = round($exactUnitPrice, 2);
|
||||
$itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
|
||||
$displayedItemTotal = round(bcmul($displayUnitPrice, $transaction_detail->quantity, 7), 2);
|
||||
@@ -76,12 +87,13 @@
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Service Charges</td>
|
||||
<?php
|
||||
$serviceCharge = $transaction->service_charge;
|
||||
|
||||
// if has payment, calculate and deduct the refund
|
||||
if ($totalPayment) {
|
||||
$serviceCharge = $serviceCharge - $voucherDiscount;
|
||||
}
|
||||
$serviceCharge = $booking->transactions()
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('status', ApprovalStatus::COMPLETED)
|
||||
->get()
|
||||
->sum(function ($transaction) {
|
||||
return $transaction->service_charge;
|
||||
});
|
||||
?>
|
||||
<td class="right">{{ number_format($serviceCharge, 2) }}</td>
|
||||
</tr>
|
||||
@@ -90,8 +102,6 @@
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Refunded Service Charges</td>
|
||||
<?php
|
||||
$serviceCharge = $transaction->service_charge;
|
||||
|
||||
// if has payment, calculate and deduct the refund
|
||||
if ($totalPayment) {
|
||||
$serviceCharge = $serviceCharge - $refundedServiceCharge;
|
||||
@@ -134,6 +144,12 @@
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $serviceCharge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($expectedTotal, $displayedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $serviceCharge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
|
||||
if ($totalPayment) {
|
||||
$expectedTotal = $totalPayment;
|
||||
$discrepancy = bcsub($expectedTotal, $displayedTotal, 5);
|
||||
$total = $totalPayment;
|
||||
}
|
||||
@endphp
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
|
||||
Reference in New Issue
Block a user