This commit is contained in:
AdisakKanthawilang 2024-03-01 14:46:06 +07:00
parent 134fb53fce
commit a1b0936bf6

View file

@ -343,33 +343,34 @@ export class SalaryPeriodController extends Controller {
salaryProfile.salaryOrgId = salaryOrg.id;
await this.salaryProfileRepository.save(salaryProfile);
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
if(salaryOrg.salaryPeriod.period == "APR"){
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.quantityUsed = amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}else if(salaryOrg.salaryPeriod.period == "OCT"){
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select('SUM(salaryProfile.amountUse)', 'totalAmount')
.where({
salaryOrgId: salaryProfile?.salaryOrg.id,
type: 'FULL',
})
.getRawOne();
const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
if (salaryOrg) {
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
if(salaryOrg.salaryPeriod.period == "APR"){
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.quantityUsed = amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}else if(salaryOrg.salaryPeriod.period == "OCT"){
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select('SUM(salaryProfile.amountUse)', 'totalAmount')
.where({
salaryOrgId: salaryProfile?.salaryOrg.id,
type: 'FULL',
})
.getRawOne();
const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
}
return new HttpSuccess();