Files
hats-app/app/admin/report/history/component/Columns.tsx
T
2025-12-19 13:57:55 +07:00

228 lines
7.6 KiB
TypeScript

import { IHistory } from '@/app/(dashboard)/history/components/type';
import { Badge } from '@/components/ui/badge';
import { getVariantApproved, getVariantWorkingStatus } from '@/lib/helper';
import { type ColumnsType } from 'antd/es/table';
import dayjs from 'dayjs';
import Link from 'next/link';
const ColumnsHistory: ColumnsType<IHistory> = [
{
title: 'Date',
dataIndex: 'presence_date',
sorter: ((a, b) => (dayjs(a.presence_date).isAfter(dayjs(b.presence_date)) ? 1 : -1)),
render: (val) => dayjs(val).format('MMM DD, YYYY')
},
{
title: 'Name',
dataIndex: 'fullname',
sorter: (a, b) => a.user.fullname.localeCompare(b.user.fullname),
render: (val, record) => record.user.fullname
},
{
title: 'Working Status',
dataIndex: 'working_status',
filters: [
{
text: 'WFO',
value: 'WFO',
},
{
text: 'WFS',
value: 'WFS',
},
{
text: 'WFH',
value: 'WFH',
},
{
text: 'Sakit',
value: 'SKT',
},
{
text: 'Izin',
value: 'IZ01',
}
],
onFilter: (value, record) => record.working_status!.indexOf(value as string) === 0,
sorter: (a, b) => a.working_status?.localeCompare(b.working_status),
render: (val, record) => <Badge variant={getVariantWorkingStatus(val)}>{val}</Badge>
},
{
title: 'Approval',
dataIndex: 'status',
filters: [
{
text: 'Approved',
value: 'AP',
},
{
text: 'Rejected',
value: 'R',
},
{
text: 'Need to be Appove',
value: 'NA',
}
],
onFilter: (value, record) => record.status.code!.indexOf(value as string) === 0,
render: (val, record) => !record.manual_presence && (record.working_status === 'WFH' || record.working_status === 'WFS') ? <Badge variant={getVariantApproved(record.status.code as any)}>{record.status.name}</Badge> : ''
},
{
title: 'Check-in',
dataIndex: 'working_hours_start',
filters: [
{
text: 'Less than 10:00 AM',
value: 'lt_10', // You can use any value you prefer
},
{
text: 'More than or equal to 10:00 AM',
value: 'gte_10', // You can use any value you prefer
},
],
onFilter: (value, record) => {
const time = new Date(record.working_hours_start).getHours();
if (value === 'lt_10') {
return time < 10;
} else if (value === 'gte_10') {
return time >= 10;
}
return false; // If the value doesn't match any filter
},
render: (val) => <span className='text-green-500'>{dayjs(val).format('HH:mm A')}</span>
},
{
title: 'Check-in Device',
dataIndex: 'device',
filters: [
{
text: 'FR Device',
value: '11001',
},
{
text: 'Web App',
value: '40001',
},
{
text: 'Android App',
value: '20001',
},
{
text: 'IOS App',
value: '30001',
}
],
onFilter: (value, record) => record.device.code!.indexOf(value as string) === 0,
render: (val, record) => record.device.name,
},
{
title: 'Check-in Location',
dataIndex: 'location_name',
onCell: (record, index) => {
return {
onClick: (evt) => {
const url = `http://maps.google.com/maps?q=${record.latitude}+${record.longitude}`
window.open(url, '_blank');
}
}
}
},
{
title: 'Check-in Note',
dataIndex: 'note',
},
{
title: 'Check-in Photo',
dataIndex: 'face_image',
render: (val, record) => val ? <Link onClick={(e) => e.stopPropagation()} className='text-his! hover:opacity-70 duration-200' href={process.env.BASE_URL_IMG + val} target="_blank">View Photo</Link> : ''
},
{
title: 'Check-out',
dataIndex: 'working_hours_end',
filters: [
{
text: 'Less than 17:00 PM',
value: 'lt_17', // You can use any value you prefer
},
{
text: 'More than or equal to 17:00 PM',
value: 'gte_17', // You can use any value you prefer
},
],
onFilter: (value, record) => {
const time = new Date(record.presence_checkout?.working_hours_end).getHours();
if (value === 'lt_17') {
return time < 17;
} else if (value === 'gte_17') {
return time >= 17;
}
return false; // If the value doesn't match any filter
},
render: (val, record) => record.presence_checkout?.working_hours_end ? <span className='text-rose-500'>{dayjs(record.presence_checkout?.working_hours_end).format('HH:mm A')}</span> : undefined
},
{
title: 'Check-out Device',
dataIndex: 'device',
filters: [
{
text: 'FR Device',
value: '11001',
},
{
text: 'Web App',
value: '40001',
},
{
text: 'Android App',
value: '20001',
},
{
text: 'IOS App',
value: '30001',
}
],
onFilter: (value, record) => record.presence_checkout?.device?.code!.indexOf(value as string) === 0,
render: (val, record) => record.presence_checkout?.device?.name,
},
{
title: 'Check-out Location',
dataIndex: 'location_name',
render: (val, record) => record.presence_checkout?.location_name
},
{
title: 'Check-out Note',
dataIndex: 'note',
render: (val, record) => record.presence_checkout?.note
},
{
title: 'Check-out Photo',
dataIndex: 'face_image',
render: (val, record) => record.presence_checkout?.face_image ? <Link onClick={(e) => e.stopPropagation()} className='text-his! hover:opacity-70 duration-200' href={process.env.BASE_URL_IMG + record.presence_checkout?.face_image} target="_blank">View Photo</Link> : ''
},
{
title: 'Auto Checkout',
dataIndex: 'autocheckout',
filters: [
{
text: 'Auto Checkout',
value: true,
}
],
onFilter: (value, record) => record.presence_checkout?.auto_checkout?.valueOf() === true,
render: (val, record) => record.presence_checkout?.auto_checkout ? <i className="ti ti-check text-xl text-green-500"></i> : null
},
{
title: 'Clear AutoChekout',
dataIndex: 'status',
render: (val, record) => record?.is_clear_auto_checkout === false ? <Badge>need to be approve</Badge> : record.is_clear_auto_checkout === true ? <Badge variant='secondary'>approved</Badge> : undefined
},
{
title: 'Manual Presence',
dataIndex: 'manual_presence',
render: (val, record) => val ? <i className="ti ti-check text-xl text-green-500"></i> : null
},
];
export default ColumnsHistory