feat(invoice): show refund + outstanding-amount rows on the PDF
When a Shopify order has been (partially or fully) refunded the PDF
now mirrors the order-page totals block:
Gesamtbetrag brutto 629,95 EUR
Zurückerstattet -629,95 EUR
Offener Betrag 0,00 EUR
So the customer immediately sees that nothing is owed any more, even
though the original invoice gross stays unchanged for tax-document
correctness (the refund is itemised as a separate row, not subtracted
from the line totals).
Plumbing:
- GraphQL: added `totalRefundedSet` to OrderForInvoice query.
- RawOrderForInvoice: new optional `totalRefundedSet` field
(null for drafts/offers — they never have refunds).
- InvoiceViewModel: new `refundedAmount: number` (gross, in the
same currency as `totals.gross`). Always present, 0 for storno
and offer documents and for non-refunded invoices.
- composeInvoice parses the gross refund out of `totalRefundedSet`
(defensive parseFloat, clamped to >= 0).
- InvoiceDocument renders the two extra rows under `grossTotal`
only when `refundedAmount > 0`. Uses the existing total-row
styles for visual consistency.
- i18n: added `refundedLabel` ("Zurückerstattet" / "Refunded") and
`outstandingLabel` ("Offener Betrag" / "Outstanding amount") to
both languages.
Verification: render-sample fixture now mirrors the full gross as
refunded and asserts the PDF text contains "Zurückerstattet",
"Offener Betrag", and "0,00 EUR" as the final outstanding row, on
top of the previous suppressions (no GiroCode, no payment terms).
tsc / smoke / tests / build all green.
This commit is contained in:
@@ -94,6 +94,12 @@ export function composeInvoice({
|
||||
// just whether the money was kept (`paid`) or returned (`refunded`).
|
||||
const requiresPayment =
|
||||
!storno && !offer && paymentStatus !== "paid" && paymentStatus !== "refunded";
|
||||
// Refunded gross amount, mirrored from Shopify's `totalRefundedSet`.
|
||||
// Storno/offer documents don't carry a refund row — a storno *is*
|
||||
// already the cancellation document, and offers have no payments yet.
|
||||
const refundedAmount = storno || offer
|
||||
? 0
|
||||
: Math.max(0, parseFloat(order.totalRefundedSet?.shopMoney.amount ?? "0") || 0);
|
||||
const paymentGatewayNames = (order.paymentGatewayNames ?? []).filter(
|
||||
(n) => typeof n === "string" && n.trim().length > 0,
|
||||
);
|
||||
@@ -139,6 +145,7 @@ export function composeInvoice({
|
||||
paid,
|
||||
paymentStatus,
|
||||
requiresPayment,
|
||||
refundedAmount,
|
||||
paymentGatewayNames,
|
||||
orderName: order.name,
|
||||
separateShippingAddress,
|
||||
|
||||
@@ -44,6 +44,14 @@ export interface InvoiceStrings {
|
||||
recipientLabel: string;
|
||||
amountLabel: string;
|
||||
referenceLabel: string;
|
||||
/** Label for the refund row that appears below `grossTotal` when the
|
||||
* order has been (partially or fully) refunded. Mirrors what Shopify
|
||||
* shows on the order page ("Zurückerstattet" / "Refunded"). */
|
||||
refundedLabel: string;
|
||||
/** Label for the final outstanding balance row (`grossTotal -
|
||||
* refundedAmount`) shown when there has been a refund. "Offener
|
||||
* Betrag" / "Outstanding amount". */
|
||||
outstandingLabel: string;
|
||||
addressHeading: string;
|
||||
contactHeading: string;
|
||||
legalHeading: string;
|
||||
@@ -159,6 +167,8 @@ const de: InvoiceStrings = {
|
||||
recipientLabel: "Empfänger",
|
||||
amountLabel: "Betrag",
|
||||
referenceLabel: "Referenz",
|
||||
refundedLabel: "Zurückerstattet",
|
||||
outstandingLabel: "Offener Betrag",
|
||||
addressHeading: "Adresse",
|
||||
contactHeading: "Kontakt",
|
||||
legalHeading: "Rechtliches",
|
||||
@@ -246,6 +256,8 @@ const en: InvoiceStrings = {
|
||||
recipientLabel: "Recipient",
|
||||
amountLabel: "Amount",
|
||||
referenceLabel: "Reference",
|
||||
refundedLabel: "Refunded",
|
||||
outstandingLabel: "Outstanding amount",
|
||||
addressHeading: "Address",
|
||||
contactHeading: "Contact",
|
||||
legalHeading: "Legal",
|
||||
|
||||
@@ -172,6 +172,8 @@ export async function loadDraftOrderForOffer(
|
||||
subtotalSet: draft.subtotalPriceSet,
|
||||
totalTaxSet: draft.totalTaxSet,
|
||||
totalPriceSet: draft.totalPriceSet,
|
||||
// Drafts have no concept of refunds.
|
||||
totalRefundedSet: null,
|
||||
taxLines: draft.taxLines || [],
|
||||
lineItems: (draft.lineItems?.edges || []).map((e) => {
|
||||
const node = e.node;
|
||||
|
||||
@@ -38,6 +38,11 @@ export interface RawOrderForInvoice {
|
||||
subtotalSet: { shopMoney: RawMoney } | null;
|
||||
totalTaxSet: { shopMoney: RawMoney } | null;
|
||||
totalPriceSet: { shopMoney: RawMoney } | null;
|
||||
/** Cumulative gross amount that has been refunded against this order
|
||||
* via Shopify (sum of all refund transactions). Always present on
|
||||
* real orders — may be `null` for synthetic / draft fixtures, in
|
||||
* which case the composer treats it as 0. */
|
||||
totalRefundedSet: { shopMoney: RawMoney } | null;
|
||||
purchasingEntity: {
|
||||
company?: {
|
||||
name: string;
|
||||
@@ -153,6 +158,7 @@ const QUERY = `#graphql
|
||||
subtotalPriceSet { shopMoney { amount currencyCode } }
|
||||
totalTaxSet { shopMoney { amount currencyCode } }
|
||||
totalPriceSet { shopMoney { amount currencyCode } }
|
||||
totalRefundedSet { shopMoney { amount currencyCode } }
|
||||
taxLines {
|
||||
title
|
||||
rate
|
||||
@@ -247,6 +253,7 @@ interface RawAdminResponse {
|
||||
subtotalPriceSet: { shopMoney: RawMoney } | null;
|
||||
totalTaxSet: { shopMoney: RawMoney } | null;
|
||||
totalPriceSet: { shopMoney: RawMoney } | null;
|
||||
totalRefundedSet: { shopMoney: RawMoney } | null;
|
||||
taxLines: RawTaxLine[];
|
||||
discountCode: string | null;
|
||||
discountCodes: string[] | null;
|
||||
@@ -300,6 +307,7 @@ export async function loadOrderForInvoice(
|
||||
subtotalSet: order.subtotalPriceSet,
|
||||
totalTaxSet: order.totalTaxSet,
|
||||
totalPriceSet: order.totalPriceSet,
|
||||
totalRefundedSet: order.totalRefundedSet ?? null,
|
||||
taxLines: order.taxLines || [],
|
||||
discountCodes: order.discountCodes && order.discountCodes.length > 0
|
||||
? order.discountCodes
|
||||
|
||||
@@ -428,6 +428,22 @@ export function InvoiceDocument({ invoice }: DocProps) {
|
||||
{formatMoney(invoice.totals.gross, cur, invoice.language)}
|
||||
</Text>
|
||||
</View>
|
||||
{invoice.refundedAmount > 0 && (
|
||||
<>
|
||||
<View style={styles.totalRow}>
|
||||
<Text style={styles.totalLabel}>{t.refundedLabel}</Text>
|
||||
<Text style={styles.totalValue}>
|
||||
{formatMoney(-invoice.refundedAmount, cur, invoice.language)}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[styles.totalRow, { borderTopWidth: 0.5, borderTopColor: TABLE_BORDER, marginTop: 4, paddingTop: 4 }]}>
|
||||
<Text style={styles.totalLabelBlue}>{t.outstandingLabel}</Text>
|
||||
<Text style={styles.totalValueBoldBlue}>
|
||||
{formatMoney(invoice.totals.gross - invoice.refundedAmount, cur, invoice.language)}
|
||||
</Text>
|
||||
</View>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{invoice.notices.length > 0 && (
|
||||
|
||||
@@ -57,6 +57,15 @@ export interface InvoiceViewModel {
|
||||
* original total.
|
||||
*/
|
||||
requiresPayment: boolean;
|
||||
/** Cumulative gross amount that has been refunded against the
|
||||
* underlying Shopify order, in the same currency as `totals.gross`.
|
||||
* 0 when there has been no refund (the common case) or when the
|
||||
* document is structurally not subject to refunds (storno / offer).
|
||||
* When > 0 the renderer adds two extra rows beneath the gross total:
|
||||
* a negative "Zurückerstattet" row and a final "Offener Betrag"
|
||||
* row showing `gross - refundedAmount` so the printed PDF mirrors
|
||||
* what the merchant sees on the Shopify order page. */
|
||||
refundedAmount: number;
|
||||
/** Names of the payment gateways used (e.g. ["bogus"], ["manual",
|
||||
* "shopify_payments"]). Empty when unknown / draft. */
|
||||
paymentGatewayNames: string[];
|
||||
|
||||
Reference in New Issue
Block a user