From b32515779f60ba9a4131f28ffb4e82eb8afbf4a0 Mon Sep 17 00:00:00 2001 From: x2Skyz Date: Sat, 29 Nov 2025 12:13:17 +0700 Subject: [PATCH] - --- .../src/controllers/accountingSumController.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/exthernal-accountingwep-api/src/controllers/accountingSumController.js b/exthernal-accountingwep-api/src/controllers/accountingSumController.js index 532d0fb..6b51e11 100644 --- a/exthernal-accountingwep-api/src/controllers/accountingSumController.js +++ b/exthernal-accountingwep-api/src/controllers/accountingSumController.js @@ -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