// import { Injectable, NotFoundException } from "@nestjs/common"; // import { PrismaService } from "src/prisma/prisma.service"; // import { NotificationsService } from "src/modules/notifications/services/notifications.service"; // import { computeHours } from "src/common/utils/date-utils"; // import { OverviewRow } from "../types-and-interfaces/shifts-overview-row.interface"; // // const DAILY_LIMIT_HOURS = Number(process.env.DAILY_LIMIT_HOURS ?? 12); // @Injectable() // export class ShiftsQueryService { // constructor( // private readonly prisma: PrismaService, // private readonly notifs: NotificationsService, // ) {} // async getSummary(period_id: number): Promise { // //fetch pay-period to display // const period = await this.prisma.payPeriods.findFirst({ // where: { pay_period_no: period_id }, // }); // if(!period) { // throw new NotFoundException(`pay-period ${period_id} not found`); // } // const { period_start, period_end } = period; // //prepare shifts and expenses for display // const shifts = await this.prisma.shifts.findMany({ // where: { date: { gte: period_start, lte: period_end } }, // include: { // bank_code: true, // timesheet: { include: { // employee: { include: { // user:true, // supervisor: { include: { user: true } }, // } }, // } }, // }, // }); // const expenses = await this.prisma.expenses.findMany({ // where: { date: { gte: period_start, lte: period_end } }, // include: { // bank_code: true, // timesheet: { include: { employee: { // include: { user:true, // supervisor: { include: { user:true } }, // } }, // } }, // }, // }); // const mapRow = new Map(); // for(const shift of shifts) { // const employeeId = shift.timesheet.employee.user_id; // const user = shift.timesheet.employee.user; // const sup = shift.timesheet.employee.supervisor?.user; // let row = mapRow.get(employeeId); // if(!row) { // row = { // full_name: `${user.first_name} ${user.last_name}`, // supervisor: sup? `${sup.first_name} ${sup.last_name }` : '', // total_regular_hrs: 0, // total_evening_hrs: 0, // total_overtime_hrs: 0, // total_expenses: 0, // total_mileage: 0, // is_approved: false, // }; // } // const hours = computeHours(shift.start_time, shift.end_time); // switch(shift.bank_code.type) { // case 'regular' : row.total_regular_hrs += hours; // break; // case 'evening' : row.total_evening_hrs += hours; // break; // case 'overtime' : row.total_overtime_hrs += hours; // break; // default: row.total_regular_hrs += hours; // } // mapRow.set(employeeId, row); // } // for(const exp of expenses) { // const employee_id = exp.timesheet.employee.user_id; // const user = exp.timesheet.employee.user; // const sup = exp.timesheet.employee.supervisor?.user; // let row = mapRow.get(employee_id); // if(!row) { // row = { // full_name: `${user.first_name} ${user.last_name}`, // supervisor: sup? `${sup.first_name} ${sup.last_name }` : '', // total_regular_hrs: 0, // total_evening_hrs: 0, // total_overtime_hrs: 0, // total_expenses: 0, // total_mileage: 0, // is_approved: false, // }; // } // const amount = Number(exp.amount); // row.total_expenses += amount; // if(exp.bank_code.type === 'mileage') { // row.total_mileage += amount; // } // mapRow.set(employee_id, row); // } // //return by default the list of employee in ascending alphabetical order // return Array.from(mapRow.values()).sort((a,b) => a.full_name.localeCompare(b.full_name)); // } // }