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 c955663..19f7896 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 @@ -25,7 +25,6 @@ export class EmployeePeriodOverviewDto { expenses: number; mileage: number; is_approved: boolean; - is_remote: boolean; } export class PayPeriodBundleDto { 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 59b399c..cb9bf1a 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 @@ -127,11 +127,13 @@ export class PayPeriodsQueryService { return { success: true, data: overview.data } } + + private async buildOverview( period: { period_start: string | Date; period_end: string | Date; payday: string | Date; period_no: number; pay_year: number; label: string; - }, //add is_approved + }, options?: { filtered_employee_ids?: number[]; seed_names?: Map } ): Promise> { const toDateString = (d: Date) => d.toISOString().slice(0, 10); @@ -167,6 +169,7 @@ export class PayPeriodsQueryService { is_remote: true, timesheet: { select: { + id: true, is_approved: true, employee: { select: { @@ -193,6 +196,7 @@ export class PayPeriodsQueryService { amount: true, timesheet: { select: { + id: true, is_approved: true, employee: { select: { @@ -211,9 +215,20 @@ export class PayPeriodsQueryService { bank_code: { select: { categorie: true, modifier: true, type: true } }, }, }); + const timesheet_id = shifts[0].timesheet.id ? expenses[0].timesheet.id : null; + if (timesheet_id === null) return { success: false, error: 'INVALID_TIMESHEET' }; const by_employee = new Map(); + const timesheet = await this.prisma.timesheets.findFirst({ + where: { id: timesheet_id }, + select: { + is_approved: true, + id: true, + }, + }); + if (!timesheet) return { success: false, error: 'INVALID_TIMESHEET' }; + // seed for employee without data if (options?.seed_names) { for (const [id, { name, email }] of options.seed_names.entries()) { @@ -234,7 +249,6 @@ export class PayPeriodsQueryService { expenses: 0, mileage: 0, is_approved: false, - is_remote: false, }); } } else { @@ -245,8 +259,8 @@ export class PayPeriodsQueryService { first_name: true, last_name: true, email: true - } - } + }, + }, }, }); @@ -256,7 +270,7 @@ export class PayPeriodsQueryService { if (employee.last_work_day !== null) { 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, @@ -273,8 +287,7 @@ export class PayPeriodsQueryService { total_hours: 0, expenses: 0, mileage: 0, - is_approved: false, - is_remote: false, + is_approved: timesheet.is_approved, }); } } @@ -297,8 +310,7 @@ export class PayPeriodsQueryService { total_hours: 0, expenses: 0, mileage: 0, - is_approved: false, - is_remote: false, + is_approved: timesheet.is_approved, }); } return by_employee.get(id)!; @@ -336,7 +348,6 @@ export class PayPeriodsQueryService { } record.is_approved = record.is_approved && shift.timesheet.is_approved; - record.is_remote = record.is_remote || !!shift.is_remote; } for (const expense of expenses) {