add fields amountSpecial

This commit is contained in:
Bright 2024-12-06 18:43:07 +07:00
parent 2c60dd7a6c
commit 27409a892f
4 changed files with 62 additions and 26 deletions

View file

@ -1622,12 +1622,16 @@ export class CommandController extends Controller {
remarkVertical?: string | null;
remarkHorizontal?: string | null;
rootId?: string | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
}[];
},
@Request() request: RequestWithUser,
) {
let command = new Command();
let commandCode = null;
let commandCode:string = "";
let null_: any = null;
if (
requestBody.commandId != undefined &&
@ -1707,30 +1711,40 @@ export class CommandController extends Controller {
commandRecive = Object.assign(new CommandRecive(), item);
commandRecive.order = order;
let salaryData = null_;
if (item.profileId) {
salaryData = await this.profileRepository.findOne({
where: {
id: item.profileId,
},
});
let null_: any = 0;
if (!salaryData) {
salaryData = await this.profileEmployeeRepository.findOne({
const excludedCommands = ["C-PM-33", "C-PM-34", "C-PM-35", "C-PM-36", "C-PM-37"];
if (!excludedCommands.includes(commandCode)) {
if (item.profileId) {
salaryData = await this.profileRepository.findOne({
where: {
id: item.profileId,
},
});
let null_: any = 0;
if (!salaryData) {
salaryData = await this.profileEmployeeRepository.findOne({
where: {
id: item.profileId,
},
});
}
commandRecive.amount = salaryData ? salaryData.amount : null_;
commandRecive.positionSalaryAmount = salaryData
? salaryData.positionSalaryAmount
: null_;
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
} else {
commandRecive.amount = null_;
commandRecive.positionSalaryAmount = null_;
commandRecive.mouthSalaryAmount = null_;
}
commandRecive.amount = salaryData ? salaryData.amount : null_;
commandRecive.positionSalaryAmount = salaryData
? salaryData.positionSalaryAmount
: null_;
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
} else {
commandRecive.amount = null_;
commandRecive.positionSalaryAmount = null_;
commandRecive.mouthSalaryAmount = null_;
commandRecive.amount = item.amount ?? null_;
commandRecive.amountSpecial = item.amountSpecial ?? null_;
commandRecive.positionSalaryAmount = item.positionSalaryAmount ?? null_;
commandRecive.mouthSalaryAmount = item.mouthSalaryAmount ?? null_;
}
commandRecive.remarkVertical =
item.remarkVertical == null ? null_ : item.remarkVertical;
commandRecive.remarkHorizontal =
@ -1898,6 +1912,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -1917,7 +1932,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOneBy({ id: item.profileId });
const profile:any = await this.profileRepository.findOneBy({ id: item.profileId });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
@ -2002,6 +2017,8 @@ export class CommandController extends Controller {
profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName;
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
await this.profileRepository.save(profile);
await this.positionRepository.save(positionNew);
}
@ -2020,6 +2037,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -2036,7 +2054,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
const profile:any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
@ -2131,7 +2149,8 @@ export class CommandController extends Controller {
profile.position = positionNew.positionName;
profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null;
profile.positionEmployeePositionId = positionNew.positionName;
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew);
}
@ -2150,6 +2169,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -2266,6 +2286,8 @@ export class CommandController extends Controller {
})),
);
}
profile.amount = item.amount ?? _null;
profile.amountSpecial = item.amountSpecial ?? _null;
profile.isActive = true;
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
@ -2383,6 +2405,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -2403,7 +2426,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
const profile:any = await this.profileRepository.findOne({
where: { id: item.profileId },
relations: ["roleKeycloaks"],
});
@ -2446,6 +2469,8 @@ export class CommandController extends Controller {
profile.posLevelId = _null;
profile.leaveReason = item.leaveReason ?? _null;
profile.dateLeave = item.dateLeave ?? _null;
profile.amount = item.amount ?? _null;
profile.amountSpecial = item.amountSpecial ?? _null;
await this.profileRepository.save(profile, { data: req });
}
Object.assign(data, { ...item, ...meta });
@ -3087,6 +3112,8 @@ export class CommandController extends Controller {
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
profile.email = item.bodyProfile.email;
profile.dateStart = item.bodyProfile.dateStart;
profile.amount = item.bodyProfile.amount ?? null;
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile });
}
@ -3130,13 +3157,17 @@ export class CommandController extends Controller {
where: { profileId: profile.id },
order: { order: "DESC" },
});
const profileSal = new ProfileSalary();
const profileSal: any = new ProfileSalary();
Object.assign(profileSal, { ...item.bodySalarys, ...meta });
const salaryHistory = new ProfileSalaryHistory();
Object.assign(salaryHistory, { ...profileSal, id: undefined });
profileSal.order = dest_item == null ? 1 : dest_item.order + 1;
profileSal.profileId = profile.id;
profileSal.dateGovernment = meta.createdAt;
profileSal.amount = item.bodySalarys.amount ?? null;
profileSal.amountSpecial = item.bodySalarys.amountSpecial ?? null;
profileSal.positionSalaryAmount = item.bodySalarys.positionSalaryAmount ?? null;
profileSal.mouthSalaryAmount = item.bodySalarys.mouthSalaryAmount ?? null;
await this.salaryRepo.save(profileSal, { data: req });
setLogDataDiff(req, { before, after: profileSal });
salaryHistory.profileSalaryId = profileSal.id;
@ -3284,6 +3315,7 @@ export class CommandController extends Controller {
commandYear: number;
templateDoc: string | null;
amount: Double | null;
amountSpecial: Double | null;
positionSalaryAmount: Double | null;
mouthSalaryAmount: Double | null;
}[];
@ -3313,6 +3345,7 @@ export class CommandController extends Controller {
profileEmployeeId: profile.id,
date: new Date(),
amount: item.amount,
amountSpecial: item.amountSpecial,
commandId: item.commandId,
positionSalaryAmount: item.positionSalaryAmount,
mouthSalaryAmount: item.mouthSalaryAmount,
@ -3431,9 +3464,8 @@ export class CommandController extends Controller {
const _null: any = null;
profile.employeeWage = item.amount == null ? _null : item.amount.toString();
profile.dateStart = new Date();
// profile.amount = item.amount == null ? _null : item.amount.toString(); //เผื่อไว้
// profile.positionSalaryAmount = item.positionSalaryAmount == null ? _null : item.positionSalaryAmount.toString();
// profile.mouthSalaryAmount = item.mouthSalaryAmount == null ? _null : item.mouthSalaryAmount.toString();
profile.amount = item.amount == null ? _null : item.amount;
profile.amountSpecial = item.amountSpecial == null ? _null : item.amountSpecial;
await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew);