"use client"
import { CrudResource } from '@/shared/data-view/resource-page'
import { ColumnHeader } from '@/shared/data-view/table-view'
import { BadgeDollarSignIcon, CalendarIcon, ClipboardListIcon, CreditCardIcon, HashIcon, UserIcon } from 'lucide-react'
import { PAYMENT_RECEIVED_ROUTES } from '@garage/api'
import FormDialog from '@/shared/components/form-dialog'
import { PaymentReceivedForm } from '@/modules/payment-received/payment-received-form'
import { useInvoice } from './invoice-context'
import { Card, CardContent } from '@/shared/components/ui/card'
import { useRouter } from 'next/navigation'
export default function InvoicePaymentsSection() {
const invoice = useInvoice()
const router = useRouter()
console.log("InvoicePaymentsSection invoice:", invoice)
return (
extraParams={{ invoice_id: invoice?.id }}
routeKey={PAYMENT_RECEIVED_ROUTES.INDEX}
getClient={(api) => ({
list: (query?: any) => api.paymentReceived.list(query),
destroy: (id: string) => api.paymentReceived.destroy(id),
})}
tableHeader={({ invalidateQuery }) =>
Payments
{(resourceId) => (
{router.refresh(); invalidateQuery()}}
/>
)}
}
columns={({ actionsColumn }) => [
{
accessorKey: "payment_number",
header: ({ column }) => ,
cell: ({ row }) => {
const item = row.original as any
return (
{item.payment_number || "—"}
)
},
},
{
accessorKey: "customer_name",
header: ({ column }) => ,
cell: ({ row }) => {
const item = row.original as any
return (
{item.customer_name || "—"}
)
},
},
{
accessorKey: "job_card_name",
header: ({ column }) => ,
cell: ({ row }) => {
const item = row.original as any
const label = item.job_card_number || item.job_card_name
return (
{label || "—"}
)
},
},
{
accessorKey: "amount_received",
header: ({ column }) => ,
cell: ({ row }) => {
const item = row.original as any
const amount = item.amount_received
? Number(item.amount_received).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?.title || "—"}
)
},
},
{
accessorKey: "payment_date",
header: ({ column }) => ,
cell: ({ row }) => {
const item = row.original as any
const formatted = item.payment_date
? new Date(item.payment_date).toLocaleDateString(undefined, {
year: "numeric",
month: "short",
day: "numeric",
})
: "—"
return (
{formatted}
)
},
},
{
accessorKey: "note",
header: () => Note,
enableSorting: false,
cell: ({ row }) => {
const item = row.original as any
const note = item.note
if (!note) return —
return (
{note}
)
},
},
// actionsColumn(),
]}
>
)
}