automate and view gl entries
This commit is contained in:
+63
-3
@@ -256,11 +256,14 @@
|
||||
<td class="py-3 fw-semibold">${format_number(inv.grand_total, 2)}</td>
|
||||
<td class="py-3">${inv.due_date ? format_date(inv.due_date) : '<span class="text-muted">—</span>'}</td>
|
||||
<td class="py-3">${invoice_status_badge(inv.status, inv.due_date)}</td>
|
||||
<td class="py-3">
|
||||
<a href="<?php echo $server_url?>po/manage_purchase_invoice.php?id=${inv.id}" title="View">
|
||||
<td class="py-3 text-nowrap">
|
||||
<a href="<?php echo $server_url?>po/manage_purchase_invoice.php?id=${inv.id}" title="View" class="me-2">
|
||||
<i class="ti ti-eye fs-5"></i>
|
||||
</a>
|
||||
${can_delete ? `<a href="javascript:void(0);" class="link-danger ms-2" title="Delete" onclick="delete_invoice(${inv.id})"><i class="ti ti-trash fs-5"></i></a>` : ''}
|
||||
<a href="javascript:;" title="View GL Entry" class="me-2" onclick="show_gl_modal('${inv.doc_type}',${inv.id})">
|
||||
<i class="ti ti-book fs-5 text-secondary"></i>
|
||||
</a>
|
||||
${can_delete ? `<a href="javascript:void(0);" class="link-danger" title="Delete" onclick="delete_invoice(${inv.id})"><i class="ti ti-trash fs-5"></i></a>` : ''}
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
@@ -286,6 +289,47 @@
|
||||
});
|
||||
}
|
||||
|
||||
var _GL_SOURCE_LABELS = { invoice:'Invoice', credit_note:'Credit Note', purchase_invoice:'Purchase Invoice', supplier_credit_note:'Supplier Credit Note', receipt:'Receipt', payment:'Payment', manual:'Manual', reversal:'Reversal' };
|
||||
var _GL_SOURCE_BADGE = { invoice:'bg-success-subtle text-success', credit_note:'bg-warning-subtle text-warning', purchase_invoice:'bg-primary-subtle text-primary', supplier_credit_note:'bg-secondary-subtle text-secondary', receipt:'bg-info-subtle text-info', payment:'bg-danger-subtle text-danger', manual:'bg-dark-subtle text-dark', reversal:'bg-danger-subtle text-danger' };
|
||||
function _gl_source_badge(t) { return '<span class="badge ' + (_GL_SOURCE_BADGE[t]||'bg-light text-dark') + '">' + (_GL_SOURCE_LABELS[t]||t) + '</span>'; }
|
||||
|
||||
function show_gl_modal(doc_type, source_id) {
|
||||
$('#gl-modal-body').html('<div class="text-center text-muted py-4"><i class="ti ti-loader ti-spin me-1"></i>Loading…</div>');
|
||||
$('#glModal').modal('show');
|
||||
ajax_request({
|
||||
url: server_url + 'accounting/api/engine/get_gl_by_source.php',
|
||||
autoPrepare: true, checkRequired: 0, noLoading: true, action: 'read',
|
||||
data: { doc_type: doc_type, source_id: source_id },
|
||||
onSuccess: function(res) {
|
||||
if (!res.output) { $('#gl-modal-body').html('<p class="text-muted text-center py-4">No GL entry posted for this document.</p>'); return; }
|
||||
var h = res.output.header, lines = res.output.lines || [];
|
||||
var total_debit = 0, total_credit = 0, lines_html = '';
|
||||
$.each(lines, function(i, l) {
|
||||
total_debit += parseFloat(l.debit) || 0;
|
||||
total_credit += parseFloat(l.credit) || 0;
|
||||
var dept = l.dept_code ? escape_html(l.dept_code + (l.dept_name ? ' - ' + l.dept_name : '')) : '<span class="text-muted">—</span>';
|
||||
lines_html += '<tr><td class="fw-semibold">' + escape_html(l.account_code) + '</td><td>' + escape_html(l.account_name) + '</td><td>' + dept + '</td>' +
|
||||
'<td class="text-end">' + (parseFloat(l.debit) ? format_number(l.debit, 2) : '<span class="text-muted">—</span>') + '</td>' +
|
||||
'<td class="text-end">' + (parseFloat(l.credit) ? format_number(l.credit, 2) : '<span class="text-muted">—</span>') + '</td>' +
|
||||
'<td class="text-muted small">' + escape_html(l.description || '—') + '</td></tr>';
|
||||
});
|
||||
lines_html += '<tr class="table-light fw-semibold"><td colspan="3">Total</td><td class="text-end">' + format_number(total_debit, 2) + '</td><td class="text-end">' + format_number(total_credit, 2) + '</td><td></td></tr>';
|
||||
var balanced = Math.abs(total_debit - total_credit) < 0.01;
|
||||
var bal_badge = balanced ? '<span class="badge bg-success-subtle text-success ms-2">Balanced</span>' : '<span class="badge bg-danger-subtle text-danger ms-2">Unbalanced</span>';
|
||||
$('#gl-modal-body').html(
|
||||
'<div class="row g-3 mb-4 text-sm">' +
|
||||
'<div class="col-sm-4"><div class="text-muted small">Source</div><div>' + _gl_source_badge(h.source_type) + '</div></div>' +
|
||||
'<div class="col-sm-4"><div class="text-muted small">Period</div><div class="fw-semibold">' + escape_html(h.period) + '</div></div>' +
|
||||
'<div class="col-sm-4"><div class="text-muted small">Formula</div><div>' + escape_html(h.formula_name || '—') + '</div></div>' +
|
||||
'<div class="col-sm-4"><div class="text-muted small">Posted At</div><div class="text-muted small">' + escape_html(h.posted_at) + '</div></div>' +
|
||||
'<div class="col-sm-4"><div class="text-muted small">Updated At</div><div class="text-muted small">' + escape_html(h.updated_at_fmt) + '</div></div>' +
|
||||
'</div><div class="d-flex align-items-center mb-2"><span class="fw-semibold">Journal Lines</span>' + bal_badge + '</div>' +
|
||||
'<table class="table table-sm table-hover mb-0 table-centered"><thead class="table-light"><tr><th>Account Code</th><th>Account Name</th><th>Department</th><th class="text-end">Debit</th><th class="text-end">Credit</th><th>Description</th></tr></thead><tbody>' + lines_html + '</tbody></table>'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(async function() {
|
||||
await load_dept_cache();
|
||||
populate_dept_filter('filter_dept');
|
||||
@@ -297,5 +341,21 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- GL Entry Modal -->
|
||||
<div class="modal fade" id="glModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="ti ti-book me-2"></i>GL Entry</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body" id="gl-modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -364,7 +364,14 @@
|
||||
invoice_id: invoice_id,
|
||||
due_date: is_dn ? '' : due_date.split('/').reverse().join('-')
|
||||
},
|
||||
onSuccess: function() { retrieve_invoice(); }
|
||||
onSuccess: function(res) {
|
||||
retrieve_invoice();
|
||||
if (res.gl_posted === true) {
|
||||
toastr.success('GL entry posted automatically.', 'GL Posted');
|
||||
} else if (res.gl_posted === false) {
|
||||
toastr.warning('Document issued, but GL posting failed: ' + (res.gl_message || 'Unknown error'), 'GL Skipped', { timeOut: 8000 });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user