From 8b01454d0a0b70c8a7d253618a24132ce225e458 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 6 Jan 2025 14:41:25 +0700 Subject: [PATCH] #984(3) --- src/controllers/EvaluationController.ts | 2 + src/controllers/ReportController.ts | 51 ++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index ce954d7..de25b31 100644 --- a/src/controllers/EvaluationController.ts +++ b/src/controllers/EvaluationController.ts @@ -331,6 +331,8 @@ export class EvaluationController { posNo: null, oc: null, salary: null, + root: null, + orgRootId: null, positionLevel: null, birthDate: null, govAge: null, diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 5b1fd4c..fab4290 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -64,14 +64,61 @@ export class ReoportController { const evaluation = await AppDataSource.getRepository(Evaluation) .createQueryBuilder("evaluation") - .where( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD }) + .where('evaluation.evaluationResult NOT IN (:...evaluationResults)', { evaluationResults: ['PENDING'] }) + .andWhere( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD }) .andWhere(rootId?'orgRootId = :rootId': "1=1", { rootId: rootId }) + .andWhere('evaluation.step = :step', { step: 'DONE' }) .getMany(); + const groupedData = evaluation.reduce((acc:any, item) => { + const key = item.root; + if (!acc[key]) { + acc[key] = { + agency: item.root && item.root != "" ? item.root: "-", + submitter: 0, + passCount: 0, + notPassCount: 0, + }; + } + if (item.evaluationResult === 'PASS') { + acc[key].passCount++; + } else if (item.evaluationResult === 'NOTPASS') { + acc[key].notPassCount++; + } + return acc; + }, {}); + + const result = Object.values(groupedData).map((item: any) => ({ + ...item , + submitter: Extension.ToThaiNumber((item.passCount + item.notPassCount).toString()), + passCount: Extension.ToThaiNumber(item.passCount.toString()), + notPassCount: Extension.ToThaiNumber(item.notPassCount.toString()), + })); + + const submitter = Object.values(groupedData).reduce((acc: number, item: any) => { + return acc + item.passCount + item.notPassCount; + }, 0); + + const sumPass = Object.values(groupedData).reduce((acc: number, item: any) => { + return acc + item.passCount; + }, 0); + + const sumNotPass = Object.values(groupedData).reduce((acc: number, item: any) => { + return acc + item.notPassCount; + }, 0); + return new HttpSuccess({ template: "summary-evaluation", reportName: "xlsx-report", - data: null, + data: { + year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), + date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), + mainAgency: rootId?result[0].root:"ทุกสำนักงานเขต", + list: result, + total: Extension.ToThaiNumber(submitter.toString()), + sumPass: Extension.ToThaiNumber(sumPass.toString()), + sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()), + }, }); }