Merge branch 'fix/void-refunded'
# Conflicts: # CHANGELOG.md
This commit is contained in:
@@ -123,6 +123,15 @@ function InvoiceDetail({ id }: { id: string }) {
|
||||
} catch (e) { setMsg({ type: "err", text: errorText(e) }); } finally { setBusy(null); }
|
||||
};
|
||||
const pdf = (path: string) => openPdf(path).catch(e => setMsg({ type: "err", text: errorText(e) }));
|
||||
const refund = async (p: Invoice["payments"][number]) => {
|
||||
const note = prompt(`Mark ${p.receiptNumber} (${money(p.amountCents)}) as refunded to the church? It stays on record, no longer counts as paid, and the statement shows the refund. Note (optional, e.g. the EFT reference):`, "");
|
||||
if (note === null) return;
|
||||
try {
|
||||
const r = await api<{ message: string }>(`/api/admin/billing/payments/${p.id}/refund`, { method: "POST", body: { note } });
|
||||
setMsg({ type: "ok", text: r.message });
|
||||
load();
|
||||
} catch (e) { setMsg({ type: "err", text: errorText(e) }); }
|
||||
};
|
||||
const paymentAction = async (pid: string, what: "resend" | "delete") => {
|
||||
if (what === "delete" && !confirm("Remove this payment? Its receipt number won't be used again.")) return;
|
||||
try {
|
||||
@@ -150,7 +159,7 @@ function InvoiceDetail({ id }: { id: string }) {
|
||||
{inv.status === "sent" && inv.balanceCents > 0 && <button className="btn-primary" onClick={() => setPaying(true)}>Record payment</button>}
|
||||
{inv.status === "sent" && <button className="btn-secondary" onClick={() => act("resend", "resend")} disabled={!!busy}><Send className="h-4 w-4" /> Send again</button>}
|
||||
<button className="btn-secondary" onClick={() => pdf(`/api/admin/billing/invoices/${id}/pdf`)}><FileText className="h-4 w-4" /> {editable ? "Preview PDF" : "PDF"}</button>
|
||||
{inv.status !== "void" && inv.payments.length === 0 && <button className="btn-danger" onClick={voidIt} disabled={!!busy}><XCircle className="h-4 w-4" /> Void</button>}
|
||||
{inv.status !== "void" && inv.payments.every(p => p.refundedAt) && <button className="btn-danger" onClick={voidIt} disabled={!!busy}><XCircle className="h-4 w-4" /> Void</button>}
|
||||
</div>
|
||||
|
||||
{inv.sendError && <div className="mb-4 rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-800">The last attempt to send it failed: {inv.sendError}. It's tried again every 15 minutes.</div>}
|
||||
@@ -227,11 +236,13 @@ function InvoiceDetail({ id }: { id: string }) {
|
||||
<h2 className="mb-2 font-semibold">Payments</h2>
|
||||
{inv.payments.map(p => (
|
||||
<div key={p.id} className="border-t border-slate-100 py-2 first:border-0">
|
||||
<div className="flex justify-between"><span>{p.receiptNumber} · {day(p.paidOn)}</span><strong className="tabular-nums">{money(p.amountCents)}</strong></div>
|
||||
<div className="flex justify-between"><span>{p.receiptNumber} · {day(p.paidOn)}</span><strong className={`tabular-nums ${p.refundedAt ? "text-slate-400 line-through" : ""}`}>{money(p.amountCents)}</strong></div>
|
||||
<div className="text-xs text-slate-500">{METHOD[p.method] || p.method}{p.reference && p.reference !== inv.number ? ` · ${p.reference}` : ""}{p.receiptSentAt ? " · receipt sent" : ""}</div>
|
||||
{p.refundedAt && <div className="text-xs font-medium text-amber-800">Refunded {day(p.refundedAt)}{p.refundNote ? ` · ${p.refundNote}` : ""}</div>}
|
||||
<div className="mt-1 flex gap-3 text-xs">
|
||||
<button className="text-indigo-700 hover:underline" onClick={() => pdf(`/api/admin/billing/payments/${p.id}/pdf`)}>Receipt</button>
|
||||
<button className="text-indigo-700 hover:underline" onClick={() => paymentAction(p.id, "resend")}>Email receipt</button>
|
||||
{!p.refundedAt && <button className="text-amber-800 hover:underline" onClick={() => refund(p)}>Refund</button>}
|
||||
<button className="text-red-700 hover:underline" onClick={() => paymentAction(p.id, "delete")}>Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user