"use client" import { useRouter } from "next/navigation" import { BadgeDollarSignIcon, CalendarIcon, CreditCardIcon, HashIcon, UserIcon, } from "lucide-react" import { CrudResource } from "@/shared/data-view/resource-page" import { ColumnHeader } from "@/shared/data-view/table-view" import FormDialog from "@/shared/components/form-dialog" import { Card, CardContent } from "@/shared/components/ui/card" import { PAYMENT_MADE_ROUTES } from "@garage/api" import { PaymentMadeForm } from "@/modules/payment-mades/payment-made-form" import { useBill } from "./bill-context" import { formatDate } from "@/shared/utils/formatters" import { getFullName } from "@/shared/utils/getFullName" import { toRelation } from "@/shared/lib/utils" export function BillPaymentsSection() { const bill = useBill() const router = useRouter() return ( extraParams={{ bill_id: bill?.id }} routeKey={PAYMENT_MADE_ROUTES.INDEX} getClient={(api) => ({ list: (query?: any) => api.paymentMades.list(query), destroy: (id: string) => api.paymentMades.destroy(id), })} tableHeader={({ invalidateQuery }) => (

Payments Made

{(resourceId) => ( { router.refresh() invalidateQuery() }} /> )}
)} columns={({ actionsColumn }) => [ { accessorKey: "payment_number", header: ({ column }) => , cell: ({ row }) => { const item = row.original as any return (
{item.payment_number || "—"}
) }, }, { accessorKey: "vendor", header: ({ column }) => , cell: ({ row }) => { const item = row.original as any return (
{item.vendor?.name || item.vendor_name || "—"}
) }, }, { accessorKey: "payment_made", header: ({ column }) => , cell: ({ row }) => { const item = row.original as any const amount = item.payment_made != null ? Number(item.payment_made).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, }) : "—" return (
{amount}
) }, }, { accessorKey: "payment_mode", header: ({ column }) => , cell: ({ row }) => { const item = row.original as any return (
{item.payment_mode?.name || item.payment_mode_name || "—"}
) }, }, { accessorKey: "payment_date", header: ({ column }) => , cell: ({ row }) => { const item = row.original as any return (
{formatDate(item.payment_date) || "—"}
) }, }, { accessorKey: "notes", header: () => Notes, enableSorting: false, cell: ({ row }) => { const item = row.original as any const notes = item.notes if (!notes) return return ( {notes} ) }, }, actionsColumn(), ]} /> ) }