From 27105c7bca41eaeeb825712971c4e8a7723c7b63 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 10 Mar 2025 15:49:44 +0700 Subject: [PATCH] =?UTF-8?q?registy=20=3D=3D>=20=E0=B8=82=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=20=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=88=E0=B8=87=E0=B9=80=E0=B8=87=E0=B8=B4=E0=B8=99?= =?UTF-8?q?=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/02_organizational/api.organization.ts | 3 +- .../GovernmentInformation/07_Position.vue | 1349 +++++++++-------- .../07_PositionHistory.vue | 101 +- .../interface/index/government.ts | 26 +- .../interface/response/Position.ts | 119 ++ .../04_registryPerson/stores/Position.ts | 43 + 6 files changed, 926 insertions(+), 715 deletions(-) create mode 100644 src/modules/04_registryPerson/interface/response/Position.ts create mode 100644 src/modules/04_registryPerson/stores/Position.ts diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index d5cd35260..76c37250e 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -37,6 +37,7 @@ export default { orgPosExecutive: `${orgPos}/executive`, orgPosType: `${orgPos}/type`, orgPosTypeSearch: `${orgPos}/position/search`, + orgCommandCode: `${organization}/metadata/commandCode`, orgPosTypeId: (id: string) => `${orgPos}/type/${id}`, orgPosLevel: `${orgPos}/level`, @@ -129,12 +130,10 @@ export default { orgProfileEmpTemp: `${orgEmployeePosTemp}/profile`, orgSearchProfileEmpTemp: `${orgProfile}-temp/search`, - orgProfileById: (id: string, type: string) => `${orgProfile}${type}/admin/${id}`, orgDeceasedProfile: `${orgPos}/profile/search`, - orgCheckAvatar: (id: string) => `${orgProfile}/avatar/profileId-admin/${id}`, orgCheckAvatarAdmin: (id: string) => `${orgProfile}/avatar/profileid-admin/${id}`, diff --git a/src/modules/04_registryPerson/components/detail/GovernmentInformation/07_Position.vue b/src/modules/04_registryPerson/components/detail/GovernmentInformation/07_Position.vue index 08f6f263b..9c6343bdb 100644 --- a/src/modules/04_registryPerson/components/detail/GovernmentInformation/07_Position.vue +++ b/src/modules/04_registryPerson/components/detail/GovernmentInformation/07_Position.vue @@ -4,27 +4,28 @@ import { checkPermission } from "@/utils/permissions"; import { useQuasar } from "quasar"; import { useRoute } from "vue-router"; +import { useCounterMixin } from "@/stores/mixin"; +import { useGovernmentPosDataStore } from "@/modules/04_registryPerson/stores/Position"; import http from "@/plugins/http"; import config from "@/app.config"; import type { QTableProps } from "quasar"; +import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main"; +import type { FormPostition } from "@/modules/04_registryPerson/interface/index/government"; import type { - DataOption2, - DataOption, -} from "@/modules/04_registryPerson/interface/index/Main"; - -import type { FormSalaryNew } from "@/modules/04_registryPerson/interface/request/Salary"; -import type { - ResListSalary, - ResType, -} from "@/modules/04_registryPerson/interface/response/Salary"; + DataPositions, + DataCommandCode, + DataPosType, + DataPosLevel, + DataPosPosition, + DataPosExecutive, + DataTenure, +} from "@/modules/04_registryPerson/interface/response/Position"; +import type { ResListSalary } from "@/modules/04_registryPerson/interface/response/Salary"; import type { DataCardPos } from "@/modules/04_registryPerson/interface/index/government"; import DialogHeader from "@/components/DialogHeader.vue"; import DialogHistory from "@/modules/04_registryPerson/components/detail/GovernmentInformation/07_PositionHistory.vue"; - -import { useCounterMixin } from "@/stores/mixin"; -import { useSalaryDataStore } from "@/modules/04_registryPerson/stores/salary"; import DialogPreviewCommand from "@/modules/18_command/components/DialogPreviewCommand.vue"; const $q = useQuasar(); @@ -38,7 +39,7 @@ const isLeave = defineModel("isLeave", { required: true, }); -const store = useSalaryDataStore(); +const store = useGovernmentPosDataStore(); const { date2Thai, dialogConfirm, @@ -55,8 +56,8 @@ const { const empType = ref(pathRegistryEmp(route.name?.toString() ?? "")); //Table -const rows = ref([]); //รายการตำแหน่งเงินเดือน -const rowsMain = ref([]); //รายการตำแหน่งเงินเดือน +const rows = ref([]); //รายการตำแหน่งเงินเดือน +const rowsMain = ref([]); //รายการตำแหน่งเงินเดือน const keyword = ref(""); //คำค้นหา const modalCommand = ref(false); const command = ref(""); @@ -86,7 +87,7 @@ const baseColumns = ref([ style: "font-size: 14px", format(val, row) { return row.posNoAbb && row.posNo - ? `${row.posNoAbb}${row.posNo}` + ? `${row.posNoAbb}.${row.posNo}` : row.posNo ? row.posNo : "-"; @@ -161,46 +162,26 @@ const baseColumns = ref([ field: "amount", headerStyle: "font-size: 14px", style: "font-size: 14px", - format: (v) => Number(v).toLocaleString(), + format(v, row) { + return row.amount + ? `${row.amount.toLocaleString()}${ + row.amountSpecial !== 0 && row.amountSpecial + ? ` (${row.amountSpecial.toLocaleString()})` + : "" + }` + : "-"; + }, sort: (a: string, b: string) => a .toString() .localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, - // { - // name: "positionSalaryAmount", - // align: "left", - // label: "เงินประจำตำแหน่ง", - // sortable: true, - // field: "positionSalaryAmount", - // headerStyle: "font-size: 14px", - // style: "font-size: 14px", - // format: (v) => Number(v).toLocaleString(), - // sort: (a: string, b: string) => - // a - // .toString() - // .localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), - // }, - // { - // name: "mouthSalaryAmount", - // align: "left", - // label: "เงินค่าตอบแทนรายเดือน", - // sortable: true, - // field: "mouthSalaryAmount", - // headerStyle: "font-size: 14px", - // style: "font-size: 14px", - // format: (v) => Number(v).toLocaleString(), - // sort: (a: string, b: string) => - // a - // .toString() - // .localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), - // }, { - name: "refCommandNo", + name: "commandNo", align: "left", label: "เลขที่คำสั่ง", sortable: true, - field: "refCommandNo", + field: "commandNo", format(val, row) { return row.commandNo && row.commandYear ? `${row.commandNo}/${row.commandYear}` @@ -212,13 +193,16 @@ const baseColumns = ref([ a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { - name: "commandName", + name: "commandCode", align: "left", label: "ประเภทคำสั่ง", sortable: true, - field: "commandName", + field: "commandCode", headerStyle: "font-size: 14px", style: "font-size: 14px", + format(val, row) { + return store.convertCommandCodeName(val); + }, sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -282,63 +266,62 @@ const columns = computed(() => { }); const visibleColumns = ref([ "commandDateAffect", - "amount", - "positionSalaryAmount", - "mouthSalaryAmount", "posNo", "positionName", "positionType", "positionLevel", "positionExecutive", + "amount", + "commandNo", + "commandCode", "commandDateSign", - "commandName", - "refCommandNo", - "remark", "organization", + "remark", ]); const pagination = ref({ sortBy: "", }); -const formDataSalary = reactive({ - date: null, //วัน/เดือน/ปี - posNo: "", //ตำแหน่งเลขที่ - templatePos: "", //ต้นแบบ (template) ตำแหน่ง - position: "", //ตำแหน่ง - positionType: "", //ประเภทตำแหน่ง, กลุ่มงาน - positionLevel: "", //ระดับตำแหน่ง, ระดับชั้นงาน +//ฟร์อมข้อมูลตำแหน่ง/เงินเดือน +const formData = reactive({ + commandCode: "", //ประเภทคำสั่ง + commandNo: "", //เลขที่คำสั่ง + commandYear: null, //ปี + commandDateAffect: null, //วันที่มีผล + commandDateSign: null, //วันที่ลงนาม + posNoAbb: "", //ตัวย่อเลขที่ตำแหน่ง + posNo: "", //เลขที่ตำแหน่ง + positionName: "", //ตำแหน่ง + positionType: "", //ประเภทตำแหน่ง | กลุ่มงาน + positionLevel: "", //ระดับตำแหน่ง | ระดับชั้นงาน positionLine: "", // สายงาน positionPathSide: "", //ด้าน/สาขา positionExecutive: "", //ตำแหน่งทางการบริหาร - salary: null, //เงินเดือน - salaryPos: null, //เงินประจำตำแหน่ง - salaryCompensation: null, //เงินค่าตอบแทนรายเดือน - refCommandNo: "", //เลขที่คำสั่ง - templateDoc: "", //ต้นแบบ (template) เอกสารอ้างอิง - doc: "", //เอกสารอ้างอิง + amount: null, //เงินเดือน amountSpecial: null, //เงินค่าตอบแทนพิเศษ + orgRoot: "", //หน่วยงาน + orgChild1: "", //ส่วนราชการระดับ 1 + orgChild2: "", //ส่วนราชการระดับ 2 + orgChild3: "", //ส่วนราชการระดับ 3 + orgChild4: "", //ส่วนราชการระดับ 4 + remark: "", //หมายเหตุ }); const modalDialogSalary = ref(false); //แสดง popup ตำแหน่งเงินเดือน const isStatusEdit = ref(false); //สถานะแก้ไขข้อมูลตำแหน่งเงินเดือน const salaryId = ref(""); //id ที่ต้องการแก้ไข -const dataLevel = ref([]); //รายการ ตำแหน่งเงินเดือน +const dataLevel = ref([]); //รายการ ตำแหน่งเงินเดือน -const posNoOptions = ref(store.optionTemplatePos); +const commandCodeOptions = ref(store.commandCodeData); //รายการปรเภทคำสั่ง +const posTypeOptions = ref(store.posTypeData); //รายการประเภทตำแหน่ง | กลุ่มงาน +const posLevelOptions = ref(store.posLevelData); //รายการระดับตำแหน่ง | ระดับชั้นงาน +const posLineOptions = ref(store.posLineData); //รายการสายงาน +const posPathSideOptions = ref(store.posPathSideData); //รายการด้าน/สาขา +const posExecutiveOptions = ref(store.posExecutiveData); //รายการตำแหน่งทางการบริหาร -const posTypeOptions = ref([]); -const posTypeOptionsMain = ref([]); -const posLevelOption = ref([]); -const posLevelOptionMain = ref([]); -const positionFielOptiond = ref([]); -const positionFielOptiondMain = ref([]); -const positionAreaOptiond = ref([]); -const positionAreaOptiondMain = ref([]); -const posExecutiveOption = ref([]); -const posExecutiveOptionMain = ref([]); - -const docOption = ref(store.optionTemplateDoc); +const modalHistory = ref(false); //popup ประวัติการแก้ไข +//ข้อมูลระยะเวลาดำรงตำแหน่ง const cardData = ref([ { label: "ระยะเวลาดำรงตำแหน่งในสายงาน", @@ -354,8 +337,8 @@ const cardData = ref([ }, ]); -/** function fetch รายการ ตำแหน่งเงินเดือน*/ -async function fetchListSalary() { +/** function fetch รายการ ตำแหน่ง*/ +async function fetchDataPosition() { await http .get( config.API.profileListSalaryPositionNew(profileId.value, empType.value) @@ -369,311 +352,79 @@ async function fetchListSalary() { }); } -/** function fetch รายการ ตำแหน่งเงินเดือน*/ -function fetchType() { - http +/** function fetch ข้อมูลประเภทคำสั่ง*/ +async function fetchDataCommandCode() { + if (store.commandCodeData.length > 0) return false; + await http + .get(config.API.orgCommandCode) + .then((res) => { + const data = res.data.result; + const DataCommandCode = data.filter((e: DataCommandCode) => + store.positionCode.includes(e.code) + ); + + const options = DataCommandCode.map((e: DataCommandCode) => ({ + id: e.code.toString(), + name: e.name, + })); + + store.commandCodeData = options; + commandCodeOptions.value = options; + }) + .catch((err) => { + messageError($q, err); + }); +} + +/** function fetch ข้อมูลปรเภทตำแหน่งข้าราชการ */ +async function fetchType() { + await http .get(config.API.orgPosType) .then((res) => { dataLevel.value = res.data.result; - posTypeOptionsMain.value = res.data.result.map((e: any) => ({ + store.posTypeData = res.data.result.map((e: DataPosType) => ({ id: e.id, name: e.posTypeName, })); - posTypeOptions.value = posTypeOptionsMain.value; + posTypeOptions.value = store.posTypeData; }) .catch((err) => { messageError($q, err); }); } -/** - * function เลือกประเภทตำแหน่ง - * @param val - * @param status - */ -async function updateSelectType(val: string, status: boolean = false) { - const listLevel = await dataLevel.value.find( - (e: any) => e.posTypeName === val - ); - - if (listLevel) { - posLevelOptionMain.value = listLevel.posLevels.map((e: any) => ({ - id: e.id, - name: - empType.value === "" - ? e.posLevelName - : `${listLevel.posTypeShortName} ${e.posLevelName}`, - })); - - formDataSalary.positionLevel = !status ? "" : formDataSalary.positionLevel; - } -} - -/** - * function เปิด dialog ตำแหน่งเงินเดือน - * @param statusEdit แก้ไข,เพิ่ม - * @param data - */ -function onClickOpenDialog(statusEdit: boolean = false, data: any = []) { - if (empType.value === "") { - dataLevel.value.length === 0 && fetchType(); - fetchDataOption(); - fetchDataOptionExecutive(); - } else { - fetchOptionGroup(); - } - - // หาระดับตำแหน่ง - setTimeout(async () => { - statusEdit && (await updateSelectType(data.positionType, true)); - isStatusEdit.value = statusEdit; - }, 500); - - posLevelOptionMain.value = !statusEdit ? [] : posLevelOptionMain.value; - modalDialogSalary.value = true; - salaryId.value = data.id; - formDataSalary.date = statusEdit ? data.date : null; - formDataSalary.posNo = statusEdit ? data.posNo : ""; - formDataSalary.templatePos = ""; - formDataSalary.position = statusEdit ? data.position : ""; - formDataSalary.positionLine = statusEdit ? data.positionLine : ""; - formDataSalary.positionType = statusEdit ? data.positionType : ""; - formDataSalary.positionLevel = statusEdit ? data.positionLevel : ""; - formDataSalary.positionPathSide = statusEdit ? data.positionPathSide : ""; - formDataSalary.positionExecutive = statusEdit ? data.positionExecutive : ""; - formDataSalary.salaryCompensation = statusEdit ? data.mouthSalaryAmount : ""; - formDataSalary.salary = statusEdit - ? data.amount - ? data.amount.toLocaleString() - : "" - : ""; - formDataSalary.salaryPos = statusEdit - ? data.positionSalaryAmount - ? data.positionSalaryAmount.toLocaleString() - : "" - : ""; - formDataSalary.refCommandNo = statusEdit ? data.refCommandNo : ""; - formDataSalary.templateDoc = ""; - formDataSalary.doc = statusEdit ? data.templateDoc : ""; - - formDataSalary.amountSpecial = statusEdit - ? data.amountSpecial === 0 - ? "" - : data.amountSpecial - : ""; -} - -/** function ปิด dialog ตำแหน่งเงินเดือน*/ -function onClickCloseDialog() { - modalDialogSalary.value = false; -} - -/** - * ฟิลเตอร์ข้อมูลจาก input - * @param val ค่าที่ป้อนให้ input - * @param update function จาก quasar - * @param filtername type ที่กำหนด ของ input นั้นๆ - */ -function filterSelector(val: string, update: Function, filtername: string) { - switch (filtername) { - case "pos": - update(() => { - posNoOptions.value = store.optionTemplatePos.filter( - (v: DataOption2) => v.name.indexOf(val) > -1 - ); - }); - break; - case "positionLine": - update(() => { - positionFielOptiond.value = positionFielOptiondMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - case "posType": - update(() => { - posTypeOptions.value = posTypeOptionsMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - case "posLevel": - update(() => { - posLevelOption.value = posLevelOptionMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - case "doc": - update(() => { - docOption.value = store.optionTemplateDoc.filter( - (v: DataOption2) => v.name.indexOf(val) > -1 - ); - }); - break; - case "positionPathSide": - update(() => { - positionAreaOptiond.value = positionAreaOptiondMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - - case "positionExecutive": - update(() => { - posExecutiveOption.value = posExecutiveOptionMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - - default: - break; - } -} - -/** - * function เลือกต้นแบบ tamplate ตำแหน่ง - * @param val - */ -function updatePos(val: string) { - formDataSalary.position = val; -} - -/** - * function เลือกต้นแบบ tamplate เอกสาร - * @param val - */ -function updateDoc(val: string) { - formDataSalary.doc = val; -} - -/** function ยืนยันการบันทึกข้อมูล */ -function onSubmit() { - dialogConfirm($q, async () => { - showLoader(); - const formData = { - profileEmployeeId: - !isStatusEdit.value && empType.value !== "" - ? profileId.value - : undefined, - profileId: - !isStatusEdit.value && empType.value === "" - ? profileId.value - : undefined, - // date: formDataSalary.date, // วันที่ - posNo: formDataSalary.posNo, //ตำแหน่งเลขที่ - // position: formDataSalary.position, //ตำแหน่ง - // positionLine: - // empType.value === "" ? formDataSalary.positionLine : undefined, //สายงาน - // positionPathSide: - // empType.value === "" ? formDataSalary.positionPathSide : undefined, // ด้าน/สาขา - positionExecutive: - empType.value === "" ? formDataSalary.positionExecutive : undefined, //ตำแหน่งทางการบริหาร - positionType: formDataSalary.positionType, // ประเภทตำแหน่ง - positionLevel: formDataSalary.positionLevel, // ระดับตำแหน่ง - amount: - typeof formDataSalary.salary === "number" - ? formDataSalary.salary - : Number(formDataSalary?.salary?.replace(/,/g, "")), //เงินเดือนฐาน - positionSalaryAmount: - typeof formDataSalary.salaryPos === "number" - ? formDataSalary.salaryPos - : Number(formDataSalary?.salaryPos?.replace(/,/g, "")), // เงินประจำตำแหน่ง - mouthSalaryAmount: - typeof formDataSalary.salaryCompensation === "number" - ? formDataSalary.salaryCompensation - : Number(formDataSalary?.salaryCompensation?.replace(/,/g, "")), //เงินค่าตอบแทนรายเดือน - amountSpecial: - typeof formDataSalary.amountSpecial === "number" - ? formDataSalary.amountSpecial - : Number(formDataSalary?.amountSpecial?.replace(/,/g, "")), //เงินค่าตอบแทนพิเศษ - // refCommandNo: formDataSalary.refCommandNo, // เลขที่คำสั่ง - // templateDoc: formDataSalary.doc, // เอกสารอ้างอิง - posNoAbb: null, - positionName: "positionName", - remark: "remark", - commandCode: "1", - }; - - try { - const url = isStatusEdit.value - ? config.API.profileListSalaryNew(salaryId.value, empType.value) - : config.API.profileSalaryNew(empType.value); - const method = isStatusEdit.value ? "patch" : "post"; - await http[method](url, formData); - await fetchListSalary(); - await onClickCloseDialog(); - success($q, "บันทึกข้อมูลสำเร็จ"); - } catch (e) { - messageError($q, e); - } finally { - hideLoader(); - } - }); -} - -/** - * function เลื่อนรายการเงินเดือนขึ้น - * @param id รายการเงินเดือน - */ -function onSwapUp(id: string) { - showLoader(); - http - .get(config.API.profileSalaryPositionSwapNew("up", id, empType.value)) - .then(async () => { - await fetchListSalary(); +/** function fetch ข้อมูลปรเภทตำแหน่งลูกจ้าง*/ +async function fetchOptionGroup() { + await http + .get(config.API.orgEmployeeType) + .then((res) => { + dataLevel.value = res.data.result; + store.posTypeData = res.data.result.map((e: DataPosType) => ({ + id: e.id, + name: e.posTypeName, + })); + posTypeOptions.value = store.posTypeData; }) .catch((err) => { messageError($q, err); - }) - .finally(() => { - hideLoader(); }); } -/** - * function เลื่อนรายการเงินเดือนลง - * @param id รายการเงินเดือน - */ -function onSwapDown(id: string) { - showLoader(); - http - .get(config.API.profileSalaryPositionSwapNew("down", id, empType.value)) - .then(async () => { - await fetchListSalary(); - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); - }); -} - -const modalHistory = ref(false); - -/** - * function ดูข้อมูลประวัติการแก้ไขรายการเงินเดือน - * @param id รายการเงินเดือน - */ -function onClikcHistory(id: string) { - salaryId.value = id; - modalHistory.value = true; -} - /** function fetch ข้อมูลสายงาน*/ -function fetchDataOption() { - showLoader(); - http +async function fetchDataOption() { + if (store.posLineData.length > 0 && store.posPathSideData.length > 0) + return false; + await http .get(config.API.orgPosPosition + `?keyword=&type=ALL`) .then((res) => { const data = res.data.result; + console.log(data); + const seen = new Set(); const seen2 = new Set(); - const listPositionField = data.filter((item: any) => { + const listPositionField = data.filter((item: DataPosPosition) => { if (seen.has(item.positionField)) { return false; } else { @@ -681,12 +432,12 @@ function fetchDataOption() { return true; } }); - positionFielOptiondMain.value = listPositionField.map((e: any) => ({ + store.posLineData = listPositionField.map((e: DataPosPosition) => ({ id: e.positionField, name: e.positionField, })); - const listPositionArea = data.filter((item: any) => { + const listPositionArea = data.filter((item: DataPosPosition) => { if ( item.positionArea === null || item.positionArea === "" || @@ -699,82 +450,34 @@ function fetchDataOption() { return true; } }); - positionAreaOptiondMain.value = listPositionArea.map((e: any) => ({ + store.posPathSideData = listPositionArea.map((e: DataPosPosition) => ({ id: e.positionArea, name: e.positionArea, })); }) .catch((err) => { messageError($q, err); - }) - .finally(() => { - hideLoader(); }); } /** function fetch ข้อมูลตำแหน่งข้อมูลทางการบริหาร*/ -function fetchDataOptionExecutive() { - showLoader(); - http +async function fetchDataOptionExecutive() { + if (store.posExecutiveData.length > 0) return false; + await http .get(config.API.orgPosExecutive) .then((res) => { const data = res.data.result; - posExecutiveOptionMain.value = data.map((e: any) => ({ + store.posExecutiveData = data.map((e: DataPosExecutive) => ({ id: e.posExecutiveName, name: e.posExecutiveName, })); }) .catch((e) => { messageError($q, e); - }) - .finally(() => { - hideLoader(); }); } -/** function fetch ข้อมูลปรเภทตำแหน่ง*/ -function fetchOptionGroup() { - showLoader(); - http - .get(config.API.orgEmployeeType) - .then((res) => { - dataLevel.value = res.data.result; - posTypeOptionsMain.value = res.data.result.map((e: any) => ({ - id: e.id, - name: e.posTypeName, - })); - posTypeOptions.value = posTypeOptionsMain.value; - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); - }); -} - -const classInput = (val: boolean) => { - return { - "full-width inputgreen cursor-pointer": val, - "full-width cursor-pointer": !val, - }; -}; - -function onRefCommand(data: ResListSalary) { - modalCommand.value = true; - command.value = data.refCommandNo; - commandId.value = data.commandId; - // commandId.value = 'bdf9da91-ba45-497a-a2b7-cc49e2446d97'; //จำลอง -} - -function serchDataTable() { - rows.value = onSearchDataTable( - keyword.value, - rowsMain.value, - columns.value ? columns.value : [] - ); -} - +/** functiopn fetch ข้อมูลระยะเวลาดำลงตำแหน่ง*/ async function fetchDataTenure() { await http .get(config.API.salaryTenurePosition(profileId.value, empType.value)) @@ -782,10 +485,14 @@ async function fetchDataTenure() { const data = res.data.result; if (data) { // map ข้อมูลระยะเวลาดำรงตำแหน่ง - const formatData = (list: any) => - list.map((e: any) => ({ + const formatData = (list: DataTenure[]) => + list.map((e: DataTenure) => ({ name: e.name ?? "", - time: formatDatePosition(e.year, e.month, e.day), + time: formatDatePosition( + e.year?.toString(), + e.month?.toString(), + e.day?.toString() + ), })); // แปลงข้อมูลจาก data @@ -817,6 +524,240 @@ async function fetchDataTenure() { }); } +/** + * function เลือกประเภทตำแหน่ง + * @param val id ประเภทตำแหน่ง + * @param status แก่ไข , เพิ่ม + */ +async function updateSelectType(val: string, status: boolean = false) { + const listLevel = dataLevel.value.find( + (e: DataPosType) => e.posTypeName === val + ); + + if (listLevel) { + store.posLevelData = listLevel.posLevels.map((e: DataPosLevel) => ({ + id: e.id, + name: + empType.value === "" + ? e.posLevelName + : `${listLevel.posTypeShortName} ${e.posLevelName}`, + })); + + formData.positionLevel = !status ? "" : formData.positionLevel; + } +} + +/** + * function เปิด dialog ตำแหน่งเงินเดือน + * @param statusEdit แก้ไข,เพิ่ม + * @param data ข้อมูลตำแหน่งที่ต้องการแก้ไข + */ +async function onClickOpenDialog( + statusEdit: boolean = false, + data: DataPositions = {} as DataPositions +) { + showLoader(); + if (empType.value === "") { + await Promise.all([ + fetchType(), + fetchDataOption(), + fetchDataOptionExecutive(), + ]); + } else { + await fetchOptionGroup(); + } + + // หาระดับตำแหน่ง + statusEdit && (await updateSelectType(data.positionType, true)); + isStatusEdit.value = statusEdit; + + store.posLevelData = !statusEdit ? [] : store.posLevelData; + modalDialogSalary.value = true; + salaryId.value = data.id ?? ""; + formData.commandCode = statusEdit ? data.commandCode : ""; + formData.commandNo = statusEdit ? data.commandNo : ""; + formData.commandYear = statusEdit ? data.commandYear : null; + formData.commandDateAffect = statusEdit ? data.commandDateAffect : null; + formData.commandDateSign = statusEdit ? data.commandDateSign : null; + formData.posNoAbb = statusEdit ? data.posNoAbb : ""; + formData.posNo = statusEdit ? data.posNo : ""; + formData.positionName = statusEdit ? data.positionName : ""; + formData.positionType = statusEdit ? data.positionType : ""; + formData.positionLevel = statusEdit ? data.positionLevel : ""; + formData.positionLine = statusEdit ? data.positionLine : ""; + formData.positionPathSide = statusEdit ? data.positionPathSide : ""; + formData.positionExecutive = statusEdit ? data.positionExecutive : ""; + formData.amount = statusEdit ? data.amount : null; + formData.amountSpecial = statusEdit ? data.amountSpecial : null; + formData.orgRoot = statusEdit ? data.orgRoot : ""; + formData.orgChild1 = statusEdit ? data.orgChild1 : ""; + formData.orgChild2 = statusEdit ? data.orgChild2 : ""; + formData.orgChild3 = statusEdit ? data.orgChild3 : ""; + formData.orgChild4 = statusEdit ? data.orgChild4 : ""; + formData.remark = statusEdit ? data.remark : ""; + hideLoader(); +} + +/** function ปิด dialog ตำแหน่งเงินเดือน*/ +function onClickCloseDialog() { + modalDialogSalary.value = false; + formData.commandCode = ""; + formData.commandNo = ""; + formData.commandYear = null; + formData.commandDateAffect = null; + formData.commandDateSign = null; + formData.posNoAbb = ""; + formData.posNo = ""; + formData.positionName = ""; + formData.positionType = ""; + formData.positionLevel = ""; + formData.positionLine = ""; + formData.positionPathSide = ""; + formData.positionExecutive = ""; + formData.amount = null; + formData.amountSpecial = null; + formData.orgRoot = ""; + formData.orgChild1 = ""; + formData.orgChild2 = ""; + formData.orgChild3 = ""; + formData.orgChild4 = ""; + formData.remark = ""; +} + +/** + * ฟิลเตอร์ข้อมูลจาก input + * @param val ค่าที่ป้อนให้ input + * @param update function จาก quasar + * @param filtername type ที่กำหนด ของ input นั้นๆ + */ +function filterSelector(val: string, update: Function, filtername: string) { + switch (filtername) { + case "commandCode": + update(() => { + commandCodeOptions.value = store.commandCodeData.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + break; + + case "posType": + update(() => { + posTypeOptions.value = store.posTypeData.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + break; + + case "posLevel": + update(() => { + posLevelOptions.value = store.posLevelData.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + break; + + case "posLine": + update(() => { + posLineOptions.value = store.posLineData.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + break; + + case "posPathSide": + update(() => { + posPathSideOptions.value = store.posPathSideData.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + break; + + case "posExecutive": + update(() => { + posExecutiveOptions.value = store.posExecutiveData.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + break; + + default: + break; + } +} + +/** function ยืนยันการบันทึกข้อมูล */ +function onSubmit() { + dialogConfirm($q, async () => { + showLoader(); + try { + const url = isStatusEdit.value + ? config.API.profileListSalaryNew(salaryId.value, empType.value) + : config.API.profileSalaryNew(empType.value); + const method = isStatusEdit.value ? "patch" : "post"; + await http[method](url, { + profileEmployeeId: + !isStatusEdit.value && empType.value !== "" + ? profileId.value + : undefined, + profileId: + !isStatusEdit.value && empType.value === "" + ? profileId.value + : undefined, + ...formData, + amount: Number(String(formData.amount)?.replace(/,/g, "")), + amountSpecial: Number( + String(formData.amountSpecial)?.replace(/,/g, "") + ), + }); + await Promise.all([ + fetchDataPosition(), + fetchDataTenure(), + onClickCloseDialog(), + ]); + success($q, "บันทึกข้อมูลสำเร็จ"); + } catch (e) { + messageError($q, e); + } finally { + hideLoader(); + } + }); +} + +/** + * function ดูข้อมูลประวัติการแก้ไขรายการเงินเดือน + * @param id รายการเงินเดือน + */ +function onClikcHistory(id: string) { + salaryId.value = id; + modalHistory.value = true; +} + +/** + * function Preview ข้อมูลคำสั่ง + * @param data ข้อมูลคำสั่งที่ต้องการ Preview + */ +function onRefCommand(data: ResListSalary) { + modalCommand.value = true; + command.value = data.refCommandNo; + commandId.value = data.commandId; +} + +/** function ค้นหาข้อมูลในตาราง*/ +function serchDataTable() { + rows.value = onSearchDataTable( + keyword.value, + rowsMain.value, + columns.value ? columns.value : [] + ); +} + +function classInput(val: boolean) { + return { + "full-width inputgreen cursor-pointer": val, + "full-width cursor-pointer": !val, + }; +} + /** ทำงานเมื่อ Components ถูกเรียกใช้งาน*/ onMounted(async () => { try { @@ -825,8 +766,9 @@ onMounted(async () => { cardData.value.splice(2, 1); } await Promise.all([ - fetchListSalary(), + fetchDataPosition(), fetchDataTenure(), + fetchDataCommandCode(), // empType.value === "" ? : Promise.resolve(), ]); } finally { @@ -890,120 +832,93 @@ onMounted(async () => { style="min-width: 140px" /> - - - + + - +
-
+
+ + + +
+ +
+
+
+ +
+ +
+ + + + + +
+
+
+ +
{ outlined dense borderless - :model-value="date2Thai(formDataSalary.date)" + :model-value="date2Thai(formData.commandDateAffect)" :rules="[ (val: string) => !!val || - `${'กรุณาเลือก วัน/เดือน/ปี'}`, + `${'กรุณาเลือกวันที่คำสั่งมีผล'}`, ]" - :label="`${'วัน/เดือน/ปี'}`" + :label="`${'วันที่คำสั่งมีผล'}`" hide-bottom-space >
-
{ dense lazy-rules borderless - v-model="formDataSalary.positionLine" + v-model="formData.positionLine" :label="`${'สายงาน'}`" emit-value map-options option-label="name" - :options="positionFielOptiond" + :options="posLineOptions" option-value="id" hide-bottom-space use-input @@ -1214,7 +1238,7 @@ onMounted(async () => { clearable input-debounce="0" @filter="(inputValue: string, - doneFn: Function) => filterSelector(inputValue, doneFn, 'positionLine' + doneFn: Function) => filterSelector(inputValue, doneFn, 'posLine' )" >