-
All checks were successful
Build Docker Image / Build Docker Image (push) Successful in 1m7s
Build Docker Image / Restart Docker Compose (push) Successful in 1s

This commit is contained in:
x2Skyz
2025-11-29 12:13:17 +07:00
parent 16c3c1dc15
commit b32515779f

View File

@@ -2,7 +2,8 @@ import { AccountingSumService } from '../services/accountingSumService.js'
import { sendError } from '../utils/response.js'
import { GeneralService } from '../share/generalservice.js';
import { trim_all_array } from '../utils/trim.js'
import { verifyToken, generateToken } from '../utils/token.js'
import { verifyToken,
generateToken } from '../utils/token.js'
export class accountingSum {
@@ -44,7 +45,7 @@ export class accountingSum {
if (!result) return sendError('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง', 'Invalid credentials');
try {
// 1) เตรียม data สำหรับใช้คำนวณ
// 1) เตรียม data สำหรับใช้คำนวณ
// ถ้า service คืนมาเป็น { code, message, data: [...] }
const data = Array.isArray(result)
? result
@@ -57,7 +58,7 @@ export class accountingSum {
return result;
}
// 2) แยก income / expense
// 2) แยก income / expense
const incomeList = data.filter(i => i.acttyp === 'i');
const expenseList = data.filter(e => e.acttyp === 'e');
@@ -68,7 +69,7 @@ export class accountingSum {
const profitRate = totalIncome > 0 ? (netProfit / totalIncome) * 100 : 0;
const adjustedProfitRate = profitRate + 1.9;
// 3) แนบ summary (เหมือนที่เราทำไปก่อนหน้า)
// 3) แนบ summary (เหมือนที่เราทำไปก่อนหน้า)
var summary = {
totalIncome: totalIncome.toFixed(2),
totalExpense: totalExpense.toFixed(2),
@@ -78,14 +79,14 @@ export class accountingSum {
period: '30 วัน'
};
// 4) ดึงสีจาก dtlmst (แนะนำให้เรียกจาก service เพิ่ม)
// 4) ดึงสีจาก dtlmst (แนะนำให้เรียกจาก service เพิ่ม)
// ตัวอย่างสมมติ: คุณไป query มาจาก service ก่อนหน้าแล้วได้เป็น object แบบนี้
// key = ชื่อหมวด (actcatnam หรือ code), value = color
const categoryColorMap = await this.accountingSumService.getCategoryColorMap(database);
// ตัวอย่างที่คาดหวังจาก service:
// { 'ค่าอาหาร': '#FF6384', 'ค่าเดินทาง': '#36A2EB', 'ขายสินค้า': '#4BC0C0', ... }
// 5) สรุปยอดตามหมวด แล้วคำนวณ % สำหรับ expense
// 5) สรุปยอดตามหมวด แล้วคำนวณ % สำหรับ expense
const expenseAgg = {};
expenseList.forEach(row => {
const key = row.actcatnam; // หรือใช้รหัส category ถ้ามี เช่น row.actcatcod
@@ -122,7 +123,7 @@ export class accountingSum {
};
});
// 6) แนบข้อมูล pie chart เข้า result
// 6) แนบข้อมูล pie chart เข้า result
var pie = {
expense: expensePie,
income: incomePie