คำนวนโควต้าตอนเพิ่มคน

This commit is contained in:
Kittapath 2024-03-06 18:28:05 +07:00
parent 972539cc6b
commit 8c7ea64985
2 changed files with 28 additions and 14 deletions

View file

@ -175,7 +175,9 @@ export class SalaryPeriodController extends Controller {
})
.getRawOne();
const calRemainAmount =
salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
@ -322,7 +324,9 @@ export class SalaryPeriodController extends Controller {
})
.getRawOne();
const calRemainAmount =
salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
@ -381,7 +385,8 @@ export class SalaryPeriodController extends Controller {
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
@ -555,7 +560,9 @@ export class SalaryPeriodController extends Controller {
})
.getRawOne();
const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg);
@ -793,6 +800,10 @@ export class SalaryPeriodController extends Controller {
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
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;
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
@ -804,6 +815,10 @@ export class SalaryPeriodController extends Controller {
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;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
@ -812,7 +827,8 @@ export class SalaryPeriodController extends Controller {
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);