From b14ca52808f2399deed547946a2d2a31bbbc4db5 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 6 Dec 2024 15:59:51 +0700 Subject: [PATCH 1/2] ui report leave --- src/api/09_leave/api.leave.ts | 6 +- src/modules/09_leave/interface/index/Main.ts | 13 +- src/modules/09_leave/views/06_ReportMain.vue | 855 +++++++++++------- .../09_leave/views/07_ReportCheckin.vue | 314 +++---- 4 files changed, 696 insertions(+), 492 deletions(-) diff --git a/src/api/09_leave/api.leave.ts b/src/api/09_leave/api.leave.ts index 0ef73073e..120aca326 100644 --- a/src/api/09_leave/api.leave.ts +++ b/src/api/09_leave/api.leave.ts @@ -40,6 +40,10 @@ export default { leaveDeleteReject: (id: string) => `${leave}/admin/delete/reject/${id}`, /**รายงาน */ - leaveReportTimeRecords: () => `${leaveReport}/time-records/officer`, + leaveReportTimeRecords: (type: string) => + `${leaveReport}/time-records/${type}`, + leaveReportTimeLate: (type: string) => `${leaveReport}/late/${type}`, + leaveReportLeaveday: (type: string) => `${leaveReport}/leaveday/${type}`, + leaveReportLeave2: (type: string) => `${leaveReport}/leave2/${type}`, }; diff --git a/src/modules/09_leave/interface/index/Main.ts b/src/modules/09_leave/interface/index/Main.ts index 3c52287a0..0f0a59dd5 100644 --- a/src/modules/09_leave/interface/index/Main.ts +++ b/src/modules/09_leave/interface/index/Main.ts @@ -7,19 +7,8 @@ interface DataOption2 { name: string; } -interface DataDateWeeklyObject { - startDay: number; - endDay: number; - month: number; - year: number; -} interface DataDateMonthObject { month: number; year: number; } -export type { - DataOption, - DataOption2, - DataDateWeeklyObject, - DataDateMonthObject, -}; +export type { DataOption, DataOption2, DataDateMonthObject }; diff --git a/src/modules/09_leave/views/06_ReportMain.vue b/src/modules/09_leave/views/06_ReportMain.vue index a17e24433..7422243b0 100644 --- a/src/modules/09_leave/views/06_ReportMain.vue +++ b/src/modules/09_leave/views/06_ReportMain.vue @@ -4,33 +4,59 @@ import { ref, onMounted } from "vue"; import { VuePDF, usePDF } from "@tato30/vue-pdf"; import { useQuasar } from "quasar"; -import http from "@/plugins/http"; -import config from "@/app.config"; +import { useRoute } from "vue-router"; import { checkPermission } from "@/utils/permissions"; import { useCounterMixin } from "@/stores/mixin"; +import { useStructureTree } from "@/stores/structureTree"; +import genReportXLSX from "@/plugins/genreportxlsx"; +import http from "@/plugins/http"; +import config from "@/app.config"; -import type { DataOption } from "@/modules/09_leave/interface/index/Main"; +import type { DataStructureTree } from "@/interface/main"; +import type { + DataOption, + DataDateMonthObject, +} from "@/modules/09_leave/interface/index/Main"; + +import LoadView from "@/components/LoadView.vue"; /** use*/ -const mixin = useCounterMixin(); const $q = useQuasar(); -const { showLoader, hideLoader, date2Thai, dateToISO, messageError } = mixin; - -const apiGenReport = - "https://report-server.frappet.synology.me/api/v1/report-template/xlsx"; +const route = useRoute(); +const { fetchStructureTree } = useStructureTree(); +const { + showLoader, + hideLoader, + date2Thai, + dateToISO, + messageError, + monthYear2Thai, +} = useCounterMixin(); const year = ref(new Date().getFullYear()); const dateStart = ref(new Date(year.value, 9, 1)); const dateEnd = ref(new Date(year.value + 1, 8, 30)); -const employeeClass = ref("employee"); +const dateMonth = ref({ + month: new Date().getMonth(), + year: new Date().getFullYear(), +}); + +const typeReport = ref(""); +const optionReport = ref([ + { id: "1", name: "รายงานการลางานตามประเภทการลา" }, + { id: "2", name: "รายงานการลางาน" }, +]); + +const employeeClass = ref("officer"); const yearType = ref("FULL"); const employeeClassMain = ref([ - { id: "employee", name: "ลูกจ้างประจำ กทม." }, { id: "officer", name: "ข้าราชการ กทม. สามัญ" }, + { id: "employee", name: "ลูกจ้างประจำ กทม." }, ]); const yearTypeOptionMain = ref([ { id: "FULL", name: "รายปี" }, + { id: "MONTH", name: "รายเดือน" }, { id: "FIRSTHAFT", name: "ครึ่งปีแรก" }, { id: "SECONDHAFT", name: "ครึ่งปีหลัง" }, ]); @@ -38,26 +64,76 @@ const employeeClassOption = ref(employeeClassMain.value); const yearTypeOptionOption = ref(yearTypeOptionMain.value); const detailReport = ref(); +const isReport = ref(false); +const isLoadPDF = ref(false); + +/** tree*/ +const filterTree = ref(""); +const nodeId = ref(""); +const nodeLevel = ref(0); +const node = ref([]); +const expanded = ref([]); + +async function fetchDataTree() { + node.value = await fetchStructureTree(route.meta.Key as string, true); +} + +function onSelectedNode(id: string, level: number) { + nodeId.value = id; + nodeLevel.value = level; + updateLeaveday(); +} /** function อัปเดทบัญชีแสดงวันลา */ async function updateLeaveday() { - if (yearType.value === "FULL") { - dateStart.value = new Date(year.value - 1, 9, 1); - dateEnd.value = new Date(year.value, 8, 30); - } else if (yearType.value === "FIRSTHAFT") { - dateStart.value = new Date(year.value - 1, 9, 1); - dateEnd.value = new Date(year.value, 2, 31); - } else if (yearType.value === "SECONDHAFT") { - dateStart.value = new Date(year.value, 3, 1); - dateEnd.value = new Date(year.value, 8, 30); + if (!nodeId.value || !typeReport.value) { + return false; } - fetchLeaveday( - employeeClass.value, - yearType.value, - dateStart.value, - dateEnd.value - ); + isReport.value = false; + isLoadPDF.value = true; + pdfSrc.value = undefined; + switch (yearType.value) { + case "FULL": + dateStart.value = new Date(year.value - 1, 9, 1); + dateEnd.value = new Date(year.value, 8, 30); + break; + + case "MONTH": + const mount = dateMonth.value.month + 1; + // วันเริ่มต้นของเดือน + dateStart.value = new Date(dateMonth.value.year, mount - 1, 1); + // วันสิ้นสุดของเดือนถัดไป + dateEnd.value = new Date(dateMonth.value.year, mount, 0); + break; + + case "FIRSTHAFT": + dateStart.value = new Date(year.value - 1, 9, 1); + dateEnd.value = new Date(year.value, 2, 31); + break; + + case "SECONDHAFT": + dateStart.value = new Date(year.value, 3, 1); + dateEnd.value = new Date(year.value, 8, 30); + break; + + default: + break; + } + + typeReport.value === "1" + ? fetchLeaveday( + employeeClass.value, + yearType.value, + dateStart.value, + dateEnd.value + ) + : fetchLeaveday2( + employeeClass.value, + yearType.value, + dateStart.value, + dateEnd.value + ); } /** @@ -73,25 +149,57 @@ async function fetchLeaveday( startDate: Date, endDate: Date ) { - showLoader(); const body = { - type: year === "FULL" ? "FULL" : "HAFT", + type: year === "FULL" ? "FULL" : year === "MONTH" ? "MONTH" : "HAFT", startDate: dateToISO(startDate), endDate: dateToISO(endDate), + nodeId: nodeId.value, + node: nodeLevel.value, }; await http .post(config.API.leaveReportLeaveday(type), body) .then(async (res) => { const data = res.data.result; - data && (await genReport(data)); + data && (await fetchDocumentTemplate(data)); + isReport.value = data ? true : false; detailReport.value = data; }) .catch((err) => { messageError($q, err); }) .finally(() => { - hideLoader(); + isLoadPDF.value = false; + }); +} + +async function fetchLeaveday2( + type: string, + year: string, + startDate: Date, + endDate: Date +) { + const body = { + type: year === "FULL" ? "FULL" : year === "MONTH" ? "MONTH" : "HAFT", + startDate: dateToISO(startDate), + endDate: dateToISO(endDate), + nodeId: nodeId.value, + node: nodeLevel.value, + }; + + await http + .post(config.API.leaveReportLeave2(type), body) + .then(async (res) => { + const data = res.data.result; + data && (await fetchDocumentTemplate(data)); + isReport.value = data ? true : false; + detailReport.value = data; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + isLoadPDF.value = false; }); } @@ -99,7 +207,7 @@ async function fetchLeaveday( * function เรียกไฟล์ PDF * @param data ข้อมูลบัญชีวันลา */ -async function genReport(data: any) { +async function fetchDocumentTemplate(data: any) { await axios .post(`${config.API.reportTemplate}/xlsx`, data, { headers: { @@ -111,7 +219,6 @@ async function genReport(data: any) { .then(async (res) => { const blob = new Blob([res.data]); const objectUrl = URL.createObjectURL(blob); - fileBlob.value = blob; const pdfData = await usePDF(`${objectUrl}`); setTimeout(() => { @@ -129,53 +236,11 @@ async function genReport(data: any) { }); } -/** - * function เรียกไฟล์ XLSX - * @param data ข้อมูลบัญชีวันลา - */ -async function genReportXLSX(data: any) { - await axios - .post(`${config.API.reportTemplate}/xlsx`, data, { - headers: { - accept: - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "content-Type": "application/json", - }, - responseType: "blob", - }) - .then(async (res) => { - const blob = new Blob([res.data]); - downloadReport(blob, "xlsx"); - }) - .catch(async (e) => { - messageError($q, JSON.parse(await e.response.data.text())); - }) - .finally(() => { - hideLoader(); - }); -} - -/** - * function Download ไฟล์ - * @param data ข้อมูลบัญชีวันลา - * @param type นามสกุลไฟล์ - */ -async function downloadReport(data: any, type: string) { - const link = document.createElement("a"); - var fileName = "บัญชีแสดงวันลา"; - link.href = window.URL.createObjectURL(new Blob([data])); - link.setAttribute("download", `${fileName}.${type}`); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); -} - const splitterModel = ref(14); const numOfPages = ref(0); const page = ref(1); const pdfSrc = ref(); -// const modalFull = ref(false); -const fileBlob = ref(); + /** ไปหน้าต่อไปของรายงาน */ function nextPage() { if (page.value < numOfPages.value) { @@ -190,42 +255,23 @@ function backPage() { } } -/** - * function ค้นหาข้อมูล Option - * @param val คำค้นหา - * @param update function - * @param type ประเภท option - */ -function filterFnOptions(val: any, update: Function, type: string) { - switch (type) { - case "employeeClass": - update(() => { - employeeClassOption.value = employeeClassMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - case "yearType": - update(() => { - yearTypeOptionOption.value = yearTypeOptionMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - } +function monthYearThai(val: DataDateMonthObject) { + if (val == null) return ""; + else return monthYear2Thai(val.month, val.year); } onMounted(() => { - updateLeaveday(); + fetchDataTree(); }); + - + diff --git a/src/modules/09_leave/views/07_ReportCheckin.vue b/src/modules/09_leave/views/07_ReportCheckin.vue index ae8fbfddd..e19a341ec 100644 --- a/src/modules/09_leave/views/07_ReportCheckin.vue +++ b/src/modules/09_leave/views/07_ReportCheckin.vue @@ -15,7 +15,6 @@ import genReportXLSX from "@/plugins/genreportxlsx"; import type { DataStructureTree } from "@/interface/main"; import type { DataOption, - DataDateWeeklyObject, DataDateMonthObject, } from "@/modules/09_leave/interface/index/Main"; @@ -161,10 +160,8 @@ async function updateFilterType(type: string) { * @param body วันเรื่มต้นและสิ้นสุด */ async function fetchReportTimeRecords(body: any) { - console.log(body); - await http - .post(config.API.leaveReportTimeRecords(), body) + .post(config.API.leaveReportTimeRecords(employeeClass.value), body) .then(async (res) => { const data = res.data.result; detailReport.value = data; @@ -185,7 +182,7 @@ async function fetchReportTimeRecords(body: any) { */ async function fetchReportTimeLate(body: any) { await http - .post(config.API.leaveReportTimeRecords(), body) + .post(config.API.leaveReportTimeLate(employeeClass.value), body) .then(async (res) => { const data = res.data.result; detailReport.value = data; @@ -274,9 +271,9 @@ onMounted(() => { รายงานสถิติการลงเวลา -
+
-
+
{ />
-
+
{
-
+
{
-
+
{
-
+
{
- -
- - -
- - - -
+ + + +
+ + + +
-
- - - -
-
- - - - + - From 3ec21e48658071d6dbec50f11081e95476ba6e3b Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 6 Dec 2024 16:16:29 +0700 Subject: [PATCH 2/2] =?UTF-8?q?fix=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=A5=E0=B8=87=E0=B9=80=E0=B8=A7=E0=B8=A5?= =?UTF-8?q?=E0=B8=B2=E0=B8=9B=E0=B8=8F=E0=B8=B4=E0=B8=9A=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/09_leave/views/02_WorkingMain.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/09_leave/views/02_WorkingMain.vue b/src/modules/09_leave/views/02_WorkingMain.vue index 0335224c2..d28f5b1ab 100644 --- a/src/modules/09_leave/views/02_WorkingMain.vue +++ b/src/modules/09_leave/views/02_WorkingMain.vue @@ -4,7 +4,7 @@ import { ref } from "vue"; /** import Components */ import Tab1 from "@/modules/09_leave/components/02_WorkList/Tab1.vue"; import Tab2 from "@/modules/09_leave/components/02_WorkList/Tab2.vue"; -import DialogReport from "@/modules/09_leave/components/02_WorkList/DialogReport.vue"; +// import DialogReport from "@/modules/09_leave/components/02_WorkList/DialogReport.vue"; const tab = ref("1"); @@ -18,7 +18,7 @@ function onClickOpenDialog() {
รายการลงเวลาปฏิบัติงาน - รายงานสถิติการลงเวลา - + -->
@@ -60,7 +60,7 @@ function onClickOpenDialog() {
- +