From 803ba41a79686c2a3d08b3f7f9f5ba0a372c8290 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Thu, 23 Apr 2026 10:00:20 +0700 Subject: [PATCH] refactor: add column commandCode --- .../10_registry/utils/exportPosition.ts | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/modules/10_registry/utils/exportPosition.ts b/src/modules/10_registry/utils/exportPosition.ts index ccd1dbf..4c77019 100644 --- a/src/modules/10_registry/utils/exportPosition.ts +++ b/src/modules/10_registry/utils/exportPosition.ts @@ -53,9 +53,10 @@ export async function exportToExcelPosition(data: DataPosition[]) { { header: "เลขที่คำสั่ง", key: "commandNo", width: 15 }, { header: "ปีเลขที่คำสั่ง", key: "commandYear", width: 12 }, { header: "วันที่ลงนาม", key: "commandDateSign", width: 18 }, - { header: "ประเภทคำสั่ง", key: "commandCode", width: 25 }, // AA + { header: "ประเภทคำสั่ง", key: "commandCodeName", width: 25 }, // AA { header: "หมายเหตุ", key: "remark", width: 20 }, { header: "commandId", key: "commandId", width: 20 }, // AC (ลำดับที่ 29) + { header: "commandCode", key: "commandCode", width: 20 }, // AD (ลำดับที่ 30) ]; // 3. Map ข้อมูล @@ -86,9 +87,10 @@ export async function exportToExcelPosition(data: DataPosition[]) { commandNo: e.commandNo, commandYear: e.commandYear ? Number(e.commandYear) + 543 : "", commandDateSign: date2Thai(e.commandDateSign), - commandCode: store.convertCommandCodeName(e.commandCode), + commandCodeName: store.convertCommandCodeName(e.commandCode), remark: e.remark, - commandId: e.commandCode, // ใส่ค่าเริ่มต้นไว้ + commandId: e.commandId, + commandCode: e.commandCode, // ใส่ค่าเริ่มต้นไว้ })); worksheet.addRows(newData); @@ -97,24 +99,6 @@ export async function exportToExcelPosition(data: DataPosition[]) { newData.forEach((_, index) => { const rowIndex = index + 2; - // --- ระบายสีเหลืองเข้ม (ถอด # ออกจาก ARGB) --- - ["B", "O", "U", "V", "X", "Z"].forEach((col) => { - worksheet.getCell(`${col}${rowIndex}`).fill = { - type: "pattern", - pattern: "solid", - fgColor: { argb: "FFBF00" }, // ลบ # ออก - }; - }); - - // --- ระบายสีเหลืองอ่อน --- - ["F", "G", "H", "N", "P", "Q", "R", "S", "T", "W", "Y"].forEach((col) => { - worksheet.getCell(`${col}${rowIndex}`).fill = { - type: "pattern", - pattern: "solid", - fgColor: { argb: "FFFFD7" }, // ลบ # ออก - }; - }); - // --- ทำ Dropdown คอลัมน์ AA --- // อ้างอิงรายการจาก MasterData Sheet จะทำให้ Excel ทำงานได้เสถียรกว่า (กรณีรายการเยอะ) worksheet.getCell(`AA${rowIndex}`).dataValidation = { @@ -123,9 +107,9 @@ export async function exportToExcelPosition(data: DataPosition[]) { formulae: [`MasterData!$A$1:$A$${masterData.length}`], }; - // --- ผูกสูตรให้ commandId (AC) เปลี่ยนตามการเลือกใน AA --- - // AA คือประเภทคำสั่ง, AB คือหมายเหตุ, AC คือ commandId - worksheet.getCell(`AC${rowIndex}`).value = { + // --- ผูกสูตรให้ commandCode (AD) เปลี่ยนตามการเลือกใน AA --- + // AA คือประเภทคำสั่ง, AD คือ commandCode + worksheet.getCell(`AD${rowIndex}`).value = { formula: `=IFERROR(VLOOKUP(AA${rowIndex}, MasterData!$A$1:$B$${masterData.length}, 2, FALSE), "")`, }; });