diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 76351837..0a6a053e 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -19,7 +19,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { Command } from "../entities/Command"; -import { Brackets, LessThan, MoreThan } from "typeorm"; +import { Brackets, LessThan, MoreThan, Double } from "typeorm"; import { CommandType } from "../entities/CommandType"; import { CommandSend } from "../entities/CommandSend"; import { Profile } from "../entities/Profile"; @@ -123,6 +123,7 @@ export class CommandController extends Controller { assignFullName: _data.createdFullName, createdFullName: _data.createdFullName, status: _data.status, + issue: _data.issue, })); return new HttpSuccess({ data, total }); @@ -261,15 +262,21 @@ export class CommandController extends Controller { commandSalaryId: command.commandSalaryId, commandSalary: command.commandSalary?.name || null, positionDetail: command.positionDetail, - sendCC: command.commandRecives + commandRecives: command.commandRecives .sort((a, b) => a.order - b.order) .map((x) => ({ + id: x.id, citizenId: x.citizenId, prefix: x.prefix, fristName: x.fristName, lastName: x.lastName, profileId: x.profileId, order: x.order, + remarkVertical: x.remarkVertical, + remarkHorizontal: x.remarkHorizontal, + amount: x.amount, + positionSalaryAmount: x.positionSalaryAmount, + mouthSalaryAmount: x.mouthSalaryAmount, })), }; return new HttpSuccess(_command); @@ -354,6 +361,41 @@ export class CommandController extends Controller { return new HttpSuccess(); } + /** + * API แก้ไขรายการ body คำสั่ง Tab2 + * + * @summary API แก้ไขรายการ body คำสั่ง Tab2 + * + * @param {string} id Id คำสั่ง + */ + @Put("tab2/recive/{commandReciveId}") + async PutTab2Recive( + @Path() commandReciveId: string, + @Body() + requestBody: { + remarkVertical: string | null; + remarkHorizontal: string | null; + amount: Double | null; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | null; + }, + @Request() request: RequestWithUser, + ) { + const commandRecive = await this.commandReciveRepository.findOne({ + where: { id: commandReciveId }, + }); + if (!commandRecive) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง"); + } + const data = new CommandRecive(); + Object.assign(data, { ...commandRecive, ...requestBody }); + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.lastUpdatedAt = new Date(); + await this.commandReciveRepository.save(data); + return new HttpSuccess(); + } + /** * API ลบรายการผู้ได้รับคำสั่ง * @@ -361,15 +403,27 @@ export class CommandController extends Controller { * * @param {string} id Id ผู้ได้รับคำสั่ง */ - @Delete("tab2/{id}") - async DeleteTab2(@Path() id: string) { + @Delete("tab2/{commandReciveId}") + async DeleteTab2(@Path() commandReciveId: string) { const commandRecive = await this.commandReciveRepository.findOne({ - where: { id: id }, + where: { id: commandReciveId }, }); if (!commandRecive) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง"); } - await this.commandReciveRepository.delete(commandRecive.id); + const commandId = commandRecive.commandId; + // await this.commandReciveRepository.delete(commandRecive.id); + + const commandReciveList = await this.commandReciveRepository.find({ + where: { + commandId: commandId, + }, + order: { order: "ASC" }, + }); + commandReciveList.map(async (p, i) => { + p.order = i + 1; + await this.commandReciveRepository.save(p); + }); return new HttpSuccess(); } diff --git a/src/controllers/PosMasterActController.ts b/src/controllers/PosMasterActController.ts index 9575e0df..ff2d96a6 100644 --- a/src/controllers/PosMasterActController.ts +++ b/src/controllers/PosMasterActController.ts @@ -123,11 +123,9 @@ export class PosMasterActController extends Controller { posMasterId: posMasterAct.posMasterId, }, }); - let num = 0; - posMasterActList.forEach(async (p) => { - p.posMasterOrder = num + 1; + posMasterActList.forEach(async (p, i) => { + p.posMasterOrder = i + 1; await this.posMasterActRepository.save(p); - num = num + 1; }); } return new HttpSuccess(); diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 8ff9bec6..58611604 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -79,7 +79,7 @@ export class ProfileSalaryController extends Controller { } @Get("history/{salaryId}") - public async salaryHistory(@Path() salaryId: string,) { + public async salaryHistory(@Path() salaryId: string) { const record = await this.salaryHistoryRepo.find({ where: { profileSalaryId: salaryId, @@ -170,12 +170,25 @@ export class ProfileSalaryController extends Controller { _record.profileId, ); } + const data = await this.salaryRepo.findOneBy({ id: salaryId }); + if (!data) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (data == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const profileId = data.profileId; await this.salaryHistoryRepo.delete({ profileSalaryId: salaryId, }); const result = await this.salaryRepo.delete({ id: salaryId }); + const salaryList = await this.salaryRepo.find({ + where: { + profileId: profileId, + }, + }); + salaryList.forEach(async (p, i) => { + p.order = i + 1; + await this.salaryRepo.save(p); + }); if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index 8fbf41e4..b3dc27e5 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -184,13 +184,26 @@ export class ProfileSalaryEmployeeController extends Controller { _record.profileEmployeeId, ); } - + const data = await this.salaryRepo.findOneBy({ id: salaryId }); + if (!data) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (data == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const profileId = data.profileEmployeeId; await this.salaryHistoryRepo.delete({ profileSalaryId: salaryId, }); const result = await this.salaryRepo.delete({ id: salaryId }); + const salaryList = await this.salaryRepo.find({ + where: { + profileEmployeeId: profileId, + }, + }); + salaryList.forEach(async (p, i) => { + p.order = i + 1; + await this.salaryRepo.save(p); + }); + if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } diff --git a/src/controllers/ProfileSalaryEmployeeTempController.ts b/src/controllers/ProfileSalaryEmployeeTempController.ts index 792f63fa..e7280f90 100644 --- a/src/controllers/ProfileSalaryEmployeeTempController.ts +++ b/src/controllers/ProfileSalaryEmployeeTempController.ts @@ -171,9 +171,22 @@ export class ProfileSalaryEmployeeTempController extends Controller { await this.salaryHistoryRepo.delete({ profileSalaryId: salaryId, }); - + const data = await this.salaryRepo.findOneBy({ id: salaryId }); + if (!data) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (data == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const profileId = data.profileEmployeeId; const result = await this.salaryRepo.delete({ id: salaryId }); + const salaryList = await this.salaryRepo.find({ + where: { + profileEmployeeId: profileId, + }, + }); + salaryList.forEach(async (p, i) => { + p.order = i + 1; + await this.salaryRepo.save(p); + }); + if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } diff --git a/src/entities/CommandRecive.ts b/src/entities/CommandRecive.ts index 70a52ab3..59a53f03 100644 --- a/src/entities/CommandRecive.ts +++ b/src/entities/CommandRecive.ts @@ -1,4 +1,4 @@ -import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm"; +import { Entity, Column, JoinColumn, ManyToOne, OneToMany, Double } from "typeorm"; import { EntityBase } from "./base/Base"; import { Command } from "./Command"; import { Profile } from "./Profile"; @@ -60,6 +60,46 @@ export class CommandRecive extends EntityBase { }) order: number; + @Column({ + nullable: true, + comment: "หมายเหตุแนวตั้ง", + type: "text", + default: null, + }) + remarkVertical: string; + + @Column({ + nullable: true, + comment: "หมายเหตุแนวนอน", + type: "text", + default: null, + }) + remarkHorizontal: string; + + @Column({ + comment: "เงินเดือนฐาน", + default: 0, + nullable: true, + type: "double", + }) + amount: Double; + + @Column({ + comment: "เงินประจำตำแหน่ง", + default: 0, + nullable: true, + type: "double", + }) + positionSalaryAmount: Double; + + @Column({ + comment: "เงินค่าตอบแทนรายเดือน", + default: 0, + nullable: true, + type: "double", + }) + mouthSalaryAmount: Double; + @Column({ length: 40, comment: "คีย์นอก(FK)ของตาราง command", diff --git a/src/migration/1727246671059-update_commandRecive_add_salary.ts b/src/migration/1727246671059-update_commandRecive_add_salary.ts new file mode 100644 index 00000000..025e650e --- /dev/null +++ b/src/migration/1727246671059-update_commandRecive_add_salary.ts @@ -0,0 +1,24 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateCommandReciveAddSalary1727246671059 implements MigrationInterface { + name = 'UpdateCommandReciveAddSalary1727246671059' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`order\` int NULL COMMENT 'ลำดับแสดงผล'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`remarkVertical\` text NULL COMMENT 'หมายเหตุแนวตั้ง'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`remarkHorizontal\` text NULL COMMENT 'หมายเหตุแนวนอน'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`amount\` double NULL COMMENT 'เงินเดือนฐาน' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`positionSalaryAmount\` double NULL COMMENT 'เงินประจำตำแหน่ง' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`mouthSalaryAmount\` double NULL COMMENT 'เงินค่าตอบแทนรายเดือน' DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`mouthSalaryAmount\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`positionSalaryAmount\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`remarkHorizontal\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`remarkVertical\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`order\``); + } + +}