feat(reminders): per-company reminder text overrides with per-field reset (#2038)

* feat(reminders): per-company reminder text overrides with per-field reset

Add company_settings.reminder_text_overrides (JSONB, migration
20260830100000): optional subject/body per reminder level, storing only
diffs from the defaults. Reminder templates now express their defaults as
placeholder patterns and render stock and override mails through one
substitution pipeline (placeholders, HTML escaping, subject sanitizing),
so the settings prefill is exactly the sent mail. The level 3 default is
strengthened into an explicit inkassovarning (8 days, handover to
inkasso, costs per lag (1981:739)); text only, no fee or interest math
changes. New ReminderEmailTextsSettings editor (per-level tabs, effective
value prefilled, per-field reset, placeholder legend) mounted in the
invoicing settings, strings in sv + en, and reminder_text_overrides added
to UpdateSettingsSchema with schema and template tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018zGah8Yy49esAwpnKGxiGy

* chore(migrations): bump reminder_text_overrides to 20260830120000

Main gained 20260830101500_seed_agent_atom_bodies after this branch cut
its version, so the file moves to a fresh later timestamp to keep
remote migration history append-only.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018zGah8Yy49esAwpnKGxiGy

* fix(reminders): serialize override saves and fix Swedish hint grammar

CodeRabbit review: queue the whole-object PUTs in
ReminderEmailTextsSettings so an older in-flight snapshot cannot replace
a newer edit, and start the level 3 hint with "Den slutliga
paminnelsen". The NOT VALID suggestion on the migration CHECK is
declined: company_settings is one row per company, migration files run
in a single transaction, and the invoice_email_texts precedent shipped
the identical constraint shape.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018zGah8Yy49esAwpnKGxiGy

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Mattsson
2026-08-30 16:06:00 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent e313bfa8ec
commit 3cf2e10740
13 changed files with 672 additions and 55 deletions
+20
View File
@@ -366,6 +366,24 @@ export interface InvoiceEmailTexts {
en?: InvoiceEmailTextOverrides
}
// Editable reminder email texts per reminder level (Swedish only, matching
// the reminder templates). Missing / whitespace-only fields fall back to the
// defaults in lib/email/reminder-templates.ts (REMINDER_EMAIL_DEFAULT_TEXTS).
// Supports the fixed placeholder set {fakturanummer} {kundnamn} {förnamn}
// {företag} {fakturadatum} {förfallodatum} {belopp} {dagar}. TEXT only:
// reminder fee and interest math are unaffected (Lag 1981:739 caps the
// påminnelseavgift at 60 kr; the 450 kr förseningsersättning is out of scope).
export interface ReminderTextOverride {
subject?: string
body?: string
}
export interface ReminderTextOverrides {
level_1?: ReminderTextOverride
level_2?: ReminderTextOverride
level_3?: ReminderTextOverride
}
export type InvoiceFontFamily =
| 'Helvetica'
| 'Times-Roman'
@@ -544,6 +562,8 @@ export interface CompanySettings {
reminder_days_level_1: number
reminder_days_level_2: number
reminder_days_level_3: number
// Editable reminder email texts per level. null = all defaults.
reminder_text_overrides: ReminderTextOverrides | null
// Reminder surcharges (dröjsmålsränta + lagstadgad påminnelseavgift)
reminder_fee_enabled: boolean