import { ColumnDef } from '@tanstack/react-table'; import { Order } from '@/types/order'; 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, ShoppingBag, Printer } from 'lucide-react'; import { Link } from '@inertiajs/react'; import * as orderRoutes from '@/routes/order'; import { format } from 'date-fns'; import { id } from 'date-fns/locale'; import { Badge } from '@/components/ui/badge'; interface ColumnProps { onDelete: (order: Order) => void; onPrint: (order: Order) => void; } export const getColumns = ({ onDelete, onPrint }: ColumnProps): ColumnDef[] => [ { accessorKey: "invoice_number", header: ({ column }) => ( ), cell: ({ row }) => (
{row.original.invoice_number} {format(new Date(row.original.created_at), 'dd MMM yyyy HH:mm', { locale: id })}
), meta: { title: "No. Invoice" }, }, { accessorKey: "customer_name", header: ({ column }) => ( ), cell: ({ row }) => (
{row.original.customer_name} {row.original.order_channel}
), meta: { title: "Pelanggan" }, }, { accessorKey: "items", header: ({ column }) => ( ), cell: ({ row }) => { const items = row.original.items; if (!items || !Array.isArray(items) || items.length === 0) { return -; } return (
{items.slice(0, 2).map((item, i) => (
{item.product?.name}:{' '} {item.qty} x {item.price_formatted}
))} {items.length > 2 && ( +{items.length - 2} item lainnya... )}
); }, meta: { title: "Item" }, }, { accessorKey: "total", header: ({ column }) => ( ), cell: ({ row }) => (
{row.original.total_formatted} {row.original.order_status}
), meta: { title: "Total" }, }, { id: "actions", header: "Aksi", cell: ({ row }) => { const order = row.original; return (

Cetak Struk

Ubah

Hapus

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