fix(invoice): unify customer-facing remittance reference with the printed invoice number

Two related fixes around the order/invoice number:

1) The thank-you page and the customer-account order page were showing
   the bare Shopify order name (e.g. '#1034') as the payment reference,
   while the PDF (and its GiroCode QR) used the canonical invoice
   number (e.g. 'RE-1034'). Banks treat each unique reference as a
   separate payment, and several reject the '#' character outright \u2014
   so customers who pasted the thank-you reference into their banking
   app ended up with a payment the shop couldn't reconcile.

   New shared helper resolveOrderRemittance() (services/invoice/
   remittance.server.ts) returns the single source of truth for the
   reference: latest non-cancelled Invoice row for the order, falling
   back to '${prefix}${orderNumber}' when no PDF has been generated yet.
   Both /api/public/payment-info and /api/public/girocode.png now route
   through it, so the thank-you page, the customer-account page and the
   GiroCode QR are guaranteed to match the PDF byte-for-byte.

2) Drop the redundant '\u00b7 Bestellnummer: #1004' suffix from the PDF
   title when the invoice number's trailing digits already match the
   Shopify order name (default 'order_number' numbering mode). In that
   mode the two strings carry identical numeric content and the suffix
   only adds noise; sequential mode (RE-7 vs #1004) keeps the suffix.

- New smoke assertion verifies the suppression triggers on
  invoiceNumber='RE-1004' + orderName='#1004' and that the invoice
  number itself is still shown.
- Both endpoints now also query 'Order.number' (already covered by
  read_orders) so the fallback path can build the prefix+order-number
  string without requiring the Invoice row.
This commit is contained in:
Gerhard Scheikl
2026-05-15 15:51:10 +02:00
parent a2b3c14022
commit 2a4a7fd983
5 changed files with 98 additions and 3 deletions
+13
View File
@@ -572,6 +572,19 @@ async function main() {
assert("EN PDF shows tracking row 'Tracking no.'", enText.includes("Tracking no."));
assert("EN PDF shows separate delivery address heading", enText.includes("Shipping address"));
// Order-number suppression: when the invoice number's trailing digits
// match the Shopify order name (default numbering mode), the redundant
// "· Bestellnummer: #1004" suffix should be dropped from the title.
const sameNumVm = composeInvoice({
order, settings: settings as never, invoiceNumber: "RE-1004",
});
sameNumVm.issuer.logoDataUrl = vm.issuer.logoDataUrl;
const sameNumText = await pdfToText(await renderInvoicePdf(sameNumVm));
assert("PDF suppresses 'Bestellnummer' suffix when invoice# matches order#",
!sameNumText.includes("Bestellnummer"));
assert("PDF still shows the invoice number itself when suppressed",
sameNumText.includes("RE-1004"));
// ----------------------------------------------------------------
// Delivery date follows latest fulfillment, not processedAt
// ----------------------------------------------------------------