From f0a815f75caa60bafdf0de5692c631183c279827 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 4 Mar 2024 13:40:33 +0700 Subject: [PATCH] no message --- src/controllers/SalaryPeriodController.ts | 130 +++++++++++----------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 360621d..c342d9e 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -143,18 +143,18 @@ export class SalaryPeriodController extends Controller { @Delete("profile/{id}") async deleteSalaryProfile(@Path() id: string) { const salaryProfile = await this.salaryProfileRepository.findOne({ - relations: ["salaryOrg","salaryOrg.salaryPeriod"], + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { id: id }, }); if (!salaryProfile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ"); } - await this.salaryProfileRepository.remove(salaryProfile); - + // await this.salaryProfileRepository.remove(salaryProfile); + // หาจำนวน Quota คงเหลือ if (salaryProfile.salaryOrg.snapshot == "SNAP1") { - if(salaryProfile.salaryOrg.salaryPeriod.period == "APR"){ + if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") { const amountFullType = await this.salaryProfileRepository.count({ where: { salaryOrgId: salaryProfile?.salaryOrg.id, @@ -165,16 +165,17 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrg.quantityUsed = amountFullType; salaryProfile.salaryOrg.remainQuota = calRemainQuota; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); - }else if(salaryProfile.salaryOrg.salaryPeriod.period == "OCT"){ + } else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") { const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) - .createQueryBuilder("salaryProfile") - .select('SUM(salaryProfile.amountUse)', 'totalAmount') - .where({ + .createQueryBuilder("salaryProfile") + .select("SUM(salaryProfile.amountUse)", "totalAmount") + .where({ salaryOrgId: salaryProfile?.salaryOrg.id, - type: 'FULL', - }) - .getRawOne(); - const calRemainAmount = salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + type: "FULL", + }) + .getRawOne(); + const calRemainAmount = + salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); @@ -195,7 +196,7 @@ export class SalaryPeriodController extends Controller { @Post("change/amount") async changeAmount(@Body() body: { profileId: string; amount: number }) { const salaryProfile = await this.salaryProfileRepository.findOne({ - relations: ["salaryOrg","salaryOrg.salaryPeriod"], + relations: ["salaryOrg"], where: { id: body.profileId }, }); if (!salaryProfile) { @@ -285,10 +286,10 @@ export class SalaryPeriodController extends Controller { } await this.salaryProfileRepository.save(salaryProfile); - + // หาจำนวน Quota คงเหลือ if (salaryProfile.salaryOrg.snapshot == "SNAP1") { - if(salaryProfile.salaryOrg.salaryPeriod.period == "APR"){ + if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") { const amountFullType = await this.salaryProfileRepository.count({ where: { salaryOrgId: salaryProfile?.salaryOrg.id, @@ -299,16 +300,17 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrg.quantityUsed = amountFullType; salaryProfile.salaryOrg.remainQuota = calRemainQuota; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); - }else if(salaryProfile.salaryOrg.salaryPeriod.period == "OCT"){ + } else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") { const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) - .createQueryBuilder("salaryProfile") - .select('SUM(salaryProfile.amountUse)', 'totalAmount') - .where({ + .createQueryBuilder("salaryProfile") + .select("SUM(salaryProfile.amountUse)", "totalAmount") + .where({ salaryOrgId: salaryProfile?.salaryOrg.id, - type: 'FULL', - }) - .getRawOne(); - const calRemainAmount = salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + type: "FULL", + }) + .getRawOne(); + const calRemainAmount = + salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); @@ -334,7 +336,6 @@ export class SalaryPeriodController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ"); } const salaryOrg = await this.salaryOrgRepository.findOne({ - relations: ["salaryPeriod"], where: { id: body.groupId }, }); if (!salaryOrg) { @@ -343,34 +344,33 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrgId = salaryOrg.id; await this.salaryProfileRepository.save(salaryProfile); - if (salaryOrg) { - // หาจำนวน 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); - }else if(salaryOrg.salaryPeriod.period == "OCT"){ - const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) + + // หาจำนวน 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); + } else if (salaryOrg.salaryPeriod.period == "OCT") { + const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") - .select('SUM(salaryProfile.amountUse)', 'totalAmount') + .select("SUM(salaryProfile.amountUse)", "totalAmount") .where({ - salaryOrgId: salaryOrg.id, - type: 'FULL', + salaryOrgId: salaryProfile?.salaryOrg.id, + type: "FULL", }) .getRawOne(); - const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; - salaryOrg.useAmount = sumAmountUse.totalAmount; - salaryOrg.remainingAmount = calRemainAmount; - await this.salaryOrgRepository.save(salaryOrg); - } + const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryOrg.remainingAmount = calRemainAmount; + await this.salaryOrgRepository.save(salaryOrg); } } return new HttpSuccess(); @@ -509,7 +509,7 @@ export class SalaryPeriodController extends Controller { .andWhere( new Brackets((qb) => { qb.andWhere(body.type != null && body.type != "" ? `profile.type LIKE :type` : "1=1", { - type: body.type == null ? "" : `%${body.type.toUpperCase()}%`, + type: body.type == null ? "" : `${body.type.toUpperCase()}`, }) .andWhere(body.isRetire != null ? `profile.isRetired = ${body.isRetire}` : "1=1") .andWhere({ @@ -563,7 +563,6 @@ export class SalaryPeriodController extends Controller { @Request() request: { user: Record }, ) { const salaryOrg = await this.salaryOrgRepository.findOne({ - relations:["salaryPeriod"], where: { id: requestBody.id, }, @@ -593,7 +592,7 @@ export class SalaryPeriodController extends Controller { if (salaryProfileAll != null) { throw new HttpError( HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถเพิ่มรายชื่อนี้ได้ เนื่องจากมีการยื่นขอเลื่อนเงินเดือนแล้ว", + "ไม่สามารถเพิ่มรายชื่อนี้ได้ เนื่องจากมีการยื่นของเลื่อนเงินเดือนแล้ว", ); } @@ -693,7 +692,7 @@ export class SalaryPeriodController extends Controller { // หาจำนวน Quota คงเหลือ if (salaryOrg.snapshot == "SNAP1") { - if(salaryOrg.salaryPeriod.period == "APR"){ + if (salaryOrg.salaryPeriod.period == "APR") { const amountFullType = await this.salaryProfileRepository.count({ where: { salaryOrgId: salaryOrg.id, @@ -704,15 +703,15 @@ export class SalaryPeriodController extends Controller { salaryOrg.quantityUsed = amountFullType; salaryOrg.remainQuota = calRemainQuota; await this.salaryOrgRepository.save(salaryOrg); - }else if(salaryOrg.salaryPeriod.period == "OCT"){ + } else if (salaryOrg.salaryPeriod.period == "OCT") { const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) - .createQueryBuilder("salaryProfile") - .select('SUM(salaryProfile.amountUse)', 'totalAmount') - .where({ - salaryOrgId: salaryOrg.id, - type: 'FULL', - }) - .getRawOne(); + .createQueryBuilder("salaryProfile") + .select("SUM(salaryProfile.amountUse)", "totalAmount") + .where({ + salaryOrgId: salaryProfile?.salaryOrg.id, + type: "FULL", + }) + .getRawOne(); const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; salaryOrg.useAmount = sumAmountUse.totalAmount; salaryOrg.remainingAmount = calRemainAmount; @@ -751,7 +750,7 @@ export class SalaryPeriodController extends Controller { if (chk_period) { throw new HttpError( HttpStatusCode.NOT_FOUND, - "ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ", + "ประเภทผังปี " + salaryPeriod.effectiveDate.getFullYear() + " ซ้ำ", ); } @@ -799,7 +798,7 @@ export class SalaryPeriodController extends Controller { if (chk_period) { throw new HttpError( HttpStatusCode.NOT_FOUND, - "ประเภทผังปี " + Extension.ToThaiYear(requestBody.year) + " ซ้ำ", + "ประเภทผังปี " + (requestBody.effectiveDate.getFullYear() + 543) + " ซ้ำ", ); } @@ -880,10 +879,9 @@ export class SalaryPeriodController extends Controller { ) { const [salaryPeriod, total] = await AppDataSource.getRepository(SalaryPeriod) .createQueryBuilder("salaryPeriod") - .andWhere(year != 0 ? "salaryPeriod.year LIKE :year" : "1=1", { year: `%${year}%` }) - .orWhere("salaryPeriod.period LIKE :keyword", { keyword: `%${keyword}%` }) - .orWhere("salaryPeriod.isActive LIKE :keyword", { keyword: `%${keyword}%` }) - .orWhere("salaryPeriod.year LIKE :keyword", { keyword: `%${year}%` }) + .andWhere(year != 0 ? "salaryPeriod.year LIKE :year" : "1=1", { year: `${year}` }) + .orWhere("salaryPeriod.period LIKE :keyword", { keyword: `${keyword}` }) + // .orWhere("salaryPeriod.isActive LIKE :keyword", { keyword: `${keyword}` }) .select([ "salaryPeriod.id", "salaryPeriod.period",