feat: integrate dialog close context in vendor select field and CRUD dialog components feat: enhance vendor general info to format status using utility function feat: implement form dialog context for managing dialog close actions feat: add async select field dialog close context for better form handling fix: update form mutation hook to close dialog on successful submission feat: extend document print types to include expense and credit note feat: add settings update payload type to include logo and other fields feat: create employee attendance and work history pages with resource management feat: implement payment made and received detail pages with actions feat: add quick shortcuts component for easy navigation in the dashboard feat: create actions for payment made and received with print and delete options feat: implement dialog close context for better dialog management feat: add error parsing utility for improved error handling in API responses
120 lines
5.2 KiB
TypeScript
120 lines
5.2 KiB
TypeScript
"use client"
|
|
|
|
import { useRouter } from "next/navigation"
|
|
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 { formatDate, formatEnum } from "@/shared/utils/formatters"
|
|
import { getFullName } from "@/shared/utils/getFullName"
|
|
import { Money } from "@/shared/components/money"
|
|
import { RelationLink } from "@/shared/components/relation-link"
|
|
import { Building2, Printer } from "lucide-react"
|
|
import { useDocumentPrint } from "@/shared/hooks/use-document-print"
|
|
|
|
export default function BillsPage() {
|
|
const router = useRouter()
|
|
const { print, isPrinting } = useDocumentPrint()
|
|
|
|
return (
|
|
<ResourcePage<BillsClient>
|
|
pageTitle="Bills"
|
|
routeKey={BILL_ROUTES.INDEX}
|
|
searchable
|
|
searchPlaceholder="Search bills..."
|
|
statusFilter={{ statuses: BillStatus }}
|
|
getClient={(api) => api.bills}
|
|
onRowClick={(row) => router.push(`/purchase/bill/${(row as any).id}`)}
|
|
headerProps={({ selectedItem, invalidateQuery }) => ({
|
|
actions: (
|
|
<FormDialog classNames={{ dialogContent: "lg:min-w-6xl" }} title="Bill">
|
|
{(resourceId) => (
|
|
<BillForm
|
|
resourceId={resourceId}
|
|
initialData={selectedItem}
|
|
onSuccess={invalidateQuery}
|
|
/>
|
|
)}
|
|
</FormDialog>
|
|
),
|
|
})}
|
|
columns={({ actionsColumn }) => [
|
|
{
|
|
accessorKey: "bill_number",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Bill #" />,
|
|
cell: ({ row }) => (row.original as any).bill_number || "—",
|
|
},
|
|
{
|
|
accessorKey: "total",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Total" />,
|
|
cell: ({ row }) => {
|
|
const v = (row.original as any).total
|
|
return v != null && v !== "" ? <Money value={v} /> : "—"
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "balance_due",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Balance Due" />,
|
|
cell: ({ row }) => {
|
|
const v = (row.original as any).balance_due
|
|
return v != null && v !== "" ? <Money value={v} /> : "—"
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "title",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Title" />,
|
|
},
|
|
{
|
|
accessorKey: "vendor",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Vendor" />,
|
|
cell: ({ row }) => {
|
|
const vendor = (row.original as any).vendor
|
|
return (
|
|
<RelationLink
|
|
href={vendor?.id ? `/purchase/vendor/${vendor.id}` : null}
|
|
icon={Building2}
|
|
label={vendor?.company_name || getFullName(vendor)}
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "bill_date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Bill Date" />,
|
|
cell: ({ row }) => formatDate((row.original as any).bill_date) || "—",
|
|
},
|
|
{
|
|
accessorKey: "bill_due_date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Due Date" />,
|
|
cell: ({ row }) => formatDate((row.original as any).bill_due_date) || "—",
|
|
},
|
|
{
|
|
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"}>
|
|
{formatEnum(status)}
|
|
</Badge>
|
|
)
|
|
},
|
|
},
|
|
actionsColumn({
|
|
extraItems: (row) => [
|
|
{
|
|
label: isPrinting ? "Printing..." : "Print",
|
|
icon: Printer,
|
|
onClick: (r) => print("bill", String(r.id), "print"),
|
|
},
|
|
],
|
|
}),
|
|
]}
|
|
/>
|
|
)
|
|
}
|
|
|