diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index ce954d7..24a13b7 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, @@ -2326,6 +2328,7 @@ export class EvaluationController { "commanderPositionDoc2", "commanderAboveFullnameDoc2", "commanderAbovePositionDoc2", + "evaluationResult", ], }); if (!evaluation) { @@ -2359,6 +2362,7 @@ export class EvaluationController { "commanderPositionDoc2", "commanderAboveFullnameDoc2", "commanderAbovePositionDoc2", + "evaluationResult", ], }); if (!evaluation) { diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 63a5328..5470421 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -59,10 +59,67 @@ export class ReoportController { */ @Get() async sumaryEvaluationReport(@Query("year") year?: string, @Query("rootid") rootId?: string) { + + const yearInAD = year?year:null; + const yearInBE = yearInAD ? (parseInt(yearInAD) - 543).toString() : null; + + const evaluation = await AppDataSource.getRepository(Evaluation) + .createQueryBuilder("evaluation") + .where('evaluation.evaluationResult NOT IN (:...evaluationResults)', { evaluationResults: ['PENDING'] }) + .andWhere( yearInBE && yearInBE != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInBE }) + .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.length > 0?result[0].agency:"ทุกสำนักงานเขต", + list: result, + total: Extension.ToThaiNumber(submitter.toString()), + sumPass: Extension.ToThaiNumber(sumPass.toString()), + sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()), + }, }); } diff --git a/src/entities/Evaluation.ts b/src/entities/Evaluation.ts index 5aa0945..5c5f12d 100644 --- a/src/entities/Evaluation.ts +++ b/src/entities/Evaluation.ts @@ -33,6 +33,12 @@ export class Evaluation extends EntityBase { @Column({ nullable: true, comment: "สังกัด" }) oc: string; + @Column({ nullable: true, comment: "สำนักงานที่สังกัด" }) + root: string; + + @Column({ nullable: true, length: 255, comment: "ไอดีสำนักงานที่สังกัด" }) + orgRootId: string; + @Column({ nullable: true, comment: "root", @@ -294,6 +300,12 @@ export class CreateEvaluation { @Column() assessments?: CreateAssessment[]; + + @Column() + root?: string | null; + + @Column() + orgRootId?: string | null; } export class CreateEducation { diff --git a/src/migration/1736140332359-update_eva_add_root.ts b/src/migration/1736140332359-update_eva_add_root.ts new file mode 100644 index 0000000..434ad04 --- /dev/null +++ b/src/migration/1736140332359-update_eva_add_root.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateEvaAddRoot1736140332359 implements MigrationInterface { + name = 'UpdateEvaAddRoot1736140332359' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`root\` varchar(255) NULL COMMENT 'สำนักงานที่สังกัด'`); + await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`orgRootId\` varchar(255) NULL COMMENT 'ไอดีสำนักงานที่สังกัด'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`orgRootId\``); + await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`root\``); + } + +}