Add safe load_form fallback and resilient invoice navigation

This commit is contained in:
DevSoftTech Server 2026-07-10 00:39:58 +05:30
parent 60d708c7b8
commit 644449b3de
3 changed files with 49 additions and 6 deletions

View File

@ -9,7 +9,7 @@
</div>
<div class="col-md-6 d-flex gap-2">
<button type="button" class="btn btn-primary" onclick="chargesInvoiceSearch()">Search</button>
<button type="button" class="btn btn-light" onclick="load_form('<?= base_url('Invoice/chargeslist') ?>','Charges Invoice')">Reset</button>
<button type="button" class="btn btn-light" onclick="navigateOrLoad('<?= base_url('Invoice/chargeslist') ?>','Charges Invoice')">Reset</button>
</div>
</form>
@ -42,7 +42,7 @@
<td><?= esc($invType) ?></td>
<td><?= esc(number_format((float) ($row->net_amount ?? 0), 2, '.', '')) ?></td>
<td>
<button type="button" class="btn btn-outline-primary btn-sm" onclick="load_form('<?= base_url('billing/charges/show') ?>/<?= (int) ($row->inv_id ?? 0) ?>','Charges Invoice');">Open</button>
<button type="button" class="btn btn-outline-primary btn-sm" onclick="navigateOrLoad('<?= base_url('billing/charges/show') ?>/<?= (int) ($row->inv_id ?? 0) ?>','Charges Invoice');">Open</button>
</td>
</tr>
<?php endforeach; ?>
@ -53,9 +53,17 @@
</div>
<script>
function navigateOrLoad(url, title) {
if (typeof window.load_form === 'function') {
window.load_form(url, title || '');
return;
}
window.location.href = url;
}
function chargesInvoiceSearch() {
var q = (document.getElementById('charges_invoice_search') || {}).value || '';
load_form('<?= base_url('Invoice/chargeslist') ?>?q=' + encodeURIComponent(q), 'Charges Invoice');
navigateOrLoad('<?= base_url('Invoice/chargeslist') ?>?q=' + encodeURIComponent(q), 'Charges Invoice');
}
(function() {

View File

@ -9,7 +9,7 @@
</div>
<div class="col-md-6 d-flex gap-2">
<button type="button" class="btn btn-primary" onclick="opdInvoiceSearch()">Search</button>
<button type="button" class="btn btn-light" onclick="load_form('<?= base_url('Invoice/opdlist') ?>','OPD Invoice')">Reset</button>
<button type="button" class="btn btn-light" onclick="navigateOrLoad('<?= base_url('Invoice/opdlist') ?>','OPD Invoice')">Reset</button>
</div>
</form>
@ -42,7 +42,7 @@
<td><?= esc((string) ($row->mphone1 ?? '-')) ?></td>
<td><?= esc($invType) ?></td>
<td>
<button type="button" class="btn btn-outline-primary btn-sm" onclick="load_form('<?= base_url('Opd/invoice') ?>/<?= (int) ($row->opd_id ?? 0) ?>','OPD Invoice');">Open</button>
<button type="button" class="btn btn-outline-primary btn-sm" onclick="navigateOrLoad('<?= base_url('Opd/invoice') ?>/<?= (int) ($row->opd_id ?? 0) ?>','OPD Invoice');">Open</button>
</td>
</tr>
<?php endforeach; ?>
@ -53,9 +53,17 @@
</div>
<script>
function navigateOrLoad(url, title) {
if (typeof window.load_form === 'function') {
window.load_form(url, title || '');
return;
}
window.location.href = url;
}
function opdInvoiceSearch() {
var q = (document.getElementById('opd_invoice_search') || {}).value || '';
load_form('<?= base_url('Invoice/opdlist') ?>?q=' + encodeURIComponent(q), 'OPD Invoice');
navigateOrLoad('<?= base_url('Invoice/opdlist') ?>?q=' + encodeURIComponent(q), 'OPD Invoice');
}
(function() {

View File

@ -31,6 +31,33 @@
<link href="<?= base_url('assets/css/style.css') ?>" rel="stylesheet">
<link href="<?= base_url('assets/css/custom-theme-dark-borders.css') ?>" rel="stylesheet">
<script>
// Early fallback so javascript:load_form(...) links never fail before full app scripts initialize.
if (typeof window.load_form !== 'function') {
window.load_form = function(ourl) {
if (ourl) {
window.location.href = ourl;
}
};
}
if (typeof window.load_form_div !== 'function') {
window.load_form_div = function(ourl, xdiv) {
if (!ourl) {
return;
}
if (!xdiv) {
window.location.href = ourl;
return;
}
var el = document.getElementById(String(xdiv));
if (el) {
el.innerHTML = '<div class="text-muted">Loading...</div>';
}
window.location.href = ourl;
};
}
</script>
</head>
<body>