อนุมัติเงินเดือน

This commit is contained in:
Kittapath 2024-03-14 21:52:48 +07:00
parent c680dcd6a8
commit c22dd4ecf2
3 changed files with 192 additions and 9 deletions

View file

@ -134,6 +134,7 @@ export class SalaryPeriodController extends Controller {
remainingAmount: salaryOrg.remainingAmount,
totalAmountSpecial: sum,
totalBackup: salaryOrg.salaryProfiles.filter((x) => x.isReserve == true).length,
status: salaryOrg.status,
};
return new HttpSuccess(data);
}
@ -1319,17 +1320,55 @@ export class SalaryPeriodController extends Controller {
const SalaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id },
});
if (!SalaryPeriod) {
if (!SalaryPeriod)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (SalaryPeriod?.period == "SPECIAL") {
const SalaryOrg = await this.salaryOrgRepository.find({
where: { salaryPeriodId: SalaryPeriod.id },
relations: ["salaryProfiles"],
});
const salaryProfile = SalaryOrg.find((x) => x.salaryProfiles.length > 0);
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
await this.salaryOrgRepository.remove(SalaryOrg);
await this.salaryPeriodRepository.remove(SalaryPeriod);
return new HttpSuccess();
} else {
const SalaryOrg = await this.salaryOrgRepository.findOne({
where: { salaryPeriodId: SalaryPeriod.id },
});
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
await this.salaryPeriodRepository.remove(SalaryPeriod);
return new HttpSuccess();
}
const SalaryOrg = await this.salaryOrgRepository.findOne({
where: { salaryPeriodId: SalaryPeriod.id },
});
if (SalaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
}
await this.salaryPeriodRepository.remove(SalaryPeriod);
return new HttpSuccess();
}
/**
* API (active)
*
*
*/
@Get("active")
async GetListsSalaryPeriodActive() {
const salaryPeriod = await AppDataSource.getRepository(SalaryPeriod)
.createQueryBuilder("salaryPeriod")
.where({ isActive: true })
.select([
"salaryPeriod.id",
"salaryPeriod.period",
"salaryPeriod.isActive",
"salaryPeriod.isClose",
"salaryPeriod.effectiveDate",
"salaryPeriod.status",
"salaryPeriod.year",
"salaryPeriod.revisionId",
])
.orderBy("salaryPeriod.effectiveDate", "DESC")
.getMany();
return new HttpSuccess(salaryPeriod);
}
/**
@ -1922,4 +1961,118 @@ export class SalaryPeriodController extends Controller {
);
}
}
/**
* API
*
*
* @param {string} orgId Guid, *Id
*/
@Get("officer/approve/{orgId}")
async OfficerApprove(@Path() orgId: string) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "PENDING")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
salaryOrg.status = "WAITHEAD1";
await this.salaryOrgRepository.save(salaryOrg);
return new HttpSuccess();
}
/**
* API
*
*
* @param {string} orgId Guid, *Id
*/
@Get("head/approve/{orgId}")
async HeadApprove(@Path() orgId: string) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITHEAD1")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
salaryOrg.status = "WAITOWNER1";
await this.salaryOrgRepository.save(salaryOrg);
return new HttpSuccess();
}
/**
* API
*
*
* @param {string} orgId Guid, *Id
*/
@Get("owner/approve/{orgId}")
async OwnerApprove(@Path() orgId: string) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITOWNER1")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
salaryOrg.status = "REPORT";
await this.salaryOrgRepository.save(salaryOrg);
return new HttpSuccess();
}
/**
* API
*
*
* @param {string} orgId Guid, *Id
*/
@Put("owner/comment/{orgId}")
async WaitOwnerApprove(
@Path() orgId: string,
@Body()
body: {
titleRecommend: string;
},
) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITOWNER1")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
salaryOrg.status = "WAITHEAD2";
salaryOrg.ownerRecommend = body.titleRecommend;
await this.salaryOrgRepository.save(salaryOrg);
return new HttpSuccess();
}
/**
* API
*
*
* @param {string} orgId Guid, *Id
*/
@Put("head/comment/{orgId}")
async WaitHeadApprove(
@Path() orgId: string,
@Body()
body: {
titleRecommend: string;
},
) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITOFFICER2")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
salaryOrg.status = "REPORT";
salaryOrg.headRecommend = body.titleRecommend;
await this.salaryOrgRepository.save(salaryOrg);
return new HttpSuccess();
}
}