|
|
@@ -3,7 +3,7 @@ import { HolidaysResult } from "../holidays"; |
|
|
|
import { LeaveEntry, RecordTimeLeaveInput, TimeEntry } from "./actions"; |
|
|
|
import { convertDateArrayToString } from "@/app/utils/formatUtil"; |
|
|
|
import compact from "lodash/compact"; |
|
|
|
import dayjs from "dayjs"; |
|
|
|
import dayjs, { Dayjs } from "dayjs"; |
|
|
|
|
|
|
|
export type TimeEntryError = { |
|
|
|
[field in keyof TimeEntry]?: string; |
|
|
@@ -117,6 +117,7 @@ export const validateTimeLeaveRecord = ( |
|
|
|
|
|
|
|
// Check total hours |
|
|
|
const totalHourError = checkTotalHours( |
|
|
|
dayJsObj, |
|
|
|
entries.filter((e) => e.type === "timeEntry") as TimeEntry[], |
|
|
|
entries.filter((e) => e.type === "leaveEntry") as LeaveEntry[], |
|
|
|
isHoliday, |
|
|
@@ -132,6 +133,7 @@ export const validateTimeLeaveRecord = ( |
|
|
|
}; |
|
|
|
|
|
|
|
export const checkTotalHours = ( |
|
|
|
dayJsObj: Dayjs, |
|
|
|
timeEntries: TimeEntry[], |
|
|
|
leaves: LeaveEntry[], |
|
|
|
isHoliday?: boolean, |
|
|
@@ -152,6 +154,7 @@ export const checkTotalHours = ( |
|
|
|
} else if ( |
|
|
|
isFullTime && |
|
|
|
!isHoliday && |
|
|
|
!dayJsObj.isSame(dayjs(), "day") && |
|
|
|
totalInputHours + leaveHours !== DAILY_NORMAL_MAX_HOURS |
|
|
|
) { |
|
|
|
return "The daily normal hours (timesheet hours + leave hours) for full-time staffs should be {{DAILY_NORMAL_MAX_HOURS}}."; |
|
|
|