Post-audit cleanup batch: dead email forks, Docker extension drift, English error locale (#653)
* chore(email): remove dead, diverged email-template forks (audit E2)
extensions/general/email/lib/{invoice,reminder}-templates.ts had zero importers and had diverged from the live lib/email/* copies (which carry later i18n / CSP / Räntelagen-dunning fixes). Pure deletion of a drift hazard.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(docker): hosted preset was missing skatteverket / invoice-inbox / document-extraction / cloud-backup (audit E7)
docker/extensions.hosted.json shipped only 5 of the 9 extensions in extensions.config.json — so a Docker 'hosted' image silently ran without Skatteverket filing, the invoice inbox, document extraction and cloud backup. Aligned with the hosted config.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(errors): return English error messages on the en locale (audit C9)
The structured-error branches in getErrorMessage returned hardcoded Swedish regardless of locale, so English users saw Swedish prose. For the en locale, prefer the registry's English message for any known code; the Swedish (default) path is left entirely unchanged, and codes absent from the registry still fall through. + regression test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b91f0bdbf8
commit
c1be9f15dd
@@ -1 +1 @@
|
||||
{"extensions": ["enable-banking", "email", "arcim-migration", "tic", "mcp-server"]}
|
||||
{"extensions": ["enable-banking", "email", "arcim-migration", "tic", "mcp-server", "cloud-backup", "skatteverket", "invoice-inbox", "document-extraction"]}
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
import type { Invoice, Customer, CompanySettings, InvoiceDocumentType } from '@/types'
|
||||
import { formatCurrency, formatDate, getCompanyDisplayName, getCompanyPrimaryName } from '@/lib/utils'
|
||||
|
||||
function getDocumentLabel(invoice: Invoice): string {
|
||||
if (invoice.credited_invoice_id) return 'Kreditfaktura'
|
||||
const docType = (invoice as Invoice & { document_type?: InvoiceDocumentType }).document_type || 'invoice'
|
||||
if (docType === 'proforma') return 'Proformafaktura'
|
||||
if (docType === 'delivery_note') return 'Följesedel'
|
||||
return 'Faktura'
|
||||
}
|
||||
|
||||
export interface InvoiceEmailData {
|
||||
invoice: Invoice
|
||||
customer: Customer
|
||||
company: CompanySettings
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate HTML email for sending an invoice
|
||||
*/
|
||||
export function generateInvoiceEmailHtml(data: InvoiceEmailData): string {
|
||||
const { invoice, customer, company } = data
|
||||
|
||||
const documentType = getDocumentLabel(invoice)
|
||||
const isCreditNote = !!invoice.credited_invoice_id
|
||||
const docType = (invoice as Invoice & { document_type?: InvoiceDocumentType }).document_type || 'invoice'
|
||||
const isDeliveryNote = docType === 'delivery_note'
|
||||
const isProforma = docType === 'proforma'
|
||||
const hidePayment = isCreditNote || isDeliveryNote || isProforma
|
||||
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html lang="sv">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>${documentType} ${invoice.invoice_number}</title>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.6; color: #333;">
|
||||
<div style="max-width: 600px; margin: 0 auto; padding: 40px 20px;">
|
||||
<!-- Header -->
|
||||
<div style="margin-bottom: 30px;">
|
||||
<h1 style="margin: 0 0 10px 0; font-size: 24px; font-weight: 600; color: #111;">
|
||||
${documentType} från ${getCompanyPrimaryName(company)}
|
||||
</h1>
|
||||
<p style="margin: 0; color: #666; font-size: 14px;">
|
||||
${documentType}nummer: ${invoice.invoice_number}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Greeting -->
|
||||
<div style="margin-bottom: 30px;">
|
||||
<p style="margin: 0 0 15px 0;">
|
||||
Hej${customer.name ? ` ${customer.name.split(' ')[0]}` : ''},
|
||||
</p>
|
||||
<p style="margin: 0;">
|
||||
${isCreditNote
|
||||
? `Bifogat hittar du en kreditfaktura som korrigerar en tidigare faktura.`
|
||||
: `Tack för ditt förtroende! Bifogat hittar du din faktura.`
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Invoice Summary Box -->
|
||||
<div style="background: #f8f9fa; border-radius: 8px; padding: 25px; margin-bottom: 30px;">
|
||||
<table style="width: 100%; border-collapse: collapse;">
|
||||
<tr>
|
||||
<td style="padding: 8px 0; color: #666; font-size: 14px;">${documentType}nummer:</td>
|
||||
<td style="padding: 8px 0; text-align: right; font-weight: 500;">${invoice.invoice_number}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0; color: #666; font-size: 14px;">${documentType}datum:</td>
|
||||
<td style="padding: 8px 0; text-align: right;">${formatDate(invoice.invoice_date)}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0; color: #666; font-size: 14px;">Förfallodatum:</td>
|
||||
<td style="padding: 8px 0; text-align: right; font-weight: 500; color: ${isCreditNote ? '#333' : '#e11d48'};">
|
||||
${formatDate(invoice.due_date)}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="padding: 15px 0 8px 0; border-top: 1px solid #e5e7eb;"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0; font-size: 18px; font-weight: 600;">Att betala:</td>
|
||||
<td style="padding: 8px 0; text-align: right; font-size: 18px; font-weight: 600; color: ${isCreditNote ? '#059669' : '#111'};">
|
||||
${formatCurrency(invoice.total, invoice.currency)}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Payment Details -->
|
||||
${!hidePayment ? `
|
||||
<div style="margin-bottom: 30px;">
|
||||
<h2 style="margin: 0 0 15px 0; font-size: 16px; font-weight: 600; color: #111;">
|
||||
Betalningsinformation
|
||||
</h2>
|
||||
<table style="width: 100%; border-collapse: collapse;">
|
||||
${company.bank_name ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px; width: 140px;">Bank:</td>
|
||||
<td style="padding: 6px 0;">${company.bank_name}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
${company.clearing_number && company.account_number ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">Kontonummer:</td>
|
||||
<td style="padding: 6px 0;">${company.clearing_number}-${company.account_number}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
${company.iban ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">IBAN:</td>
|
||||
<td style="padding: 6px 0;">${company.iban}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
${company.bic ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">BIC/SWIFT:</td>
|
||||
<td style="padding: 6px 0;">${company.bic}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">Meddelande:</td>
|
||||
<td style="padding: 6px 0; font-weight: 500;">${invoice.invoice_number}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- Footer -->
|
||||
<div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #e5e7eb;">
|
||||
<p style="margin: 0 0 10px 0; color: #666; font-size: 14px;">
|
||||
Har du frågor om fakturan? Svara direkt på detta mejl så hjälper vi dig.
|
||||
</p>
|
||||
<p style="margin: 0; color: #666; font-size: 14px;">
|
||||
Med vänliga hälsningar,<br>
|
||||
<strong>${getCompanyPrimaryName(company)}</strong>
|
||||
</p>
|
||||
${company.org_number ? `
|
||||
<p style="margin: 10px 0 0 0; color: #999; font-size: 12px;">
|
||||
Org.nr: ${company.org_number}
|
||||
${company.vat_number ? ` | VAT: ${company.vat_number}` : ''}
|
||||
${company.f_skatt ? ' | Innehar F-skattsedel' : ''}
|
||||
</p>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate plain text email for sending an invoice
|
||||
*/
|
||||
export function generateInvoiceEmailText(data: InvoiceEmailData): string {
|
||||
const { invoice, customer, company } = data
|
||||
|
||||
const documentType = getDocumentLabel(invoice)
|
||||
const isCreditNote = !!invoice.credited_invoice_id
|
||||
const docType = (invoice as Invoice & { document_type?: InvoiceDocumentType }).document_type || 'invoice'
|
||||
const isDeliveryNote = docType === 'delivery_note'
|
||||
const isProforma = docType === 'proforma'
|
||||
const hidePayment = isCreditNote || isDeliveryNote || isProforma
|
||||
|
||||
let text = `${documentType} från ${getCompanyPrimaryName(company)}\n`
|
||||
text += `${documentType}nummer: ${invoice.invoice_number}\n\n`
|
||||
|
||||
text += `Hej${customer.name ? ` ${customer.name.split(' ')[0]}` : ''},\n\n`
|
||||
|
||||
if (isCreditNote) {
|
||||
text += `Bifogat hittar du en kreditfaktura som korrigerar en tidigare faktura.\n\n`
|
||||
} else {
|
||||
text += `Tack för ditt förtroende! Bifogat hittar du din faktura.\n\n`
|
||||
}
|
||||
|
||||
text += `${documentType}sammanfattning:\n`
|
||||
text += `---\n`
|
||||
text += `${documentType}nummer: ${invoice.invoice_number}\n`
|
||||
text += `${documentType}datum: ${formatDate(invoice.invoice_date)}\n`
|
||||
text += `Förfallodatum: ${formatDate(invoice.due_date)}\n`
|
||||
text += `Att betala: ${formatCurrency(invoice.total, invoice.currency)}\n`
|
||||
text += `---\n\n`
|
||||
|
||||
if (!hidePayment) {
|
||||
text += `Betalningsinformation:\n`
|
||||
if (company.bank_name) text += `Bank: ${company.bank_name}\n`
|
||||
if (company.clearing_number && company.account_number) {
|
||||
text += `Kontonummer: ${company.clearing_number}-${company.account_number}\n`
|
||||
}
|
||||
if (company.iban) text += `IBAN: ${company.iban}\n`
|
||||
if (company.bic) text += `BIC/SWIFT: ${company.bic}\n`
|
||||
text += `Meddelande: ${invoice.invoice_number}\n\n`
|
||||
}
|
||||
|
||||
text += `Har du frågor om fakturan? Svara direkt på detta mejl så hjälper vi dig.\n\n`
|
||||
text += `Med vänliga hälsningar,\n`
|
||||
text += `${getCompanyDisplayName(company)}\n`
|
||||
|
||||
if (company.org_number) {
|
||||
text += `\nOrg.nr: ${company.org_number}`
|
||||
if (company.vat_number) text += ` | VAT: ${company.vat_number}`
|
||||
if (company.f_skatt) text += ` | Innehar F-skattsedel`
|
||||
text += `\n`
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate email subject for an invoice
|
||||
*/
|
||||
export function generateInvoiceEmailSubject(data: InvoiceEmailData): string {
|
||||
const { invoice, company } = data
|
||||
const documentType = getDocumentLabel(invoice)
|
||||
|
||||
return `${documentType} ${invoice.invoice_number} från ${getCompanyPrimaryName(company)}`
|
||||
}
|
||||
@@ -1,280 +0,0 @@
|
||||
import type { Invoice, Customer, CompanySettings } from '@/types'
|
||||
import { formatCurrency, formatDate, getCompanyDisplayName, getCompanyPrimaryName } from '@/lib/utils'
|
||||
|
||||
export interface ReminderEmailData {
|
||||
invoice: Invoice
|
||||
customer: Customer
|
||||
company: CompanySettings
|
||||
reminderLevel: 1 | 2 | 3
|
||||
daysOverdue: number
|
||||
actionUrl: string // URL for customer to mark as paid or dispute
|
||||
}
|
||||
|
||||
// Reminder level configurations
|
||||
const REMINDER_CONFIG = {
|
||||
1: {
|
||||
title: 'Vänlig påminnelse',
|
||||
tone: 'friendly',
|
||||
daysAfterDue: 15
|
||||
},
|
||||
2: {
|
||||
title: 'Andra påminnelsen',
|
||||
tone: 'firm',
|
||||
daysAfterDue: 30
|
||||
},
|
||||
3: {
|
||||
title: 'Slutlig påminnelse',
|
||||
tone: 'urgent',
|
||||
daysAfterDue: 45
|
||||
}
|
||||
} as const
|
||||
|
||||
/**
|
||||
* Generate HTML email for payment reminder
|
||||
*/
|
||||
export function generateReminderEmailHtml(data: ReminderEmailData): string {
|
||||
const { invoice, customer, company, reminderLevel, daysOverdue, actionUrl } = data
|
||||
const config = REMINDER_CONFIG[reminderLevel]
|
||||
|
||||
// Different styling based on urgency
|
||||
const headerColor = reminderLevel === 3 ? '#dc2626' : reminderLevel === 2 ? '#ea580c' : '#2563eb'
|
||||
const buttonColor = reminderLevel === 3 ? '#dc2626' : reminderLevel === 2 ? '#ea580c' : '#2563eb'
|
||||
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html lang="sv">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>${config.title} - Faktura ${invoice.invoice_number}</title>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.6; color: #333; background-color: #f9fafb;">
|
||||
<div style="max-width: 600px; margin: 0 auto; padding: 40px 20px;">
|
||||
<div style="background: white; border-radius: 12px; padding: 40px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
||||
<!-- Header -->
|
||||
<div style="text-align: center; margin-bottom: 30px;">
|
||||
<div style="display: inline-block; background: ${headerColor}15; color: ${headerColor}; padding: 8px 16px; border-radius: 20px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;">
|
||||
${config.title}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Title -->
|
||||
<h1 style="margin: 0 0 20px 0; font-size: 22px; font-weight: 600; color: #111; text-align: center;">
|
||||
Faktura ${invoice.invoice_number} förföll för ${daysOverdue} dagar sedan
|
||||
</h1>
|
||||
|
||||
<!-- Greeting and Message -->
|
||||
<div style="margin-bottom: 30px;">
|
||||
<p style="margin: 0 0 15px 0;">
|
||||
Hej${customer.name ? ` ${customer.name.split(' ')[0]}` : ''},
|
||||
</p>
|
||||
|
||||
${reminderLevel === 1 ? `
|
||||
<p style="margin: 0 0 15px 0;">
|
||||
Vi vill påminna dig om att faktura ${invoice.invoice_number} förföll till betalning den ${formatDate(invoice.due_date)}.
|
||||
Om du redan har betalat kan du bortse från denna påminnelse.
|
||||
</p>
|
||||
` : reminderLevel === 2 ? `
|
||||
<p style="margin: 0 0 15px 0;">
|
||||
Trots vår tidigare påminnelse har vi ännu inte mottagit betalning för faktura ${invoice.invoice_number}
|
||||
som förföll den ${formatDate(invoice.due_date)}.
|
||||
</p>
|
||||
<p style="margin: 0 0 15px 0;">
|
||||
Vi ber dig vänligen att omgående reglera detta belopp för att undvika ytterligare åtgärder.
|
||||
</p>
|
||||
` : `
|
||||
<p style="margin: 0 0 15px 0; color: #dc2626; font-weight: 500;">
|
||||
Detta är vår slutliga påminnelse gällande faktura ${invoice.invoice_number}.
|
||||
</p>
|
||||
<p style="margin: 0 0 15px 0;">
|
||||
Fakturan förföll till betalning den ${formatDate(invoice.due_date)} och vi har ännu inte mottagit betalning
|
||||
trots tidigare påminnelser.
|
||||
</p>
|
||||
<p style="margin: 0 0 15px 0;">
|
||||
Om betalning inte inkommer inom 7 dagar kommer ärendet att överlämnas för vidare hantering.
|
||||
</p>
|
||||
`}
|
||||
</div>
|
||||
|
||||
<!-- Invoice Summary Box -->
|
||||
<div style="background: #f8f9fa; border-radius: 8px; padding: 25px; margin-bottom: 30px; border-left: 4px solid ${headerColor};">
|
||||
<table style="width: 100%; border-collapse: collapse;">
|
||||
<tr>
|
||||
<td style="padding: 8px 0; color: #666; font-size: 14px;">Fakturanummer:</td>
|
||||
<td style="padding: 8px 0; text-align: right; font-weight: 500;">${invoice.invoice_number}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0; color: #666; font-size: 14px;">Fakturadatum:</td>
|
||||
<td style="padding: 8px 0; text-align: right;">${formatDate(invoice.invoice_date)}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0; color: #666; font-size: 14px;">Förfallodatum:</td>
|
||||
<td style="padding: 8px 0; text-align: right; color: #dc2626; font-weight: 500;">
|
||||
${formatDate(invoice.due_date)}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="padding: 15px 0 8px 0; border-top: 1px solid #e5e7eb;"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 8px 0; font-size: 18px; font-weight: 600;">Belopp att betala:</td>
|
||||
<td style="padding: 8px 0; text-align: right; font-size: 18px; font-weight: 600; color: ${headerColor};">
|
||||
${formatCurrency(invoice.total, invoice.currency)}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Payment Details -->
|
||||
<div style="margin-bottom: 30px;">
|
||||
<h2 style="margin: 0 0 15px 0; font-size: 16px; font-weight: 600; color: #111;">
|
||||
Betalningsinformation
|
||||
</h2>
|
||||
<table style="width: 100%; border-collapse: collapse;">
|
||||
${company.bank_name ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px; width: 140px;">Bank:</td>
|
||||
<td style="padding: 6px 0;">${company.bank_name}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
${company.clearing_number && company.account_number ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">Kontonummer:</td>
|
||||
<td style="padding: 6px 0;">${company.clearing_number}-${company.account_number}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
${company.iban ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">IBAN:</td>
|
||||
<td style="padding: 6px 0;">${company.iban}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
${company.bic ? `
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">BIC/SWIFT:</td>
|
||||
<td style="padding: 6px 0;">${company.bic}</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
<tr>
|
||||
<td style="padding: 6px 0; color: #666; font-size: 14px;">Meddelande:</td>
|
||||
<td style="padding: 6px 0; font-weight: 500;">${invoice.invoice_number}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div style="text-align: center; margin-bottom: 30px;">
|
||||
<p style="margin: 0 0 20px 0; color: #666; font-size: 14px;">
|
||||
Har du redan betalat eller har frågor om fakturan?
|
||||
</p>
|
||||
<a href="${actionUrl}" style="display: inline-block; background: ${buttonColor}; color: white; padding: 14px 28px; border-radius: 8px; text-decoration: none; font-weight: 500; font-size: 14px;">
|
||||
Hantera faktura
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div style="padding-top: 20px; border-top: 1px solid #e5e7eb;">
|
||||
<p style="margin: 0 0 10px 0; color: #666; font-size: 14px;">
|
||||
Har du frågor? Svara direkt på detta mejl så hjälper vi dig.
|
||||
</p>
|
||||
<p style="margin: 0; color: #666; font-size: 14px;">
|
||||
Med vänliga hälsningar,<br>
|
||||
<strong>${getCompanyPrimaryName(company)}</strong>
|
||||
</p>
|
||||
${company.org_number ? `
|
||||
<p style="margin: 10px 0 0 0; color: #999; font-size: 12px;">
|
||||
Org.nr: ${company.org_number}
|
||||
${company.vat_number ? ` | VAT: ${company.vat_number}` : ''}
|
||||
</p>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Unsubscribe note -->
|
||||
<p style="text-align: center; margin-top: 20px; color: #999; font-size: 12px;">
|
||||
Detta är ett automatiskt meddelande angående en obetald faktura.
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate plain text email for payment reminder
|
||||
*/
|
||||
export function generateReminderEmailText(data: ReminderEmailData): string {
|
||||
const { invoice, customer, company, reminderLevel, daysOverdue, actionUrl } = data
|
||||
const config = REMINDER_CONFIG[reminderLevel]
|
||||
|
||||
let text = `${config.title.toUpperCase()}\n`
|
||||
text += `Faktura ${invoice.invoice_number} förföll för ${daysOverdue} dagar sedan\n`
|
||||
text += `=`.repeat(50) + `\n\n`
|
||||
|
||||
text += `Hej${customer.name ? ` ${customer.name.split(' ')[0]}` : ''},\n\n`
|
||||
|
||||
if (reminderLevel === 1) {
|
||||
text += `Vi vill påminna dig om att faktura ${invoice.invoice_number} förföll till betalning den ${formatDate(invoice.due_date)}.\n`
|
||||
text += `Om du redan har betalat kan du bortse från denna påminnelse.\n\n`
|
||||
} else if (reminderLevel === 2) {
|
||||
text += `Trots vår tidigare påminnelse har vi ännu inte mottagit betalning för faktura ${invoice.invoice_number} som förföll den ${formatDate(invoice.due_date)}.\n\n`
|
||||
text += `Vi ber dig vänligen att omgående reglera detta belopp för att undvika ytterligare åtgärder.\n\n`
|
||||
} else {
|
||||
text += `DETTA ÄR VÅR SLUTLIGA PÅMINNELSE\n\n`
|
||||
text += `Fakturan förföll till betalning den ${formatDate(invoice.due_date)} och vi har ännu inte mottagit betalning trots tidigare påminnelser.\n\n`
|
||||
text += `Om betalning inte inkommer inom 7 dagar kommer ärendet att överlämnas för vidare hantering.\n\n`
|
||||
}
|
||||
|
||||
text += `Fakturasammanfattning:\n`
|
||||
text += `-`.repeat(30) + `\n`
|
||||
text += `Fakturanummer: ${invoice.invoice_number}\n`
|
||||
text += `Fakturadatum: ${formatDate(invoice.invoice_date)}\n`
|
||||
text += `Förfallodatum: ${formatDate(invoice.due_date)}\n`
|
||||
text += `Belopp att betala: ${formatCurrency(invoice.total, invoice.currency)}\n`
|
||||
text += `-`.repeat(30) + `\n\n`
|
||||
|
||||
text += `Betalningsinformation:\n`
|
||||
if (company.bank_name) text += `Bank: ${company.bank_name}\n`
|
||||
if (company.clearing_number && company.account_number) {
|
||||
text += `Kontonummer: ${company.clearing_number}-${company.account_number}\n`
|
||||
}
|
||||
if (company.iban) text += `IBAN: ${company.iban}\n`
|
||||
if (company.bic) text += `BIC/SWIFT: ${company.bic}\n`
|
||||
text += `Meddelande: ${invoice.invoice_number}\n\n`
|
||||
|
||||
text += `Har du redan betalat eller har frågor om fakturan?\n`
|
||||
text += `Hantera faktura: ${actionUrl}\n\n`
|
||||
|
||||
text += `Har du frågor? Svara direkt på detta mejl så hjälper vi dig.\n\n`
|
||||
text += `Med vänliga hälsningar,\n`
|
||||
text += `${getCompanyDisplayName(company)}\n`
|
||||
|
||||
if (company.org_number) {
|
||||
text += `\nOrg.nr: ${company.org_number}`
|
||||
if (company.vat_number) text += ` | VAT: ${company.vat_number}`
|
||||
text += `\n`
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate email subject for payment reminder
|
||||
*/
|
||||
export function generateReminderEmailSubject(data: ReminderEmailData): string {
|
||||
const { invoice, reminderLevel } = data
|
||||
const config = REMINDER_CONFIG[reminderLevel]
|
||||
|
||||
return `${config.title}: Faktura ${invoice.invoice_number} - ${formatCurrency(invoice.total, invoice.currency)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of days after due date for each reminder level
|
||||
*/
|
||||
export function getReminderDaysConfig(): Record<1 | 2 | 3, number> {
|
||||
return {
|
||||
1: REMINDER_CONFIG[1].daysAfterDue,
|
||||
2: REMINDER_CONFIG[2].daysAfterDue,
|
||||
3: REMINDER_CONFIG[3].daysAfterDue
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,25 @@ describe('getErrorMessage — typed bookkeeping error codes', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getErrorMessage — English locale uses registry English (C9)', () => {
|
||||
it('returns the registry English message for a known structured code instead of Swedish', () => {
|
||||
const code = 'FISCAL_PERIOD_NOT_FOUND'
|
||||
const sv = getErrorMessage({ error: { code, message: '...' } })
|
||||
const en = getErrorMessage({ error: { code, message: '...' } }, { locale: 'en' })
|
||||
|
||||
expect(sv).toMatch(/[åäö]/i) // default (Swedish) path is unchanged
|
||||
expect(en).not.toBe(sv) // English locale now differs
|
||||
expect(en).not.toMatch(/[åäö]/i) // …and is no longer Swedish prose
|
||||
expect(en.toLowerCase()).toContain('fiscal period')
|
||||
})
|
||||
|
||||
it('leaves the Swedish (default-locale) message identical to before', () => {
|
||||
expect(getErrorMessage({ error: { code: 'CANNOT_REVERSE_NON_POSTED', message: '...' } })).toBe(
|
||||
'Endast bokförda verifikationer kan stornas.',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getErrorMessage — existing patterns still work', () => {
|
||||
it('regex match for "Entry date ... outside fiscal period" on plain string', () => {
|
||||
const msg = getErrorMessage('Entry date 2024-06-15 is outside fiscal period "FY 2025"')
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
import { formatCurrency } from '@/lib/utils'
|
||||
import { getErrorEntry } from './structured-errors'
|
||||
|
||||
type ErrorContext =
|
||||
| 'invoice'
|
||||
@@ -279,6 +280,17 @@ export function getErrorMessage(
|
||||
details?: unknown
|
||||
}
|
||||
|
||||
// For English UI, return the registry's English message for any known
|
||||
// code instead of falling through to the Swedish branches below (which
|
||||
// ignored locale — English users were shown Swedish prose). The Swedish
|
||||
// path is left entirely unchanged; codes absent from the registry still
|
||||
// fall through. The dynamic branches (amounts / lock date / reason) keep
|
||||
// owning Swedish display.
|
||||
if (locale === 'en' && typeof structured.code === 'string') {
|
||||
const entry = getErrorEntry(structured.code)
|
||||
if (entry?.message_en) return entry.message_en
|
||||
}
|
||||
|
||||
if (structured.code === 'ACCOUNTS_NOT_IN_CHART' && Array.isArray(structured.account_numbers)) {
|
||||
const numbers = structured.account_numbers as string[]
|
||||
return `Följande konton behöver aktiveras: ${numbers.join(', ')}`
|
||||
|
||||
Reference in New Issue
Block a user