import type { ColumnDef } from '@tanstack/react-table'; import { CheckCircle, CircleDollarSign, Pencil, Trash2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@/components/ui/tooltip'; import { formatCurrency } from '@/lib/utils'; export type EmployeeAdvance = { id: number; amount: number; paid_amount: number; description: string; due_date: string; status: 'pending' | 'approved' | 'paid' | 'rejected' | 'cancelled'; created_at: string; employee: { user: { user_profile: { full_name: string; }; }; }; }; function formatDate(dateString: string): string { const date = new Date(dateString); return ( date.toLocaleDateString('id-ID', { day: '2-digit', month: 'short', year: 'numeric', }) + ' ' + date.toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit', }) ); } function formatShortDate(dateString: string): string { const date = new Date(dateString); return date.toLocaleDateString('id-ID', { day: '2-digit', month: 'short', year: 'numeric', }); } function getStatusBadge(status: string) { const statusConfig: Record = { pending: { label: 'Menunggu', className: 'bg-yellow-100 text-yellow-800 hover:bg-yellow-100', }, approved: { label: 'Disetujui', className: 'bg-green-100 text-green-800 hover:bg-green-100', }, paid: { label: 'Dibayar', className: 'bg-blue-100 text-blue-800 hover:bg-blue-100', }, rejected: { label: 'Ditolak', className: 'bg-red-100 text-red-800 hover:bg-red-100', }, cancelled: { label: 'Dibatalkan', className: 'bg-gray-100 text-gray-800 hover:bg-gray-100', }, }; const config = statusConfig[status] ?? statusConfig.pending; return ( {config.label} ); } type CreateColumnsParams = { handleEdit: (employeeAdvance: EmployeeAdvance) => void; handleDeleteClick: (employeeAdvance: EmployeeAdvance) => void; handleApprove: (employeeAdvance: EmployeeAdvance) => void; handlePay: (employeeAdvance: EmployeeAdvance) => void; }; export function createEmployeeAdvanceColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, handleApprove, handlePay } = params; return [ { accessorKey: 'created_at', header: () => Tanggal, cell: ({ row }) => ( {formatDate(row.getValue('created_at') as string)} ), }, { id: 'employee_name', header: () => Oleh, cell: ({ row }) => { const employee = row.original.employee; return ( {employee?.user?.user_profile?.full_name ?? '-'} ); }, }, { accessorKey: 'amount', header: () => Jumlah, cell: ({ row }) => ( - {formatCurrency(row.getValue('amount') as number)} ), }, { accessorKey: 'description', header: () => Keterangan, cell: ({ row }) => ( {row.getValue('description') as string} ), }, { accessorKey: 'due_date', header: () => Jatuh Tempo, cell: ({ row }) => ( {formatShortDate(row.getValue('due_date') as string)} ), }, { accessorKey: 'status', header: () => Status, cell: ({ row }) => ( {getStatusBadge(row.getValue('status') as string)} ), }, { id: 'actions', header: () => Aksi, meta: { className: 'w-[150px] text-center', headerClassName: 'w-[150px] text-center', }, cell: ({ row }) => { const employeeAdvance = row.original; return (
{employeeAdvance.status === 'pending' && ( Setujui )} {employeeAdvance.status === 'approved' && ( Bayar )} Edit Hapus
); }, }, ]; }