import { useTranslations, useFormatter } from "next-intl"; import { Card } from "@/components/ui/card"; import type { CreditNote } from "@/types"; interface Props { creditNotes: CreditNote[]; } const kindColors: Record = { // Voids = the invoice was cancelled; gentle red. void: "text-error bg-error/10", // Refunds = money returned; also red but slightly differentiated. refund: "text-error bg-error/10", }; /** * Phase 7 — customer's credit-note history below the invoice list. * * Hidden entirely when the org has zero credit notes (most orgs in * normal operation). When present, each row shows the credit-note * number, the invoice it relates to, kind (void / refund), amount, * and a download link to the PDF. * * No detail page — clicking the PDF link opens the document inline * (browser PDF viewer), which IS the credit-note detail view. A * separate per-credit-note web page would duplicate what's in the * PDF and add no value. */ export function CustomerCreditNoteList({ creditNotes }: Props) { const t = useTranslations("customerBilling"); const fmt = useFormatter(); if (creditNotes.length === 0) { return null; } return ( {creditNotes.map((cn) => ( ))}
{t("creditNoteNumberCol")} {t("creditNoteInvoiceCol")} {t("creditNoteIssuedCol")} {t("creditNoteAmountCol")} {t("creditNoteKindCol")} {t("creditNotePdfCol")}
{cn.creditNoteNumber} {cn.invoiceNumber} {fmt.dateTime(new Date(cn.issuedAt), { dateStyle: "medium" })} CHF {cn.amountChf.toFixed(2)} {t(`creditNoteKind_${cn.kind}` as any)} {cn.hasPdf ? ( {t("downloadPdf")} ) : ( {t("creditNoteNoPdf")} )}
); }