feat(pay-period): added is_active to payload to filter inactive employee from the timesheets_approval page

This commit is contained in:
Matthieu Haineault 2025-12-19 16:16:35 -05:00
parent 52c2e5f70c
commit c0d00d0ca9
2 changed files with 27 additions and 9 deletions

View File

@ -11,6 +11,7 @@ export class PayPeriodOverviewDto {
export class EmployeePeriodOverviewDto {
email: string;
employee_name: string;
is_active: boolean;
regular_hours: number;
other_hours: {
evening_hours: number;

View File

@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "src/prisma/prisma.service";
import { computeHours, computePeriod, listPayYear, payYearOfDate } from "src/common/utils/date-utils";
import { computeHours, computePeriod, listPayYear, payYearOfDate, toStringFromDate } from "src/common/utils/date-utils";
import { EmployeePeriodOverviewDto, PayPeriodDto, PayPeriodOverviewDto } from "../dtos/overview-pay-period.dto";
import { Result } from "src/common/errors/result-error.factory";
import { mapPayPeriodToDto } from "src/time-and-attendance/pay-period/pay-periods.mapper";
@ -220,6 +220,7 @@ export class PayPeriodsQueryService {
by_employee.set(id, {
email,
employee_name: name,
is_active: true,
regular_hours: 0,
other_hours: {
evening_hours: 0,
@ -232,8 +233,8 @@ export class PayPeriodsQueryService {
total_hours: 0,
expenses: 0,
mileage: 0,
is_approved: true,
is_remote: true,
is_approved: false,
is_remote: false,
});
}
} else {
@ -250,9 +251,14 @@ export class PayPeriodsQueryService {
});
for (const employee of all_employees) {
let is_active = true;
if (employee.last_work_day) {
is_active = this.checkForInactiveDate(employee.last_work_day)
}
by_employee.set(employee.id, {
email: employee.user.email,
employee_name: employee.user.first_name + ' ' + employee.user.last_name,
is_active: is_active,
regular_hours: 0,
other_hours: {
evening_hours: 0,
@ -265,8 +271,8 @@ export class PayPeriodsQueryService {
total_hours: 0,
expenses: 0,
mileage: 0,
is_approved: true,
is_remote: true,
is_approved: false,
is_remote: false,
});
}
}
@ -276,6 +282,7 @@ export class PayPeriodsQueryService {
by_employee.set(id, {
email,
employee_name: name,
is_active: true,
regular_hours: 0,
other_hours: {
evening_hours: 0,
@ -288,8 +295,8 @@ export class PayPeriodsQueryService {
total_hours: 0,
expenses: 0,
mileage: 0,
is_approved: true,
is_remote: true,
is_approved: false,
is_remote: false,
});
}
return by_employee.get(id)!;
@ -336,12 +343,12 @@ export class PayPeriodsQueryService {
const record = ensure(exp.id, name, exp.user.email);
const amount = toMoney(expense.amount);
record.expenses = Number((record.expenses += amount).toFixed(2));
record.expenses = Number((record.expenses += amount).toFixed(2));
const type = (expense.bank_code?.type || "").toUpperCase();
const rate = expense.bank_code?.modifier ?? 0;
if (type === "MILEAGE" && rate > 0) {
record.mileage = Number((record.mileage += Math.round((amount / rate) * 100) / 100).toFixed(2));
record.mileage = Number((record.mileage += Math.round((amount / rate) * 100) / 100).toFixed(2));
}
record.is_approved = record.is_approved && expense.timesheet.is_approved;
}
@ -456,4 +463,14 @@ export class PayPeriodsQueryService {
select: { period_start: true, period_end: true },
});
}
private checkForInactiveDate = (last_work_day: Date) => {
const inactive_date = toStringFromDate(last_work_day);
const limit = new Date(inactive_date);
limit.setDate(limit.getDate() + 14);
if(limit >= new Date()) {
return false
}
return true;
}
}