This commit is contained in:
101
src/components/billing/customer-credit-note-list.tsx
Normal file
101
src/components/billing/customer-credit-note-list.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
import { useTranslations, useFormatter } from "next-intl";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import type { CreditNote } from "@/types";
|
||||
|
||||
interface Props {
|
||||
creditNotes: CreditNote[];
|
||||
}
|
||||
|
||||
const kindColors: Record<string, string> = {
|
||||
// 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 (
|
||||
<Card>
|
||||
<table className="w-full text-sm">
|
||||
<thead className="text-xs text-text-muted text-left">
|
||||
<tr>
|
||||
<th className="pb-2">{t("creditNoteNumberCol")}</th>
|
||||
<th className="pb-2">{t("creditNoteInvoiceCol")}</th>
|
||||
<th className="pb-2">{t("creditNoteIssuedCol")}</th>
|
||||
<th className="pb-2 text-right">{t("creditNoteAmountCol")}</th>
|
||||
<th className="pb-2 text-right">{t("creditNoteKindCol")}</th>
|
||||
<th className="pb-2 text-right">{t("creditNotePdfCol")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{creditNotes.map((cn) => (
|
||||
<tr
|
||||
key={cn.id}
|
||||
className="border-t border-border align-middle"
|
||||
>
|
||||
<td className="py-2 font-mono text-xs">
|
||||
{cn.creditNoteNumber}
|
||||
</td>
|
||||
<td className="py-2 font-mono text-xs text-text-secondary">
|
||||
{cn.invoiceNumber}
|
||||
</td>
|
||||
<td className="py-2 text-text-secondary">
|
||||
{fmt.dateTime(new Date(cn.issuedAt), { dateStyle: "medium" })}
|
||||
</td>
|
||||
<td className="py-2 text-right font-mono">
|
||||
CHF {cn.amountChf.toFixed(2)}
|
||||
</td>
|
||||
<td className="py-2 text-right">
|
||||
<span
|
||||
className={`px-2 py-0.5 rounded text-xs ${
|
||||
kindColors[cn.kind] ?? ""
|
||||
}`}
|
||||
>
|
||||
{t(`creditNoteKind_${cn.kind}` as any)}
|
||||
</span>
|
||||
</td>
|
||||
<td className="py-2 text-right">
|
||||
{cn.hasPdf ? (
|
||||
<a
|
||||
href={`/api/credit-notes/${encodeURIComponent(
|
||||
cn.creditNoteNumber
|
||||
)}/pdf`}
|
||||
className="text-accent hover:underline text-xs"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{t("downloadPdf")}
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-text-muted text-xs italic">
|
||||
{t("creditNoteNoPdf")}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,13 @@ const statusColors: Record<string, string> = {
|
||||
paid: "text-success bg-success/10",
|
||||
overdue: "text-error bg-error/10",
|
||||
void: "text-text-muted bg-surface-3 line-through",
|
||||
// Phase 7: refund states. Red tinting matches the credit-note
|
||||
// PDF accent so customers reading the table get a visual cue
|
||||
// that something was credited back. partially_refunded reads
|
||||
// as a partial state (mixed colour), fully_refunded reads as
|
||||
// closed (line-through like void).
|
||||
partially_refunded: "text-error bg-error/10",
|
||||
fully_refunded: "text-text-muted bg-error/10 line-through",
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user