diff --git a/app/Views/billing/ipd/bill_print.php b/app/Views/billing/ipd/bill_print.php index 5173f44..37c8fc2 100644 --- a/app/Views/billing/ipd/bill_print.php +++ b/app/Views/billing/ipd/bill_print.php @@ -6,7 +6,11 @@ $ipdItems = $ipd_invoice_items ?? []; $showItems = $showinvoice ?? []; $medicalItems = $inv_med_list ?? []; $payments = $ipd_payment ?? []; -$billTotals = $bill_totals ?? ['gross' => 0, 'net' => 0, 'paid' => 0, 'balance' => 0]; +$billTotals = is_array($bill_totals ?? null) ? $bill_totals : []; +$hasGrossTotal = array_key_exists('gross', $billTotals); +$hasNetTotal = array_key_exists('net', $billTotals); +$hasPaidTotal = array_key_exists('paid', $billTotals); +$hasBalanceTotal = array_key_exists('balance', $billTotals); $printMode = (int) ($print_mode ?? 1); $showPaymentDetails = (bool) ($show_payment_details ?? true); @@ -66,23 +70,23 @@ if ($dischargeTimeText !== '') { $dischargeDateText = trim($dischargeDateText . ' ' . substr($dischargeTimeText, 0, 5)); } -$grossAmount = (float) ($billTotals['gross'] ?? 0); -if ($grossAmount <= 0 && $ipd) { +$grossAmount = $hasGrossTotal ? (float) ($billTotals['gross'] ?? 0) : (float) ($ipd->gross_amount ?? 0); +if (! $hasGrossTotal && $grossAmount <= 0 && $ipd) { $grossAmount = (float) ($ipd->gross_amount ?? 0); } -$netAmount = (float) ($billTotals['net'] ?? 0); -if ($netAmount <= 0 && $ipd) { +$netAmount = $hasNetTotal ? (float) ($billTotals['net'] ?? 0) : (float) ($ipd->net_amount ?? 0); +if (! $hasNetTotal && $netAmount <= 0 && $ipd) { $netAmount = (float) ($ipd->net_amount ?? 0); } -$paidAmount = (float) ($billTotals['paid'] ?? 0); -if ($paidAmount <= 0) { +$paidAmount = $hasPaidTotal ? (float) ($billTotals['paid'] ?? 0) : (float) ($ipd->total_paid_amount ?? 0); +if (! $hasPaidTotal && $paidAmount <= 0) { $paidAmount = (float) ($ipd->total_paid_amount ?? 0); } -$balanceAmount = (float) ($billTotals['balance'] ?? 0); -if ($balanceAmount === 0.0 && $ipd) { +$balanceAmount = $hasBalanceTotal ? (float) ($billTotals['balance'] ?? 0) : (float) ($ipd->balance_amount ?? 0); +if (! $hasBalanceTotal && $balanceAmount === 0.0 && $ipd) { $balanceAmount = (float) ($ipd->balance_amount ?? 0); } diff --git a/app/Views/billing/ipd/panel_bill_details.php b/app/Views/billing/ipd/panel_bill_details.php index b23bab4..d8089cf 100644 --- a/app/Views/billing/ipd/panel_bill_details.php +++ b/app/Views/billing/ipd/panel_bill_details.php @@ -12,25 +12,35 @@ if ($ipd) { $discountTotal = (float) ($ipd->Discount ?? 0) + (float) ($ipd->Discount2 ?? 0) + (float) ($ipd->Discount3 ?? 0); $extraCharge = (float) ($ipd->chargeamount1 ?? 0) + (float) ($ipd->chargeamount2 ?? 0); } -$billTotals = $bill_totals ?? ['gross' => 0.0, 'net' => 0.0]; -$paidTotal = (float) ($billTotals['paid'] ?? 0); -$balanceTotal = (float) ($billTotals['balance'] ?? 0); +$billTotals = is_array($bill_totals ?? null) ? $bill_totals : []; +$hasGrossTotal = array_key_exists('gross', $billTotals); +$hasNetTotal = array_key_exists('net', $billTotals); +$hasPaidTotal = array_key_exists('paid', $billTotals); +$hasBalanceTotal = array_key_exists('balance', $billTotals); +$paidTotal = $hasPaidTotal ? (float) ($billTotals['paid'] ?? 0) : (float) ($ipd->total_paid_amount ?? 0); +$balanceTotal = $hasBalanceTotal ? (float) ($billTotals['balance'] ?? 0) : (float) ($ipd->balance_amount ?? 0); $showPrintActions = (bool) ($show_print_actions ?? true); $canPrintBill = (bool) ($can_print_bill ?? false); $showPaymentDetails = (bool) ($show_payment_details ?? true); -$grossAmount = (float) ($billTotals['gross'] ?? 0); -$netAmount = (float) ($billTotals['net'] ?? 0); +$grossAmount = $hasGrossTotal ? (float) ($billTotals['gross'] ?? 0) : (float) ($ipd->gross_amount ?? 0); +$netAmount = $hasNetTotal ? (float) ($billTotals['net'] ?? 0) : (float) ($ipd->net_amount ?? 0); $balanceAmount = $balanceTotal; -if ($grossAmount <= 0 && $ipd) { +if (! $hasGrossTotal && $grossAmount <= 0 && $ipd) { $grossAmount = (float) ($ipd->gross_amount ?? 0); } -if ($netAmount <= 0 && $ipd) { +if (! $hasNetTotal && $netAmount <= 0 && $ipd) { $netAmount = (float) ($ipd->net_amount ?? 0); } -if ($balanceAmount === 0.0 && $ipd) { +if (! $hasBalanceTotal && $balanceAmount === 0.0 && $ipd) { $balanceAmount = (float) ($ipd->balance_amount ?? 0); } +$payableByTpa = (float) ($ipd->payable_by_tpa ?? 0); +$discountForTpa = (float) ($ipd->discount_for_tpa ?? 0); +$discountByHospital = (float) ($ipd->discount_by_hospital ?? 0); +$discountByHospital2 = (float) ($ipd->discount_by_hospital_2 ?? 0); +$hasFinalAdjustments = $payableByTpa > 0 || $discountForTpa > 0 || $discountByHospital > 0 || $discountByHospital2 > 0; +$finalBalanceAmount = $hasFinalAdjustments ? (float) ($ipd->balance_discount_after ?? $balanceAmount) : $balanceAmount; $isDischargeFinal = (int) ($ipd->discarge_patient_status ?? 0) > 0; $billHeaderTitle = $isDischargeFinal ? 'Bill No. : ' . (string) ($ipd->ipd_code ?? '') : 'IPD Invoice'; ?> @@ -296,40 +306,40 @@ $billHeaderTitle = $isDischargeFinal ? 'Bill No. : ' . (string) ($ipd->ipd_code