'use client' import { FC, Suspense, lazy, useEffect, useState } from 'react'; import { Table } from 'antd'; import dayjs from 'dayjs'; import { TableProps, type ColumnsType } from 'antd/es/table'; import { CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import LazyLoading from '@/components/loader/LazyLoading'; import { type IHistory } from '@/app/(dashboard)/history/components/type'; const ExportComponent = lazy(() => import('./Export')); type Props = { data: IHistory[] }; const ComponentPage: FC = ({ data }) => { const [groupData, setGroupData] = useState(null) useEffect(() => { if (data) { const groupedData: any = {}; // Loop through the data and group it by presence_date data.forEach((item) => { const presenceDate = item.presence_date; if (!groupedData[presenceDate]) { groupedData[presenceDate] = []; } groupedData[presenceDate].push(item); }); const tableData = Object.entries(groupedData).map(([presenceDate, items]) => ({ presence_date: presenceDate, items: items, })); const tableDataWithCount = tableData.map((row: any) => { const presence_checkout_count = row.items.reduce((accumulator: any, item: any) => { if (item.presence_checkout !== null) { return accumulator + 1; } return accumulator; }, 0); let ci: any = {} for (let i = 0; i <= 23; i++) { ci[`ci_${i}`] = row.items.reduce((accumulator: any, item: any) => { if (Number(dayjs(item.working_hours_start).format('HH')) === i) { return accumulator + 1; } return accumulator; }, 0); } let co: any = {} for (let i = 0; i <= 23; i++) { co[`co_${i}`] = row.items.reduce((accumulator: any, item: any) => { if (item.presence_checkout !== null) { if (Number(dayjs(item.presence_checkout.working_hours_end).format('HH')) === i) { return accumulator + 1; } } return accumulator; }, 0); } return { ...{ presence_date: row.presence_date, presence_checkin_count: row.items.length, }, presence_checkout_count, ...ci, ...co }; }); setGroupData(tableDataWithCount) } }, [data]) const Columns: ColumnsType = [ { title: 'Date', align: 'center', dataIndex: 'presence_date', sorter: ((a, b) => (dayjs(a.presence_date).isAfter(dayjs(b.presence_date)) ? 1 : -1)), render: (val) => dayjs(val).format('dddd, MMM DD, YYYY') }, { title: "Check-In", children: [ { title: "Total", dataIndex: "presence_checkin_count", key: 99, }, { title: "0", dataIndex: "ci_0", key: 0, // render: (val) =>
{val}
render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "1", dataIndex: "ci_1", key: 1, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "2", dataIndex: "ci_2", key: 2, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "3", dataIndex: "ci_3", key: 3, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "4", dataIndex: "ci_4", key: 4, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "5", dataIndex: "ci_5", key: 5, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "6", dataIndex: "ci_6", key: 6, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "7", dataIndex: "ci_7", key: 7, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "8", dataIndex: "ci_8", key: 8, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "9", dataIndex: "ci_9", key: 9, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "10", dataIndex: "ci_10", key: 10, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "11", dataIndex: "ci_11", key: 11, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "12", dataIndex: "ci_12", key: 12, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "13", dataIndex: "ci_13", key: 13, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "14", dataIndex: "ci_14", key: 14, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "15", dataIndex: "ci_15", key: 15, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "16", dataIndex: "ci_16", key: 16, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "17", dataIndex: "ci_17", key: 17, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "18", dataIndex: "ci_18", key: 18, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "19", dataIndex: "ci_19", key: 19, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "20", dataIndex: "ci_20", key: 20, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "21", dataIndex: "ci_21", key: 21, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "22", dataIndex: "ci_22", key: 22, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, { title: "23", dataIndex: "ci_23", key: 23, render(val) { return { props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } }, children:
{val}
}; } }, ] }, { title: "Check-Out", children: [ { title: "Total", dataIndex: "presence_checkout_count", key: 100, }, { title: "0", dataIndex: "co_0", key: 0, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "1", dataIndex: "co_1", key: 1, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "2", dataIndex: "co_2", key: 2, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "3", dataIndex: "co_3", key: 3, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "4", dataIndex: "co_4", key: 4, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "5", dataIndex: "co_5", key: 5, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "6", dataIndex: "co_6", key: 6, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "7", dataIndex: "co_7", key: 7, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "8", dataIndex: "co_8", key: 8, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "9", dataIndex: "co_9", key: 9, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "10", dataIndex: "co_10", key: 10, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "11", dataIndex: "co_11", key: 11, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "12", dataIndex: "co_12", key: 12, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "13", dataIndex: "co_13", key: 13, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "14", dataIndex: "co_14", key: 14, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "15", dataIndex: "co_15", key: 15, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "16", dataIndex: "co_16", key: 16, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "17", dataIndex: "co_17", key: 17, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "18", dataIndex: "co_18", key: 18, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "19", dataIndex: "co_19", key: 19, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "20", dataIndex: "co_20", key: 20, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "21", dataIndex: "co_21", key: 21, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "22", dataIndex: "co_22", key: 22, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, { title: "23", dataIndex: "co_23", key: 23, render(val) { return { props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } }, children:
{val}
}; } }, ] } ]; const tableProps: TableProps = { size: 'small', bordered: false, showHeader: true, pagination: { pageSizeOptions: [5, 10, 20, 50], defaultPageSize: 15, showSizeChanger: true, showQuickJumper: true, size: 'middle' as any }, scroll: { x: 'max-content' }, tableLayout: 'auto', }; return ( <>
Attendance Distribution Here's a list of all employee attendance distribution!
}>
{ return { onClick: event => { console.log(record.face_image); }, // click row }; }} rowKey='presence_date' columns={Columns} dataSource={groupData || []} style={{ cursor: "pointer" }} /> ); } export default ComponentPage;