From 965dd6fe5bd44b37e9a3cea0d04337265e17d1bc Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 11 Mar 2024 14:19:26 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=84=E0=B8=B4?= =?UTF-8?q?=E0=B8=A7=E0=B8=A3=E0=B8=B5=E0=B9=88=E0=B9=80=E0=B8=87=E0=B8=B4?= =?UTF-8?q?=E0=B8=99=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 --- .../OrganizationUnauthorizeController.ts | 46 +++++++++++++++++-- src/controllers/ProfileController.ts | 42 ++++++++++++++++- src/entities/Profile.ts | 8 ++++ ...pdate_table_salaryProfile_add_birthDate.ts | 20 ++++++++ 4 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 src/migration/1710129049964-update_table_salaryProfile_add_birthDate.ts diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 2445ff83..e1b158da 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -24,6 +24,7 @@ import HttpStatusCode from "../interfaces/http-status"; import { Brackets, IsNull, Not } from "typeorm"; import { OrgRoot } from "../entities/OrgRoot"; import { PosMaster } from "../entities/PosMaster"; +import { calculateRetireDate } from "../interfaces/utils"; @Route("api/v1/org/unauthorize") @Tags("OrganizationUnauthorize") @@ -49,6 +50,8 @@ export class OrganizationUnauthorizeController extends Controller { page: number; pageSize: number; keyword?: string; + year: number; + period: string; }, ) { const findRevision = await this.orgRevisionRepository.findOne({ @@ -137,6 +140,7 @@ export class OrganizationUnauthorizeController extends Controller { ); }), ) + .orderBy("current_holder.citizenId", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); @@ -173,7 +177,25 @@ export class OrganizationUnauthorizeController extends Controller { item.current_holder == null || item.current_holder.profileSalary.length == 0 ? null : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; - + let datePeriodStart = new Date( + `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ); + let datePeriodEnd = new Date( + `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ); + if (body.period.toLocaleUpperCase() == "APR") { + datePeriodStart = new Date(`${body.year}-03-31T00:00:00.000Z`); + datePeriodEnd = new Date(`${body.year}-03-31T00:00:00.000Z`); + } + if (body.period.toLocaleUpperCase() == "OCT") { + datePeriodStart = new Date(`${body.year}-09-30T00:00:00.000Z`); + datePeriodEnd = new Date(`${body.year}-09-30T00:00:00.000Z`); + } + datePeriodStart = new Date( + new Date(datePeriodStart.setDate(datePeriodStart.getDate() + 1)).setMonth( + datePeriodStart.getMonth() - 6, + ), + ); return { prefix: item.current_holder.prefix, firstName: item.current_holder.firstName, @@ -200,14 +222,28 @@ export class OrganizationUnauthorizeController extends Controller { child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null, result: null, duration: null, - isPunish: item.current_holder.profileDiscipline.length > 0 ? true : false, - isSuspension: item.current_holder == null ? false : true, + isPunish: + item.current_holder.profileDiscipline.filter( + (x: any) => + new Date( + `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ) >= datePeriodStart && + new Date( + `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ) <= datePeriodEnd, + ).length > 0 + ? true + : false, + isSuspension: item.current_holder.dateRetire == null ? false : true, isAbsent: false, isLeave: false, - isRetired: false, + isRetired: + item.current_holder.birthDate == null || + calculateRetireDate(item.current_holder.birthDate).getFullYear() != body.year + ? false + : true, }; }); - return new HttpSuccess({ data: formattedData, total: total }); } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index f1f3db6c..b88dd8d8 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -25,6 +25,7 @@ import { PosMaster } from "../entities/PosMaster"; import { PosLevel } from "../entities/PosLevel"; import { PosType } from "../entities/PosType"; import { request } from "http"; +import { calculateRetireDate } from "../interfaces/utils"; @Route("api/v1/org/profile") @Tags("Profile") @@ -910,6 +911,8 @@ export class ProfileController extends Controller { pageSize: number; keyword?: string; rootId?: string; + year: number; + period: string; }, ) { const findRevision = await this.orgRevisionRepository.findOne({ @@ -1003,6 +1006,7 @@ export class ProfileController extends Controller { ); }), ) + .orderBy("current_holder.citizenId", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); @@ -1039,6 +1043,25 @@ export class ProfileController extends Controller { item.current_holder == null || item.current_holder.profileSalary.length == 0 ? null : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; + let datePeriodStart = new Date( + `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ); + let datePeriodEnd = new Date( + `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ); + if (body.period.toLocaleUpperCase() == "APR") { + datePeriodStart = new Date(`${body.year}-03-31T00:00:00.000Z`); + datePeriodEnd = new Date(`${body.year}-03-31T00:00:00.000Z`); + } + if (body.period.toLocaleUpperCase() == "OCT") { + datePeriodStart = new Date(`${body.year}-09-30T00:00:00.000Z`); + datePeriodEnd = new Date(`${body.year}-09-30T00:00:00.000Z`); + } + datePeriodStart = new Date( + new Date(datePeriodStart.setDate(datePeriodStart.getDate() + 1)).setMonth( + datePeriodStart.getMonth() - 6, + ), + ); return { prefix: item.current_holder.prefix, @@ -1067,11 +1090,26 @@ export class ProfileController extends Controller { child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null, result: null, duration: null, - isPunish: item.current_holder.profileDiscipline.length > 0 ? true : false, + isPunish: + item.current_holder.profileDiscipline.filter( + (x: any) => + new Date( + `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ) >= datePeriodStart && + new Date( + `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, + ) <= datePeriodEnd, + ).length > 0 + ? true + : false, isSuspension: item.current_holder.dateRetire == null ? false : true, isAbsent: false, isLeave: false, - isRetired: false, + isRetired: + item.current_holder.birthDate == null || + calculateRetireDate(item.current_holder.birthDate).getFullYear() != body.year + ? false + : true, }; }); diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index ed1df480..da7bde80 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -117,6 +117,14 @@ export class Profile extends EntityBase { }) dateRetire: Date; + @Column({ + nullable: true, + type: "datetime", + comment: "วันเกิด", + default: null, + }) + birthDate: Date; + @OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder) current_holders: PosMaster[]; diff --git a/src/migration/1710129049964-update_table_salaryProfile_add_birthDate.ts b/src/migration/1710129049964-update_table_salaryProfile_add_birthDate.ts new file mode 100644 index 00000000..947cdd30 --- /dev/null +++ b/src/migration/1710129049964-update_table_salaryProfile_add_birthDate.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSalaryProfileAddBirthDate1710129049964 implements MigrationInterface { + name = 'UpdateTableSalaryProfileAddBirthDate1710129049964' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`birthDate\` datetime NULL COMMENT 'วันเกิด'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP FOREIGN KEY \`FK_7534d36579c78107ba08a96be6f\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`profileId\` \`profileId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD CONSTRAINT \`FK_7534d36579c78107ba08a96be6f\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP FOREIGN KEY \`FK_7534d36579c78107ba08a96be6f\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`profileId\` \`profileId\` varchar(40) NOT NULL COMMENT 'ไอดีโปรไฟล์'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD CONSTRAINT \`FK_7534d36579c78107ba08a96be6f\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`birthDate\``); + } + +}