- Implemented TemplateCheckpointEditDialog for creating and editing inspection checkpoints. - Added VendorActions component for managing vendor actions including edit, activate/deactivate, and delete. - Created VendorContext for managing vendor state across components. - Developed VendorGeneralInfo component to display detailed vendor information. - Introduced AedSymbol and Money components for consistent currency representation. - Added PromptDialog for user input prompts throughout the application. - Implemented RelationLink component for unified related-data display in CRUD tables. - Created InspectionTemplatesClient for API interactions related to inspection templates.
113 lines
4.7 KiB
TypeScript
113 lines
4.7 KiB
TypeScript
"use client"
|
|
|
|
import { use } from "react"
|
|
import FormDialog from "@/shared/components/form-dialog"
|
|
import { Badge } from "@/shared/components/ui/badge"
|
|
import { ResourcePage } from "@/shared/data-view/resource-page"
|
|
import { ColumnHeader } from "@/shared/data-view/table-view"
|
|
import { BillForm } from "@/modules/bills/bill-form"
|
|
import { BILL_ROUTES, BillStatus } from "@garage/api"
|
|
import type { BillsClient } from "@garage/api"
|
|
import { useJobCard } from "@/modules/job-cards/job-card-context"
|
|
import { RelationLink } from "@/shared/components/relation-link"
|
|
import { Building2, FileTextIcon } from "lucide-react"
|
|
import { getFullName } from "@/shared/utils/getFullName"
|
|
|
|
export default function JobCardBillsPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>
|
|
}) {
|
|
const { id: jobCardId } = use(params)
|
|
const jobCard = useJobCard()
|
|
|
|
const defaultJobCard = jobCard
|
|
? { value: String((jobCard as any).id), label: (jobCard as any).label || (jobCard as any).title || `Job Card` }
|
|
: null
|
|
|
|
return (
|
|
<ResourcePage<BillsClient>
|
|
routeKey={BILL_ROUTES.INDEX}
|
|
searchable
|
|
searchPlaceholder="Search bills..."
|
|
statusFilter={{ statuses: BillStatus }}
|
|
getClient={(api) => api.bills}
|
|
extraParams={{ job_card_id: jobCardId }}
|
|
header={null}
|
|
tableHeader={({ invalidateQuery, selectedItem, closeDialog }) => (
|
|
<div className="flex justify-end">
|
|
|
|
<FormDialog title="Bill">
|
|
{(resourceId) => (
|
|
<BillForm
|
|
resourceId={resourceId}
|
|
initialData={selectedItem ?? { job_card: defaultJobCard }}
|
|
onSuccess={() => { closeDialog(); invalidateQuery() }}
|
|
/>
|
|
)}
|
|
</FormDialog>
|
|
</div>
|
|
)}
|
|
columns={({ actionsColumn }) => [
|
|
{
|
|
accessorKey: "bill_number",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Bill #" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original as any
|
|
return (
|
|
<RelationLink
|
|
href={item.id ? `/purchase/bill/${item.id}` : null}
|
|
icon={FileTextIcon}
|
|
label={item.bill_number}
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "title",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Title" />,
|
|
},
|
|
{
|
|
accessorKey: "vendor_name",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Vendor" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original as any
|
|
return (
|
|
<RelationLink
|
|
href={item.vendor?.id ? `/purchase/vendor/${item.vendor.id}` : null}
|
|
icon={Building2}
|
|
label={item.vendor?.company_name || getFullName(item.vendor) || item.vendor_name}
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "bill_date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Bill Date" />,
|
|
cell: ({ row }) => {
|
|
const value = (row.original as any).bill_date
|
|
return value ? new Date(value).toLocaleDateString() : "—"
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "bill_due_date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Due Date" />,
|
|
cell: ({ row }) => {
|
|
const value = (row.original as any).bill_due_date
|
|
return value ? new Date(value).toLocaleDateString() : "—"
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "status",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Status" />,
|
|
cell: ({ row }) => {
|
|
const status = (row.original as any).status
|
|
return <Badge variant={status === "paid" ? "default" : "secondary"}>{status || "—"}</Badge>
|
|
},
|
|
},
|
|
actionsColumn(),
|
|
]}
|
|
/>
|
|
)
|
|
}
|