diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e9d8dc3..1d62fbd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -184,11 +184,6 @@ model TimesheetsArchive { @@map("timesheets_archive") } - - - - - model SchedulePresets { id Int @id @default(autoincrement()) employee Employees @relation("SchedulePreset", fields: [employee_id], references: [id]) diff --git a/src/modules/business-logics/services/overtime.service.ts b/src/modules/business-logics/services/overtime.service.ts index 6c6d1b0..24c7a75 100644 --- a/src/modules/business-logics/services/overtime.service.ts +++ b/src/modules/business-logics/services/overtime.service.ts @@ -14,7 +14,7 @@ export class OvertimeService { constructor(private prisma: PrismaService) {} //calculate daily overtime - async getDailyOvertimeHoursForDay(employee_id: number, date: Date): Promise { + async getDailyOvertimeHours(employee_id: number, date: Date): Promise { const shifts = await this.prisma.shifts.findMany({ where: { date: date, timesheet: { employee_id: employee_id } }, select: { start_time: true, end_time: true }, diff --git a/src/modules/shared/classes/timesheet.dto.ts b/src/modules/shared/classes/timesheet.dto.ts new file mode 100644 index 0000000..4a3f307 --- /dev/null +++ b/src/modules/shared/classes/timesheet.dto.ts @@ -0,0 +1,58 @@ +export class Session { + user_id: number; + +} + + +export class Timesheets { + timesheet_id: number; + days: TimesheetDay[]; + weekly_hours: TotalHours[]; + weekly_expenses: TotalExpenses[]; +} + +export class TimesheetDay { + date: string; + shifts: Shift[]; + expenses: Expense[]; + daily_hours: TotalHours[]; + daily_expenses: TotalExpenses[]; +} + +export class TotalHours { + regular: number; + evening: number; + emergency: number; + overtime: number; + vacation: number; + holiday: number; + sick: number; +} +export class TotalExpenses { + expenses: number; + perd_diem: number; + on_call: number; + mileage: number; +} + +export class Shift { + date: Date; + start_time: Date; + end_time: Date; + type: string; + is_remote: boolean; + is_approved: boolean; + shift_id?: number | null; + comment?: string | null; +} + +export class Expense { + date: string; + is_approved: boolean; + comment: string; + amount?: number; + mileage?: number; + attachment?: string; + expense_id?: number | null; + supervisor_comment?: string | null; +} \ No newline at end of file diff --git a/src/modules/shared/constants/utils.constant.ts b/src/modules/shared/constants/utils.constant.ts new file mode 100644 index 0000000..271bbbf --- /dev/null +++ b/src/modules/shared/constants/utils.constant.ts @@ -0,0 +1 @@ +export const COMMENT_MAX_LENGTH = 280; \ No newline at end of file diff --git a/src/modules/shifts/helpers/shifts.helpers.ts b/src/modules/shifts/helpers/shifts.helpers.ts index 09a17e1..6fb216d 100644 --- a/src/modules/shifts/helpers/shifts.helpers.ts +++ b/src/modules/shifts/helpers/shifts.helpers.ts @@ -114,7 +114,7 @@ export class ShiftsHelpersService { async afterWriteOvertimeAndLog(tx: Tx, employee_id: number, date_only: Date) { // Switch regular → weekly overtime si > 40h await this.overtimeService.transformRegularHoursToWeeklyOvertime(employee_id, date_only, tx); - const daily = await this.overtimeService.getDailyOvertimeHoursForDay(employee_id, date_only); + const daily = await this.overtimeService.getDailyOvertimeHours(employee_id, date_only); const weekly = await this.overtimeService.getWeeklyOvertimeHours(employee_id, date_only); // const [daily, weekly] = await Promise.all([ // this.overtimeService.getDailyOvertimeHoursForDay(employee_id, date_only), diff --git a/src/modules/timesheets/services/timesheets-command.service.ts b/src/modules/timesheets/services/timesheets-command.service.ts index f8142b0..179a21a 100644 --- a/src/modules/timesheets/services/timesheets-command.service.ts +++ b/src/modules/timesheets/services/timesheets-command.service.ts @@ -10,6 +10,7 @@ import { EmailToIdResolver } from "src/modules/shared/utils/resolve-email-id.uti import { BankCodesResolver } from "src/modules/shared/utils/resolve-bank-type-id.utils"; import { PrismaService } from "src/prisma/prisma.service"; import { TimesheetMap } from "../utils-helpers-others/timesheet.types"; +import { Shift, Expense } from "../dtos/timesheet.dto"; @Injectable() export class TimesheetsCommandService extends BaseApprovalService{ @@ -50,6 +51,44 @@ export class TimesheetsCommandService extends BaseApprovalService{ return timesheet; } +/**_____________________________________________________________________________________________ + create/update/delete shifts and expenses from 1 or many timesheet(s) + + -this function receives an email and an array of timesheets + + -this function will find the timesheets with all shifts and expenses + -this function will calculate total hours, total expenses, filtered by types, + cumulate in daily and weekly. + + -the timesheet_id will be determined using the employee email + -with the timesheet_id, all shifts and expenses will be fetched + + -with shift_id and expense_id, this function will compare both + datas from the DB and from the body of the function and then: + -it will create a shift if no shift is found in the DB + -it will update a shift if a shift is found in the DB + -it will delete a shift if a shift is found and no data is received from the frontend + + This function will be used for the Timesheet Page for an employee to enter, modify or delete and entry + This function will also be used in the modal of the timesheet validation page to + allow a supervisor to enter, modify or delete and entry of a selected employee +_____________________________________________________________________________________________*/ + +async findTimesheetsByEmailAndPayPeriod(email: string, year: number, period_no: number, timesheets: Timesheets[]): Promise { + const employee_id = await this.emailResolver.findIdByEmail(email); + + + return timesheets; +} + +async upsertOrDeleteShiftsByEmailAndDate(email:string, shift_ids: Shift[]) {} + +async upsertOrDeleteExpensesByEmailAndDate(email:string, expenses_id: Expense[]) {} + + + + + //_____________________________________________________________________________________________ // //_____________________________________________________________________________________________