cal sixPercent

This commit is contained in:
AdisakKanthawilang 2024-02-29 14:52:54 +07:00
parent b8e4e8270b
commit b2205ff3ce

View file

@ -143,7 +143,7 @@ export class SalaryPeriodController extends Controller {
@Delete("profile/{id}")
async deleteSalaryProfile(@Path() id: string) {
const salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg"],
relations: ["salaryOrg","salaryOrg.salaryPeriod"],
where: { id: id },
});
if (!salaryProfile) {
@ -151,19 +151,34 @@ export class SalaryPeriodController extends Controller {
}
await this.salaryProfileRepository.remove(salaryProfile);
// หาจำนวน Quota คงเหลือ
if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryProfile?.salaryOrg.id,
type: "FULL",
},
});
const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.quantityUsed = amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
if(salaryProfile.salaryOrg.salaryPeriod.period == "APR"){
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryProfile?.salaryOrg.id,
type: "FULL",
},
});
const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.quantityUsed = amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}else if(salaryProfile.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 = salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}
}
return new HttpSuccess();
@ -272,17 +287,32 @@ export class SalaryPeriodController extends Controller {
await this.salaryProfileRepository.save(salaryProfile);
// หาจำนวน Quota คงเหลือ
if (salaryProfile?.salaryOrg.snapshot == "SNAP1") {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryProfile?.salaryOrg.id,
type: "FULL",
},
});
const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.quantityUsed = amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
if(salaryProfile.salaryOrg.salaryPeriod.period == "APR"){
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryProfile?.salaryOrg.id,
type: "FULL",
},
});
const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.quantityUsed = amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}else if(salaryProfile.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 = salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}
}
return new HttpSuccess();
}
@ -313,18 +343,33 @@ export class SalaryPeriodController extends Controller {
salaryProfile.salaryOrgId = salaryOrg.id;
await this.salaryProfileRepository.save(salaryProfile);
//หาจำนวน Quota คงเหลือ
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
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);
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;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
return new HttpSuccess();
}
@ -634,18 +679,33 @@ export class SalaryPeriodController extends Controller {
salaryProfile.lastUpdateFullName = request.user.name;
await this.salaryProfileRepository.save(salaryProfile);
//หาจำนวน Quota คงเหลือ
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
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);
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;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
return new HttpSuccess(salaryProfile.id);