refactor: add column commandCode

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-04-23 10:00:20 +07:00
parent 573a76448e
commit 803ba41a79

View file

@ -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), "")`,
};
});