diff --git a/package.json b/package.json
index fc5a6bd..d84d6c4 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"@tato30/vue-pdf": "^1.5.1",
"@vuepic/vue-datepicker": "^3.6.3",
"bma-org-chart": "^0.0.7",
+ "exceljs": "^4.4.0",
"html-to-image": "^1.11.13",
"keycloak-js": "^20.0.2",
"moment": "^2.29.4",
diff --git a/src/components/DialogDebug.vue b/src/components/DialogDebug.vue
index d51100e..401d641 100644
--- a/src/components/DialogDebug.vue
+++ b/src/components/DialogDebug.vue
@@ -316,6 +316,9 @@ function onClose() {
+
+ ผู้ดูแลระบบจะติดต่อกลับผ่านทางอีเมลที่ท่านระบุ กรุณาตรวจสอบอีเมลของท่านเป็นระยะ
+
@@ -341,12 +345,6 @@ function onClose() {
v-model="formData.phone"
class="inputgreen"
hide-bottom-space
- :rules="[
- () =>
- !!formData.email ||
- !!formData.phone ||
- 'กรุณากรอกอีเมลหรือเบอร์โทรติดต่อกลับ',
- ]"
/>
diff --git a/src/modules/05_leave/components/DialogDetail.vue b/src/modules/05_leave/components/DialogDetail.vue
index 2c05ebd..3333374 100644
--- a/src/modules/05_leave/components/DialogDetail.vue
+++ b/src/modules/05_leave/components/DialogDetail.vue
@@ -206,7 +206,7 @@ async function fetchDataDetail(id: string) {
formData.leaveDateEnd = data.leaveEndDate && date2Thai(data.leaveEndDate);
formData.leaveCount = calculateDurationYmd(
data.leaveStartDate,
- data.leaveEndDate
+ data.leaveEndDate,
);
formData.leaveWrote = data.leaveWrote ?? "-";
formData.leaveAddress = data.leaveAddress ?? "-";
@@ -255,8 +255,7 @@ async function fetchDataDetail(id: string) {
formData.studyDaySubject = data.studyDaySubject ?? "-";
formData.studyDayDegreeLevel = data.studyDayDegreeLevel ?? "-";
formData.studyDayUniversityName = data.studyDayUniversityName ?? "-";
- formData.studyDayTrainingSubject =
- data.studyDayTrainingSubject ?? "-" ?? "-";
+ formData.studyDayTrainingSubject = data.studyDayTrainingSubject ?? "-";
formData.studyDayTrainingName = data.studyDayTrainingName ?? "-";
formData.studyDayCountry = data.studyDayCountry ?? "-";
formData.studyDayScholarship = data.studyDayScholarship ?? "-";
@@ -383,7 +382,7 @@ async function onClickSave() {
onSubmit();
},
"ยืนยันการบันทึกข้อมูล",
- "ต้องการยินยันการบันทึกข้อมูลนี้หรือไม่ ?"
+ "ต้องการยินยันการบันทึกข้อมูลนี้หรือไม่ ?",
);
} else {
}
@@ -425,7 +424,7 @@ watch(
? props.leaveId && fetchDataCancelDetail(props.leaveId)
: props.leaveId && fetchDataDetail(props.leaveId);
}
- }
+ },
);
diff --git a/src/modules/05_leave/components/FormLeave/01_SickForm.vue b/src/modules/05_leave/components/FormLeave/01_SickForm.vue
index f1e754e..9b6df27 100644
--- a/src/modules/05_leave/components/FormLeave/01_SickForm.vue
+++ b/src/modules/05_leave/components/FormLeave/01_SickForm.vue
@@ -131,11 +131,11 @@ function onValidate() {
formData.append("leaveRangeEnd", formDataSick.leaveRangeEnd);
formData.append(
"leaveStartDate",
- convertDateToAPI(formDataSick.leaveStartDate) ?? ""
+ convertDateToAPI(formDataSick.leaveStartDate) ?? "",
);
formData.append(
"leaveEndDate",
- convertDateToAPI(formDataSick.leaveEndDate) ?? ""
+ convertDateToAPI(formDataSick.leaveEndDate) ?? "",
);
formData.append("leaveWrote", formDataSick.leaveWrote);
formData.append("leaveAddress", dataStore.currentAddress);
@@ -202,7 +202,6 @@ function mapPropsToFormData() {
statusCheck.value = props.data.status;
leaveId.value = props.data.id;
formDataSick.leaveDocument = [];
- console.log(props.data.leaveDocument);
}
}
@@ -211,7 +210,7 @@ watch(
() => {
mapPropsToFormData();
},
- { deep: true }
+ { deep: true },
);
/** Hook */
diff --git a/src/modules/05_leave/components/FormLeave/Form.vue b/src/modules/05_leave/components/FormLeave/Form.vue
index d80b64b..d5fd5fe 100644
--- a/src/modules/05_leave/components/FormLeave/Form.vue
+++ b/src/modules/05_leave/components/FormLeave/Form.vue
@@ -293,7 +293,7 @@ function getSearch() {
/>
+
diff --git a/src/modules/05_leave/components/ListView.vue b/src/modules/05_leave/components/ListView.vue
index 37aea58..294c302 100644
--- a/src/modules/05_leave/components/ListView.vue
+++ b/src/modules/05_leave/components/ListView.vue
@@ -163,7 +163,7 @@ async function updatePagination(p: number, ps: number, s: string, d: boolean) {
function convert(val: any) {
if (leaveType.value) {
const filtertype = leaveType.value.find(
- (e: any) => e.id === val.leaveTypeId
+ (e: any) => e.id === val.leaveTypeId,
);
const type = filtertype?.code;
if (type == "LV-006" && val.hajjDayStatus == false) {
@@ -242,7 +242,7 @@ onMounted(async () => {
:props="props"
@click="onClickView(props.row.id, props.row.status)"
>
- {{ props.row.dateSendLeave }}
+ {{ props.row.status === "DRAFT" ? "-" : props.row.dateSendLeave }}
@@ -419,7 +419,7 @@ onMounted(async () => {
{{ (page - 1) * pageSize + props.rowIndex + 1 }}
-
+
{
{{ props.row.statusConvert }}
- {{ col.value }}
+
+ {{
+ props.row.status === "DRAFT" ? "-" : props.row.dateSendLeave
+ }}
+
+ {{ col.value }}
diff --git a/src/modules/05_leave/components/formDetail/01_SickForm.vue b/src/modules/05_leave/components/formDetail/01_SickForm.vue
index d186c94..43530d7 100644
--- a/src/modules/05_leave/components/formDetail/01_SickForm.vue
+++ b/src/modules/05_leave/components/formDetail/01_SickForm.vue
@@ -18,7 +18,9 @@ const props = defineProps({
วันที่ยื่นใบลา
-
{{ props.data.dateSendLeave }}
+
+ {{ props.data.status === "DRAFT" ? "-" : props.data.dateSendLeave }}
+
เรื่อง
@@ -30,11 +32,33 @@ const props = defineProps({
ลาตั้งแต่วันที่
-
{{ props.data.leaveDateStart }} {{ `${props.data.leaveRange && props.data.leaveRange !== 'ALL' ? `(${converstType(props.data.leaveRange)})`:''}` }}
+
+ {{ props.data.leaveDateStart }}
+ {{
+ `${
+ props.data.leaveRange && props.data.leaveRange !== "ALL"
+ ? `(${converstType(props.data.leaveRange)})`
+ : ""
+ }`
+ }}
+
ลาถึงวันที่
-
{{ props.data.leaveDateEnd }} {{ `${props.data.leaveDateStart !== props.data.leaveDateEnd ? `${props.data.leaveRangeEnd && props.data.leaveRangeEnd !== 'ALL' ? `(${converstType(props.data.leaveRangeEnd)})`:''}` :''}` }}
+
+ {{ props.data.leaveDateEnd }}
+ {{
+ `${
+ props.data.leaveDateStart !== props.data.leaveDateEnd
+ ? `${
+ props.data.leaveRangeEnd && props.data.leaveRangeEnd !== "ALL"
+ ? `(${converstType(props.data.leaveRangeEnd)})`
+ : ""
+ }`
+ : ""
+ }`
+ }}
+
จำนวนวันที่ลา
@@ -87,10 +111,12 @@ const props = defineProps({
target="_blank"
outline
color="blue"
- :label="`ดาวน์โหลดเอกสารแนบที่ ${index + 1}`"
+ :label="`ดาวน์โหลดเอกสารแนบที่ ${Number(index) + 1}`"
size="12px"
>
-
ดาวน์โหลดเอกสารแนบที่ {{ index + 1 }}
+
ดาวน์โหลดเอกสารแนบที่ {{ Number(index) + 1 }}
diff --git a/src/modules/05_leave/components/formDetail/04_HelpWifeBirthForm.vue b/src/modules/05_leave/components/formDetail/04_HelpWifeBirthForm.vue
index 80ec85d..52d358c 100644
--- a/src/modules/05_leave/components/formDetail/04_HelpWifeBirthForm.vue
+++ b/src/modules/05_leave/components/formDetail/04_HelpWifeBirthForm.vue
@@ -1,8 +1,8 @@
diff --git a/src/modules/10_registry/05_Other/03_FileOther.vue b/src/modules/10_registry/05_Other/03_FileOther.vue
index 585997b..585e68c 100644
--- a/src/modules/10_registry/05_Other/03_FileOther.vue
+++ b/src/modules/10_registry/05_Other/03_FileOther.vue
@@ -1,11 +1,12 @@
diff --git a/src/modules/10_registry/components/PositionReview/Table.vue b/src/modules/10_registry/components/PositionReview/Table.vue
index d2b7712..4523be3 100644
--- a/src/modules/10_registry/components/PositionReview/Table.vue
+++ b/src/modules/10_registry/components/PositionReview/Table.vue
@@ -24,6 +24,8 @@ import type { DataPosition } from "@/modules/10_registry/interface/review/Edit";
// import DialogSort from "@/modules/04_registryPerson/views/edit/components/DialogSort.vue";
// import CurruncyInput from "@/components/CurruncyInput.vue";
+import { exportToExcelPosition } from "@/modules/10_registry/utils/exportPosition";
+
const dataStore = useDataStore();
const store = useGovernmentPosDataStore();
const $q = useQuasar();
@@ -323,20 +325,23 @@ async function fetchData() {
// .get(
// `${config.API.profileSalaryTemp}/${empType.value}/done/${profileId.value}`,
// )
- http
- .get(`${config.API.profileSalaryTemp}/${empType.value}/${profileId.value}`)
- .then((res) => {
- const data = res.data.result;
- rowsMain.value = data;
- rows.value = data;
- serchDataTable();
- })
- .catch((err) => {
- messageError($q, err);
- })
- .finally(() => {
- isLoad.value = false;
- });
+ try {
+ await http.get(
+ `${config.API.profileSalaryTemp}/${empType.value}/${profileId.value}`,
+ );
+
+ const res = await http.get(
+ `${config.API.profileSalaryTemp}/${empType.value}/done/${profileId.value}`,
+ );
+ const data = res.data.result;
+ rowsMain.value = data;
+ rows.value = data;
+ serchDataTable();
+ } catch (err) {
+ messageError($q, err);
+ } finally {
+ isLoad.value = false;
+ }
}
/** function ค้นหาข้อมูลรายการในตาราง*/
@@ -442,67 +447,68 @@ function classColorRow(isDelete: boolean, isEdit: boolean, isEntry: boolean) {
/** ฟังก์ชันดาวน์โหลดไฟล Excel */
function exportToExcel() {
- const newData = rows.value.map((e: DataPosition, index: number) => {
- return {
- no: index + 1,
- commandDateAffect: date2Thai(e.commandDateAffect),
- positionName: e.positionName,
- positionType: e.positionType,
- positionLevel: e.positionLevel
- ? e.positionLevel
- : e.positionCee
- ? e.positionCee
- : "",
- positionExecutive: e.positionExecutive,
- amount: e.amount,
- mouthSalaryAmount: e.mouthSalaryAmount,
- positionSalaryAmount: e.positionSalaryAmount,
- organization: findOrgName({
- root: e.orgRoot,
- child1: e.orgChild1,
- child2: e.orgChild2,
- child3: e.orgChild3,
- child4: e.orgChild4,
- }),
- posNo:
- e.posNoAbb && e.posNo
- ? `${e.posNoAbb} ${e.posNo}`
- : e.posNo
- ? e.posNo
- : "",
- posNumCodeSit:
- e.posNumCodeSitAbb && e.posNumCodeSit
- ? `${e.posNumCodeSit} (${e.posNumCodeSitAbb})`
- : e.posNumCodeSit
- ? e.posNumCodeSit
- : "",
- commandNo:
- e.commandNo && e.commandYear
- ? `${e.commandNo}/${Number(e.commandYear) + 543}`
- : "",
- commandDateSign: date2Thai(e.commandDateSign),
- commandCode: store.convertCommandCodeName(e.commandCode),
- remark: e.remark,
- };
- });
+ exportToExcelPosition(rows.value);
+ // const newData = rows.value.map((e: DataPosition, index: number) => {
+ // return {
+ // no: index + 1,
+ // commandDateAffect: date2Thai(e.commandDateAffect),
+ // positionName: e.positionName,
+ // positionType: e.positionType,
+ // positionLevel: e.positionLevel
+ // ? e.positionLevel
+ // : e.positionCee
+ // ? e.positionCee
+ // : "",
+ // positionExecutive: e.positionExecutive,
+ // amount: e.amount,
+ // mouthSalaryAmount: e.mouthSalaryAmount,
+ // positionSalaryAmount: e.positionSalaryAmount,
+ // organization: findOrgName({
+ // root: e.orgRoot,
+ // child1: e.orgChild1,
+ // child2: e.orgChild2,
+ // child3: e.orgChild3,
+ // child4: e.orgChild4,
+ // }),
+ // posNo:
+ // e.posNoAbb && e.posNo
+ // ? `${e.posNoAbb} ${e.posNo}`
+ // : e.posNo
+ // ? e.posNo
+ // : "",
+ // posNumCodeSit:
+ // e.posNumCodeSitAbb && e.posNumCodeSit
+ // ? `${e.posNumCodeSit} (${e.posNumCodeSitAbb})`
+ // : e.posNumCodeSit
+ // ? e.posNumCodeSit
+ // : "",
+ // commandNo:
+ // e.commandNo && e.commandYear
+ // ? `${e.commandNo}/${Number(e.commandYear) + 543}`
+ // : "",
+ // commandDateSign: date2Thai(e.commandDateSign),
+ // commandCode: store.convertCommandCodeName(e.commandCode),
+ // remark: e.remark,
+ // };
+ // });
- const headers = columns.value.map((item: any) => item.label) || []; // หัวคอลัมน์ภาษาไทย
- const worksheet = XLSX.utils.json_to_sheet(newData, {
- header: visibleColumns.value,
- });
+ // const headers = columns.value.map((item: any) => item.label) || []; // หัวคอลัมน์ภาษาไทย
+ // const worksheet = XLSX.utils.json_to_sheet(newData, {
+ // header: visibleColumns.value,
+ // });
//แทรกหัวคอลัมน์ภาษาไทย (ใช้ A1, B1, C1 แทน)
- XLSX.utils.sheet_add_aoa(worksheet, [headers], { origin: "A1" });
+ // XLSX.utils.sheet_add_aoa(worksheet, [headers], { origin: "A1" });
// Create a new workbook and append the worksheet
- const workbook = XLSX.utils.book_new();
+ // const workbook = XLSX.utils.book_new();
- XLSX.utils.book_append_sheet(
- workbook,
- worksheet,
- `รายการประวัติตำแหน่งเงินเดือน`,
- );
- XLSX.writeFile(workbook, "รายการประวัติตำแหน่งเงินเดือน.xlsx");
+ // XLSX.utils.book_append_sheet(
+ // workbook,
+ // worksheet,
+ // `รายการประวัติตำแหน่งเงินเดือน`,
+ // );
+ // XLSX.writeFile(workbook, "รายการประวัติตำแหน่งเงินเดือน.xlsx");
}
// const commandCodeOptions = ref(store.commandCodeData); //รายการปรเภทคำสั่ง
@@ -880,12 +886,20 @@ async function fetchDataCommandCode() {
// }
onMounted(async () => {
- // เพิ่ม delay เล็กน้อยเพื่อรอให้ dataStore fetch ข้อมูล position เสร็จก่อน
- await new Promise((resolve) => setTimeout(resolve, 800));
if (dataStore.officerType && dataStore.profileId) {
await Promise.all([fetchData(), fetchDataCommandCode()]);
}
});
+
+watch(
+ () => [dataStore.officerType, dataStore.profileId],
+ async ([officerType, profileId]) => {
+ if (officerType && profileId) {
+ await Promise.all([fetchData(), fetchDataCommandCode()]);
+ }
+ },
+ { immediate: true },
+);
diff --git a/src/modules/10_registry/interface/review/Edit.ts b/src/modules/10_registry/interface/review/Edit.ts
index 04041b2..545dc35 100644
--- a/src/modules/10_registry/interface/review/Edit.ts
+++ b/src/modules/10_registry/interface/review/Edit.ts
@@ -71,6 +71,7 @@ interface DataPosition {
status: string;
posNumCodeSitAbb: string;
posNumCodeSit: string;
+ positionExecutiveField: string;
}
export type { DataSalaryPos, DataPosition };
diff --git a/src/modules/10_registry/utils/downloadFile.ts b/src/modules/10_registry/utils/downloadFile.ts
new file mode 100644
index 0000000..99c06c5
--- /dev/null
+++ b/src/modules/10_registry/utils/downloadFile.ts
@@ -0,0 +1,60 @@
+export interface DownloadFileOptions {
+ downloadUrl: string;
+ fileName: string;
+}
+
+const isMobile =
+ /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
+ navigator.userAgent,
+ );
+
+export async function downloadBlobFile({
+ downloadUrl,
+ fileName,
+}: DownloadFileOptions): Promise {
+ // Use window.open for desktop, blob download for mobile
+ if (!isMobile) {
+ window.open(downloadUrl, "_blank");
+ return;
+ }
+
+ const response = await fetch(downloadUrl);
+ const blob = await response.blob();
+
+ const contentType: string | null = response.headers.get("Content-Type");
+
+ const extensionMap: Record = {
+ "application/pdf": "pdf",
+ "image/jpeg": "jpg",
+ "image/png": "png",
+ "image/gif": "gif",
+ "application/zip": "zip",
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
+ "docx",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
+ };
+
+ let extension = contentType ? extensionMap[contentType] : undefined;
+
+ if (!extension) {
+ const urlWithoutQuery = downloadUrl.split("?")[0];
+ extension = urlWithoutQuery.includes(".")
+ ? urlWithoutQuery.split(".").pop()
+ : "pdf";
+ }
+
+ const blobForDownload = new Blob([blob], {
+ type: "application/octet-stream",
+ });
+ const url = URL.createObjectURL(blobForDownload);
+ const link = document.createElement("a");
+ link.href = url;
+ const downloadFileName = fileName.includes(".") ? fileName : `${fileName}.${extension}`;
+ link.download = downloadFileName;
+ document.body.appendChild(link);
+ link.click();
+ setTimeout(() => {
+ document.body.removeChild(link);
+ URL.revokeObjectURL(url);
+ }, 100);
+}
diff --git a/src/modules/10_registry/utils/exportPosition.ts b/src/modules/10_registry/utils/exportPosition.ts
new file mode 100644
index 0000000..1761408
--- /dev/null
+++ b/src/modules/10_registry/utils/exportPosition.ts
@@ -0,0 +1,157 @@
+import ExcelJS from "exceljs";
+import { useGovernmentPosDataStore } from "@/modules/10_registry/store/Position";
+
+import type { DataPosition } from "@/modules/10_registry/interface/review/Edit";
+
+const store = useGovernmentPosDataStore();
+
+// ฟังก์ชันแปลงวันที่จาก ISO format เป็นรูปแบบ dd/mm/yyyy (เช่น 18/05/2564)
+function formatDateToDDMMYYYY(dateString: string | null | Date): string {
+ if (!dateString) return "";
+
+ const date = new Date(dateString);
+ if (isNaN(date.getTime())) return "";
+
+ const day = String(date.getDate()).padStart(2, "0");
+ const month = String(date.getMonth() + 1).padStart(2, "0");
+ const year = date.getFullYear() + 543; // แปลงเป็นปีพุทธศักราช
+
+ return `${day}/${month}/${year}`;
+}
+
+export async function exportToExcelPosition(data: DataPosition[]) {
+ const workbook = new ExcelJS.Workbook();
+ const worksheet = workbook.addWorksheet("รายการประวัติตำแหน่งเงินเดือน");
+
+ // --- ส่วนที่ 1: สร้าง Master Data Sheet สำหรับอ้างอิง ID ---
+ // เราจะซ่อนแผ่นงานนี้ไว้ (hidden) เพื่อใช้ทำ Dropdown และ VLOOKUP
+ const masterSheet = workbook.addWorksheet("MasterData", { state: "hidden" });
+ const masterData = store.commandCodeData; // [{id: 1, name: "ย้าย"}, ...]
+
+ masterData.forEach((item, index) => {
+ masterSheet.getCell(`A${index + 1}`).value = item.name;
+ masterSheet.getCell(`B${index + 1}`).value = item.id;
+ });
+
+ // --- ส่วนที่ 2: กำหนด Columns ---
+ worksheet.columns = [
+ { header: "ลำดับ", key: "no", width: 8 },
+ { header: "วันที่คำสั่งมีผล", key: "commandDateAffect", width: 18 },
+ { header: "ตำแหน่งในสายงาน", key: "positionName", width: 25 },
+ { header: "ตำแหน่งประเภท", key: "positionType", width: 18 },
+ { header: "ระดับ", key: "positionLevel", width: 12 },
+ { header: "ระดับซี", key: "positionCee", width: 12 },
+ { header: "สายงาน", key: "positionLine", width: 20 },
+ { header: "ด้าน/สาขา", key: "positionPathSide", width: 15 },
+ { header: "ตำแหน่งทางการบริหาร", key: "positionExecutive", width: 20 },
+ { header: "ด้านทางการบริหาร", key: "positionExecutiveField", width: 20 },
+ { header: "เงินเดือน", key: "amount", width: 15 },
+ { header: "เงินค่าตอบแทนรายเดือน", key: "mouthSalaryAmount", width: 15 },
+ { header: "เงินประจำตำแหน่ง", key: "positionSalaryAmount", width: 15 },
+ { header: "เงินค่าตอบแทนพิเศษ", key: "amountSpecial", width: 15 },
+ { header: "หน่วยงาน", key: "organization", width: 30 },
+ { header: "ส่วนราชการระดับ 1", key: "orgChild1", width: 20 },
+ { header: "ส่วนราชการระดับ 2", key: "orgChild2", width: 20 },
+ { header: "ส่วนราชการระดับ 3", key: "orgChild3", width: 20 },
+ { header: "ส่วนราชการระดับ 4", key: "orgChild4", width: 20 },
+ { header: "ตัวย่อเลขที่ตำแหน่ง", key: "posNoAbb", width: 15 },
+ { header: "เลขที่ตำแหน่ง", key: "posNo", width: 15 },
+ { header: "หน่วยงานที่ออกคำสั่ง", key: "posNumCodeSit", width: 20 },
+ {
+ header: "ตัวย่อหน่วยงานที่ออกคำสั่ง",
+ key: "posNumCodeSitAbb",
+ width: 15,
+ },
+ { header: "เลขที่คำสั่ง", key: "commandNo", width: 15 },
+ { header: "ปีเลขที่คำสั่ง", key: "commandYear", width: 12 },
+ { header: "วันที่ลงนาม", key: "commandDateSign", width: 18 },
+ { 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 ข้อมูล
+ const newData = data.map((e, index) => ({
+ no: index + 1,
+ commandDateAffect: e.commandDateAffect
+ ? formatDateToDDMMYYYY(e.commandDateAffect)
+ : "",
+ positionName: e.positionName,
+ positionType: e.positionType,
+ positionLevel: e.positionLevel,
+ positionCee: e.positionCee,
+ positionLine: e.positionLine || "",
+ positionPathSide: e.positionPathSide || "",
+ positionExecutive: e.positionExecutive,
+ positionExecutiveField: e.positionExecutiveField || "",
+ amount: e.amount || 0,
+ mouthSalaryAmount: e.mouthSalaryAmount || 0,
+ positionSalaryAmount: e.positionSalaryAmount || 0,
+ amountSpecial: e.amountSpecial || 0,
+ organization: e.orgRoot,
+ orgChild1: e.orgChild1,
+ orgChild2: e.orgChild2,
+ orgChild3: e.orgChild3,
+ orgChild4: e.orgChild4,
+ posNoAbb: e.posNoAbb,
+ posNo: e.posNo,
+ posNumCodeSit: e.posNumCodeSit,
+ posNumCodeSitAbb: e.posNumCodeSitAbb,
+ commandNo: e.commandNo,
+ commandYear: e.commandYear ? Number(e.commandYear) + 543 : "",
+ commandDateSign: e.commandDateSign
+ ? formatDateToDDMMYYYY(e.commandDateSign)
+ : "",
+ commandCodeName: store.convertCommandCodeName(e.commandCode),
+ remark: e.remark,
+ commandId: e.commandId || "",
+ commandCode: e.commandCode || "", // ใส่ค่าเริ่มต้นไว้
+ }));
+
+ worksheet.addRows(newData);
+
+ // 4. ตกแต่งสี, Dropdown และ สูตร VLOOKUP
+ newData.forEach((_, index) => {
+ const rowIndex = index + 2;
+
+ // --- ตั้งค่า Format สำหรับเซลล์วันที่ ---
+ // เซลล์ B (commandDateAffect) และ Z (commandDateSign)
+ const dateAffectCell = worksheet.getCell(`B${rowIndex}`);
+ const dateSignCell = worksheet.getCell(`Z${rowIndex}`);
+
+ [dateAffectCell, dateSignCell].forEach((cell) => {
+ cell.numFmt = "dd/mm/yyyy";
+ });
+
+ // --- ทำ Dropdown คอลัมน์ AA ---
+ // อ้างอิงรายการจาก MasterData Sheet จะทำให้ Excel ทำงานได้เสถียรกว่า (กรณีรายการเยอะ)
+ worksheet.getCell(`AA${rowIndex}`).dataValidation = {
+ type: "list",
+ allowBlank: true,
+ formulae: [`MasterData!$A$1:$A$${masterData.length}`],
+ };
+
+ // --- ผูกสูตรให้ commandCode (AD) เปลี่ยนตามการเลือกใน AA ---
+ // AA คือประเภทคำสั่ง, AD คือ commandCode
+ worksheet.getCell(`AD${rowIndex}`).value = {
+ formula: `=IFERROR(VLOOKUP(AA${rowIndex}, MasterData!$A$1:$B$${masterData.length}, 2, FALSE), "")`,
+ };
+ });
+
+ // 5. สไตล์ Header
+ worksheet.getRow(1).font = { bold: true };
+ worksheet.getRow(1).alignment = { vertical: "middle", horizontal: "center" };
+
+ // 6. เขียนไฟล์
+ const buffer = await workbook.xlsx.writeBuffer();
+ const blob = new Blob([buffer], {
+ type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ });
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = "รายการประวัติตำแหน่งเงินเดือน.xlsx";
+ a.click();
+ window.URL.revokeObjectURL(url);
+}
diff --git a/src/plugins/genreport.ts b/src/plugins/genreport.ts
index 520ec00..19e2856 100644
--- a/src/plugins/genreport.ts
+++ b/src/plugins/genreport.ts
@@ -2,6 +2,7 @@ import axios from "axios";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
+import { downloadBlobFile } from "@/modules/10_registry/utils/downloadFile";
const mixin = useCounterMixin();
const { showLoader, hideLoader } = mixin;
@@ -19,7 +20,7 @@ async function genReport(data: any, fileName: string, type: string = "docx") {
},
responseType: "arraybuffer",
})
- .then((res) => {
+ .then(async (res) => {
const responseData = res.data;
if (responseData) {
const mimeType =
@@ -31,18 +32,11 @@ async function genReport(data: any, fileName: string, type: string = "docx") {
const url = URL.createObjectURL(blob);
const baseName = fileName.trim();
- const extension = type === "docx" ? "docx" : "pdf";
-
- const link = document.createElement("a");
- link.href = url;
- link.download = `${baseName}.${extension}`;
- document.body.appendChild(link);
- link.click();
-
- setTimeout(() => {
- document.body.removeChild(link);
- URL.revokeObjectURL(url);
- }, 100);
+ // const extension = type === "docx" ? "docx" : "pdf";
+ await downloadBlobFile({
+ downloadUrl: url,
+ fileName: baseName,
+ });
}
})
.catch((err) => {
diff --git a/src/stores/mixin.ts b/src/stores/mixin.ts
index 41c7161..02981bb 100644
--- a/src/stores/mixin.ts
+++ b/src/stores/mixin.ts
@@ -14,7 +14,7 @@ export const useCounterMixin = defineStore("mixin", () => {
const calAge = (
srcDate: Date,
birthCal: Date = new Date(),
- eng: boolean = false
+ eng: boolean = false,
) => {
const year = eng ? "years" : "ปี";
const month = eng ? "months" : "เดือน";
@@ -82,7 +82,7 @@ export const useCounterMixin = defineStore("mixin", () => {
function date2Thai(
srcDate: Date | null,
isFullMonth: boolean = false,
- isTime: boolean = false
+ isTime: boolean = false,
) {
if (srcDate == null || !moment(srcDate).isValid()) return "";
@@ -98,7 +98,7 @@ export const useCounterMixin = defineStore("mixin", () => {
function dateThai(
srcDate: Date,
isFullMonth: boolean = true,
- isTime: boolean = false
+ isTime: boolean = false,
) {
if (srcDate == null) {
return null;
@@ -490,7 +490,7 @@ export const useCounterMixin = defineStore("mixin", () => {
color: string | undefined,
ok?: Function | undefined,
cancel?: Function | undefined,
- onlycancel: Boolean = false
+ onlycancel: Boolean = false,
) => {
q.dialog({
component: CustomComponent,
@@ -529,7 +529,7 @@ export const useCounterMixin = defineStore("mixin", () => {
title: string,
message: string,
ok: Function,
- cancel?: Function
+ cancel?: Function,
) {
q.dialog({
title: `${title}`,
@@ -559,7 +559,7 @@ export const useCounterMixin = defineStore("mixin", () => {
title: string,
message: string,
ok: Function,
- cancel?: Function
+ cancel?: Function,
) {
q.dialog({
title: `${title}`,
@@ -795,7 +795,7 @@ export const useCounterMixin = defineStore("mixin", () => {
ok?: Function,
title?: string, // ถ้ามี cancel action ใส่เป็น null
desc?: string, // ถ้ามี cancel action ใส่เป็น null
- cancel?: Function
+ cancel?: Function,
) => {
q.dialog({
component: CustomComponent,
@@ -824,7 +824,7 @@ export const useCounterMixin = defineStore("mixin", () => {
ok?: Function,
title?: string, // ถ้ามี cancel action ใส่เป็น null
desc?: string, // ถ้ามี cancel action ใส่เป็น null
- cancel?: Function
+ cancel?: Function,
) => {
q.dialog({
component: CustomComponent,
@@ -851,7 +851,7 @@ export const useCounterMixin = defineStore("mixin", () => {
const dialogMessageNotify = (
q: any,
desc?: string, // ถ้ามี cancel action ใส่เป็น null
- cancel?: Function
+ cancel?: Function,
) => {
q.dialog({
component: CustomComponent,
@@ -973,7 +973,7 @@ export const useCounterMixin = defineStore("mixin", () => {
* @returns ผลการคำนวน ปี เดือน วัน ในรูปแบบ 1 ปี 10 เดือน 5 วัน
*/
function calculateDurationYmd(startDate: any, endDate: any) {
- if (!startDate || !endDate) return "";
+ if (!startDate || !endDate) return "";
let start = moment(startDate).startOf("day");
let end = moment(endDate).startOf("day").add(1, "day");
@@ -1252,9 +1252,15 @@ export const useCounterMixin = defineStore("mixin", () => {
// กรณีมีเฉพาะ date
function convertDateToAPI(date: Date | null) {
- return date
- ? format(utcToZonedTime(date, "Asia/Bangkok"), "yyyy-MM-dd")
- : null;
+ if (!date) return null;
+
+ const parsedDate = new Date(date);
+
+ if (parsedDate) {
+ return format(parsedDate, "yyyy-MM-dd");
+ } else {
+ return null;
+ }
}
// กรณี datetime
diff --git a/src/views/MainLayout.vue b/src/views/MainLayout.vue
index f14d08e..165bf6e 100644
--- a/src/views/MainLayout.vue
+++ b/src/views/MainLayout.vue
@@ -172,13 +172,13 @@ const doLogout = () => {
);
};
-const clickDelete = async (id: string, index: number) => {
+const clickDelete = async (id: string, index: number | string) => {
dialogRemove($q, async () => {
// showLoader();
await http
.delete(config.API.msgId(id))
.then(() => {
- notiList.value.splice(index, 1);
+ notiList.value.splice(Number(index), 1);
totalInbox.value--;
totalNoti.value--;
success($q, "ลบข้อมูลสำเร็จ");
@@ -772,10 +772,10 @@ watch(
-
-
-
+
+
+