add endpoint spend by unit
This commit is contained in:
@ -49,7 +49,9 @@ class DashboardAdapter extends Adapter {
|
||||
let budget = budgetResult[0];
|
||||
|
||||
budget.total_budget =
|
||||
parseFloat(budget.total_remaining_budget) + parseFloat(budget.total_requested_budget) + + parseFloat(budget.total_used_budget);
|
||||
parseFloat(budget.total_remaining_budget) +
|
||||
parseFloat(budget.total_requested_budget) +
|
||||
+parseFloat(budget.total_used_budget);
|
||||
|
||||
/* JUSTIFICATION */
|
||||
|
||||
@ -399,6 +401,67 @@ class DashboardAdapter extends Adapter {
|
||||
callback("error", apires);
|
||||
}
|
||||
}
|
||||
|
||||
async querySpendByUnitChart(req, callback) {
|
||||
var apires = this.getApiResultDefined();
|
||||
|
||||
try {
|
||||
let year = req.query.year || new Date().getFullYear();
|
||||
|
||||
let qry = `
|
||||
SELECT
|
||||
division,
|
||||
SUM(amount) as total_used_budget
|
||||
FROM tbl_justification
|
||||
WHERE isdeleted = 0
|
||||
AND idt >= CONCAT(?, '-01-01 00:00:00')
|
||||
AND idt < CONCAT(? + 1, '-01-01 00:00:00')
|
||||
AND division IN ('FBP','MarSal','MNO')
|
||||
GROUP BY division
|
||||
`;
|
||||
|
||||
db.query(qry, [year, year], function (err, result) {
|
||||
if (err) {
|
||||
apires.meta.code = 500;
|
||||
apires.meta.message = err.toString();
|
||||
return callback("err", apires);
|
||||
}
|
||||
|
||||
let divisions = ["MNO", "MarSal", "FBP"];
|
||||
let values = {
|
||||
MNO: 0,
|
||||
MarSal: 0,
|
||||
FBP: 0,
|
||||
};
|
||||
|
||||
result.forEach((r) => {
|
||||
values[r.division] = r.total_used_budget;
|
||||
});
|
||||
|
||||
let data = divisions.map((d) => values[d]);
|
||||
|
||||
let total = data.reduce((a, b) => a + b, 0);
|
||||
|
||||
apires.success = true;
|
||||
apires.data = {
|
||||
categories: divisions,
|
||||
series: [
|
||||
{
|
||||
name: "Spend",
|
||||
data: data,
|
||||
},
|
||||
],
|
||||
total: total,
|
||||
};
|
||||
|
||||
callback(null, apires);
|
||||
});
|
||||
} catch (err) {
|
||||
apires.meta.code = 500;
|
||||
apires.meta.message = err.toString();
|
||||
callback("error", apires);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DashboardAdapter;
|
||||
|
||||
@ -60,3 +60,19 @@ exports.getMonthlyBudgetUtilization = (req, res) => {
|
||||
dashboardAdapter.sendResponse(502, apireshandler, res);
|
||||
}
|
||||
};
|
||||
|
||||
exports.getSpendByUnitChart = (req, res) => {
|
||||
try {
|
||||
dashboardAdapter.querySpendByUnitChart(req, function (err, data) {
|
||||
let statusCode = data != null ? data.meta.code : 200;
|
||||
|
||||
if (err) statusCode = 500;
|
||||
|
||||
dashboardAdapter.sendResponse(statusCode, data, res);
|
||||
});
|
||||
} catch (err) {
|
||||
apireshandler.meta.code = 502;
|
||||
apireshandler.meta.message = "Dashboard controller error : " + err.toString();
|
||||
dashboardAdapter.sendResponse(502, apireshandler, res);
|
||||
}
|
||||
};
|
||||
|
||||
@ -9,5 +9,6 @@ router.get('/summary',[jwtauth], dashboardController.getDashboardSummary);
|
||||
router.get('/budget-line',dashboardController.getBudgetLineChart);
|
||||
router.get('/procurement-chart',dashboardController.getProcurementStackedChart);
|
||||
router.get('/budget-utilization',dashboardController.getMonthlyBudgetUtilization);
|
||||
router.get('/spend-by-unit',dashboardController.getSpendByUnitChart);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user