179b59d73d
Invoice + Stornorechnung/Gutschrift PDFs get a modern header-band layout, a "bereits beglichen" badge for immediately-paid orders, labelled bank details, and a per-tax-rate summary breakdown. Correction invoices can now be re-downloaded from the account (regenerated deterministically, not stored as files, same approach as the original invoice). Return requests capture a reason. Products can define bundles (bundleItems) and a per-product VAT rate override, both snapshotted onto order items.
46 lines
2.1 KiB
TypeScript
46 lines
2.1 KiB
TypeScript
import { getInvoiceSettings, type InvoiceSettings } from "./payload";
|
|
import { renderInvoicePdf, type InvoiceOrder } from "./invoicePdf";
|
|
import { renderCorrectionInvoicePdf, type CorrectionInvoiceKind, type CorrectionInvoiceOrder } from "./correctionInvoicePdf";
|
|
|
|
export type { InvoiceSettings };
|
|
|
|
// Fetched once by callers that need seller data for more than one purpose
|
|
// in the same request (e.g. orderEmail.ts also needs it for the email
|
|
// footer's companyLine) — avoids a second identical invoice-settings round
|
|
// trip, unlike calling getInvoiceSettings() again inside each generator.
|
|
export async function getSellerForInvoice(): Promise<InvoiceSettings | null> {
|
|
return getInvoiceSettings();
|
|
}
|
|
|
|
// Shared by app/lib/orderEmail.ts (checkout — attaches to the confirmation
|
|
// mail) and app/api/account/orders/[orderNumber]/invoice/route.ts (on-demand
|
|
// download) — same render call both times, so what a customer downloads
|
|
// later always matches what they were emailed. `seller` is passed in
|
|
// rather than fetched here, so a caller that already has it (see above)
|
|
// doesn't fetch it twice.
|
|
export async function generateInvoicePdf(order: InvoiceOrder, seller: InvoiceSettings | null): Promise<Buffer | null> {
|
|
if (!seller) {
|
|
console.error("generateInvoicePdf: no invoice-settings row found for tenant");
|
|
return null;
|
|
}
|
|
return renderInvoicePdf(order, seller);
|
|
}
|
|
|
|
// Frontend-side regeneration for the "Stornorechnung/Gutschrift
|
|
// herunterladen" download button — the real document was already
|
|
// generated once (Payload's Orders.ts afterChange hook) and emailed; this
|
|
// reproduces the identical PDF from the order's own stored
|
|
// correctionInvoiceNumber/correctionInvoiceIssuedAt, same "deterministic
|
|
// regeneration, not file storage" approach as the original invoice.
|
|
export async function generateCorrectionInvoicePdf(
|
|
kind: CorrectionInvoiceKind,
|
|
order: CorrectionInvoiceOrder,
|
|
seller: InvoiceSettings | null,
|
|
): Promise<Buffer | null> {
|
|
if (!seller) {
|
|
console.error("generateCorrectionInvoicePdf: no invoice-settings row found for tenant");
|
|
return null;
|
|
}
|
|
return renderCorrectionInvoicePdf(kind, order, seller);
|
|
}
|