แก้บัคเพิ่มคนเข้าระบบเงินเดือน

This commit is contained in:
Kittapath 2024-03-08 14:51:10 +07:00
parent a4f9676297
commit c3b47b4867

View file

@ -1082,39 +1082,47 @@ export class SalaryPeriodController extends Controller {
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
const _salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: salaryOrg.id,
},
});
if (!_salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
if (salaryOrg.salaryPeriod.period == "APR") {
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
_salaryOrg.total = salaryOrg.salaryProfiles.length;
_salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
_salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg?.id,
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.quantityUsed = amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
_salaryOrg.quantityUsed = amountFullType;
_salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(_salaryOrg);
} else if (salaryOrg.salaryPeriod.period == "OCT") {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
_salaryOrg.currentAmount = totalProfile;
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg?.id,
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
_salaryOrg.useAmount = sumAmountUse.totalAmount;
_salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(_salaryOrg);
}
}