feat: add route dashboard

This commit is contained in:
Rizki
2026-03-11 15:34:48 +07:00
parent fc74e23dbf
commit 8c7634298f

View File

@ -281,13 +281,28 @@ class DashboardAdapter extends Adapter {
} }
} }
async queryProcurementStackedChart(req, callback) { async queryMonthlyBudgetUtilization(req, callback) {
var apires = this.getApiResultDefined(); var apires = this.getApiResultDefined();
try { try {
let year = req.query.year || new Date().getFullYear(); let year = req.query.year || new Date().getFullYear();
let start = year + "-01-01";
let end = parseInt(year) + 1 + "-01-01"; let qry = `
SELECT
MONTH(idt) as month,
SUM(amount) as used_budget
FROM tbl_justification
WHERE isdeleted=0
AND YEAR(idt)=?
GROUP BY MONTH(idt)
`;
db.query(qry, [year], function (err, result) {
if (err) {
apires.meta.code = 500;
apires.meta.message = err.toString();
return callback("err", apires);
}
let months = [ let months = [
"Jan", "Jan",
@ -303,34 +318,22 @@ class DashboardAdapter extends Adapter {
"Nov", "Nov",
"Dec", "Dec",
]; ];
let used = new Array(12).fill(0);
let justification = new Array(12).fill(0);
let pr = new Array(12).fill(0);
let po = new Array(12).fill(0);
let bast = new Array(12).fill(0);
let qry = `
SELECT MONTH(idt) as month, COUNT(*) total
FROM tbl_justification
WHERE isdeleted=0
AND idt>=? AND idt<?
GROUP BY MONTH(idt)
`;
db.query(qry, [start, end], function (err, result) {
result.forEach((r) => { result.forEach((r) => {
justification[r.month - 1] = r.total; used[r.month - 1] = r.used_budget;
}); });
apires.success = true; apires.success = true;
apires.data = { apires.data = {
year: year, year: year,
months: months, months: months,
series: [ series: [
{name: "Justification", data: justification}, {
{name: "PR", data: pr}, name: "Budget Utilization",
{name: "PO", data: po}, data: used,
{name: "BAST", data: bast}, },
], ],
}; };