feat(email): split invoice email into paid/unpaid variants

Persist paymentStatus on the Invoice at generation time and use it at send
time to pick the default email body. Paid orders (paid/refunded/voided) now
get a body without the bank-transfer reference hint; outstanding orders keep
it. Custom merchant templates still override the defaults for both cases.

- Add Invoice.paymentStatus column + migration
- Split DEFAULT_EMAIL_BODY_{DE,EN} into _PAID/_UNPAID variants
- Persist paymentStatus in generateInvoice; select default in email.server
- Document behaviour on the settings page
- Add email-templates test (paid omits hint, unpaid keeps it)
This commit is contained in:
Gerhard Scheikl
2026-08-24 16:16:17 +02:00
parent 60288f6260
commit ff5c435bd4
7 changed files with 138 additions and 26 deletions
@@ -131,6 +131,7 @@ export async function generateInvoice(
const version = latest ? latest.version + 1 : 1;
const totalsJson = JSON.stringify(viewModel.totals);
const paymentStatus = viewModel.paymentStatus;
const customerJson = JSON.stringify({
recipient: viewModel.recipient,
isB2B: viewModel.isB2B,
@@ -148,6 +149,7 @@ export async function generateInvoice(
pdfUrl: upload.url,
totalsJson,
customerJson,
paymentStatus,
issuedAt: new Date(),
status: "issued",
lastError: "",
@@ -167,6 +169,7 @@ export async function generateInvoice(
pdfUrl: upload.url,
totalsJson,
customerJson,
paymentStatus,
status: "issued",
},
});