sort profile send report

This commit is contained in:
kittapath 2024-09-25 16:17:06 +07:00
parent e2939cae3a
commit 7697d6d46a
7 changed files with 169 additions and 14 deletions

View file

@ -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();
}

View file

@ -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();

View file

@ -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, "ไม่พบข้อมูล");
}

View file

@ -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, "ไม่พบข้อมูล");
}

View file

@ -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, "ไม่พบข้อมูล");
}

View file

@ -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",

View file

@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateCommandReciveAddSalary1727246671059 implements MigrationInterface {
name = 'UpdateCommandReciveAddSalary1727246671059'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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\``);
}
}