From 33a5cf2a57da0e2ae4ba221f7858e6ff1dba37ae Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 7 Mar 2024 15:28:23 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A7=E0=B8=84=E0=B8=B8=E0=B8=93=E0=B8=AA?= =?UTF-8?q?=E0=B8=A1=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=9A=E0=B8=B8?= =?UTF-8?q?=E0=B8=84=E0=B8=84=E0=B8=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 109 +++++++++++++++------- src/entities/SalaryProfile.ts | 41 +++++--- 2 files changed, 106 insertions(+), 44 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index e5707d3..24ee843 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -133,6 +133,7 @@ export class SalaryPeriodController extends Controller { useAmount: salaryOrg.useAmount, remainingAmount: salaryOrg.remainingAmount, totalAmountSpecial: sum, + totalBackup: salaryOrg.salaryProfiles.filter((x) => x.isReserve == true).length, }; return new HttpSuccess(data); } @@ -308,16 +309,18 @@ export class SalaryPeriodController extends Controller { // หาจำนวน Quota คงเหลือ if (salaryProfile.salaryOrg.snapshot == "SNAP1") { if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") { - const amountFullType = await this.salaryProfileRepository.count({ - where: { - salaryOrgId: salaryProfile?.salaryOrg.id, - type: "FULL", - }, - }); - const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType; - salaryProfile.salaryOrg.quantityUsed = amountFullType; - salaryProfile.salaryOrg.remainQuota = calRemainQuota; - await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); + if (salaryProfile.isReserve == false) { + const amountFullType = await this.salaryProfileRepository.count({ + where: { + salaryOrgId: salaryProfile?.salaryOrg.id, + type: "FULL", + }, + }); + const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType; + salaryProfile.salaryOrg.quantityUsed = amountFullType; + salaryProfile.salaryOrg.remainQuota = calRemainQuota; + await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); + } } else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") { const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") @@ -370,16 +373,18 @@ export class SalaryPeriodController extends Controller { // หาจำนวน Quota คงเหลือ if (salaryOrg.snapshot == "SNAP1") { if (salaryOrg.salaryPeriod.period == "APR") { - const amountFullType = await this.salaryProfileRepository.count({ - where: { - salaryOrgId: salaryOrg.id, - type: "FULL", - }, - }); - const calRemainQuota = salaryOrg.fifteenPercent - amountFullType; - salaryOrg.quantityUsed = amountFullType; - salaryOrg.remainQuota = calRemainQuota; - await this.salaryOrgRepository.save(salaryOrg); + if (salaryProfile.isReserve == false) { + const amountFullType = await this.salaryProfileRepository.count({ + where: { + salaryOrgId: salaryOrg.id, + type: "FULL", + }, + }); + const calRemainQuota = salaryOrg.fifteenPercent - amountFullType; + salaryOrg.quantityUsed = amountFullType; + salaryOrg.remainQuota = calRemainQuota; + await this.salaryOrgRepository.save(salaryOrg); + } } else if (salaryOrg.salaryPeriod.period == "OCT") { const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") @@ -409,7 +414,7 @@ export class SalaryPeriodController extends Controller { * @param {string} type ประเภทการเลื่อน NONE->ไม่ได้เลื่อน HAFT->ครึ่งขั้น FULL->1ขั้น FULLHAFT->1.5ขั้น */ @Post("change/type") - async changeType(@Body() body: { profileId: string; type: string }) { + async changeType(@Body() body: { profileId: string; type: string; isReserve: boolean }) { const salaryProfile = await this.salaryProfileRepository.findOne({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { id: body.profileId }, @@ -538,22 +543,25 @@ export class SalaryPeriodController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); } salaryProfile.type = body.type; + salaryProfile.isReserve = body.isReserve; await this.salaryProfileRepository.save(salaryProfile); if (salaryProfile.salaryOrg) { // หาจำนวน Quota คงเหลือ if (salaryProfile.salaryOrg.snapshot == "SNAP1") { if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") { - const amountFullType = await this.salaryProfileRepository.count({ - where: { - salaryOrgId: salaryProfile.salaryOrg.id, - type: "FULL", - }, - }); - const calRemainQuota = salaryProfile.salaryOrg.fifteenPercent - amountFullType; - salaryProfile.salaryOrg.quantityUsed = amountFullType; - salaryProfile.salaryOrg.remainQuota = calRemainQuota; - await this.salaryOrgRepository.save(salaryProfile.salaryOrg); + if (body.isReserve == false) { + const amountFullType = await this.salaryProfileRepository.count({ + where: { + salaryOrgId: salaryProfile.salaryOrg.id, + type: "FULL", + }, + }); + const calRemainQuota = salaryProfile.salaryOrg.fifteenPercent - amountFullType; + salaryProfile.salaryOrg.quantityUsed = amountFullType; + salaryProfile.salaryOrg.remainQuota = calRemainQuota; + await this.salaryOrgRepository.save(salaryProfile.salaryOrg); + } } else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") { const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") @@ -649,6 +657,43 @@ export class SalaryPeriodController extends Controller { return new HttpSuccess({ data: salaryProfile, total }); } + /** + * API แก้คุณสมบัติ + * + * @summary SLR_031 - แก้คุณสมบัติ #30 + * + */ + @Put("org/property/{id}") + async editProperty( + @Path() id: string, + @Body() + body: { + isPunish: boolean; + isSuspension: boolean; + isAbsent: boolean; + isLeave: boolean; + }, + @Request() request: { user: Record }, + ) { + const salaryProfile = await this.salaryProfileRepository.findOne({ + where: { + id: id, + }, + }); + if (!salaryProfile) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้"); + } + salaryProfile.isPunish = body.isPunish; + salaryProfile.isSuspension = body.isSuspension; + salaryProfile.isAbsent = body.isAbsent; + salaryProfile.isLeave = body.isLeave; + salaryProfile.lastUpdateUserId = request.user.sub; + salaryProfile.lastUpdateFullName = request.user.name; + salaryProfile.lastUpdatedAt = new Date(); + await this.salaryProfileRepository.save(salaryProfile); + return new HttpSuccess(); + } + /** * API เพิ่มคนเลื่อนเงินเดือนตามรอบ * @@ -661,7 +706,7 @@ export class SalaryPeriodController extends Controller { @Request() request: { user: Record }, ) { const salaryOrg = await this.salaryOrgRepository.findOne({ - relations: ["salaryPeriod"], + relations: ["salaryPeriod", "salaryProfiles"], where: { id: requestBody.id, }, diff --git a/src/entities/SalaryProfile.ts b/src/entities/SalaryProfile.ts index 9c2377a..28a52fa 100644 --- a/src/entities/SalaryProfile.ts +++ b/src/entities/SalaryProfile.ts @@ -233,38 +233,45 @@ export class SalaryProfile extends EntityBase { @Column({ nullable: true, - comment: "ผลการประเมิน", + comment: "ผลการประเมินผลการปฏิบัติราชการ", default: null, }) result: string; @Column({ nullable: true, - comment: "ระยะเวลา", + comment: "ระยะเวลาการปฏิบัติราชการในรอบครึ่งปี", default: null, }) duration: string; @Column({ nullable: true, - comment: "การลงโทษ", - default: null, + comment: "การลงโทษทางวินัย", + default: false, }) - punish: string; + isPunish: boolean; @Column({ nullable: true, comment: "พักราชการ", - default: null, + default: false, }) - retired: string; + isSuspension: boolean; @Column({ nullable: true, comment: "ขาดราชการ", - default: null, + default: false, }) - retired2: string; + isAbsent: boolean; + + @Column({ + nullable: true, + comment: "วันลา", + default: false, + }) + isLeave: boolean; @Column({ nullable: true, @@ -273,6 +280,13 @@ export class SalaryProfile extends EntityBase { }) isRetired: boolean; + @Column({ + nullable: true, + comment: "สำรอง", + default: false, + }) + isReserve: boolean; + @ManyToOne(() => SalaryOrg, (salaryOrg) => salaryOrg.salaryProfiles) @JoinColumn({ name: "salaryOrgId" }) salaryOrg: SalaryOrg; @@ -361,13 +375,16 @@ export class CreateSalaryProfile { duration: string | null; @Column() - punish: string | null; + isPunish: boolean; @Column() - retired: string | null; + isSuspension: boolean; @Column() - retired2: string | null; + isAbsent: boolean; + + @Column() + isLeave: boolean; @Column() isRetired: boolean;