Files
hats-app/app/admin/report/distribution/component/index.tsx
T
Ichsan Kurniawan 5a3629badf update performance, manual attendance, redownload leave form
Added the ability to view and re-download leave application forms in the Employee History page (Leave, Permit, and Sick tabs)
Added employee alpha stats and employee alpha detail in Employee Performance Page
Added total WFO, WFH and WFS in Admin Summary Report
Added batch import from Excel files in Admin Manual Attendance
2026-02-20 15:19:42 +07:00

691 lines
26 KiB
TypeScript

'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<Props> = ({ data }) => {
const [groupData, setGroupData] = useState<any>(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<any> = [
{
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) => <div className='bg-green-500 text-white w-full h-full'>{val}</div>
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "1",
dataIndex: "ci_1",
key: 1,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "2",
dataIndex: "ci_2",
key: 2,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "3",
dataIndex: "ci_3",
key: 3,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "4",
dataIndex: "ci_4",
key: 4,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "5",
dataIndex: "ci_5",
key: 5,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "6",
dataIndex: "ci_6",
key: 6,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "7",
dataIndex: "ci_7",
key: 7,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "8",
dataIndex: "ci_8",
key: 8,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "9",
dataIndex: "ci_9",
key: 9,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "10",
dataIndex: "ci_10",
key: 10,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "11",
dataIndex: "ci_11",
key: 11,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "12",
dataIndex: "ci_12",
key: 12,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "13",
dataIndex: "ci_13",
key: 13,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "14",
dataIndex: "ci_14",
key: 14,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "15",
dataIndex: "ci_15",
key: 15,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "16",
dataIndex: "ci_16",
key: 16,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "17",
dataIndex: "ci_17",
key: 17,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "18",
dataIndex: "ci_18",
key: 18,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "19",
dataIndex: "ci_19",
key: 19,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "20",
dataIndex: "ci_20",
key: 20,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "21",
dataIndex: "ci_21",
key: 21,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "22",
dataIndex: "ci_22",
key: 22,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "23",
dataIndex: "ci_23",
key: 23,
render(val) {
return {
props: { style: { background: val > 20 ? '#0e0' : val > 10 ? "#0b0" : val > 0 ? 'green' : "none" } },
children: <div>{val}</div>
};
}
},
]
},
{
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: <div>{val}</div>
};
}
},
{
title: "1",
dataIndex: "co_1",
key: 1,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "2",
dataIndex: "co_2",
key: 2,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "3",
dataIndex: "co_3",
key: 3,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "4",
dataIndex: "co_4",
key: 4,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "5",
dataIndex: "co_5",
key: 5,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "6",
dataIndex: "co_6",
key: 6,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "7",
dataIndex: "co_7",
key: 7,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "8",
dataIndex: "co_8",
key: 8,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "9",
dataIndex: "co_9",
key: 9,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "10",
dataIndex: "co_10",
key: 10,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "11",
dataIndex: "co_11",
key: 11,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "12",
dataIndex: "co_12",
key: 12,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "13",
dataIndex: "co_13",
key: 13,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "14",
dataIndex: "co_14",
key: 14,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "15",
dataIndex: "co_15",
key: 15,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "16",
dataIndex: "co_16",
key: 16,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "17",
dataIndex: "co_17",
key: 17,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "18",
dataIndex: "co_18",
key: 18,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "19",
dataIndex: "co_19",
key: 19,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "20",
dataIndex: "co_20",
key: 20,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "21",
dataIndex: "co_21",
key: 21,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "22",
dataIndex: "co_22",
key: 22,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
{
title: "23",
dataIndex: "co_23",
key: 23,
render(val) {
return {
props: { style: { background: val > 20 ? '#e00' : val > 10 ? "#b00" : val > 0 ? 'red' : "none" } },
children: <div>{val}</div>
};
}
},
]
}
];
const tableProps: TableProps<IHistory> = {
size: 'small',
bordered: false,
showHeader: true,
pagination: {
pageSizeOptions: [5, 10, 20, 50],
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
};
return (
<>
<CardHeader className='flex flex-col md:flex-row items-center justify-between space-y-5 sm:space-y-0'>
<div>
<CardTitle>Attendance Distribution</CardTitle>
<CardDescription className='mt-1 sm:block hidden'>Here&apos;s a list of all employee attendance distribution!</CardDescription>
</div>
<Suspense fallback={<LazyLoading />}>
<ExportComponent data={groupData} />
</Suspense>
</CardHeader>
<CardContent>
<div className='flex flex-col space-y-4'>
<Table
{...tableProps}
onRow={(record, rowIndex) => {
return {
onClick: event => { console.log(record.face_image); }, // click row
};
}}
rowKey='presence_date'
columns={Columns}
dataSource={groupData || []}
style={{ cursor: "pointer" }}
/>
</div>
</CardContent>
</>
);
}
export default ComponentPage;