diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 9042669..67883db 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -433,7 +433,7 @@ export class SalaryPeriodController extends Controller { if (body.type == "NONE") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; - salaryProfile.positionSalaryAmount = salaryProfile.amount; + salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount; } else if (body.type == "PENDING") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; @@ -485,7 +485,14 @@ export class SalaryPeriodController extends Controller { @Put("org/{id}") async GetListsSalaryProfile( @Path() id: string, - @Body() body: { page: number; pageSize: number; keyword?: string; type: string }, + @Body() + body: { + page: number; + pageSize: number; + keyword?: string; + type?: any; + isRetire?: boolean | null; + }, ) { const salaryOrg = await this.salaryOrgRepository.findOne({ where: { @@ -497,11 +504,12 @@ export class SalaryPeriodController extends Controller { } const [salaryProfile, total] = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("profile") - .orWhere( + .andWhere( new Brackets((qb) => { - qb.andWhere(body.type != null && body.type != "" ? "profile.type LIKE :type" : "1=1", { - type: `%${body.type.toUpperCase()}%`, + qb.andWhere(body.type != null && body.type != "" ? `profile.type LIKE :type` : "1=1", { + type: body.type == null ? "" : `%${body.type.toUpperCase()}%`, }) + .andWhere(body.isRetire != null ? `profile.isRetired = ${body.isRetire}` : "1=1") .andWhere({ salaryOrgId: salaryOrg.id, }) @@ -564,6 +572,7 @@ export class SalaryPeriodController extends Controller { const salaryOrgAll = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salaryOrg.salaryPeriodId, + snapshot: salaryOrg.snapshot, }, }); if (!salaryOrgAll) { diff --git a/src/entities/SalaryProfile.ts b/src/entities/SalaryProfile.ts index 7b72baf..9c2377a 100644 --- a/src/entities/SalaryProfile.ts +++ b/src/entities/SalaryProfile.ts @@ -111,31 +111,28 @@ export class SalaryProfile extends EntityBase { comment: "เงินเดือนฐาน", default: null, }) - amount: number; + amount: number | null; @Column({ - nullable: true, type: "double", comment: "เงินพิเศษ", - default: null, + default: 0, }) amountSpecial: number; @Column({ - nullable: true, type: "double", comment: "จำนวนเงินที่ใช้เลื่อน", - default: null, + default: 0, }) - amountUse: number | null; + amountUse: number; @Column({ - nullable: true, type: "double", comment: "เงินเดือนหลังเลื่อน", - default: null, + default: 0, }) - positionSalaryAmount: number | null; + positionSalaryAmount: number; @Column({ comment: @@ -325,7 +322,7 @@ export class CreateSalaryProfile { posExecutive: string | null; @Column() - amount: number; + amount: number | null; @Column("uuid") rootId: string | null; @@ -358,19 +355,19 @@ export class CreateSalaryProfile { child4: string | null; @Column() - result: string; + result: string | null; @Column() - duration: string; + duration: string | null; @Column() - punish: string; + punish: string | null; @Column() - retired: string; + retired: string | null; @Column() - retired2: string; + retired2: string | null; @Column() isRetired: boolean; diff --git a/src/migration/1709189881087-update_table_salaryProfile_add_isretired1.ts b/src/migration/1709189881087-update_table_salaryProfile_add_isretired1.ts new file mode 100644 index 0000000..c067c3a --- /dev/null +++ b/src/migration/1709189881087-update_table_salaryProfile_add_isretired1.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSalaryProfileAddIsretired11709189881087 implements MigrationInterface { + name = 'UpdateTableSalaryProfileAddIsretired11709189881087' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountSpecial\` \`amountSpecial\` double NOT NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountUse\` \`amountUse\` double NOT NULL COMMENT 'จำนวนเงินที่ใช้เลื่อน' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`positionSalaryAmount\` \`positionSalaryAmount\` double NOT NULL COMMENT 'เงินเดือนหลังเลื่อน' DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`positionSalaryAmount\` \`positionSalaryAmount\` double NULL COMMENT 'เงินเดือนหลังเลื่อน'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountUse\` \`amountUse\` double NULL COMMENT 'จำนวนเงินที่ใช้เลื่อน'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountSpecial\` \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ'`); + } + +}