From aff5aa452e26e04d84625b05ffdee2e4c78c6961 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 7 Mar 2024 14:25:14 +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=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=9C=E0=B8=B1=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryController.ts | 31 ++++++++--------------- src/controllers/SalaryPeriodController.ts | 22 +++++++++------- src/entities/SalaryPeriod.ts | 6 +++++ src/entities/Salarys.ts | 8 +++--- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index a4842eb..b2e8192 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -43,7 +43,7 @@ export class Salary extends Controller { */ @Post() @Example({ - salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร") + name: "string", //*ชื่อผัง posTypeId: "string(Guid)", //*ระดับของตำแหน่ง posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง isActive: "boolean", //*สถานะการใช้งาน @@ -62,11 +62,6 @@ export class Salary extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - const chk_salaryType = ["OFFICER", "EMPLOYEE"]; - if (!chk_salaryType.includes(salarys.salaryType.toUpperCase())) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง"); - } - const chk_posTypeId = await this.poTypeRepository.findOne({ where: { id: salarys.posTypeId }, }); @@ -83,7 +78,7 @@ export class Salary extends Controller { const chk_3fields = await this.salaryRepository.findOne({ where: { - salaryType: salarys.salaryType, + name: salarys.name, posTypeId: salarys.posTypeId, posLevelId: salarys.posLevelId, }, @@ -91,7 +86,7 @@ export class Salary extends Controller { if (chk_3fields && salarys.isActive) { salarys.isActive = false; } - salarys.salaryType = salarys.salaryType.toUpperCase(); + salarys.name = salarys.name; salarys.isSpecial = salarys.isSpecial; salarys.createdUserId = request.user.sub; salarys.createdFullName = request.user.name; @@ -113,7 +108,7 @@ export class Salary extends Controller { */ @Put("{id}") @Example({ - salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร") + name: "string", //*ชื่อผัง posTypeId: "string(Guid)", //*ระดับของตำแหน่ง posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง isActive: "boolean", //*สถานะการใช้งาน @@ -144,7 +139,7 @@ export class Salary extends Controller { const chk_3fields = await this.salaryRepository.findOne({ where: { - salaryType: requestBody.salaryType, + name: requestBody.name, posTypeId: requestBody.posTypeId, posLevelId: requestBody.posLevelId, isActive: true, @@ -160,11 +155,6 @@ export class Salary extends Controller { await this.salaryRepository.save(chk_3fields); } - const chk_salaryType = ["OFFICER", "EMPLOYEE"]; - if (!chk_salaryType.includes(String(requestBody.salaryType).toUpperCase())) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง"); - } - const chk_posTypeId = await this.poTypeRepository.findOne({ where: { id: requestBody.posTypeId }, }); @@ -233,7 +223,7 @@ export class Salary extends Controller { */ @Get("{id}") @Example({ - salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร") + name: "string", //*ชื่อผัง posTypeId: "string(Guid)", //*ระดับของตำแหน่ง posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง isActive: "boolean", //*สถานะการใช้งาน @@ -247,7 +237,7 @@ export class Salary extends Controller { const salary = await this.salaryRepository.findOne({ where: { id: id }, select: [ - "salaryType", + "name", "isSpecial", "posTypeId", "posLevelId", @@ -289,7 +279,7 @@ export class Salary extends Controller { if (keyword != undefined && keyword !== "") { const filteredSalary = salary.filter( (x) => - x.salaryType?.toString().includes(keyword) || + x.name?.toString().includes(keyword) || x.isSpecial?.toString().includes(keyword) || //new 20.02.67 x.posLevel_?.posLevelName?.toString().includes(keyword) || x.posType_?.posTypeName?.toString().includes(keyword) || @@ -302,7 +292,7 @@ export class Salary extends Controller { const formattedData = filteredSalary.map((item) => ({ id: item.id, - salaryType: item.salaryType, + name: item.name, isSpecial: item.isSpecial, posTypeId: item.posType_?.id, posType: item.posType_?.posTypeName, @@ -320,7 +310,7 @@ export class Salary extends Controller { const formattedData = salary.map((item) => ({ id: item.id, - salaryType: item.salaryType, + name: item.name, isSpecial: item.isSpecial, posTypeId: item.posType_?.id, posType: item.posType_?.posTypeName, @@ -333,7 +323,6 @@ export class Salary extends Controller { details: item.details, })); return new HttpSuccess({ data: formattedData, total }); - } /** diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index b3a6060..e5707d3 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -118,6 +118,9 @@ export class SalaryPeriodController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } + const sum = salaryOrg.salaryProfiles.reduce((accumulator, object) => { + return accumulator + object.amountSpecial; + }, 0); const data = { total: salaryOrg.total, fifteenPercent: salaryOrg.fifteenPercent, @@ -129,6 +132,7 @@ export class SalaryPeriodController extends Controller { sixPercentSpentAmount: salaryOrg.sixPercentAmount - salaryOrg.spentAmount, useAmount: salaryOrg.useAmount, remainingAmount: salaryOrg.remainingAmount, + totalAmountSpecial: sum, }; return new HttpSuccess(data); } @@ -264,7 +268,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryHalf - salaryProfile.amount + salaryRanks.salaryHalfSpecial; + : salaryRanks.salaryHalf - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; } else if (salaryProfile.type == "FULL") { @@ -278,7 +282,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFull == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFull - salaryProfile.amount + salaryRanks.salaryFullSpecial; + : salaryRanks.salaryFull - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; } else if (salaryProfile.type == "FULLHAFT") { @@ -292,7 +296,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFullHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFullHalf - salaryProfile.amount + salaryRanks.salaryFullHalfSpecial; + : salaryRanks.salaryFullHalf - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; } else { @@ -499,7 +503,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryHalf - salaryProfile.amount + salaryRanks.salaryHalfSpecial; + : salaryRanks.salaryHalf - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; } else if (body.type == "FULL") { @@ -513,7 +517,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFull == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFull - salaryProfile.amount + salaryRanks.salaryFullSpecial; + : salaryRanks.salaryFull - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; } else if (body.type == "FULLHAFT") { @@ -527,7 +531,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFullHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFullHalf - salaryProfile.amount + salaryRanks.salaryFullHalfSpecial; + : salaryRanks.salaryFullHalf - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; } else { @@ -753,7 +757,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryHalf - salaryProfile.amount + salaryRanks.salaryHalfSpecial; + : salaryRanks.salaryHalf - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; } else if (salaryProfile.type == "FULL") { @@ -767,7 +771,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFull == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFull - salaryProfile.amount + salaryRanks.salaryFullSpecial; + : salaryRanks.salaryFull - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; } else if (salaryProfile.type == "FULLHAFT") { @@ -781,7 +785,7 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFullHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFullHalf - salaryProfile.amount + salaryRanks.salaryFullHalfSpecial; + : salaryRanks.salaryFullHalf - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; } else { diff --git a/src/entities/SalaryPeriod.ts b/src/entities/SalaryPeriod.ts index d88a18d..0c3223d 100644 --- a/src/entities/SalaryPeriod.ts +++ b/src/entities/SalaryPeriod.ts @@ -16,6 +16,12 @@ export class SalaryPeriod extends EntityBase { }) isActive: boolean; + @Column({ + comment: "ปิดรอบ", + default: false, + }) + isClose: boolean; + @Column({ nullable: true, type: "datetime", diff --git a/src/entities/Salarys.ts b/src/entities/Salarys.ts index f93995d..c85faf7 100644 --- a/src/entities/Salarys.ts +++ b/src/entities/Salarys.ts @@ -7,10 +7,10 @@ import { PosLevel } from "./PosLevel"; @Entity("salarys") export class Salarys extends EntityBase { @Column({ - comment: "ประเภทผัง", + comment: "ชื่อผัง", length: 255, }) - salaryType: string; + name: string; @Column({ length: 40, @@ -81,7 +81,7 @@ export class Salarys extends EntityBase { export class CreateSalary { @Column() - salaryType: string; + name: string; @Column("uuid") posTypeId: string; @@ -110,7 +110,7 @@ export class CreateSalary { export class UpdateSalary { @Column() - salaryType: string; + name: string; @Column("uuid") posTypeId: string;