คำนวน 6เปอรเซนใหม่ตอนsnap1

This commit is contained in:
Kittapath 2024-04-04 17:08:18 +07:00
parent b049632ef7
commit 2d68472500
2 changed files with 841 additions and 321 deletions

View file

@ -295,37 +295,93 @@ export class SalaryPeriodController extends Controller {
await this.salaryProfileRepository.remove(salaryProfile);
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน 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: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
}
}
return new HttpSuccess();
}
return new HttpSuccess();
@ -515,41 +571,94 @@ export class SalaryPeriodController extends Controller {
await this.salaryProfileRepository.save(salaryProfile);
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (salaryProfile.isReserve == false) {
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 != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(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: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}
return new HttpSuccess();
}
return new HttpSuccess();
}
/**
@ -579,39 +688,93 @@ export class SalaryPeriodController extends Controller {
salaryProfile.salaryOrgId = salaryOrg.id;
await this.salaryProfileRepository.save(salaryProfile);
if (salaryOrg) {
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
if (salaryOrg.salaryPeriod.period == "APR") {
if (salaryProfile.isReserve == false) {
const amountFullType = await this.salaryProfileRepository.count({
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
id: _salaryProfile.salaryOrg.id,
},
});
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.quantityUsed = amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
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: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
return new HttpSuccess();
}
return new HttpSuccess();
}
@ -659,7 +822,7 @@ export class SalaryPeriodController extends Controller {
);
}
}
}
}
if (body.type == "FULL") {
salaryProfile.isReserve = body.isReserve;
} else {
@ -832,41 +995,93 @@ export class SalaryPeriodController extends Controller {
}
await this.salaryProfileRepository.save(salaryProfile);
if (salaryProfile.salaryOrg) {
// หาจำนวน Quota คงเหลือ
if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (body.isReserve == false) {
const amountFullType = await this.salaryProfileRepository.count({
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryOrgId: salaryProfile.salaryOrg.id,
type: "FULL",
id: _salaryProfile.salaryOrg.id,
},
});
const calRemainQuota = salaryProfile.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.quantityUsed = amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg);
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(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: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg);
}
}
return new HttpSuccess();
}
return new HttpSuccess();
}
@ -1208,54 +1423,94 @@ export class SalaryPeriodController extends Controller {
salaryProfile.lastUpdateFullName = request.user.name;
await this.salaryProfileRepository.save(salaryProfile);
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
const _salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: salaryOrg.id,
},
});
if (!_salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
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,
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 totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
_salaryOrg.currentAmount = totalProfile;
_salaryOrg.total = salaryOrg.salaryProfiles.length;
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
_salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
_salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(_salaryOrg);
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
}
}
return new HttpSuccess();
}
return new HttpSuccess(salaryProfile.id);
}
@ -1856,6 +2111,8 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext;
salaryProfileNew.isSpecial = salaryOld == null ? false : salaryOld.isSpecial;
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
@ -1898,6 +2155,8 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext;
salaryProfileNew.isSpecial = salaryOld == null ? false : salaryOld.isSpecial;
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
}
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
}
@ -2342,6 +2601,8 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext;
salaryProfileNew.type = salaryOld == null ? false : salaryOld.isSpecial;
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
@ -2384,6 +2645,8 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext;
salaryProfileNew.type = salaryOld == null ? false : salaryOld.isSpecial;
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
}
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
}

View file

@ -257,37 +257,93 @@ export class SalaryPeriodEmployeeController extends Controller {
await this.salaryProfileRepository.remove(salaryProfile);
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน 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(SalaryProfileEmployee)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryProfile?.salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfileEmployee")
.select("SUM(salaryProfileEmployee.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
}
}
return new HttpSuccess();
}
return new HttpSuccess();
@ -649,39 +705,93 @@ export class SalaryPeriodEmployeeController extends Controller {
await this.salaryProfileRepository.save(salaryProfile);
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (salaryProfile.isReserve == false) {
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 != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfileEmployee")
.select("SUM(salaryProfileEmployee.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
}
} else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryProfile?.salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}
return new HttpSuccess();
}
return new HttpSuccess();
}
@ -713,39 +823,93 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryProfile.salaryOrgId = salaryOrg.id;
await this.salaryProfileRepository.save(salaryProfile);
if (salaryOrg) {
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
if (salaryOrg.salaryPeriod.period == "APR") {
if (salaryProfile.isReserve == false) {
const amountFullType = await this.salaryProfileRepository.count({
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
id: _salaryProfile.salaryOrg.id,
},
});
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.quantityUsed = amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfileEmployee")
.select("SUM(salaryProfileEmployee.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (salaryOrg.salaryPeriod.period == "OCT") {
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
return new HttpSuccess();
}
return new HttpSuccess();
}
@ -1141,41 +1305,93 @@ export class SalaryPeriodEmployeeController extends Controller {
}
await this.salaryProfileRepository.save(salaryProfile);
if (salaryProfile.salaryOrg) {
// หาจำนวน Quota คงเหลือ
if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (body.isReserve == false) {
const amountFullType = await this.salaryProfileRepository.count({
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryOrgId: salaryProfile.salaryOrg.id,
type: "FULL",
id: _salaryProfile.salaryOrg.id,
},
});
const calRemainQuota = salaryProfile.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.quantityUsed = amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg);
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfileEmployee")
.select("SUM(salaryProfileEmployee.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryProfile.salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg);
}
}
return new HttpSuccess();
}
return new HttpSuccess();
}
@ -1742,52 +1958,93 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryProfile.lastUpdateFullName = request.user.name;
await this.salaryProfileRepository.save(salaryProfile);
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
});
// หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") {
const _salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: salaryOrg.id,
},
});
if (!_salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
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,
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 totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
_salaryOrg.currentAmount = totalProfile;
_salaryOrg.total = salaryOrg.salaryProfiles.length;
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
_salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount;
_salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(_salaryOrg);
if (_salaryProfile != null) {
if (_salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (_salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const amountFullType = await this.salaryProfileRepository.count({
where: {
salaryOrgId: salaryOrg.id,
type: "FULL",
},
});
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
if (_salaryProfile != null) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: _salaryProfile.salaryOrg.id,
},
});
if (salaryOrg != null) {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
let totalAmount = 0;
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
where: {
year: _salaryProfile.salaryOrg.salaryPeriod.year,
period: "APR",
},
});
if (salaryPeriodAPROld != null) {
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodAPROld.id,
rootId: salaryOrg.rootId,
group: salaryOrg.group,
snapshot: "SNAP2",
},
relations: ["salaryProfiles"],
});
totalAmount =
salaryOrgSnap2Old == null
? 0
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
}
salaryOrg.spentAmount = totalAmount;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfileEmployee)
.createQueryBuilder("salaryProfileEmployee")
.select("SUM(salaryProfileEmployee.amountUse)", "totalAmount")
.where({
salaryOrgId: salaryOrg.id,
type: In(["HAFT", "FULL", "FULLHAFT"]),
})
.getRawOne();
const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount =
sumAmountUse == null || sumAmountUse.totalAmount == null
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
}
}
}
}
return new HttpSuccess();
}
return new HttpSuccess(salaryProfile.id);