Fix IPD discharge and bill print issues

This commit is contained in:
DevSoftTech Server 2026-06-14 14:34:33 +05:30
parent 4e8c5c691f
commit d4b4c95cbc
2 changed files with 55 additions and 5 deletions

View File

@ -6,7 +6,8 @@ $ipdItems = $ipd_invoice_items ?? [];
$showItems = $showinvoice ?? [];
$medicalItems = $inv_med_list ?? [];
$payments = $ipd_payment ?? [];
$billTotals = is_array($bill_totals ?? null) ? $bill_totals : [];
$rawBillTotals = $bill_totals ?? [];
$billTotals = is_array($rawBillTotals) ? $rawBillTotals : [];
$hasGrossTotal = array_key_exists('gross', $billTotals);
$hasNetTotal = array_key_exists('net', $billTotals);
$hasPaidTotal = array_key_exists('paid', $billTotals);
@ -91,6 +92,32 @@ if (! $hasBalanceTotal && $balanceAmount === 0.0 && $ipd) {
$balanceAmount = (float) ($ipd->balance_amount ?? 0);
}
$printAdjustments = [];
foreach ([1, 2, 3] as $slot) {
$amountField = $slot === 1 ? 'Discount' : 'Discount' . $slot;
$remarkField = $slot === 1 ? 'Discount_Remark' : 'Discount_Remark' . $slot;
$amount = (float) ($ipd->{$amountField} ?? 0);
if ($amount > 0) {
$printAdjustments[] = [
'label' => 'Deduction',
'remark' => (string) ($ipd->{$remarkField} ?? ''),
'amount' => $amount,
];
}
}
foreach ([1, 2] as $slot) {
$amountField = 'chargeamount' . $slot;
$remarkField = 'charge' . $slot;
$amount = (float) ($ipd->{$amountField} ?? 0);
if ($amount > 0) {
$printAdjustments[] = [
'label' => 'Charge',
'remark' => (string) ($ipd->{$remarkField} ?? ''),
'amount' => $amount,
];
}
}
$patientAddress = trim((string) (($person->add1 ?? '') . ' ' . ($person->add2 ?? '') . ' ' . ($person->city ?? '') . ' ' . ($person->state ?? '')));
$patientAddress = preg_replace('/\s+/', ' ', $patientAddress ?? '');
@ -298,6 +325,21 @@ $billHeadingText = $isDischargeFinal
<?php if ($mode3ShowAmountAfterDiscount) : ?><td class="right"></td><?php endif; ?>
</tr>
<?php foreach ($printAdjustments as $adjustment) : ?>
<tr>
<td></td>
<td colspan="<?= $mode3ShowAmountAfterDiscount ? '3' : '2' ?>">
<?php if ($adjustment['remark'] !== '') : ?>
Remark :<br><?= esc($adjustment['remark']) ?>
<?php endif; ?>
</td>
<td></td>
<td class="right totalline"><?= esc($adjustment['label']) ?></td>
<td class="right"><?= esc(number_format((float) $adjustment['amount'], 2)) ?></td>
<?php if ($mode3ShowAmountAfterDiscount) : ?><td></td><?php endif; ?>
</tr>
<?php endforeach; ?>
<tr class="totalline">
<td></td>
<td colspan="<?= $mode3ShowAmountAfterDiscount ? '5' : '4' ?>" class="right">Net Amount</td>

View File

@ -193,7 +193,9 @@ $canManageIpdStatus = auth()->user()?->can('billing.ipd.status.manage') ?? false
});
}
$(document).on('click', '#tab_discharge_content .js-update-discount', function() {
$(document)
.off('click', '#tab_discharge_content .js-update-discount')
.on('click.ipdDischargeProcess', '#tab_discharge_content .js-update-discount', function() {
var slot = Number($(this).data('slot') || 0);
if (slot < 1 || slot > 3) {
return;
@ -208,7 +210,9 @@ $canManageIpdStatus = auth()->user()?->can('billing.ipd.status.manage') ?? false
});
});
$(document).on('click', '#tab_discharge_content .js-update-charge', function() {
$(document)
.off('click', '#tab_discharge_content .js-update-charge')
.on('click.ipdDischargeProcess', '#tab_discharge_content .js-update-charge', function() {
var slot = Number($(this).data('slot') || 0);
if (slot < 1 || slot > 2) {
return;
@ -223,7 +227,9 @@ $canManageIpdStatus = auth()->user()?->can('billing.ipd.status.manage') ?? false
});
});
$(document).on('click', '#tab_discharge_content #btn-update-discharge-process', function() {
$(document)
.off('click', '#tab_discharge_content #btn-update-discharge-process')
.on('click.ipdDischargeProcess', '#tab_discharge_content #btn-update-discharge-process', function() {
var status = Number($('#discharge_status').val() || 0);
var disTime = String($('#discharge_time').val() || '').trim();
if (status === 0) {
@ -248,7 +254,9 @@ $canManageIpdStatus = auth()->user()?->can('billing.ipd.status.manage') ?? false
});
});
$(document).on('click', '#tab_discharge_content .js-toggle-ipd-status', function() {
$(document)
.off('click', '#tab_discharge_content .js-toggle-ipd-status')
.on('click.ipdDischargeProcess', '#tab_discharge_content .js-toggle-ipd-status', function() {
var currentStatus = Number($(this).data('current') || 0);
var newStatus = currentStatus === 0 ? 1 : 0;
var action = newStatus === 1 ? 'lock bills (set discharged)' : 'unlock bills (set active)';