Files
wms-app/app/asset_dashboard/index.php
T
Thanakorn c957280aa5 Add Asset Management app
Assets from purchase invoice lines, straight-line depreciation/amortization with salvage value, disposals, and [Asset Mgmt] sources in Batch GL Entries. Green third workspace with an app access guard.
2026-09-15 09:50:55 +07:00

268 lines
10 KiB
PHP

<?php
session_start();
require '../config.php';
require '../include_header.php';
?>
<body>
<?php require '../include_topbar.php'; ?>
<?php require '../include_sidebar_asset.php'; ?>
<main id="content" class="content py-15">
<div class="container-fluid">
<!-- Page header -->
<div class="row">
<div class="col-12">
<div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-6 gap-3">
<div>
<h1 class="fs-3 mb-1">Asset Management</h1>
<p class="mb-0">Fixed assets, depreciation and amortization</p>
</div>
<div class="d-flex gap-2">
<a href="<?php echo $server_url?>asset/purchase_invoices.php" class="btn btn-outline-primary">
<i class="ti ti-file-invoice me-1"></i>From Purchase Invoice
</a>
<a href="<?php echo $server_url?>asset/manage_asset.php" class="btn btn-primary">
<i class="ti ti-plus me-1"></i>New Asset
</a>
</div>
</div>
</div>
</div>
<!-- Summary cards -->
<div class="row g-5 mb-5">
<div class="col-lg-3 col-sm-6 col-12">
<div class="card p-4 bg-success bg-opacity-10 border border-success border-opacity-25 rounded-2">
<div class="d-flex gap-3">
<div class="icon-shape icon-md bg-success text-white rounded-2">
<i class="ti ti-building-warehouse fs-4"></i>
</div>
<div>
<h2 class="mb-3 fs-6">Assets in Use</h2>
<h3 class="fw-bold mb-0" id="stat_in_use">—</h3>
<p class="text-success mb-0 small" id="stat_in_use_note">&nbsp;</p>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="card p-4 bg-info bg-opacity-10 border border-info border-opacity-25 rounded-2">
<div class="d-flex gap-3">
<div class="icon-shape icon-md bg-info text-white rounded-2">
<i class="ti ti-cash fs-4"></i>
</div>
<div>
<h2 class="mb-3 fs-6">Cost</h2>
<h3 class="fw-bold mb-0" id="stat_cost">—</h3>
<p class="text-info mb-0 small">Assets in use</p>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="card p-4 bg-warning bg-opacity-10 border border-warning border-opacity-25 rounded-2">
<div class="d-flex gap-3">
<div class="icon-shape icon-md bg-warning text-white rounded-2">
<i class="ti ti-trending-down fs-4"></i>
</div>
<div>
<h2 class="mb-3 fs-6">Accumulated</h2>
<h3 class="fw-bold mb-0" id="stat_accumulated">—</h3>
<p class="text-warning mb-0 small">Depreciation + amortization</p>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="card p-4 bg-primary bg-opacity-10 border border-primary border-opacity-25 rounded-2">
<div class="d-flex gap-3">
<div class="icon-shape icon-md bg-primary text-white rounded-2">
<i class="ti ti-scale fs-4"></i>
</div>
<div>
<h2 class="mb-3 fs-6">Net Book Value</h2>
<h3 class="fw-bold mb-0" id="stat_book">—</h3>
<p class="text-primary mb-0 small">Cost minus accumulated</p>
</div>
</div>
</div>
</div>
</div>
<div class="row g-5 mb-5">
<!-- Due -->
<div class="col-lg-5">
<div class="card h-100">
<div class="card-body p-5">
<h2 class="fs-5 mb-1">Due this month</h2>
<p class="text-muted small mb-4">Months not yet charged, up to <span id="due_month"></span></p>
<div id="due_list"><div class="text-muted small">Loading...</div></div>
<div class="border-top pt-3 mt-3 small">
<span class="text-muted">Drafts waiting to be activated:</span>
<a href="<?php echo $server_url?>asset/index.php?status=0" class="fw-semibold ms-1" id="stat_draft">—</a>
</div>
</div>
</div>
</div>
<!-- Recent runs -->
<div class="col-lg-7">
<div class="card h-100">
<div class="card-body p-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fs-5 mb-0">Recent runs</h2>
<a href="<?php echo $server_url?>asset/depreciation.php" class="small">All runs</a>
</div>
<div class="table-responsive">
<table class="table table-sm mb-0 table-centered">
<thead class="table-light">
<tr>
<th>Run No.</th>
<th>Month</th>
<th class="text-end">Amount</th>
<th>GL</th>
</tr>
</thead>
<tbody id="runs_tbody">
<tr><td colspan="4" class="text-center text-muted py-4">Loading...</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- By category -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body p-5">
<h2 class="fs-5 mb-4">Assets in use by category</h2>
<div class="table-responsive">
<table class="table mb-0 table-hover table-centered">
<thead class="table-primary border-light">
<tr>
<th>Category</th>
<th>Class</th>
<th class="text-end">Assets</th>
<th class="text-end">Cost</th>
<th class="text-end">Accumulated</th>
<th class="text-end">Net Book Value</th>
</tr>
</thead>
<tbody id="category_tbody">
<tr><td colspan="6" class="text-center text-muted py-4">Loading...</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require '../include_ending.php'; ?>
<script src="<?php echo $server_url?>assets/js/asset.js"></script>
<script>
function load_stats() {
return ajax_request({
url: server_url + 'asset/api/engine/asset_stats.php',
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
var s = res.output || {};
$('#stat_in_use').text(parseInt(s.active || 0, 10) + parseInt(s.fully_depreciated || 0, 10));
$('#stat_in_use_note').text((s.fully_depreciated || 0) + ' fully depreciated · ' + (s.disposed || 0) + ' disposed');
$('#stat_cost').text(format_number(s.cost_in_use || 0, 2));
$('#stat_accumulated').text(format_number(s.accumulated_in_use || 0, 2));
$('#stat_book').text(format_number(s.book_value_in_use || 0, 2));
$('#stat_draft').text(s.draft || 0);
render_due(res.due || {});
render_categories(s.by_category || []);
}
});
}
function render_due(due) {
$('#due_month').text(current_period());
var html = '';
['tangible', 'intangible'].forEach(function(asset_class) {
var d = due[asset_class] || {};
var body = d.period_count > 0
? '<div class="fw-semibold">' + format_number(d.total, 2) + '</div>'
+ '<div class="small text-muted">' + d.period_count + ' month(s): ' + escape_html(d.from) + (d.to !== d.from ? ' → ' + escape_html(d.to) : '') + '</div>'
: '<div class="small text-success"><i class="ti ti-circle-check me-1"></i>Up to date</div>';
var button = d.period_count > 0
? '<a class="btn btn-sm btn-primary" href="' + server_url + 'asset/depreciation.php?class=' + asset_class + '">Run</a>'
: '';
html += '<div class="d-flex align-items-center justify-content-between py-2 border-bottom">'
+ '<div><div class="small text-muted">' + escape_html(d.label || asset_class) + '</div>' + body + '</div>'
+ button + '</div>';
});
$('#due_list').html(html);
}
function render_categories(rows) {
if (!rows.length) {
$('#category_tbody').html('<tr><td colspan="6" class="text-center text-muted py-4">No active assets yet.</td></tr>');
return;
}
var html = '';
rows.forEach(function(r) {
html += '<tr>'
+ '<td><span class="fw-semibold">' + escape_html(r.category_code) + '</span> ' + escape_html(r.category_name) + '</td>'
+ '<td>' + asset_class_badge(r.asset_class) + '</td>'
+ '<td class="text-end">' + r.asset_count + '</td>'
+ '<td class="text-end">' + format_number(r.cost, 2) + '</td>'
+ '<td class="text-end">' + format_number(r.accumulated, 2) + '</td>'
+ '<td class="text-end">' + format_number((parseFloat(r.cost) || 0) - (parseFloat(r.accumulated) || 0), 2) + '</td>'
+ '</tr>';
});
$('#category_tbody').html(html);
}
function load_runs() {
return ajax_request({
url: server_url + 'asset/api/engine/depreciation_run.php',
autoPrepare: true,
checkRequired: 0,
action: 'list',
onSuccess: function(res) {
var rows = (res.output || []).filter(function(r) { return String(r.status) === '1'; }).slice(0, 6);
if (!rows.length) {
$('#runs_tbody').html('<tr><td colspan="4" class="text-center text-muted py-4">No runs yet.</td></tr>');
return;
}
var html = '';
rows.forEach(function(r) {
html += '<tr>'
+ '<td>' + escape_html(r.run_number) + '</td>'
+ '<td>' + escape_html(r.period) + '</td>'
+ '<td class="text-end">' + format_number(r.total_amount, 2) + '</td>'
+ '<td>' + asset_gl_badge(r.gl_status) + '</td>'
+ '</tr>';
});
$('#runs_tbody').html(html);
}
});
}
$(async function() {
try {
await load_stats();
await load_runs();
} catch (e) { console.log(e); }
});
</script>
</body>
</html>