คำนวนเงินเดือนใหม่

This commit is contained in:
Bright 2024-02-27 13:03:34 +07:00
parent 2a7a5d5922
commit 94cece9fc5

View file

@ -23,6 +23,10 @@ import { CreateSalaryPeriod, SalaryPeriod, UpdateSalaryPeriod } from "../entitie
import Extension from "../interfaces/extension";
import { SalaryOrg } from "../entities/SalaryOrg";
import { CreateSalaryProfile, SalaryProfile } from "../entities/SalaryProfile";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import { Salarys } from "../entities/Salarys";
import { SalaryRanks } from "../entities/SalaryRanks";
@Route("api/v1/salary/period")
@Tags("Salary")
@ -31,6 +35,10 @@ export class SalaryPeriodController extends Controller {
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
private salaryRepository = AppDataSource.getRepository(Salarys);
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
/**
* API
@ -306,24 +314,58 @@ export class SalaryPeriodController extends Controller {
const salaryProfile = Object.assign(new SalaryProfile(), requestBody);
salaryProfile.type = salaryProfile.type.toUpperCase();
//Type & Level
const Type = await this.posTypeRepository.findOne({
where: {
posTypeName: salaryProfile.posType,
},
});
if (!Type) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทตำแหน่ง");
}
const Level = await this.posLevelRepository.findOne({
where: {
posTypeId: Type.id,
posLevelName: salaryProfile.posLevel,
},
});
if (!Level) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
}
//Salary
const salarys = await this.salaryRepository.findOne({
where: {
posTypeId : Level.posTypeId,
posLevelId : Level.id,
isActive : true
}
});
//SalaryRank
const SalaryRanks = await this.salaryRankRepository.findOne({
where: {
salaryId: salarys?.id,
salary: salaryProfile.amount
}
});
//xxxxxx คำนวนเงินเดือนใหม่
if (salaryProfile.type == "NONE") {
//xxxx เงินไม่เปลืี่ยน
} else if (salaryProfile.type == "HAFT") {
//xxxx เลื่อน0.5ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryHalf);
} else if (salaryProfile.type == "FULL") {
//xxxx เลื่อน1ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFull) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFull);
} else if (salaryProfile.type == "FULLHAFT") {
//xxxx เลื่อน1.0ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFullHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFullHalf);
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}