fix: recalculate IPD billing on panel open, bill-details, and print
This commit is contained in:
parent
9297849c8a
commit
d16a363a92
|
|
@ -177,6 +177,10 @@ class Ipd extends BaseController
|
|||
return $this->response->setStatusCode(404)->setBody('IPD not found');
|
||||
}
|
||||
|
||||
// Keep billing snapshot fresh on every panel open (legacy behavior parity).
|
||||
$this->recalculateIpdBillingSafely($ipdId, 'panel.open');
|
||||
$panelData = $this->ipdModel->getIpdPanelInfo($ipdId);
|
||||
|
||||
return view('billing/ipd/panel', $panelData);
|
||||
}
|
||||
|
||||
|
|
@ -547,6 +551,8 @@ class Ipd extends BaseController
|
|||
}
|
||||
|
||||
if ($tab === 'bill-details') {
|
||||
$this->recalculateIpdBillingSafely($ipdId, 'panel.tab.bill-details');
|
||||
$panelData = $this->ipdModel->getIpdPanelInfo($ipdId);
|
||||
return view('billing/ipd/panel_bill_details', $this->buildBillDetailsTabData($panelData, $ipdId));
|
||||
}
|
||||
|
||||
|
|
@ -883,6 +889,10 @@ class Ipd extends BaseController
|
|||
return $this->response->setStatusCode(404)->setBody('IPD not found');
|
||||
}
|
||||
|
||||
// Recalculate before print so PDF always reflects latest bill math.
|
||||
$this->recalculateIpdBillingSafely($ipdId, 'bill.print');
|
||||
$panelData = $this->ipdModel->getIpdPanelInfo($ipdId);
|
||||
|
||||
$mode = max(1, min(6, $mode));
|
||||
$data = $this->buildBillDetailsTabData($panelData, $ipdId);
|
||||
$data['show_print_actions'] = false;
|
||||
|
|
@ -2696,6 +2706,16 @@ class Ipd extends BaseController
|
|||
];
|
||||
}
|
||||
|
||||
private function recalculateIpdBillingSafely(int $ipdId, string $context): void
|
||||
{
|
||||
try {
|
||||
$this->ipdEditModel->calculateIPD($ipdId);
|
||||
} catch (\Throwable $e) {
|
||||
// Do not break UI render if recalculation fails; log for diagnostics.
|
||||
log_message('error', 'IPD calculateIPD failed for IPD #' . $ipdId . ' [' . $context . ']: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function buildBillDetailsTabData(array $panelData, int $ipdId): array
|
||||
{
|
||||
$panelData['ipd_packages'] = $this->ipdModel->getIpdPackages($ipdId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user