import { Button } from '@/components/ui/button'; import { formatCurrency } from '@/lib/utils'; import type { ColumnDef } from '@tanstack/react-table'; import { ArrowUpDown } from 'lucide-react'; export type CashTransaction = { id: number; amount: number; balance_after: number; type: 'deposit' | 'withdrawal' | 'expense' | 'transfer'; description: string; created_at: string; created_by: { user_profile: { full_name: string; }; }; reference: { type: string; } | null; }; 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 getTypeLabel(type: string): string { const labels: Record = { deposit: 'Deposit', withdrawal: 'Withdrawal', expense: 'Pengeluaran', transfer: 'Transfer', }; return labels[type] ?? type; } function getReferenceLabel(type: string): string { const labels: Record = { 'App\\Models\\Expense': 'Pengeluaran', 'App\\Models\\Order': 'Penjualan Tunai', 'App\\Models\\Purchase': 'Pembelian', 'App\\Models\\CashAccount': 'Transfer Kas', }; return labels[type] ?? '-'; } export function createTransactionColumns(): ColumnDef[] { return [ { id: 'no', header: () => No, cell: ({ row }) => ( {row.index + 1} ), meta: { className: 'w-[50px] text-center', headerClassName: 'w-[50px] text-center', }, }, { accessorKey: 'created_at', header: ({ column }) => ( ), cell: ({ row }) => ( {formatDate(row.getValue('created_at') as string)} ), }, { id: 'source', header: () => Sumber, cell: ({ row }) => { const transaction = row.original; return (
{getTypeLabel(transaction.type)} {getReferenceLabel(transaction.reference?.type ?? '')}
); }, }, { accessorKey: 'amount', header: ({ column }) => ( ), cell: ({ row }) => { const transaction = row.original; const isDeposit = transaction.type === 'deposit'; return ( {isDeposit ? '+' : '-'} {formatCurrency(row.getValue('amount') as number)} ); }, }, { accessorKey: 'balance_after', header: ({ column }) => ( ), cell: ({ row }) => ( {formatCurrency(row.getValue('balance_after') as number)} ), }, { accessorKey: 'description', header: () => Keterangan, cell: ({ row }) => ( {row.getValue('description') as string} ), }, { id: 'created_by', header: () => Oleh, cell: ({ row }) => { const createdBy = row.original.created_by; return {createdBy?.user_profile?.full_name ?? '-'}; }, }, ]; }