This commit is contained in:
AdisakKanthawilang 2024-03-04 14:00:40 +07:00
parent a44c8659fa
commit 606a3cfa36

View file

@ -150,36 +150,37 @@ export class SalaryPeriodController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
// await this.salaryProfileRepository.remove(salaryProfile);
await this.salaryProfileRepository.remove(salaryProfile);
// หาจำนวน Quota คงเหลือ
// 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.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
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.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}
}
// }
return new HttpSuccess();
}
@ -195,7 +196,7 @@ export class SalaryPeriodController extends Controller {
@Post("change/amount")
async changeAmount(@Body() body: { profileId: string; amount: number }) {
const salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg"],
relations: ["salaryOrg","salaryOrg.salaryPeriod"],
where: { id: body.profileId },
});
if (!salaryProfile) {
@ -287,33 +288,34 @@ export class SalaryPeriodController extends Controller {
await this.salaryProfileRepository.save(salaryProfile);
// หาจำนวน Quota คงเหลือ
// 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.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
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.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}
}
// }
return new HttpSuccess();
}
@ -328,12 +330,14 @@ export class SalaryPeriodController extends Controller {
@Post("change/group")
async changeGroup(@Body() body: { profileId: string; groupId: string }) {
const salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg","salaryOrg.salaryPeriod"],
where: { id: body.profileId },
});
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
const salaryOrg = await this.salaryOrgRepository.findOne({
relations:["salaryPeriod"],
where: { id: body.groupId },
});
if (!salaryOrg) {
@ -345,31 +349,31 @@ export class SalaryPeriodController extends Controller {
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);
}
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: 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();
@ -562,6 +566,7 @@ export class SalaryPeriodController extends Controller {
@Request() request: { user: Record<string, any> },
) {
const salaryOrg = await this.salaryOrgRepository.findOne({
relations:["salaryPeriod"],
where: {
id: requestBody.id,
},
@ -691,31 +696,31 @@ export class SalaryPeriodController extends Controller {
// หาจำนวน 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.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: 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(salaryProfile.id);