From c0d00d0ca98882f9c4067f6bb4f0630438157fe4 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Fri, 19 Dec 2025 16:16:35 -0500 Subject: [PATCH] feat(pay-period): added is_active to payload to filter inactive employee from the timesheets_approval page --- .../dtos/overview-pay-period.dto.ts | 1 + .../services/pay-periods-query.service.ts | 35 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts b/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts index 3df38c6..c955663 100644 --- a/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts +++ b/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts @@ -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; diff --git a/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts b/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts index e76e7a8..9f62271 100644 --- a/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts +++ b/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts @@ -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; + } }