เลื่อนเงินเดือนลูกจ้าง
This commit is contained in:
parent
d3dd7012a1
commit
9449a1f989
7 changed files with 448 additions and 441 deletions
|
|
@ -29,6 +29,7 @@ import {
|
|||
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
|
||||
import { SalaryEmployee } from "../entities/SalaryEmployee";
|
||||
import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
|
||||
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
||||
|
||||
@Route("api/v1/salary/period-employee")
|
||||
@Tags("SalaryEmployee")
|
||||
|
|
@ -41,6 +42,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
|
||||
private salaryRepository = AppDataSource.getRepository(SalaryEmployee);
|
||||
private salaryRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
||||
private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee);
|
||||
|
||||
/**
|
||||
* API รอบล่าสุด
|
||||
|
|
@ -231,103 +233,44 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
}
|
||||
let type = salaryProfile.type;
|
||||
let salaryRanks: any = null;
|
||||
// //Salary
|
||||
// const salarys = await this.salaryRepository.findOne({
|
||||
// where: {
|
||||
// posTypeId: Level.posTypeId,
|
||||
// posLevelId: Level.id,
|
||||
// isActive: true,
|
||||
// },
|
||||
// });
|
||||
// if (!salarys) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
// }
|
||||
// //SalaryRank
|
||||
// let salaryRanks: any = null;
|
||||
// if (salaryProfile.amount != null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryProfile.amount,
|
||||
// isNext: false,
|
||||
// },
|
||||
// });
|
||||
// if (salaryRanks == null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: MoreThan(salaryProfile.amount),
|
||||
// isNext: false,
|
||||
// },
|
||||
// order: { salary: "DESC" },
|
||||
// });
|
||||
// }
|
||||
// if (salaryRanks != null) {
|
||||
// if (salaryProfile.type == "HAFT") {
|
||||
// if (salaryRanks.salaryHalfSpecial != null && salaryRanks.salaryHalfSpecial > 0) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryHalf,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// } else if (salaryProfile.type == "FULL") {
|
||||
// if (salaryRanks.salaryFullSpecial != null && salaryRanks.salaryFullSpecial > 0) {
|
||||
// if (salaryRanks.salaryHalfSpecial == null || salaryRanks.salaryHalfSpecial == 0) {
|
||||
// type = "HAFT";
|
||||
// }
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryFull,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// } else if (salaryProfile.type == "FULLHAFT") {
|
||||
// if (salaryRanks.salaryFullHalfSpecial != null && salaryRanks.salaryFullHalfSpecial > 0) {
|
||||
// if (salaryRanks.salaryFullSpecial == null || salaryRanks.salaryFullSpecial == 0) {
|
||||
// type = "HAFT";
|
||||
// } else if (
|
||||
// salaryRanks.salaryHalfSpecial == null ||
|
||||
// salaryRanks.salaryHalfSpecial == 0
|
||||
// ) {
|
||||
// type = "FULL";
|
||||
// }
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryFullHalf,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryProfile.amount,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// if (salaryRanks == null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: MoreThan(salaryProfile.amount),
|
||||
// isNext: true,
|
||||
// },
|
||||
// order: { salary: "DESC" },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
const salaryFormula = await this.salaryFormulaEmployeeRepository.findOne({
|
||||
where: {
|
||||
position: salaryProfile.position,
|
||||
posType: { posTypeName: salaryProfile.posType },
|
||||
posLevel: { posLevelName: salaryProfile.posLevel },
|
||||
},
|
||||
relations: ["salaryEmployeeMins", "salaryEmployee"],
|
||||
});
|
||||
let group = salaryProfile.group;
|
||||
let step = salaryProfile.salaryLevel == null ? 0 : salaryProfile.salaryLevel;
|
||||
if (group == null || group == 0) {
|
||||
if (salaryFormula != null) {
|
||||
group = salaryFormula.salaryEmployeeMins.sort((a, b) => a.group - b.group)[0].group;
|
||||
} else {
|
||||
group = 1;
|
||||
}
|
||||
}
|
||||
if (salaryProfile.amount == null || salaryProfile.amount == 0) {
|
||||
if (salaryFormula != null) {
|
||||
const salaryRankMin = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: salaryFormula.salaryMin == null ? 0 : salaryFormula.salaryMin,
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (salaryRankMin == null) {
|
||||
step = 1;
|
||||
} else {
|
||||
step = salaryRankMin.step - 0.5;
|
||||
}
|
||||
} else {
|
||||
step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
salaryProfile.isNext = false;
|
||||
if (type == "NONE") {
|
||||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
|
|
@ -336,51 +279,84 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = 0;
|
||||
} else if (type == "HAFT") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryHalfSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "FULL") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryFullSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFull == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFull - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "FULLHAFT") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFullHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "HAFT" || type == "FULL" || type == "FULLHAFT") {
|
||||
if (type == "HAFT") {
|
||||
step = step + 0.5;
|
||||
} else if (type == "FULL") {
|
||||
step = step + 1;
|
||||
} else if (type == "FULLHAFT") {
|
||||
step = step + 1.5;
|
||||
}
|
||||
let salaryRankMax = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
order: { step: "DESC" },
|
||||
});
|
||||
if (salaryRankMax != null && step > salaryRankMax.step) {
|
||||
let salaryRankAmount = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: MoreThan(salaryProfile.amount),
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group + 1,
|
||||
},
|
||||
},
|
||||
order: { salaryMonth: "ASC" },
|
||||
});
|
||||
group = group + 1;
|
||||
step =
|
||||
(salaryRankAmount == null ? 1 : salaryRankAmount.step) +
|
||||
(step - (salaryRankMax == null ? 0 : salaryRankMax.step) - 0.5);
|
||||
}
|
||||
let salaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
step: step,
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (salaryRanks != null && salaryRanks.salaryMonth != null) {
|
||||
if (
|
||||
salaryFormula != null &&
|
||||
salaryFormula.salaryMax != null &&
|
||||
salaryRanks.salaryMonth > salaryFormula.salaryMax
|
||||
) {
|
||||
let salaryRankAmountMax = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: salaryFormula.salaryMax,
|
||||
salaryEmployee_: {
|
||||
id: salaryFormula.salaryEmployee.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
salaryProfile.isNext = true;
|
||||
salaryProfile.amountUse = salaryFormula.salaryMax - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null
|
||||
? 0
|
||||
: salaryRankAmountMax.salaryMonth;
|
||||
salaryProfile.positionSalaryDayAmount =
|
||||
salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay;
|
||||
salaryProfile.groupNew = salaryFormula.salaryEmployee.group;
|
||||
salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step;
|
||||
} else {
|
||||
salaryProfile.amountUse = salaryRanks.salaryMonth - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks.salaryMonth;
|
||||
salaryProfile.positionSalaryDayAmount = salaryRanks.salaryDay;
|
||||
salaryProfile.groupNew = group;
|
||||
salaryProfile.salaryLevelNew = step;
|
||||
}
|
||||
} else {
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = salaryProfile.amount;
|
||||
}
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
|
@ -551,106 +527,47 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
if (!Level) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
}
|
||||
let type = salaryProfile.type;
|
||||
let salaryRanks: any = null;
|
||||
// //Salary
|
||||
// const salarys = await this.salaryRepository.findOne({
|
||||
// where: {
|
||||
// posTypeId: Level.posTypeId,
|
||||
// posLevelId: Level.id,
|
||||
// isActive: true,
|
||||
// },
|
||||
// });
|
||||
// if (!salarys) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
// }
|
||||
salaryProfile.type = body.type;
|
||||
salaryProfile.isReserve = body.isReserve;
|
||||
// //SalaryRank
|
||||
// let salaryRanks: any = null;
|
||||
// if (salaryProfile.amount != null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryProfile.amount,
|
||||
// isNext: false,
|
||||
// },
|
||||
// });
|
||||
// if (salaryRanks == null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: MoreThan(salaryProfile.amount),
|
||||
// isNext: false,
|
||||
// },
|
||||
// order: { salary: "DESC" },
|
||||
// });
|
||||
// }
|
||||
// if (salaryRanks != null) {
|
||||
// if (salaryProfile.type == "HAFT") {
|
||||
// if (salaryRanks.salaryHalfSpecial != null && salaryRanks.salaryHalfSpecial > 0) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryHalf,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// } else if (salaryProfile.type == "FULL") {
|
||||
// if (salaryRanks.salaryFullSpecial != null && salaryRanks.salaryFullSpecial > 0) {
|
||||
// if (salaryRanks.salaryHalfSpecial == null || salaryRanks.salaryHalfSpecial == 0) {
|
||||
// type = "HAFT";
|
||||
// }
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryFull,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// } else if (salaryProfile.type == "FULLHAFT") {
|
||||
// if (salaryRanks.salaryFullHalfSpecial != null && salaryRanks.salaryFullHalfSpecial > 0) {
|
||||
// if (salaryRanks.salaryFullSpecial == null || salaryRanks.salaryFullSpecial == 0) {
|
||||
// type = "HAFT";
|
||||
// } else if (
|
||||
// salaryRanks.salaryHalfSpecial == null ||
|
||||
// salaryRanks.salaryHalfSpecial == 0
|
||||
// ) {
|
||||
// type = "FULL";
|
||||
// }
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryFullHalf,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryProfile.amount,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// if (salaryRanks == null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: MoreThan(salaryProfile.amount),
|
||||
// isNext: true,
|
||||
// },
|
||||
// order: { salary: "DESC" },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
let type = salaryProfile.type;
|
||||
const salaryFormula = await this.salaryFormulaEmployeeRepository.findOne({
|
||||
where: {
|
||||
position: salaryProfile.position,
|
||||
posType: { posTypeName: salaryProfile.posType },
|
||||
posLevel: { posLevelName: salaryProfile.posLevel },
|
||||
},
|
||||
relations: ["salaryEmployeeMins", "salaryEmployee"],
|
||||
});
|
||||
let group = salaryProfile.group;
|
||||
let step = salaryProfile.salaryLevel == null ? 0 : salaryProfile.salaryLevel;
|
||||
if (group == null || group == 0) {
|
||||
if (salaryFormula != null) {
|
||||
group = salaryFormula.salaryEmployeeMins.sort((a, b) => a.group - b.group)[0].group;
|
||||
} else {
|
||||
group = 1;
|
||||
}
|
||||
}
|
||||
if (salaryProfile.amount == null || salaryProfile.amount == 0) {
|
||||
if (salaryFormula != null) {
|
||||
const salaryRankMin = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: salaryFormula.salaryMin == null ? 0 : salaryFormula.salaryMin,
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (salaryRankMin == null) {
|
||||
step = 1;
|
||||
} else {
|
||||
step = salaryRankMin.step - 0.5;
|
||||
}
|
||||
} else {
|
||||
step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
salaryProfile.isNext = false;
|
||||
if (type == "NONE") {
|
||||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
|
|
@ -659,51 +576,87 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = 0;
|
||||
} else if (type == "HAFT") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryHalfSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "FULL") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryFullSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFull == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFull - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "FULLHAFT") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFullHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "HAFT" || type == "FULL" || type == "FULLHAFT") {
|
||||
if (type == "HAFT") {
|
||||
step = step + 0.5;
|
||||
} else if (type == "FULL") {
|
||||
step = step + 1;
|
||||
} else if (type == "FULLHAFT") {
|
||||
step = step + 1.5;
|
||||
}
|
||||
let salaryRankMax = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
order: { step: "DESC" },
|
||||
});
|
||||
if (salaryRankMax != null && step > salaryRankMax.step) {
|
||||
let salaryRankAmount = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: MoreThan(salaryProfile.amount == null ? 0 : salaryProfile.amount),
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group + 1,
|
||||
},
|
||||
},
|
||||
order: { salaryMonth: "ASC" },
|
||||
});
|
||||
group = group + 1;
|
||||
step =
|
||||
(salaryRankAmount == null ? 1 : salaryRankAmount.step) +
|
||||
(step - (salaryRankMax == null ? 0 : salaryRankMax.step) - 0.5);
|
||||
}
|
||||
let salaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
step: step,
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (salaryRanks != null && salaryRanks.salaryMonth != null) {
|
||||
if (
|
||||
salaryFormula != null &&
|
||||
salaryFormula.salaryMax != null &&
|
||||
salaryRanks.salaryMonth > salaryFormula.salaryMax
|
||||
) {
|
||||
let salaryRankAmountMax = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: salaryFormula.salaryMax,
|
||||
salaryEmployee_: {
|
||||
id: salaryFormula.salaryEmployee.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
salaryProfile.isNext = true;
|
||||
salaryProfile.amountUse =
|
||||
salaryFormula.salaryMax - (salaryProfile.amount == null ? 0 : salaryProfile.amount);
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null
|
||||
? 0
|
||||
: salaryRankAmountMax.salaryMonth;
|
||||
salaryProfile.positionSalaryDayAmount =
|
||||
salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay;
|
||||
salaryProfile.groupNew = salaryFormula.salaryEmployee.group;
|
||||
salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step;
|
||||
} else {
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks.salaryMonth - (salaryProfile.amount == null ? 0 : salaryProfile.amount);
|
||||
salaryProfile.positionSalaryAmount = salaryRanks.salaryMonth;
|
||||
salaryProfile.positionSalaryDayAmount = salaryRanks.salaryDay;
|
||||
salaryProfile.groupNew = group;
|
||||
salaryProfile.salaryLevelNew = step;
|
||||
}
|
||||
} else {
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryProfile.amount == null ? 0 : salaryProfile.amount;
|
||||
}
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
|
@ -933,102 +886,44 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
}
|
||||
let type = salaryProfile.type;
|
||||
let salaryRanks: any = null;
|
||||
// //Salary
|
||||
// const salarys = await this.salaryRepository.findOne({
|
||||
// where: {
|
||||
// posTypeId: posLevel.posTypeId,
|
||||
// posLevelId: posLevel.id,
|
||||
// isActive: true,
|
||||
// },
|
||||
// });
|
||||
// if (!salarys) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
// }
|
||||
// //SalaryRank
|
||||
// if (salaryProfile.amount != null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryProfile.amount,
|
||||
// isNext: false,
|
||||
// },
|
||||
// });
|
||||
// if (salaryRanks == null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: MoreThan(salaryProfile.amount),
|
||||
// isNext: false,
|
||||
// },
|
||||
// order: { salary: "DESC" },
|
||||
// });
|
||||
// }
|
||||
// if (salaryRanks != null) {
|
||||
// if (salaryProfile.type == "HAFT") {
|
||||
// if (salaryRanks.salaryHalfSpecial != null && salaryRanks.salaryHalfSpecial > 0) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryHalf,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// } else if (salaryProfile.type == "FULL") {
|
||||
// if (salaryRanks.salaryFullSpecial != null && salaryRanks.salaryFullSpecial > 0) {
|
||||
// if (salaryRanks.salaryHalfSpecial == null || salaryRanks.salaryHalfSpecial == 0) {
|
||||
// type = "HAFT";
|
||||
// }
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryFull,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// } else if (salaryProfile.type == "FULLHAFT") {
|
||||
// if (salaryRanks.salaryFullHalfSpecial != null && salaryRanks.salaryFullHalfSpecial > 0) {
|
||||
// if (salaryRanks.salaryFullSpecial == null || salaryRanks.salaryFullSpecial == 0) {
|
||||
// type = "HAFT";
|
||||
// } else if (
|
||||
// salaryRanks.salaryHalfSpecial == null ||
|
||||
// salaryRanks.salaryHalfSpecial == 0
|
||||
// ) {
|
||||
// type = "FULL";
|
||||
// }
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryRanks.salaryFullHalf,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: salaryProfile.amount,
|
||||
// isNext: true,
|
||||
// },
|
||||
// });
|
||||
// if (salaryRanks == null) {
|
||||
// salaryRanks = await this.salaryRankRepository.findOne({
|
||||
// where: {
|
||||
// salaryId: salarys.id,
|
||||
// salary: MoreThan(salaryProfile.amount),
|
||||
// isNext: true,
|
||||
// },
|
||||
// order: { salary: "DESC" },
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
const salaryFormula = await this.salaryFormulaEmployeeRepository.findOne({
|
||||
where: {
|
||||
position: salaryProfile.position,
|
||||
posType: { posTypeName: salaryProfile.posType },
|
||||
posLevel: { posLevelName: salaryProfile.posLevel },
|
||||
},
|
||||
relations: ["salaryEmployeeMins", "salaryEmployee"],
|
||||
});
|
||||
let group = salaryProfile.group;
|
||||
let step = salaryProfile.salaryLevel == null ? 0 : salaryProfile.salaryLevel;
|
||||
if (group == null || group == 0) {
|
||||
if (salaryFormula != null) {
|
||||
group = salaryFormula.salaryEmployeeMins.sort((a, b) => a.group - b.group)[0].group;
|
||||
} else {
|
||||
group = 1;
|
||||
}
|
||||
}
|
||||
if (salaryProfile.amount == null || salaryProfile.amount == 0) {
|
||||
if (salaryFormula != null) {
|
||||
const salaryRankMin = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: salaryFormula.salaryMin == null ? 0 : salaryFormula.salaryMin,
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (salaryRankMin == null) {
|
||||
step = 1;
|
||||
} else {
|
||||
step = salaryRankMin.step - 0.5;
|
||||
}
|
||||
} else {
|
||||
step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
salaryProfile.isNext = false;
|
||||
if (type == "NONE") {
|
||||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
|
|
@ -1037,51 +932,87 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = 0;
|
||||
} else if (type == "HAFT") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryHalfSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "FULL") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryFullSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFull == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFull - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "FULLHAFT") {
|
||||
salaryProfile.amountSpecial =
|
||||
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFullHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf;
|
||||
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext;
|
||||
} else if (type == "HAFT" || type == "FULL" || type == "FULLHAFT") {
|
||||
if (type == "HAFT") {
|
||||
step = step + 0.5;
|
||||
} else if (type == "FULL") {
|
||||
step = step + 1;
|
||||
} else if (type == "FULLHAFT") {
|
||||
step = step + 1.5;
|
||||
}
|
||||
let salaryRankMax = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
order: { step: "DESC" },
|
||||
});
|
||||
if (salaryRankMax != null && step > salaryRankMax.step) {
|
||||
let salaryRankAmount = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: MoreThan(salaryProfile.amount == null ? 0 : salaryProfile.amount),
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group + 1,
|
||||
},
|
||||
},
|
||||
order: { salaryMonth: "ASC" },
|
||||
});
|
||||
group = group + 1;
|
||||
step =
|
||||
(salaryRankAmount == null ? 1 : salaryRankAmount.step) +
|
||||
(step - (salaryRankMax == null ? 0 : salaryRankMax.step) - 0.5);
|
||||
}
|
||||
let salaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
step: step,
|
||||
salaryEmployee_: {
|
||||
isActive: true,
|
||||
group: group,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (salaryRanks != null && salaryRanks.salaryMonth != null) {
|
||||
if (
|
||||
salaryFormula != null &&
|
||||
salaryFormula.salaryMax != null &&
|
||||
salaryRanks.salaryMonth > salaryFormula.salaryMax
|
||||
) {
|
||||
let salaryRankAmountMax = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryMonth: salaryFormula.salaryMax,
|
||||
salaryEmployee_: {
|
||||
id: salaryFormula.salaryEmployee.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
salaryProfile.isNext = true;
|
||||
salaryProfile.amountUse =
|
||||
salaryFormula.salaryMax - (salaryProfile.amount == null ? 0 : salaryProfile.amount);
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null
|
||||
? 0
|
||||
: salaryRankAmountMax.salaryMonth;
|
||||
salaryProfile.positionSalaryDayAmount =
|
||||
salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay;
|
||||
salaryProfile.groupNew = salaryFormula.salaryEmployee.group;
|
||||
salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step;
|
||||
} else {
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks.salaryMonth - (salaryProfile.amount == null ? 0 : salaryProfile.amount);
|
||||
salaryProfile.positionSalaryAmount = salaryRanks.salaryMonth;
|
||||
salaryProfile.positionSalaryDayAmount = salaryRanks.salaryDay;
|
||||
salaryProfile.groupNew = group;
|
||||
salaryProfile.salaryLevelNew = step;
|
||||
}
|
||||
} else {
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount =
|
||||
salaryProfile.amount == null ? 0 : salaryProfile.amount;
|
||||
}
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {
|
|||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { Like} from "typeorm";
|
||||
import { Like } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -126,12 +126,11 @@ export class SalaryRanksController extends Controller {
|
|||
if (keyword != undefined && keyword !== "") {
|
||||
whereClause = {
|
||||
where: [
|
||||
{ salaryId: id },
|
||||
{ salary: Like(`%${keyword}%`) },
|
||||
{ salary: Like(`%${keyword}%`) },
|
||||
{ salaryHalf: Like(`%${keyword}%`) },
|
||||
{ salaryHalfSpecial: Like(`%${keyword}%`) },
|
||||
{ salaryHalfSpecial: Like(`%${keyword}%`) },
|
||||
{ salaryFull: Like(`%${keyword}%`) },
|
||||
{ salaryFullSpecial: Like(`%${keyword}%`) },
|
||||
{ salaryFullSpecial: Like(`%${keyword}%`) },
|
||||
{ salaryFullHalf: Like(`%${keyword}%`) },
|
||||
{ salaryFullHalfSpecial: Like(`%${keyword}%`) },
|
||||
],
|
||||
|
|
@ -139,6 +138,9 @@ export class SalaryRanksController extends Controller {
|
|||
}
|
||||
const [salaryRank, total] = await this.salaryRankRepository.findAndCount({
|
||||
...whereClause,
|
||||
where: {
|
||||
salaryId: id,
|
||||
},
|
||||
select: [
|
||||
"id",
|
||||
"salary",
|
||||
|
|
|
|||
|
|
@ -56,12 +56,12 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้");
|
||||
}
|
||||
const checkStep = await this.salaryRankEmployeeRepository.find({
|
||||
where: {
|
||||
where: {
|
||||
step: requestBody.step,
|
||||
salaryEmployeeId: requestBody.salaryEmployeeId
|
||||
}
|
||||
salaryEmployeeId: requestBody.salaryEmployeeId,
|
||||
},
|
||||
});
|
||||
if(checkStep.length > 0){
|
||||
if (checkStep.length > 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเพิ่มได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
||||
}
|
||||
const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody);
|
||||
|
|
@ -96,13 +96,13 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้");
|
||||
}
|
||||
const checkStep = await this.salaryRankEmployeeRepository.find({
|
||||
where: {
|
||||
where: {
|
||||
id: Not(id),
|
||||
step: requestBody.step,
|
||||
salaryEmployeeId: salaryRankEmployee.salaryEmployeeId
|
||||
}
|
||||
salaryEmployeeId: salaryRankEmployee.salaryEmployeeId,
|
||||
},
|
||||
});
|
||||
if(checkStep.length > 0){
|
||||
if (checkStep.length > 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
||||
}
|
||||
salaryRankEmployee.lastUpdateUserId = request.user.sub;
|
||||
|
|
@ -147,15 +147,17 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
if (keyword != undefined && keyword !== "") {
|
||||
whereClause = {
|
||||
where: [
|
||||
{ salaryEmployeeId: id, },
|
||||
{ step: Like(`%${keyword}%`) },
|
||||
{ salaryMonth: Like(`%${keyword}%`) },
|
||||
{ salaryMonth: Like(`%${keyword}%`) },
|
||||
{ salaryDay: Like(`%${keyword}%`) },
|
||||
],
|
||||
};
|
||||
}
|
||||
const [salaryRankEmployee, total] = await this.salaryRankEmployeeRepository.findAndCount({
|
||||
...whereClause,
|
||||
where: {
|
||||
salaryEmployeeId: id,
|
||||
},
|
||||
select: ["id", "step", "salaryMonth", "salaryDay"],
|
||||
order: {
|
||||
step: "ASC",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue