@@ -65,33 +66,104 @@ $csrfHash = csrf_hash();
var ipdMedicalBillsUpdateUrl = '= site_url('billing/ipd/medical-bill/credit-type') ?>';
var ipdMedicalBillsDetailsUrl = '= site_url('billing/ipd/medical-bill') ?>';
- function ipdMedicalBillsToggleType(checkbox, invoiceId) {
- var label = document.querySelector('label[for="' + checkbox.id + '"]');
+ function ipdMedicalBillsChangeType(select, invoiceId) {
+ var val = parseInt(select.value, 10);
+ var badge = document.getElementById('badge-bill-type-' + invoiceId);
var payload = {
ipd_id: ipdMedicalBillsIpdId,
- ipd_credit_type: checkbox.checked ? 1 : 0
+ ipd_credit_type: val
};
payload[ipdMedicalBillsCsrfName] = ipdMedicalBillsCsrfHash;
- checkbox.disabled = true;
+ select.disabled = true;
+
+ if (badge) {
+ badge.className = 'badge bg-secondary-subtle text-secondary border border-secondary';
+ badge.textContent = 'Updating...';
+ }
$.post(ipdMedicalBillsUpdateUrl + '/' + invoiceId, payload, function(resp) {
if (!resp || !resp.ok) {
- checkbox.checked = !checkbox.checked;
+ select.value = val === 1 ? '0' : '1';
alert((resp && resp.error) ? resp.error : 'Unable to update medical bill type.');
return;
}
- label.textContent = checkbox.checked ? 'Include in Bill' : 'In Package';
+
+ var isIncluded = val === 1;
+ if (badge) {
+ badge.className = isIncluded
+ ? 'badge bg-success-subtle text-success border border-success'
+ : 'badge bg-warning-subtle text-warning border border-warning';
+ badge.textContent = isIncluded ? 'Include in Bill' : 'In Package';
+ }
+
+ // Real-time update top dashboard summary numbers
+ if (resp.summary) {
+ ipdMedicalBillsUpdateDashboardCards(resp.summary);
+ }
+
+ // Invalidate Bill Details tab so it loads fresh calculated data when clicked
+ var billPanel = document.getElementById('tab_bill_content');
+ if (billPanel) {
+ billPanel.innerHTML = 'Loading...';
+ }
+
+ if (typeof window.notify === 'function') {
+ window.notify('success', 'Medical Bill', isIncluded ? 'Bill marked as Include in IPD Bill' : 'Bill marked as In Package');
+ }
}).fail(function(xhr) {
- checkbox.checked = !checkbox.checked;
+ select.value = val === 1 ? '0' : '1';
var message = xhr.responseJSON && xhr.responseJSON.error
? xhr.responseJSON.error
: 'Unable to update medical bill type.';
alert(message);
}).always(function() {
- checkbox.disabled = false;
+ select.disabled = false;
});
}
+ function ipdMedicalBillsUpdateDashboardCards(s) {
+ var orangeCard = document.querySelector('.ipd-summary-card.orange');
+ if (orangeCard) {
+ var spans = orangeCard.querySelectorAll('span');
+ spans.forEach(function(sp) {
+ var txt = sp.textContent || '';
+ if (txt.indexOf('Charges') >= 0 && s.charge_amount !== undefined) {
+ sp.textContent = 'Charges : ' + s.charge_amount;
+ } else if (txt.indexOf('Pharmacy Cr. IPD') >= 0 && s.med_amount !== undefined) {
+ sp.textContent = 'Pharmacy Cr. IPD : ' + s.med_amount;
+ } else if (txt.indexOf('Net Amount') >= 0 && s.net_amount !== undefined) {
+ sp.textContent = 'Net Amount : ' + s.net_amount;
+ }
+ });
+ }
+
+ var greenCard = document.querySelector('.ipd-summary-card.green');
+ if (greenCard) {
+ var gSpans = greenCard.querySelectorAll('span');
+ gSpans.forEach(function(sp) {
+ var txt = sp.textContent || '';
+ if (txt.indexOf('Total Paid') >= 0 && s.total_paid_amount !== undefined) {
+ sp.textContent = 'Total Paid : ' + s.total_paid_amount;
+ } else if (txt.indexOf('Balance') >= 0 && s.balance_amount !== undefined) {
+ sp.textContent = 'Balance : ' + s.balance_amount;
+ }
+ });
+ }
+
+ var blueCard = document.querySelector('.ipd-summary-card.blue');
+ if (blueCard) {
+ var bSpans = blueCard.querySelectorAll('span');
+ bSpans.forEach(function(sp) {
+ var txt = sp.textContent || '';
+ if (txt.indexOf('Pharmacy Bill') >= 0 && s.cash_med_amount !== undefined) {
+ sp.textContent = 'Pharmacy Bill : ' + s.cash_med_amount;
+ } else if (txt.indexOf('Paid Amount') >= 0 && s.med_paid !== undefined) {
+ sp.textContent = 'Paid Amount : ' + s.med_paid;
+ }
+ });
+ }
+ }
+
function ipdMedicalBillsShowInvoice(button, invoiceId) {
var details = $('#ipd-medical-bill-details');
button.disabled = true;
diff --git a/app/Views/billing/ipd/panel_package.php b/app/Views/billing/ipd/panel_package.php
index 5768cb1..2b61377 100644
--- a/app/Views/billing/ipd/panel_package.php
+++ b/app/Views/billing/ipd/panel_package.php
@@ -324,7 +324,7 @@ $ayushmanChecklistItems = $ayushman_checklist_items ?? [];
Pharmacy Bills Package Mapping
- Unchecked = In Package, Checked = Include in Bill
+ Select whether pharmacy bill is covered In Package or billed to IPD