|
|
@@ -13,18 +13,20 @@ import { MonthlyWorkHoursReportFilter } from "@/app/api/reports"; |
|
|
|
import { records } from "@/app/api/staff/actions"; |
|
|
|
import { StaffResult } from "@/app/api/staff"; |
|
|
|
import dayjs from "dayjs"; |
|
|
|
import { getPublicHolidaysForNYears } from "@/app/utils/holidayUtils"; |
|
|
|
|
|
|
|
interface Props { |
|
|
|
staffs: StaffResult[]; |
|
|
|
companyHolidays: String[]; |
|
|
|
} |
|
|
|
|
|
|
|
type SearchQuery = Partial<Omit<MonthlyWorkHoursReportFilter, "id">>; |
|
|
|
type SearchParamNames = keyof SearchQuery; |
|
|
|
|
|
|
|
const GenerateMonthlyWorkHoursReport: React.FC<Props> = ({ staffs }) => { |
|
|
|
const GenerateMonthlyWorkHoursReport: React.FC<Props> = ({ staffs, companyHolidays }) => { |
|
|
|
const { t } = useTranslation("report"); |
|
|
|
const staffCombo = staffs.map((staff) => ({label: `${staff.name} - ${staff.staffId}`, value: staff.id})) |
|
|
|
|
|
|
|
console.log(companyHolidays) |
|
|
|
|
|
|
|
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( |
|
|
|
() => [ |
|
|
@@ -44,6 +46,12 @@ const GenerateMonthlyWorkHoursReport: React.FC<Props> = ({ staffs }) => { |
|
|
|
[t] |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const holidayList: String[] = [...getPublicHolidaysForNYears(1, 2023).map((item) => dayjs(item.date).format("DD/MM/YYYY")), ...companyHolidays] |
|
|
|
const uniqueHoliday = holidayList.filter((value, index, arr) => index === arr.indexOf(value)); |
|
|
|
console.log(uniqueHoliday) |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<SearchBox |
|
|
@@ -54,11 +62,13 @@ const GenerateMonthlyWorkHoursReport: React.FC<Props> = ({ staffs }) => { |
|
|
|
let postData = { |
|
|
|
id: query.staff, |
|
|
|
yearMonth: dayjs().format("YYYY-MM").toString(), |
|
|
|
holidays: uniqueHoliday |
|
|
|
}; |
|
|
|
console.log(query.date.length > 0) |
|
|
|
if (query.date.length > 0) { |
|
|
|
postData.yearMonth = query.date |
|
|
|
} |
|
|
|
console.log(postData) |
|
|
|
const response = await fetchMonthlyWorkHoursReport(postData); |
|
|
|
if (response) { |
|
|
|
downloadFile( |
|
|
|