import { cache } from "react"; import type { Metadata } from "next"; import { readBillPayload } from "../../../lib/bills"; import { BILL_NOT_FOUND, formatBillDate, parseBill, type BillView } from "../../../lib/bill-view"; import { money } from "../../../lib/money"; export const dynamic = "force-dynamic"; const loadBill = cache(async (token: string): Promise => { const raw = await readBillPayload(token); if (!raw) return null; return parseBill(raw); }); export async function generateMetadata({ params, }: { params: Promise<{ token: string }>; }): Promise { const { token } = await params; const bill = await loadBill(token); if (!bill) return { title: "100kmph invoice" }; return { title: `${bill.number || "Invoice"} ยท 100kmph` }; } export default async function BillPage({ params }: { params: Promise<{ token: string }> }) { const { token } = await params; const bill = await loadBill(token); if (!bill) return
{BILL_NOT_FOUND}
; const when = formatBillDate(bill.createdAt); return (

{bill.shopName || "100kmph"}

{bill.address}

{bill.phone ? `Ph: ${bill.phone}` : ""}


Invoice {bill.number}
{when}

Customer: {bill.customerName || "-"}
Phone: {bill.customerPhone || "-"} {bill.vehicleReg ? ( <>
Vehicle: {bill.vehicleReg} {bill.vehicleModel} ) : null}

{bill.lines.map((line, index) => ( ))}
Item Qty Rate Amount
{line.description} {line.qty ?? ""} {money(line.unitPrice)} {money(line.lineTotal)}

Total {money(bill.total)}

Paid by: {bill.paymentMethod.toUpperCase()}

Digital invoice from 100kmph. You can print this page if you need paper.

); }