From 3fcce9c15c951cdb81eb34af4c66ca9e3049d3e9 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 20 Dec 2024 13:46:51 +0700 Subject: [PATCH] #867 (13) --- src/interfaces/utils.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 0a329890..1fbcfb14 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -9,6 +9,7 @@ import { RequestWithUser } from "../middlewares/user"; import { Command } from "../entities/Command"; import { ProfileSalary } from "../entities/ProfileSalary"; import { Profile } from "../entities/Profile"; +import { ProfileEmployee } from "../entities/ProfileEmployee"; export function calculateAge(start: Date, end = new Date()) { if (start.getTime() > end.getTime()) return null; @@ -86,11 +87,19 @@ export async function calculateGovAge(profileId: string, type: string) { return { years, months, days }; }; - const profile = await AppDataSource.getRepository(Profile).findOne({ + let profile:any; + profile = await AppDataSource.getRepository(Profile).findOne({ where:{ id:profileId } }) + if(isEmployee){ + profile = await AppDataSource.getRepository(ProfileEmployee).findOne({ + where:{ + id:profileId + } + }) + } // const firstStartDate = new Date(records[0].date); const firstStartDate = profile?.dateAppoint ? profile?.dateAppoint : new Date(); const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date(); @@ -100,7 +109,7 @@ export async function calculateGovAge(profileId: string, type: string) { months: totalMonths1, days: totalDays1, } = calculateDuration(firstStartDate, firstEndDate); - + const records_middle = await AppDataSource.getRepository(ProfileSalary).find({ where: { [isEmployee ? "profileEmployeeId" : "profileId"]: profileId,