แก้คิวรี่เงินเดือน

This commit is contained in:
Kittapath 2024-03-11 14:19:26 +07:00
parent d825373542
commit 965dd6fe5b
4 changed files with 109 additions and 7 deletions

View file

@ -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 });
}

View file

@ -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,
};
});

View file

@ -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[];

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableSalaryProfileAddBirthDate1710129049964 implements MigrationInterface {
name = 'UpdateTableSalaryProfileAddBirthDate1710129049964'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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\``);
}
}