diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index e510ce53..c02c10e5 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -40,13 +40,14 @@ export function calculateAge(start: Date, end = new Date()) { return { year, month, day }; } -export async function calculateGovAge(profileId: string , type: string) { // type = OFFICER , EMPLOYEE - const isEmployee = type === 'EMPLOYEE'; +export async function calculateGovAge(profileId: string, type: string) { + // type = OFFICER , EMPLOYEE + const isEmployee = type === "EMPLOYEE"; - const records = await AppDataSource.getRepository(ProfileSalary).find({ - where: { - [isEmployee ? 'profileEmployeeId' : 'profileId']: profileId, - }, + const records = await AppDataSource.getRepository(ProfileSalary).find({ + where: { + [isEmployee ? "profileEmployeeId" : "profileId"]: profileId, + }, select: ["date", "dateGovernment", "isGovernment"], order: { order: "ASC" }, }); @@ -56,9 +57,9 @@ export async function calculateGovAge(profileId: string , type: string) { // typ } let endDateFristRec: any = null; - endDateFristRec = await AppDataSource.getRepository(ProfileSalary).findOne({ + endDateFristRec = await AppDataSource.getRepository(ProfileSalary).findOne({ where: { - [isEmployee ? 'profileEmployeeId' : 'profileId']: profileId, + [isEmployee ? "profileEmployeeId" : "profileId"]: profileId, dateGovernment: Not(IsNull()), isGovernment: false, }, @@ -66,7 +67,7 @@ export async function calculateGovAge(profileId: string , type: string) { // typ order: { order: "ASC" }, }); - const calculateDuration = (startDate:any, endDate:any) => { + const calculateDuration = (startDate: any, endDate: any) => { let years = endDate.getFullYear() - startDate.getFullYear(); let months = endDate.getMonth() - startDate.getMonth(); let days = endDate.getDate() - startDate.getDate(); @@ -88,11 +89,15 @@ export async function calculateGovAge(profileId: string , type: string) { // typ const firstStartDate = new Date(records[0].date); const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date(); - const { years: totalYears1, months: totalMonths1, days: totalDays1 } = calculateDuration(firstStartDate, firstEndDate); + const { + years: totalYears1, + months: totalMonths1, + days: totalDays1, + } = calculateDuration(firstStartDate, firstEndDate); const records_middle = await AppDataSource.getRepository(ProfileSalary).find({ where: { - [isEmployee ? 'profileEmployeeId' : 'profileId']: profileId, + [isEmployee ? "profileEmployeeId" : "profileId"]: profileId, order: MoreThan(endDateFristRec?.order), dateGovernment: Not(IsNull()), }, @@ -104,20 +109,27 @@ export async function calculateGovAge(profileId: string , type: string) { // typ return { year: totalYears1, month: totalMonths1, day: totalDays1 }; } - let totalYears2 = 0, totalMonths2 = 0, totalDays2 = 0; + let totalYears2 = 0, + totalMonths2 = 0, + totalDays2 = 0; for (let i = 0; i < records_middle.length; i++) { const startDate = new Date(records_middle[i].dateGovernment); - const endDate = (i < records_middle.length - 1) - ? new Date(records_middle[i + 1].dateGovernment) - : new Date(); + const endDate = + i < records_middle.length - 1 ? new Date(records_middle[i + 1].dateGovernment) : new Date(); - if (records_middle[i].isGovernment === false && - (i === records_middle.length - 1 || records_middle[i + 1].isGovernment === false)) { + if ( + records_middle[i].isGovernment === false && + (i === records_middle.length - 1 || records_middle[i + 1].isGovernment === false) + ) { break; } - const { years: years_mid, months: months_mid, days: days_mid } = calculateDuration(startDate, endDate); + const { + years: years_mid, + months: months_mid, + days: days_mid, + } = calculateDuration(startDate, endDate); totalYears2 += years_mid; totalMonths2 += months_mid; @@ -126,7 +138,9 @@ export async function calculateGovAge(profileId: string , type: string) { // typ const adjustTotal = (years: any, months: any, days: any) => { if (days >= new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate()) { - months += Math.floor(days / new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate()); + months += Math.floor( + days / new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate(), + ); days %= new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate(); } @@ -139,20 +153,19 @@ export async function calculateGovAge(profileId: string , type: string) { // typ }; const adjustedTotal = adjustTotal(totalYears2, totalMonths2, totalDays2); - + let sumYears = totalYears1 + adjustedTotal.years; let sumMonths = totalMonths1 + adjustedTotal.months; let sumDays = totalDays1 + adjustedTotal.days; - + if (sumMonths >= 12) { sumYears += Math.floor(sumMonths / 12); sumMonths %= 12; } - return {year: sumYears, month: sumMonths, day: sumDays}; + return { year: sumYears, month: sumMonths, day: sumDays }; } - export function calculateRetireDate(birthDate: Date) { // let _birthDate = birthDate; @@ -293,7 +306,7 @@ export async function checkReturnCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); const _type = await commandRepository.findOne({ where: { - id: commandId + id: commandId, }, relations: ["commandType"], }); @@ -307,7 +320,7 @@ export async function checkExceptCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); const _type = await commandRepository.findOne({ where: { - id: commandId + id: commandId, }, relations: ["commandType"], }); @@ -321,11 +334,15 @@ export async function checkCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); const _type = await commandRepository.findOne({ where: { - id: commandId + id: commandId, }, relations: ["commandType"], }); - if (!["C-PM-12", "C-PM-13", "C-PM-17", "C-PM-18", "C-PM-23", "C-PM-19", "C-PM-20"].includes(String(_type?.commandType.code))) { + if ( + !["C-PM-12", "C-PM-13", "C-PM-17", "C-PM-18", "C-PM-23", "C-PM-19", "C-PM-20"].includes( + String(_type?.commandType.code), + ) + ) { return false; } return true; @@ -391,9 +408,9 @@ export function commandTypePath(commandCode: string): string | null { case "C-PM-10": return "/probation/report/command10/officer/report"; case "C-PM-11": - return "/probation/report/command11/officer/report";//PROBATION + return "/probation/report/command11/officer/report"; //PROBATION case "C-PM-12": - return "/probation/report/command12/officer/report";//PROBATION + return "/probation/report/command12/officer/report"; //PROBATION case "C-PM-13": return "/placement/transfer/command/report"; case "C-PM-14": @@ -411,11 +428,11 @@ export function commandTypePath(commandCode: string): string | null { case "C-PM-20": return "/discipline/result/command20/report"; case "C-PM-21": - return "/org/command/command21/employee/report";//ORG + return "/org/command/command21/employee/report"; //ORG case "C-PM-22": return "/placement/appointment/employee-appoint/report"; case "C-PM-23": - return "/retirement/resign/employee/report"; + return "/retirement/resign-employee/command/report"; case "C-PM-24": return "/placement/appointment/employee-move/report"; case "C-PM-25": @@ -435,23 +452,25 @@ export function commandTypePath(commandCode: string): string | null { case "C-PM-32": return "/discipline/result/command32/report"; case "C-PM-33": - return "/salary/report/command/officer/report";//SALARY + return "/salary/report/command/officer/report"; //SALARY case "C-PM-34": - return "/salary/report/command/officer/report";//SALARY + return "/salary/report/command/officer/report"; //SALARY case "C-PM-35": - return "/salary/report/command/officer/report";//SALARY + return "/salary/report/command/officer/report"; //SALARY case "C-PM-36": - return "/salary/report/command/employee/report";//SALARY + return "/salary/report/command/employee/report"; //SALARY case "C-PM-37": - return "/salary/report/command/employee/report";//SALARY + return "/salary/report/command/employee/report"; //SALARY case "C-PM-38": - return "/org/command/command38/officer/report";//ORG + return "/org/command/command38/officer/report"; //ORG case "C-PM-39": return "/placement/appointment/slip/report"; case "C-PM-40": - return "/org/command/command40/officer/report";//ORG + return "/org/command/command40/officer/report"; //ORG case "C-PM-41": return "/retirement/resign/leave-cancel/report"; + case "C-PM-42": + return "/retirement/resign-employee/leave-cancel/report"; default: return null; }