From 6782aee1a411d8dd475c5a8a286165f90d3be76c Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Fri, 10 Apr 2026 21:03:17 +0530 Subject: [PATCH] fix: use computed item totals for IPD gross/net in bill views --- app/Views/billing/ipd/bill_print.php | 18 +++++++++--------- app/Views/billing/ipd/panel_bill_details.php | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/Views/billing/ipd/bill_print.php b/app/Views/billing/ipd/bill_print.php index 134fe52..5173f44 100644 --- a/app/Views/billing/ipd/bill_print.php +++ b/app/Views/billing/ipd/bill_print.php @@ -66,14 +66,14 @@ if ($dischargeTimeText !== '') { $dischargeDateText = trim($dischargeDateText . ' ' . substr($dischargeTimeText, 0, 5)); } -$grossAmount = (float) ($ipd->gross_amount ?? 0); -if ($grossAmount <= 0) { - $grossAmount = (float) ($billTotals['gross'] ?? 0); +$grossAmount = (float) ($billTotals['gross'] ?? 0); +if ($grossAmount <= 0 && $ipd) { + $grossAmount = (float) ($ipd->gross_amount ?? 0); } -$netAmount = (float) ($ipd->net_amount ?? 0); -if ($netAmount <= 0) { - $netAmount = (float) ($billTotals['net'] ?? 0); +$netAmount = (float) ($billTotals['net'] ?? 0); +if ($netAmount <= 0 && $ipd) { + $netAmount = (float) ($ipd->net_amount ?? 0); } $paidAmount = (float) ($billTotals['paid'] ?? 0); @@ -81,9 +81,9 @@ if ($paidAmount <= 0) { $paidAmount = (float) ($ipd->total_paid_amount ?? 0); } -$balanceAmount = (float) ($ipd->balance_amount ?? 0); -if ($balanceAmount <= 0) { - $balanceAmount = (float) ($billTotals['balance'] ?? 0); +$balanceAmount = (float) ($billTotals['balance'] ?? 0); +if ($balanceAmount === 0.0 && $ipd) { + $balanceAmount = (float) ($ipd->balance_amount ?? 0); } $patientAddress = trim((string) (($person->add1 ?? '') . ' ' . ($person->add2 ?? '') . ' ' . ($person->city ?? '') . ' ' . ($person->state ?? ''))); diff --git a/app/Views/billing/ipd/panel_bill_details.php b/app/Views/billing/ipd/panel_bill_details.php index 850be00..b23bab4 100644 --- a/app/Views/billing/ipd/panel_bill_details.php +++ b/app/Views/billing/ipd/panel_bill_details.php @@ -18,17 +18,18 @@ $balanceTotal = (float) ($billTotals['balance'] ?? 0); $showPrintActions = (bool) ($show_print_actions ?? true); $canPrintBill = (bool) ($can_print_bill ?? false); $showPaymentDetails = (bool) ($show_payment_details ?? true); -$grossAmount = (float) ($ipd->gross_amount ?? 0); -$netAmount = (float) ($ipd->net_amount ?? 0); - $balanceAmount = (float) ($ipd->balance_amount ?? 0); -if ($grossAmount <= 0) { - $grossAmount = (float) ($billTotals['gross'] ?? 0); +$grossAmount = (float) ($billTotals['gross'] ?? 0); +$netAmount = (float) ($billTotals['net'] ?? 0); +$balanceAmount = $balanceTotal; + +if ($grossAmount <= 0 && $ipd) { + $grossAmount = (float) ($ipd->gross_amount ?? 0); } -if ($netAmount <= 0) { - $netAmount = (float) ($billTotals['net'] ?? 0); +if ($netAmount <= 0 && $ipd) { + $netAmount = (float) ($ipd->net_amount ?? 0); } -if ($balanceAmount <= 0) { - $balanceAmount = $balanceTotal; +if ($balanceAmount === 0.0 && $ipd) { + $balanceAmount = (float) ($ipd->balance_amount ?? 0); } $isDischargeFinal = (int) ($ipd->discarge_patient_status ?? 0) > 0; $billHeaderTitle = $isDischargeFinal ? 'Bill No. : ' . (string) ($ipd->ipd_code ?? '') : 'IPD Invoice';