From bdae843f0a8d66a235d8ccef31ead6bcb7897100 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Fri, 10 Jul 2026 22:52:33 +0530 Subject: [PATCH] Fix duplicate OPD invoice payment redirect handling --- app/Views/billing/opd_invoice_V.php | 114 +++++++++++++++++++++------- 1 file changed, 86 insertions(+), 28 deletions(-) diff --git a/app/Views/billing/opd_invoice_V.php b/app/Views/billing/opd_invoice_V.php index 7945f21..fb8b411 100644 --- a/app/Views/billing/opd_invoice_V.php +++ b/app/Views/billing/opd_invoice_V.php @@ -362,16 +362,44 @@ $paymentHistoryRows = $payment_history_rows ?? []; } } - $('#btn_update0').click(function() { + function getInvoiceIdOrWarn() { + var raw = $('#oid').val(); + var invoiceId = parseInt(raw, 10); + if (!Number.isFinite(invoiceId) || invoiceId <= 0) { + console.error('Invalid OPD invoice id', { raw: raw }); + if (typeof notify === 'function') { + notify('error', 'Please Attention', 'Invalid invoice id. Please reload and try again.'); + } else { + $('div.jsError').html('Invalid invoice id. Please reload and try again.'); + } + return null; + } + return invoiceId; + } + + function reloadCurrentInvoice() { + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + return; + } + load_form('/' + oid); + } + + $('#btn_update0').off('click.opdInvoice').on('click.opdInvoice', function() { $('#btn_update1').prop('disabled', true); $('#btn_update2').prop('disabled', true); var csrf = getCsrfPair(); var spid = $('#spid').val(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + setTimeout(enable_btn, 500); + return; + } if (confirm('Are you sure process this invoice')) { $.post('', { "mode": "0", - "oid": $('#oid').val(), + "oid": oid, "spid": spid, [csrf.name]: csrf.value }, function(data) { @@ -379,7 +407,7 @@ $paymentHistoryRows = $payment_history_rows ?? []; if (data.update == 0) { $('div.jsError').html(data.error_text); } else { - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); } }, 'json'); } else { @@ -387,16 +415,21 @@ $paymentHistoryRows = $payment_history_rows ?? []; } }); - $('#btn_update1').click(function() { + $('#btn_update1').off('click.opdInvoice').on('click.opdInvoice', function() { $('#btn_update1').prop('disabled', true); $('#btn_update2').prop('disabled', true); var csrf = getCsrfPair(); var spid = $('#spid').val(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + setTimeout(enable_btn, 500); + return; + } if (confirm('Are you sure process this invoice')) { $.post('', { "mode": "1", - "oid": $('#oid').val(), + "oid": oid, "spid": spid, [csrf.name]: csrf.value }, function(data) { @@ -404,7 +437,7 @@ $paymentHistoryRows = $payment_history_rows ?? []; if (data.update == 0) { $('div.jsError').html(data.error_text); } else { - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); } }, 'json'); } else { @@ -412,16 +445,21 @@ $paymentHistoryRows = $payment_history_rows ?? []; } }); - $('#btn_update2').click(function() { + $('#btn_update2').off('click.opdInvoice').on('click.opdInvoice', function() { $('#btn_update1').prop('disabled', true); $('#btn_update2').prop('disabled', true); var csrf = getCsrfPair(); var spid = $('#spid').val(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + setTimeout(enable_btn, 500); + return; + } if (confirm('Are you sure process this invoice')) { $.post('', { "mode": "2", - "oid": $('#oid').val(), + "oid": oid, "cbo_pay_type": $('#cbo_pay_type').val(), "input_card_tran": $('#input_card_tran').val(), "spid": spid, @@ -434,7 +472,7 @@ $paymentHistoryRows = $payment_history_rows ?? []; } setTimeout(enable_btn, 5000); } else { - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); } }, 'json'); } else { @@ -442,11 +480,15 @@ $paymentHistoryRows = $payment_history_rows ?? []; } }); - $('#btn_update4').click(function() { + $('#btn_update4').off('click.opdInvoice').on('click.opdInvoice', function() { var csrf = getCsrfPair(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + return; + } $.post('', { "mode": "4", - "oid": $('#oid').val(), + "oid": oid, "case_id": $('#hidden_case_id').val(), [csrf.name]: csrf.value }, function(data) { @@ -454,57 +496,73 @@ $paymentHistoryRows = $payment_history_rows ?? []; if (data.update == 0) { $('div.jsError').html(data.error_text); } else { - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); } }, 'json'); }); - $('#btn_update_ded').click(function() { + $('#btn_update_ded').off('click.opdInvoice').on('click.opdInvoice', function() { var csrf = getCsrfPair(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + return; + } if (confirm('Are you sure process this invoice')) { - $.post('/' + $('#oid').val(), { - "oid": $('#oid').val(), + $.post('/' + oid, { + "oid": oid, "input_dis_desc": $('#input_dis_desc').val(), "input_dis_amt": $('#input_dis_amt').val(), [csrf.name]: csrf.value }, function() { - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); }); } }); - $('#btn_cancel_opd').click(function() { + $('#btn_cancel_opd').off('click.opdInvoice').on('click.opdInvoice', function() { var csrf = getCsrfPair(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + return; + } if (confirm('Are you sure process this invoice')) { - $.post('/' + $('#oid').val(), { - "oid": $('#oid').val(), + $.post('/' + oid, { + "oid": oid, "input_remark": $('#input_remark').val(), [csrf.name]: csrf.value }, function(data) { updateCsrf(data); - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); }); } }); - $('#btn_cr_org').click(function() { + $('#btn_cr_org').off('click.opdInvoice').on('click.opdInvoice', function() { var csrf = getCsrfPair(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + return; + } if (confirm('Are you sure process this invoice')) { - $.post('/' + $('#oid').val() + '/' + $('#hid_org_id').val(), { - "oid": $('#oid').val(), + $.post('/' + oid + '/' + $('#hid_org_id').val(), { + "oid": oid, "org_code_id": $('#hid_org_id').val(), [csrf.name]: csrf.value }, function() { - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); }); } }); - $('#update_doc_date').click(function() { + $('#update_doc_date').off('click.opdInvoice').on('click.opdInvoice', function() { var csrf = getCsrfPair(); + var oid = getInvoiceIdOrWarn(); + if (oid === null) { + return; + } if (confirm('Are you sure process this invoice')) { - $.post('/' + $('#oid').val(), { - "oid": $('#oid').val(), + $.post('/' + oid, { + "oid": oid, "doc_name_id": $('#doc_name_id').val(), "opd_fee_amt": $('#input_opd_fee_amt').val(), "datepicker_opddate": $('#datepicker_opddate').val(), @@ -519,7 +577,7 @@ $paymentHistoryRows = $payment_history_rows ?? []; } return; } - load_form('/' + $('#oid').val()); + reloadCurrentInvoice(); }, 'json'); } });