diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 80525af..c03d219 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -134,6 +134,7 @@ export class SalaryPeriodController extends Controller { remainingAmount: salaryOrg.remainingAmount, totalAmountSpecial: sum, totalBackup: salaryOrg.salaryProfiles.filter((x) => x.isReserve == true).length, + status: salaryOrg.status, }; return new HttpSuccess(data); } @@ -1319,17 +1320,55 @@ export class SalaryPeriodController extends Controller { const SalaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); - if (!SalaryPeriod) { + if (!SalaryPeriod) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); + + if (SalaryPeriod?.period == "SPECIAL") { + const SalaryOrg = await this.salaryOrgRepository.find({ + where: { salaryPeriodId: SalaryPeriod.id }, + relations: ["salaryProfiles"], + }); + const salaryProfile = SalaryOrg.find((x) => x.salaryProfiles.length > 0); + if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้"); + + await this.salaryOrgRepository.remove(SalaryOrg); + await this.salaryPeriodRepository.remove(SalaryPeriod); + return new HttpSuccess(); + } else { + const SalaryOrg = await this.salaryOrgRepository.findOne({ + where: { salaryPeriodId: SalaryPeriod.id }, + }); + if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้"); + + await this.salaryPeriodRepository.remove(SalaryPeriod); + return new HttpSuccess(); } - const SalaryOrg = await this.salaryOrgRepository.findOne({ - where: { salaryPeriodId: SalaryPeriod.id }, - }); - if (SalaryOrg) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้"); - } - await this.salaryPeriodRepository.remove(SalaryPeriod); - return new HttpSuccess(); + } + + /** + * API รายการรอบเงินเดือน(active) + * + * + */ + @Get("active") + async GetListsSalaryPeriodActive() { + const salaryPeriod = await AppDataSource.getRepository(SalaryPeriod) + .createQueryBuilder("salaryPeriod") + .where({ isActive: true }) + .select([ + "salaryPeriod.id", + "salaryPeriod.period", + "salaryPeriod.isActive", + "salaryPeriod.isClose", + "salaryPeriod.effectiveDate", + "salaryPeriod.status", + "salaryPeriod.year", + "salaryPeriod.revisionId", + ]) + .orderBy("salaryPeriod.effectiveDate", "DESC") + .getMany(); + + return new HttpSuccess(salaryPeriod); } /** @@ -1922,4 +1961,118 @@ export class SalaryPeriodController extends Controller { ); } } + + /** + * API เจ้าหน้าที่ส่ง ผอ + * + * + * @param {string} orgId Guid, *Id รอบเงินเดือน + */ + @Get("officer/approve/{orgId}") + async OfficerApprove(@Path() orgId: string) { + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { id: orgId }, + }); + if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); + if (salaryOrg.status != "PENDING") + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้"); + + salaryOrg.status = "WAITHEAD1"; + await this.salaryOrgRepository.save(salaryOrg); + return new HttpSuccess(); + } + + /** + * API ผอ ส่ง สกจ + * + * + * @param {string} orgId Guid, *Id รอบเงินเดือน + */ + @Get("head/approve/{orgId}") + async HeadApprove(@Path() orgId: string) { + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { id: orgId }, + }); + if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); + if (salaryOrg.status != "WAITHEAD1") + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้"); + + salaryOrg.status = "WAITOWNER1"; + await this.salaryOrgRepository.save(salaryOrg); + return new HttpSuccess(); + } + + /** + * API สกจ อนุมัติ + * + * + * @param {string} orgId Guid, *Id รอบเงินเดือน + */ + @Get("owner/approve/{orgId}") + async OwnerApprove(@Path() orgId: string) { + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { id: orgId }, + }); + if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); + if (salaryOrg.status != "WAITOWNER1") + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้"); + + salaryOrg.status = "REPORT"; + await this.salaryOrgRepository.save(salaryOrg); + return new HttpSuccess(); + } + + /** + * API สกจ ส่ง ผอ + * + * + * @param {string} orgId Guid, *Id รอบเงินเดือน + */ + @Put("owner/comment/{orgId}") + async WaitOwnerApprove( + @Path() orgId: string, + @Body() + body: { + titleRecommend: string; + }, + ) { + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { id: orgId }, + }); + if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); + if (salaryOrg.status != "WAITOWNER1") + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้"); + + salaryOrg.status = "WAITHEAD2"; + salaryOrg.ownerRecommend = body.titleRecommend; + await this.salaryOrgRepository.save(salaryOrg); + return new HttpSuccess(); + } + + /** + * API ผอ ส่ง เจ้าหน้าที่ + * + * + * @param {string} orgId Guid, *Id รอบเงินเดือน + */ + @Put("head/comment/{orgId}") + async WaitHeadApprove( + @Path() orgId: string, + @Body() + body: { + titleRecommend: string; + }, + ) { + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { id: orgId }, + }); + if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); + if (salaryOrg.status != "WAITOFFICER2") + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้"); + + salaryOrg.status = "REPORT"; + salaryOrg.headRecommend = body.titleRecommend; + await this.salaryOrgRepository.save(salaryOrg); + return new HttpSuccess(); + } } diff --git a/src/entities/SalaryOrg.ts b/src/entities/SalaryOrg.ts index cc068f9..fd87af3 100644 --- a/src/entities/SalaryOrg.ts +++ b/src/entities/SalaryOrg.ts @@ -108,6 +108,20 @@ export class SalaryOrg extends EntityBase { }) remainingAmount: number; + @Column({ + nullable: true, + comment: "คำแนะนำ สกจ", + length: 255, + }) + ownerRecommend: string; + + @Column({ + nullable: true, + comment: "คำแนะนำ ผอ", + length: 255, + }) + headRecommend: string; + @ManyToOne(() => SalaryPeriod, (salaryPeriod) => salaryPeriod.salaryOrgs) @JoinColumn({ name: "salaryPeriodId" }) salaryPeriod: SalaryPeriod; diff --git a/src/migration/1710426604127-update_table_salaryOrg_add_recommend.ts b/src/migration/1710426604127-update_table_salaryOrg_add_recommend.ts new file mode 100644 index 0000000..44bfbcb --- /dev/null +++ b/src/migration/1710426604127-update_table_salaryOrg_add_recommend.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSalaryOrgAddRecommend1710426604127 implements MigrationInterface { + name = 'UpdateTableSalaryOrgAddRecommend1710426604127' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryOrg\` ADD \`ownerRecommend\` varchar(255) NULL COMMENT 'คำแนะนำ สกจ'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` ADD \`headRecommend\` varchar(255) NULL COMMENT 'คำแนะนำ ผอ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryOrg\` DROP COLUMN \`headRecommend\``); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` DROP COLUMN \`ownerRecommend\``); + } + +}