hrms-mgt/src/modules/07_insignia/storeResult.ts
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 7798707e96 fix เครื่องราช
2024-11-21 14:53:46 +07:00

218 lines
6.7 KiB
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
/** import Type*/
import type {
OptionData,
DataRecord,
DataInsignia,
OptionDataInsignia,
InsigniaType,
} from "@/modules/07_insignia/interface/index/Main";
import type {
ResponseInsigniaType,
ResponseRecordLists,
} from "@/modules/07_insignia/interface/response/Main";
/** import Stores */
import { useCounterMixin } from "@/stores/mixin";
const mixin = useCounterMixin();
const { date2Thai } = mixin;
export const useResultDataStore = defineStore("insigniaResult", () => {
const insignia = ref<string>("");
const insigniaOp = ref<OptionDataInsignia[]>([{ name: "ทั้งหมด", id: "" }]);
const insigniaOp2 = ref<OptionData[]>([]);
const insigniaType = ref<InsigniaType[]>([]);
const invoiceType = ref<string>("all");
const invoiceTypeop = ref<OptionData[]>([
{ name: "ทั้งหมด", id: "all" },
{ name: "ใบกำกับที่ค้างจ่าย", id: "noDate" },
{ name: "ใบกำกับที่จ่ายแล้ว", id: "haveDate" },
]);
const employeeClass = ref<string>("all");
const employeeClassOps = ref<OptionData[]>([
{ name: "ทั้งหมด", id: "all" },
{ name: "ข้าราชการ กทม.สามัญ", id: "officer" },
{ name: "ลูกจ้างประจำ", id: "employee" },
]);
const rows = ref<DataRecord[]>([]);
const listInsignia = ref<DataRecord[]>([]);
const type = ref<DataInsignia[]>([]);
/**
* function เรียกประเภทเครื่องราช
* @param data ประเภทเครื่องราช
*/
async function fetchDatainsignia(data: ResponseInsigniaType[]) {
insignia.value = "";
invoiceType.value = "all";
insigniaOp.value = [{ name: "ทั้งหมด", id: "" }];
insigniaOp2.value = [];
data.forEach((e: ResponseInsigniaType) => {
insigniaOp.value.push({
name: `${e.name} (${e.shortName})`,
id: e.id,
insigniaType: e.insigniaTypeId,
});
});
data.forEach((e: ResponseInsigniaType) => {
insigniaOp2.value.push({ name: `${e.name} (${e.shortName})`, id: e.id });
});
data.forEach((e: ResponseInsigniaType) => {
type.value.push({
name: e.name,
shortName: e.shortName,
});
});
}
/**
* function เรียกประเภทเครื่องราช
* @param data ประเภทเครื่องราช
*/
async function fetchDatainsigniaType(data: ResponseInsigniaType[]) {
insigniaType.value = data.map((e: ResponseInsigniaType) => ({
name: e.id,
label: e.name,
}));
}
/**
* function บันทึกผลการได้รับพระราชทานเครื่องราชอิสริยาภรณ์/การจ่ายใบกำกับ
* @param data รายชื่อข้าราชการสามัญฯ
*/
async function fetchlistinsignia(data: ResponseRecordLists[]) {
rows.value = [];
const alllist = await data.map((e: ResponseRecordLists) => ({
id: e.id,
citizenId: e.citizenId,
prefix: e.prefix,
position: e.position,
status: status(e.status) ?? "",
statusMain: e.status,
dateReceive: date2Thai(e.dateReceive),
name: e.fullName,
type: `${e.requestInsignia} (${
type.value.find((item) => item.name === e.requestInsignia)?.shortName ||
""
})`,
employeeType: profileType(
e.profileType === "" ? "officer" : e.profileType
),
profileType: e.profileType === "" ? "officer" : e.profileType,
date: date2Thai(e.date),
volumeNo: e.volumeNo,
section: e.section,
page: e.page,
number: e.no,
vatnumber: e.number,
datepay: date2Thai(e.datePayment),
typepay: e.typePayment,
address: e.address,
dateReceiveInsignia: e.dateReceiveInsignia,
docReceiveInsignia: e.docReceiveInsignia,
orgReceiveInsignia: e.orgReceiveInsignia,
orgReceiveInsigniaId: e.orgReceiveInsigniaId,
dateReturnInsignia: e.dateReturnInsignia,
docReturnInsignia: e.docReturnInsignia,
orgReturnInsignia: e.orgReturnInsignia,
orgReturnInsigniaId: e.orgReturnInsigniaId,
}));
rows.value = alllist;
listInsignia.value = alllist;
searchData(invoiceType.value, employeeClass.value);
}
/**
* function ค้นหาข้อมูลในตาราง
* @param invoice ใบกำกับ
* @param employeeClass สถารภาพ
*/
function searchData(invoice: string, employeeClass: string) {
if (invoice !== "all" && employeeClass !== "all") {
let list = listInsignia.value.filter(
(e: any) =>
convertDatepay(e.datepay) === invoice &&
e.employeeType === profileType(employeeClass)
);
rows.value = list;
} else if (invoice !== "all" && employeeClass === "all") {
let list = listInsignia.value.filter(
(e: any) => convertDatepay(e.datepay) === invoice
);
rows.value = list;
} else if (invoice === "all" && employeeClass !== "all") {
let list = listInsignia.value.filter(
(e: DataRecord) => e.employeeType === profileType(employeeClass)
);
rows.value = list;
} else if (invoice === "all" && employeeClass == "all") {
rows.value = listInsignia.value;
}
}
/**
* function convert สถานะ
* @param val สถานะ
*/
function status(val: string) {
switch (val) {
case "PENDING":
return "รอบันทึกข้อมูล";
case "REJECT":
return "ยกเลิก";
case "DELETE":
return "ลบ";
case "DONE":
return "บันทึกลง ก.พ. 7 แล้ว";
}
}
/**
* function convert สถานภาพ
* @param val สถานภาพ
*/
function profileType(val: string) {
const newVal = val.toLocaleLowerCase();
switch (newVal) {
case "officer":
return "ข้าราชการ กทม.สามัญ";
case "employee":
return "ลูกจ้างประจำ";
}
}
/**
* function convert สถานะ การจ่าย
* @param val สถานะ การจ่าย
*/
function convertDatepay(val: string | null) {
switch (val) {
case null:
return "noDate";
default:
return "haveDate";
}
}
return {
rows,
insignia,
insigniaOp,
insigniaOp2,
insigniaType,
invoiceType,
invoiceTypeop,
employeeClass,
employeeClassOps,
fetchDatainsignia,
fetchDatainsigniaType,
status,
profileType,
fetchlistinsignia,
searchData,
};
});