เพิ่ม call

This commit is contained in:
AdisakKanthawilang 2024-02-28 18:03:36 +07:00
parent bbe3ee2906
commit aeb034a654

View file

@ -139,11 +139,26 @@ export class SalaryPeriodController extends Controller {
@Delete("profile/{id}")
async deleteSalaryProfile(@Path() id: string) {
const salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg"],
where: { id: id },
});
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
// หาจำนวน 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);
}
await this.salaryProfileRepository.remove(salaryProfile);
return new HttpSuccess();
}
@ -242,7 +257,20 @@ export class SalaryPeriodController extends Controller {
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}
// หาจำนวน 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);
}
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess();
}
@ -269,6 +297,21 @@ export class SalaryPeriodController extends Controller {
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
}
//หาจำนวน 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);
}
salaryProfile.salaryOrgId = salaryOrg.id;
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess();
@ -456,6 +499,21 @@ export class SalaryPeriodController extends Controller {
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
//หาจำนวน 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);
}
const salaryOrgAll = await this.salaryOrgRepository.find({
where: {
salaryPeriodId: salaryOrg.salaryPeriodId,