accounting workflows
This commit is contained in:
@@ -11,19 +11,42 @@
|
||||
<main id="content" class="content py-15">
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row mb-6">
|
||||
<div class="row mb-5">
|
||||
<div class="col-12">
|
||||
<h1 class="fs-3 mb-1">Balance Sheet</h1>
|
||||
<p class="mb-0 text-muted">Assets, liabilities, and equity</p>
|
||||
<p class="mb-0 text-muted">Cumulative asset, liability, and equity positions as of a date</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card p-5 text-center text-muted">
|
||||
<i class="ti ti-table fs-1 mb-3 d-block"></i>
|
||||
<p class="mb-0">Balance Sheet coming soon.</p>
|
||||
<!-- 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">As Of Date</label>
|
||||
<input type="text" id="f_as_of" 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>
|
||||
|
||||
<div class="row g-4" id="bs_body">
|
||||
<div class="col-12">
|
||||
<div class="card p-5 text-center text-muted">Select a date and click Run.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -32,5 +55,117 @@
|
||||
|
||||
<?php require '../include_ending.php'; ?>
|
||||
|
||||
<script>
|
||||
var now = new Date();
|
||||
document.getElementById('f_as_of').value =
|
||||
now.getFullYear() + '-' + String(now.getMonth()+1).padStart(2,'0') + '-' + String(now.getDate()).padStart(2,'0');
|
||||
flatpickr('#f_as_of', { 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 as_of = document.getElementById('f_as_of').value;
|
||||
var dept = document.getElementById('f_department').value || '0';
|
||||
if (!as_of) { alert('Select a date.'); return; }
|
||||
|
||||
document.getElementById('bs_body').innerHTML =
|
||||
'<div class="col-12"><div class="card p-5 text-center text-muted"><span class="spinner-border spinner-border-sm me-2"></span>Loading...</div></div>';
|
||||
|
||||
ajax_request({
|
||||
url: server_url + 'accounting/api/engine/get_balance_sheet.php',
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
noLoading: true,
|
||||
action: 'read',
|
||||
as_of_date: as_of,
|
||||
department_id: dept,
|
||||
onSuccess: function(res) {
|
||||
var d = res.output;
|
||||
var rows = d.rows || [];
|
||||
|
||||
var assets = rows.filter(function(r){ return r.account_type === 'asset'; });
|
||||
var liabilities = rows.filter(function(r){ return r.account_type === 'liability'; });
|
||||
var equity = rows.filter(function(r){ return r.account_type === 'equity'; });
|
||||
|
||||
function sum_net(items, type) {
|
||||
return items.reduce(function(s, r) {
|
||||
var net = type === 'asset'
|
||||
? (parseFloat(r.total_debit) - parseFloat(r.total_credit))
|
||||
: (parseFloat(r.total_credit) - parseFloat(r.total_debit));
|
||||
return s + net;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function table_rows(items, type) {
|
||||
if (items.length === 0) return '<tr><td colspan="2" class="text-muted small ps-4">No entries.</td></tr>';
|
||||
return items.map(function(r) {
|
||||
var net = type === 'asset'
|
||||
? (parseFloat(r.total_debit) - parseFloat(r.total_credit))
|
||||
: (parseFloat(r.total_credit) - parseFloat(r.total_debit));
|
||||
return '<tr>' +
|
||||
'<td class="ps-3"><span class="text-muted small me-2">' + escape_html(r.account_code) + '</span>' +
|
||||
escape_html(r.account_name) + '</td>' +
|
||||
'<td class="text-end">' + format_number(net) + '</td>' +
|
||||
'</tr>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
var total_assets = sum_net(assets, 'asset');
|
||||
var total_liab = sum_net(liabilities, 'liability');
|
||||
var total_equity = sum_net(equity, 'equity') + (parseFloat(d.retained_earnings) || 0);
|
||||
|
||||
function section_card(title, items, type, total, extra_rows) {
|
||||
return '<div class="card">' +
|
||||
'<div class="card-body p-0">' +
|
||||
'<table class="table mb-0">' +
|
||||
'<thead class="table-primary border-light"><tr><th>' + title + '</th><th class="text-end">Amount</th></tr></thead>' +
|
||||
'<tbody>' +
|
||||
table_rows(items, type) +
|
||||
(extra_rows || '') +
|
||||
'<tr class="fw-semibold border-top">' +
|
||||
'<td class="text-end py-2">Total ' + title + '</td>' +
|
||||
'<td class="text-end py-2">' + format_number(total) + '</td>' +
|
||||
'</tr>' +
|
||||
'</tbody>' +
|
||||
'</table>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
var retained_row = '<tr class="table-light">' +
|
||||
'<td class="ps-3"><span class="text-muted small me-2">—</span>Retained Earnings (Cumulative P&L)</td>' +
|
||||
'<td class="text-end">' + format_number(parseFloat(d.retained_earnings) || 0) + '</td>' +
|
||||
'</tr>';
|
||||
|
||||
document.getElementById('bs_body').innerHTML =
|
||||
'<div class="col-12">' + section_card('Assets', assets, 'asset', total_assets, '') + '</div>' +
|
||||
'<div class="col-md-6">' + section_card('Liabilities', liabilities, 'liability', total_liab, '') + '</div>' +
|
||||
'<div class="col-md-6">' + section_card('Equity', equity, 'equity', total_equity, retained_row) + '</div>' +
|
||||
'<div class="col-12"><div class="card p-3 border-2 fw-bold d-flex flex-row justify-content-between align-items-center">' +
|
||||
'<span>Total Liabilities + Equity</span>' +
|
||||
'<span>' + format_number(total_liab + total_equity) + '</span>' +
|
||||
'</div></div>';
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user