This commit is contained in:
AdisakKanthawilang 2024-12-20 13:46:51 +07:00
parent ba00ce14d2
commit 3fcce9c15c

View file

@ -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,