* 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>
24 lines
1.5 KiB
SQL
24 lines
1.5 KiB
SQL
-- Per-company editable reminder email texts per reminder level (1-3).
|
|
-- NULL column / missing keys / whitespace-only values fall back to the
|
|
-- defaults in lib/email/reminder-templates.ts (REMINDER_EMAIL_DEFAULT_TEXTS);
|
|
-- only diffs from the defaults are stored (prefill-override convention).
|
|
-- TEXT only: reminder fee and interest math live in the reminder processor
|
|
-- and are not configurable here (Lag 1981:739 caps the paminnelseavgift at
|
|
-- 60 kr; no per-step fee logic exists or is added).
|
|
-- Length limits are enforced by UpdateSettingsSchema (the only write path);
|
|
-- mirrors the invoice_email_texts precedent (20260703091000).
|
|
|
|
ALTER TABLE public.company_settings
|
|
ADD COLUMN IF NOT EXISTS reminder_text_overrides JSONB NULL;
|
|
|
|
ALTER TABLE public.company_settings
|
|
DROP CONSTRAINT IF EXISTS company_settings_reminder_text_overrides_object;
|
|
ALTER TABLE public.company_settings
|
|
ADD CONSTRAINT company_settings_reminder_text_overrides_object
|
|
CHECK (reminder_text_overrides IS NULL OR jsonb_typeof(reminder_text_overrides) = 'object');
|
|
|
|
COMMENT ON COLUMN public.company_settings.reminder_text_overrides IS
|
|
'Overrides for reminder emails: { level_1?: { subject?, body? }, level_2?: {...}, level_3?: {...} }. Placeholders {fakturanummer} {kundnamn} {förnamn} {företag} {fakturadatum} {förfallodatum} {belopp} {dagar} are substituted at send time by lib/email/reminder-templates.ts. NULL / missing / whitespace-only fields fall back to the hardcoded defaults. Text only; never affects fee or interest math.';
|
|
|
|
NOTIFY pgrst, 'reload schema';
|