เลื่อนเงินเดือนลูกจ้าง

This commit is contained in:
Kittapath 2024-03-21 22:59:53 +07:00
parent d3dd7012a1
commit 9449a1f989
7 changed files with 448 additions and 441 deletions

View file

@ -29,6 +29,7 @@ import {
import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { SalaryEmployee } from "../entities/SalaryEmployee"; import { SalaryEmployee } from "../entities/SalaryEmployee";
import { SalaryRankEmployee } from "../entities/SalaryRankEmployee"; import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
@Route("api/v1/salary/period-employee") @Route("api/v1/salary/period-employee")
@Tags("SalaryEmployee") @Tags("SalaryEmployee")
@ -41,6 +42,7 @@ export class SalaryPeriodEmployeeController extends Controller {
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel); private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
private salaryRepository = AppDataSource.getRepository(SalaryEmployee); private salaryRepository = AppDataSource.getRepository(SalaryEmployee);
private salaryRankRepository = AppDataSource.getRepository(SalaryRankEmployee); private salaryRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee);
/** /**
* API * API
@ -231,103 +233,44 @@ export class SalaryPeriodEmployeeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
} }
let type = salaryProfile.type; let type = salaryProfile.type;
let salaryRanks: any = null; const salaryFormula = await this.salaryFormulaEmployeeRepository.findOne({
// //Salary where: {
// const salarys = await this.salaryRepository.findOne({ position: salaryProfile.position,
// where: { posType: { posTypeName: salaryProfile.posType },
// posTypeId: Level.posTypeId, posLevel: { posLevelName: salaryProfile.posLevel },
// posLevelId: Level.id, },
// isActive: true, relations: ["salaryEmployeeMins", "salaryEmployee"],
// }, });
// }); let group = salaryProfile.group;
// if (!salarys) { let step = salaryProfile.salaryLevel == null ? 0 : salaryProfile.salaryLevel;
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง"); if (group == null || group == 0) {
// } if (salaryFormula != null) {
// //SalaryRank group = salaryFormula.salaryEmployeeMins.sort((a, b) => a.group - b.group)[0].group;
// let salaryRanks: any = null; } else {
// if (salaryProfile.amount != null) { group = 1;
// salaryRanks = await this.salaryRankRepository.findOne({ }
// where: { }
// salaryId: salarys.id, if (salaryProfile.amount == null || salaryProfile.amount == 0) {
// salary: salaryProfile.amount, if (salaryFormula != null) {
// isNext: false, const salaryRankMin = await this.salaryRankRepository.findOne({
// }, where: {
// }); salaryMonth: salaryFormula.salaryMin == null ? 0 : salaryFormula.salaryMin,
// if (salaryRanks == null) { salaryEmployee_: {
// salaryRanks = await this.salaryRankRepository.findOne({ isActive: true,
// where: { group: group,
// salaryId: salarys.id, },
// salary: MoreThan(salaryProfile.amount), },
// isNext: false, });
// }, if (salaryRankMin == null) {
// order: { salary: "DESC" }, step = 1;
// }); } else {
// } step = salaryRankMin.step - 0.5;
// if (salaryRanks != null) { }
// if (salaryProfile.type == "HAFT") { } else {
// if (salaryRanks.salaryHalfSpecial != null && salaryRanks.salaryHalfSpecial > 0) { step = 1;
// 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" },
// });
// }
// }
// }
salaryProfile.isNext = false;
if (type == "NONE") { if (type == "NONE") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
@ -336,51 +279,84 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
salaryProfile.positionSalaryAmount = 0; salaryProfile.positionSalaryAmount = 0;
} else if (type == "HAFT") { } else if (type == "HAFT" || type == "FULL" || type == "FULLHAFT") {
salaryProfile.amountSpecial = if (type == "HAFT") {
salaryRanks == null || salaryRanks.salaryHalfSpecial == null step = step + 0.5;
? 0 } else if (type == "FULL") {
: salaryRanks.salaryHalfSpecial; step = step + 1;
salaryProfile.amountUse = } else if (type == "FULLHAFT") {
salaryRanks == null || step = step + 1.5;
salaryProfile == null || }
salaryRanks.salaryHalf == null || let salaryRankMax = await this.salaryRankRepository.findOne({
salaryProfile.amount == null where: {
? 0 salaryEmployee_: {
: salaryRanks.salaryHalf - salaryProfile.amount; isActive: true,
salaryProfile.positionSalaryAmount = group: group,
salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; },
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; },
} else if (type == "FULL") { order: { step: "DESC" },
salaryProfile.amountSpecial = });
salaryRanks == null || salaryRanks.salaryFullSpecial == null if (salaryRankMax != null && step > salaryRankMax.step) {
? 0 let salaryRankAmount = await this.salaryRankRepository.findOne({
: salaryRanks.salaryFullSpecial; where: {
salaryProfile.amountUse = salaryMonth: MoreThan(salaryProfile.amount),
salaryRanks == null || salaryEmployee_: {
salaryProfile == null || isActive: true,
salaryRanks.salaryFull == null || group: group + 1,
salaryProfile.amount == null },
? 0 },
: salaryRanks.salaryFull - salaryProfile.amount; order: { salaryMonth: "ASC" },
salaryProfile.positionSalaryAmount = });
salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; group = group + 1;
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; step =
} else if (type == "FULLHAFT") { (salaryRankAmount == null ? 1 : salaryRankAmount.step) +
salaryProfile.amountSpecial = (step - (salaryRankMax == null ? 0 : salaryRankMax.step) - 0.5);
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null }
? 0 let salaryRanks = await this.salaryRankRepository.findOne({
: salaryRanks.salaryFullHalfSpecial; where: {
salaryProfile.amountUse = step: step,
salaryRanks == null || salaryEmployee_: {
salaryProfile == null || isActive: true,
salaryRanks.salaryFullHalf == null || group: group,
salaryProfile.amount == null },
? 0 },
: salaryRanks.salaryFullHalf - salaryProfile.amount; });
salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; if (salaryRanks != null && salaryRanks.salaryMonth != null) {
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; 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 { } else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
} }
@ -551,106 +527,47 @@ export class SalaryPeriodEmployeeController extends Controller {
if (!Level) { if (!Level) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง"); 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.type = body.type;
salaryProfile.isReserve = body.isReserve; salaryProfile.isReserve = body.isReserve;
// //SalaryRank let type = salaryProfile.type;
// let salaryRanks: any = null; const salaryFormula = await this.salaryFormulaEmployeeRepository.findOne({
// if (salaryProfile.amount != null) { where: {
// salaryRanks = await this.salaryRankRepository.findOne({ position: salaryProfile.position,
// where: { posType: { posTypeName: salaryProfile.posType },
// salaryId: salarys.id, posLevel: { posLevelName: salaryProfile.posLevel },
// salary: salaryProfile.amount, },
// isNext: false, relations: ["salaryEmployeeMins", "salaryEmployee"],
// }, });
// }); let group = salaryProfile.group;
// if (salaryRanks == null) { let step = salaryProfile.salaryLevel == null ? 0 : salaryProfile.salaryLevel;
// salaryRanks = await this.salaryRankRepository.findOne({ if (group == null || group == 0) {
// where: { if (salaryFormula != null) {
// salaryId: salarys.id, group = salaryFormula.salaryEmployeeMins.sort((a, b) => a.group - b.group)[0].group;
// salary: MoreThan(salaryProfile.amount), } else {
// isNext: false, group = 1;
// }, }
// order: { salary: "DESC" }, }
// }); if (salaryProfile.amount == null || salaryProfile.amount == 0) {
// } if (salaryFormula != null) {
// if (salaryRanks != null) { const salaryRankMin = await this.salaryRankRepository.findOne({
// if (salaryProfile.type == "HAFT") { where: {
// if (salaryRanks.salaryHalfSpecial != null && salaryRanks.salaryHalfSpecial > 0) { salaryMonth: salaryFormula.salaryMin == null ? 0 : salaryFormula.salaryMin,
// salaryRanks = await this.salaryRankRepository.findOne({ salaryEmployee_: {
// where: { isActive: true,
// salaryId: salarys.id, group: group,
// salary: salaryRanks.salaryHalf, },
// isNext: true, },
// }, });
// }); if (salaryRankMin == null) {
// } step = 1;
// } else if (salaryProfile.type == "FULL") { } else {
// if (salaryRanks.salaryFullSpecial != null && salaryRanks.salaryFullSpecial > 0) { step = salaryRankMin.step - 0.5;
// if (salaryRanks.salaryHalfSpecial == null || salaryRanks.salaryHalfSpecial == 0) { }
// type = "HAFT"; } else {
// } step = 1;
// 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" },
// });
// }
// }
// }
salaryProfile.isNext = false;
if (type == "NONE") { if (type == "NONE") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
@ -659,51 +576,87 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
salaryProfile.positionSalaryAmount = 0; salaryProfile.positionSalaryAmount = 0;
} else if (type == "HAFT") { } else if (type == "HAFT" || type == "FULL" || type == "FULLHAFT") {
salaryProfile.amountSpecial = if (type == "HAFT") {
salaryRanks == null || salaryRanks.salaryHalfSpecial == null step = step + 0.5;
? 0 } else if (type == "FULL") {
: salaryRanks.salaryHalfSpecial; step = step + 1;
salaryProfile.amountUse = } else if (type == "FULLHAFT") {
salaryRanks == null || step = step + 1.5;
salaryProfile == null || }
salaryRanks.salaryHalf == null || let salaryRankMax = await this.salaryRankRepository.findOne({
salaryProfile.amount == null where: {
? 0 salaryEmployee_: {
: salaryRanks.salaryHalf - salaryProfile.amount; isActive: true,
salaryProfile.positionSalaryAmount = group: group,
salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; },
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; },
} else if (type == "FULL") { order: { step: "DESC" },
salaryProfile.amountSpecial = });
salaryRanks == null || salaryRanks.salaryFullSpecial == null if (salaryRankMax != null && step > salaryRankMax.step) {
? 0 let salaryRankAmount = await this.salaryRankRepository.findOne({
: salaryRanks.salaryFullSpecial; where: {
salaryProfile.amountUse = salaryMonth: MoreThan(salaryProfile.amount == null ? 0 : salaryProfile.amount),
salaryRanks == null || salaryEmployee_: {
salaryProfile == null || isActive: true,
salaryRanks.salaryFull == null || group: group + 1,
salaryProfile.amount == null },
? 0 },
: salaryRanks.salaryFull - salaryProfile.amount; order: { salaryMonth: "ASC" },
salaryProfile.positionSalaryAmount = });
salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; group = group + 1;
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; step =
} else if (type == "FULLHAFT") { (salaryRankAmount == null ? 1 : salaryRankAmount.step) +
salaryProfile.amountSpecial = (step - (salaryRankMax == null ? 0 : salaryRankMax.step) - 0.5);
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null }
? 0 let salaryRanks = await this.salaryRankRepository.findOne({
: salaryRanks.salaryFullHalfSpecial; where: {
salaryProfile.amountUse = step: step,
salaryRanks == null || salaryEmployee_: {
salaryProfile == null || isActive: true,
salaryRanks.salaryFullHalf == null || group: group,
salaryProfile.amount == null },
? 0 },
: salaryRanks.salaryFullHalf - salaryProfile.amount; });
salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; if (salaryRanks != null && salaryRanks.salaryMonth != null) {
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; 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 { } else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
} }
@ -933,102 +886,44 @@ export class SalaryPeriodEmployeeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
} }
let type = salaryProfile.type; let type = salaryProfile.type;
let salaryRanks: any = null; const salaryFormula = await this.salaryFormulaEmployeeRepository.findOne({
// //Salary where: {
// const salarys = await this.salaryRepository.findOne({ position: salaryProfile.position,
// where: { posType: { posTypeName: salaryProfile.posType },
// posTypeId: posLevel.posTypeId, posLevel: { posLevelName: salaryProfile.posLevel },
// posLevelId: posLevel.id, },
// isActive: true, relations: ["salaryEmployeeMins", "salaryEmployee"],
// }, });
// }); let group = salaryProfile.group;
// if (!salarys) { let step = salaryProfile.salaryLevel == null ? 0 : salaryProfile.salaryLevel;
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง"); if (group == null || group == 0) {
// } if (salaryFormula != null) {
// //SalaryRank group = salaryFormula.salaryEmployeeMins.sort((a, b) => a.group - b.group)[0].group;
// if (salaryProfile.amount != null) { } else {
// salaryRanks = await this.salaryRankRepository.findOne({ group = 1;
// where: { }
// salaryId: salarys.id, }
// salary: salaryProfile.amount, if (salaryProfile.amount == null || salaryProfile.amount == 0) {
// isNext: false, if (salaryFormula != null) {
// }, const salaryRankMin = await this.salaryRankRepository.findOne({
// }); where: {
// if (salaryRanks == null) { salaryMonth: salaryFormula.salaryMin == null ? 0 : salaryFormula.salaryMin,
// salaryRanks = await this.salaryRankRepository.findOne({ salaryEmployee_: {
// where: { isActive: true,
// salaryId: salarys.id, group: group,
// salary: MoreThan(salaryProfile.amount), },
// isNext: false, },
// }, });
// order: { salary: "DESC" }, if (salaryRankMin == null) {
// }); step = 1;
// } } else {
// if (salaryRanks != null) { step = salaryRankMin.step - 0.5;
// if (salaryProfile.type == "HAFT") { }
// if (salaryRanks.salaryHalfSpecial != null && salaryRanks.salaryHalfSpecial > 0) { } else {
// salaryRanks = await this.salaryRankRepository.findOne({ step = 1;
// 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" },
// });
// }
// }
// }
salaryProfile.isNext = false;
if (type == "NONE") { if (type == "NONE") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
@ -1037,51 +932,87 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
salaryProfile.positionSalaryAmount = 0; salaryProfile.positionSalaryAmount = 0;
} else if (type == "HAFT") { } else if (type == "HAFT" || type == "FULL" || type == "FULLHAFT") {
salaryProfile.amountSpecial = if (type == "HAFT") {
salaryRanks == null || salaryRanks.salaryHalfSpecial == null step = step + 0.5;
? 0 } else if (type == "FULL") {
: salaryRanks.salaryHalfSpecial; step = step + 1;
salaryProfile.amountUse = } else if (type == "FULLHAFT") {
salaryRanks == null || step = step + 1.5;
salaryProfile == null || }
salaryRanks.salaryHalf == null || let salaryRankMax = await this.salaryRankRepository.findOne({
salaryProfile.amount == null where: {
? 0 salaryEmployee_: {
: salaryRanks.salaryHalf - salaryProfile.amount; isActive: true,
salaryProfile.positionSalaryAmount = group: group,
salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; },
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; },
} else if (type == "FULL") { order: { step: "DESC" },
salaryProfile.amountSpecial = });
salaryRanks == null || salaryRanks.salaryFullSpecial == null if (salaryRankMax != null && step > salaryRankMax.step) {
? 0 let salaryRankAmount = await this.salaryRankRepository.findOne({
: salaryRanks.salaryFullSpecial; where: {
salaryProfile.amountUse = salaryMonth: MoreThan(salaryProfile.amount == null ? 0 : salaryProfile.amount),
salaryRanks == null || salaryEmployee_: {
salaryProfile == null || isActive: true,
salaryRanks.salaryFull == null || group: group + 1,
salaryProfile.amount == null },
? 0 },
: salaryRanks.salaryFull - salaryProfile.amount; order: { salaryMonth: "ASC" },
salaryProfile.positionSalaryAmount = });
salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; group = group + 1;
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; step =
} else if (type == "FULLHAFT") { (salaryRankAmount == null ? 1 : salaryRankAmount.step) +
salaryProfile.amountSpecial = (step - (salaryRankMax == null ? 0 : salaryRankMax.step) - 0.5);
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null }
? 0 let salaryRanks = await this.salaryRankRepository.findOne({
: salaryRanks.salaryFullHalfSpecial; where: {
salaryProfile.amountUse = step: step,
salaryRanks == null || salaryEmployee_: {
salaryProfile == null || isActive: true,
salaryRanks.salaryFullHalf == null || group: group,
salaryProfile.amount == null },
? 0 },
: salaryRanks.salaryFullHalf - salaryProfile.amount; });
salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; if (salaryRanks != null && salaryRanks.salaryMonth != null) {
salaryProfile.isNext = salaryRanks == null ? 0 : salaryRanks.isNext; 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 { } else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
} }

View file

@ -14,7 +14,7 @@ import {
Get, Get,
Query, Query,
} from "tsoa"; } from "tsoa";
import { Like} from "typeorm"; import { Like } from "typeorm";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
@ -126,7 +126,6 @@ export class SalaryRanksController extends Controller {
if (keyword != undefined && keyword !== "") { if (keyword != undefined && keyword !== "") {
whereClause = { whereClause = {
where: [ where: [
{ salaryId: id },
{ salary: Like(`%${keyword}%`) }, { salary: Like(`%${keyword}%`) },
{ salaryHalf: Like(`%${keyword}%`) }, { salaryHalf: Like(`%${keyword}%`) },
{ salaryHalfSpecial: Like(`%${keyword}%`) }, { salaryHalfSpecial: Like(`%${keyword}%`) },
@ -139,6 +138,9 @@ export class SalaryRanksController extends Controller {
} }
const [salaryRank, total] = await this.salaryRankRepository.findAndCount({ const [salaryRank, total] = await this.salaryRankRepository.findAndCount({
...whereClause, ...whereClause,
where: {
salaryId: id,
},
select: [ select: [
"id", "id",
"salary", "salary",

View file

@ -58,10 +58,10 @@ export class SalaryRankEmployeeController extends Controller {
const checkStep = await this.salaryRankEmployeeRepository.find({ const checkStep = await this.salaryRankEmployeeRepository.find({
where: { where: {
step: requestBody.step, step: requestBody.step,
salaryEmployeeId: requestBody.salaryEmployeeId salaryEmployeeId: requestBody.salaryEmployeeId,
} },
}); });
if(checkStep.length > 0){ if (checkStep.length > 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเพิ่มได้ เนื่องจากลำดับขั้นนี้ซ้ำ"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเพิ่มได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
} }
const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody); const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody);
@ -99,10 +99,10 @@ export class SalaryRankEmployeeController extends Controller {
where: { where: {
id: Not(id), id: Not(id),
step: requestBody.step, step: requestBody.step,
salaryEmployeeId: salaryRankEmployee.salaryEmployeeId salaryEmployeeId: salaryRankEmployee.salaryEmployeeId,
} },
}); });
if(checkStep.length > 0){ if (checkStep.length > 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขได้ เนื่องจากลำดับขั้นนี้ซ้ำ"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
} }
salaryRankEmployee.lastUpdateUserId = request.user.sub; salaryRankEmployee.lastUpdateUserId = request.user.sub;
@ -147,7 +147,6 @@ export class SalaryRankEmployeeController extends Controller {
if (keyword != undefined && keyword !== "") { if (keyword != undefined && keyword !== "") {
whereClause = { whereClause = {
where: [ where: [
{ salaryEmployeeId: id, },
{ step: Like(`%${keyword}%`) }, { step: Like(`%${keyword}%`) },
{ salaryMonth: Like(`%${keyword}%`) }, { salaryMonth: Like(`%${keyword}%`) },
{ salaryDay: Like(`%${keyword}%`) }, { salaryDay: Like(`%${keyword}%`) },
@ -156,6 +155,9 @@ export class SalaryRankEmployeeController extends Controller {
} }
const [salaryRankEmployee, total] = await this.salaryRankEmployeeRepository.findAndCount({ const [salaryRankEmployee, total] = await this.salaryRankEmployeeRepository.findAndCount({
...whereClause, ...whereClause,
where: {
salaryEmployeeId: id,
},
select: ["id", "step", "salaryMonth", "salaryDay"], select: ["id", "step", "salaryMonth", "salaryDay"],
order: { order: {
step: "ASC", step: "ASC",

View file

@ -36,7 +36,7 @@ export class SalaryFormulaEmployee extends EntityBase {
comment: "อัตราค่าจ้างขั้นสูงใหม่", comment: "อัตราค่าจ้างขั้นสูงใหม่",
default: null, default: null,
}) })
salaryMax?: number | null; salaryMax: number | null;
@Column({ @Column({
nullable: true, nullable: true,
@ -92,7 +92,7 @@ export class CreateSalaryFormulaEmployee {
salary?: number | null; salary?: number | null;
@Column() @Column()
salaryMax?: number | null; salaryMax: number | null;
@Column() @Column()
details?: string; details?: string;
@ -121,7 +121,7 @@ export class UpdateSalaryFormulaEmployee {
salary?: number | null; salary?: number | null;
@Column() @Column()
salaryMax?: number | null; salaryMax: number | null;
@Column() @Column()
details?: string; details?: string;

View file

@ -18,6 +18,14 @@ export class SalaryProfileEmployee extends EntityBase {
}) })
salaryLevel: number | null; salaryLevel: number | null;
@Column({
type: "double",
nullable: true,
comment: "ขั้นเงินเดือน(ใหม่)",
default: null,
})
salaryLevelNew: number;
@Column({ @Column({
nullable: true, nullable: true,
comment: "คำนำหน้า", comment: "คำนำหน้า",
@ -112,6 +120,21 @@ export class SalaryProfileEmployee extends EntityBase {
}) })
posLevel: number; posLevel: number;
@Column({
type: "double",
nullable: true,
comment: "กลุ่มบัญชีการจ้าง",
default: null,
})
group: number | null;
@Column({
nullable: true,
comment: "กลุ่มบัญชีการจ้าง(ใหม่)",
default: null,
})
groupNew: number;
// @Column({ // @Column({
// nullable: true, // nullable: true,
// comment: "ตำแหน่งทางการบริหาร", // comment: "ตำแหน่งทางการบริหาร",
@ -149,6 +172,13 @@ export class SalaryProfileEmployee extends EntityBase {
}) })
positionSalaryAmount: number; positionSalaryAmount: number;
@Column({
type: "double",
comment: "เงินเดือนหลังเลื่อน(รายวัน)",
default: 0,
})
positionSalaryDayAmount: number | null;
@Column({ @Column({
comment: comment:
"ประเภทการเลื่อน(ขั้น) PENDING->รายชื่อคนครอง NONE->ไม่ได้เลื่อน HAFT->ครึ่งขั้น FULL->1ขั้น FULLHAFT->1.5ขั้น", "ประเภทการเลื่อน(ขั้น) PENDING->รายชื่อคนครอง NONE->ไม่ได้เลื่อน HAFT->ครึ่งขั้น FULL->1ขั้น FULLHAFT->1.5ขั้น",
@ -354,6 +384,12 @@ export class CreateSalaryProfileEmployee {
@Column() @Column()
posLevel: string | null; posLevel: string | null;
@Column()
group: number | null;
@Column()
posTypeShort: string | null;
@Column() @Column()
salaryLevel: number | null; salaryLevel: number | null;

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableProfileemployeeAddGroupNew1711033284607 implements MigrationInterface {
name = 'UpdateTableProfileemployeeAddGroupNew1711033284607'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`salaryLevelNew\` double NULL COMMENT 'ขั้นเงินเดือน(ใหม่)'`);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`group\` int NULL COMMENT 'กลุ่มบัญชีการจ้าง'`);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`groupNew\` int NULL COMMENT 'กลุ่มบัญชีการจ้าง(ใหม่)'`);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`positionSalaryDayAmount\` double NOT NULL COMMENT 'เงินเดือนหลังเลื่อน(รายวัน)' DEFAULT '0'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`positionSalaryDayAmount\``);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`groupNew\``);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`group\``);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`salaryLevelNew\``);
}
}

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableProfileemployeeAddGroupNew11711035132085 implements MigrationInterface {
name = 'UpdateTableProfileemployeeAddGroupNew11711035132085'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`group\``);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`group\` double NULL COMMENT 'กลุ่มบัญชีการจ้าง'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`group\``);
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`group\` int NULL COMMENT 'กลุ่มบัญชีการจ้าง'`);
}
}