import { ColumnDef } from '@tanstack/react-table'; import { Purchase } from '@/types'; import { DataTableColumnHeader } from '@/components/data-table-column-header'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { Button } from '@/components/ui/button'; import { Pencil, Trash2 } from 'lucide-react'; import { Link } from '@inertiajs/react'; import purchaseRoutes from '@/routes/purchase'; import { format } from 'date-fns'; import { id } from 'date-fns/locale'; interface ColumnProps { onDelete: (purchase: Purchase) => void; } export const getColumns = ({ onDelete }: ColumnProps): ColumnDef[] => [ { accessorKey: "purchase_date", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.original.purchase_date; return format(new Date(date), 'dd MMMM yyyy', { locale: id }); }, meta: { title: "Tanggal" }, }, { accessorKey: "items", header: ({ column }) => ( ), cell: ({ row }) => { const purchase = row.original; const items = purchase.items; if (!items || !Array.isArray(items) || items.length === 0) { return -; } return (
{items.map((item, i) => (
{item.product?.name || 'Produk N/A'}:{' '} {item.quantity} x {item.unit_price_formatted}
))}
); }, meta: { title: "Item" }, }, { accessorKey: "total", header: ({ column }) => ( ), cell: ({ row }) => { return ( {row.original.total_formatted} ); }, meta: { title: "Total" }, }, { accessorKey: "note", header: "Catatan", cell: ({ row }) => ( {row.original.note || '-'} ), meta: { title: "Catatan" }, }, { id: "actions", header: "Aksi", cell: ({ row }) => { const purchase = row.original; return (

Ubah

Hapus

); }, meta: { title: "Aksi" }, }, ];