Fix GL journal save, edit, detail view and list filters

Send journal lines, gl_id and list filters inside the ajax data payload where ajax_request reads them, select period when replacing a manual journal, and show ledger amounts to two decimals.
This commit is contained in:
Thanakorn
2026-09-18 16:19:27 +07:00
parent d8363f6ca7
commit c60b705d98
4 changed files with 48 additions and 19 deletions
+26 -8
View File
@@ -117,16 +117,32 @@
};
function load_listing() {
var period = document.getElementById('f_period').value;
var period = document.getElementById('f_period').value; // "YYYY-MM"
var source = document.getElementById('f_source').value;
// The engine filters on a date range, not a period, so turn the chosen
// month into its first and last day.
var date_from = '', date_to = '';
if (/^\d{4}-\d{2}$/.test(period)) {
var ym = period.split('-');
var last_day = new Date(parseInt(ym[0]), parseInt(ym[1]), 0).getDate();
date_from = period + '-01';
date_to = period + '-' + ('0' + last_day).slice(-2);
}
// Payload fields must go inside `data` — ajax_request() ignores unknown
// top-level options, so as siblings of `url` these were never sent and the
// month / source filters silently did nothing.
ajax_request({
url: server_url + 'accounting/api/engine/get_journal_listing.php',
autoPrepare: true,
checkRequired: 0,
action: 'read',
period: period,
source_type: source,
data: {
source_type: source,
date_from: date_from,
date_to: date_to
},
onSuccess: function(res) {
var rows = res.output || [];
document.getElementById('jl_badge').textContent = rows.length + ' entries';
@@ -146,8 +162,8 @@
'<td><span class="badge rounded-pill ' + cls + ' small">' + escape_html(label) + '</span></td>' +
'<td class="small text-muted">' + escape_html(r.contact_name || '—') + '</td>' +
'<td class="small">' + escape_html(r.period) + '</td>' +
'<td class="text-end small">' + format_number(r.total_debit) + '</td>' +
'<td class="text-end small">' + format_number(r.total_credit) + '</td>' +
'<td class="text-end small">' + format_number(r.total_debit, 2) + '</td>' +
'<td class="text-end small">' + format_number(r.total_credit, 2) + '</td>' +
'<td class="small text-muted">' + escape_html(r.posted_at) + '</td>' +
'<td><a href="javascript:;" onclick="view_detail(' + r.id + ')"><i class="ti ti-eye fs-5"></i></a>' +
(r.source_type === 'manual' ? ' <a href="' + server_url + 'journal/new.php?gl_id=' + r.id + '" class="ms-2"><i class="ti ti-edit fs-5"></i></a>' : '') +
@@ -169,7 +185,9 @@
autoPrepare: true,
checkRequired: 0,
action: 'read',
gl_id: gl_id,
// Inside `data`, or it is never sent and the engine answers
// "gl_id is required." for every row.
data: { gl_id: gl_id },
onSuccess: function(res) {
var d = res.output;
var h = d.header;
@@ -180,8 +198,8 @@
'<td>' + escape_html(l.account_code) + '</td>' +
'<td>' + escape_html(l.account_name) + '</td>' +
'<td class="text-muted small">' + escape_html(l.description || '—') + '</td>' +
'<td class="text-end">' + (parseFloat(l.debit) ? format_number(l.debit) : '—') + '</td>' +
'<td class="text-end">' + (parseFloat(l.credit) ? format_number(l.credit) : '—') + '</td>' +
'<td class="text-end">' + (parseFloat(l.debit) ? format_number(l.debit, 2) : '—') + '</td>' +
'<td class="text-end">' + (parseFloat(l.credit) ? format_number(l.credit, 2) : '—') + '</td>' +
'</tr>';
}).join('');