170 lines
6.9 KiB
PHP
170 lines
6.9 KiB
PHP
<?php
|
|
session_start();
|
|
require '../config.php';
|
|
require '../include_header.php';
|
|
?>
|
|
|
|
<body>
|
|
<?php require '../include_topbar.php'; ?>
|
|
<?php require '../include_sidebar_ac.php'; ?>
|
|
|
|
<main id="content" class="content py-15">
|
|
<div class="container-fluid">
|
|
|
|
<div class="row mb-5">
|
|
<div class="col-12">
|
|
<h1 class="fs-3 mb-1">Trial Balance</h1>
|
|
<p class="mb-0 text-muted">Brought-forward balances, date-range movement, and carry-forward balances for posting accounts</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Filters -->
|
|
<div class="card p-4 mb-4">
|
|
<div class="row g-2 align-items-end">
|
|
<div class="col-auto">
|
|
<label class="form-label mb-1 small">From Date</label>
|
|
<input type="text" id="f_from" class="form-control form-control-sm" placeholder="DD/MM/YYYY" style="width:160px;">
|
|
</div>
|
|
<div class="col-auto">
|
|
<label class="form-label mb-1 small">To Date</label>
|
|
<input type="text" id="f_to" class="form-control form-control-sm" placeholder="DD/MM/YYYY" style="width:160px;">
|
|
</div>
|
|
<div class="col-auto">
|
|
<label class="form-label mb-1 small">Department</label>
|
|
<select id="f_department" class="form-select form-select-sm" style="width:200px;">
|
|
<option value="0">All Departments</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-auto">
|
|
<button class="btn btn-secondary btn-sm" onclick="load_report()">
|
|
<i class="ti ti-search me-1"></i>Run
|
|
</button>
|
|
</div>
|
|
<div class="col ms-auto d-flex align-items-end justify-content-end">
|
|
<button class="btn btn-outline-secondary btn-sm" onclick="window.print()">
|
|
<i class="ti ti-printer me-1"></i>Print
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Table -->
|
|
<div class="card">
|
|
<div class="card-body p-0">
|
|
<table class="table table-hover mb-0 table-centered" id="tb_table">
|
|
<thead class="table-primary border-light">
|
|
<tr>
|
|
<th>Code</th>
|
|
<th>Account Name</th>
|
|
<th>Type</th>
|
|
<th class="text-end">B/F Debit</th>
|
|
<th class="text-end">B/F Credit</th>
|
|
<th class="text-end">Period Debit</th>
|
|
<th class="text-end">Period Credit</th>
|
|
<th class="text-end">C/F Debit</th>
|
|
<th class="text-end">C/F Credit</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tb_tbody">
|
|
<tr><td colspan="9" class="text-center text-muted py-5">Select a date range and click Run.</td></tr>
|
|
</tbody>
|
|
<tfoot id="tb_tfoot"></tfoot>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
|
|
<?php require '../include_ending.php'; ?>
|
|
|
|
<script>
|
|
var type_labels = { asset:'Asset', liability:'Liability', equity:'Equity', revenue:'Revenue', expense:'Expense' };
|
|
|
|
// Default: current month date range
|
|
var now = new Date();
|
|
var curMonth = now.getFullYear() + '-' + String(now.getMonth()+1).padStart(2,'0');
|
|
document.getElementById('f_from').value = curMonth + '-01';
|
|
document.getElementById('f_to').value = curMonth + '-' + String(new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate()).padStart(2,'0');
|
|
flatpickr('#f_from, #f_to', { dateFormat: 'Y-m-d', altInput: true, altFormat: 'd/m/Y', allowInput: true });
|
|
|
|
load_departments();
|
|
|
|
function load_departments() {
|
|
ajax_request({
|
|
url: server_url + 'accounting/api/engine/department.php',
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
noLoading: true,
|
|
action: 'read',
|
|
onSuccess: function(res) {
|
|
var html = '<option value="0">All Departments</option>';
|
|
(res.output || []).filter(function(d){ return String(d.status) === '1'; }).forEach(function(d) {
|
|
html += '<option value="' + d.id + '">' + escape_html(d.dept_code + ' - ' + d.dept_name) + '</option>';
|
|
});
|
|
document.getElementById('f_department').innerHTML = html;
|
|
}
|
|
});
|
|
}
|
|
|
|
function load_report() {
|
|
var from = document.getElementById('f_from').value;
|
|
var to = document.getElementById('f_to').value;
|
|
var dept = document.getElementById('f_department').value || '0';
|
|
if (!from || !to) { alert('Select both dates.'); return; }
|
|
|
|
document.getElementById('tb_tbody').innerHTML =
|
|
'<tr><td colspan="9" class="text-center text-muted py-5"><span class="spinner-border spinner-border-sm me-2"></span>Loading...</td></tr>';
|
|
document.getElementById('tb_tfoot').innerHTML = '';
|
|
|
|
ajax_request({
|
|
url: server_url + 'accounting/api/engine/get_trial_balance.php',
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
noLoading: true,
|
|
action: 'read',
|
|
from_date: from,
|
|
to_date: to,
|
|
department_id: dept,
|
|
onSuccess: function(res) {
|
|
var d = res.output;
|
|
var rows = d.rows || [];
|
|
if (rows.length === 0) {
|
|
document.getElementById('tb_tbody').innerHTML =
|
|
'<tr><td colspan="9" class="text-center text-muted py-5">No data for this date range.</td></tr>';
|
|
document.getElementById('tb_tfoot').innerHTML = '';
|
|
return;
|
|
}
|
|
var html = '';
|
|
rows.forEach(function(r) {
|
|
html += '<tr>' +
|
|
'<td class="fw-semibold">' + escape_html(r.account_code) + '</td>' +
|
|
'<td>' + escape_html(r.account_name) + '</td>' +
|
|
'<td><span class="badge bg-secondary bg-opacity-10 text-secondary">' + escape_html(type_labels[r.account_type] || r.account_type) + '</span></td>' +
|
|
'<td class="text-end">' + format_number(r.opening_debit) + '</td>' +
|
|
'<td class="text-end">' + format_number(r.opening_credit) + '</td>' +
|
|
'<td class="text-end">' + format_number(r.period_debit) + '</td>' +
|
|
'<td class="text-end">' + format_number(r.period_credit) + '</td>' +
|
|
'<td class="text-end">' + format_number(r.closing_debit) + '</td>' +
|
|
'<td class="text-end">' + format_number(r.closing_credit) + '</td>' +
|
|
'</tr>';
|
|
});
|
|
document.getElementById('tb_tbody').innerHTML = html;
|
|
document.getElementById('tb_tfoot').innerHTML =
|
|
'<tr class="table-light fw-semibold">' +
|
|
'<td colspan="3">Total</td>' +
|
|
'<td class="text-end">' + format_number(d.total_opening_debit) + '</td>' +
|
|
'<td class="text-end">' + format_number(d.total_opening_credit) + '</td>' +
|
|
'<td class="text-end">' + format_number(d.total_period_debit) + '</td>' +
|
|
'<td class="text-end">' + format_number(d.total_period_credit) + '</td>' +
|
|
'<td class="text-end">' + format_number(d.total_closing_debit) + '</td>' +
|
|
'<td class="text-end">' + format_number(d.total_closing_credit) + '</td>' +
|
|
'</tr>';
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|