diff --git a/resources/views/pages/pdfs/purchase_order_table.blade.php b/resources/views/pages/pdfs/purchase_order_table.blade.php index 62f2f2d1..14c70333 100644 --- a/resources/views/pages/pdfs/purchase_order_table.blade.php +++ b/resources/views/pages/pdfs/purchase_order_table.blade.php @@ -18,6 +18,26 @@ $currency_id = $transaction->owner->fix_currency_id; @endphp + owner; + $paymentSum = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->where('status', ApprovalStatus::COMPLETED) + ->get() + ->sum(function ($transaction) { + return round($transaction->amount, 2); + }); + + $refundedAmount = (App()->make(CalculatesBookingRefundAmount::class))->calculateRefundAmount($booking, $booking->fix_currency_id); + + $totalPayment = $paymentSum - $refundedAmount; + ?> + @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); @@ -55,10 +75,9 @@ Service Charges service_charge; - if (isset($current_paid_amount)) { - $refundedServiceCharge = $subtotal + $serviceCharge - $current_paid_amount; - $serviceCharge = $serviceCharge - $refundedServiceCharge - $voucherDiscount; - } + $current_paid_amount = $totalPayment; + $refundedServiceCharge = $subtotal + $serviceCharge - $current_paid_amount; + $serviceCharge = $serviceCharge - $refundedServiceCharge - $voucherDiscount; ?> {{ number_format($serviceCharge, 2) }}