c1ea0d9bf2
The ISO 20022 pain.001 salary payment file could never be generated: the route required company_settings.iban/bic, but no settings screen wrote those columns, so every request returned 400. The specific reason was also swallowed by getErrorMessage (isSwedishUserMessage did not know "krävs"/"saknar"), surfacing only the generic "Förfrågan innehåller ogiltiga uppgifter" (issue #945). - Add IBAN + BIC inputs to Settings > Fakturering > Bankuppgifter. BIC auto-derives from the clearing number / bank already entered, so in practice only the IBAN is typed. Validated client- and server-side. - Route requires the company IBAN (canonical debtor form every Swedish bank accepts) and derives the BIC, with clear actionable errors. - Employees are unchanged: domestic clearing + account (BBAN), which is what Swedish payroll collects. Only the company (debtor) uses IBAN. - getErrorMessage recognizes "krävs"/"saknar" so payment-file reasons surface instead of the generic 400. Fixes #945 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
88 lines
3.8 KiB
TypeScript
88 lines
3.8 KiB
TypeScript
'use client'
|
|
|
|
import { useTranslations } from 'next-intl'
|
|
import { BankDetailsForm, validateBankFields } from '@/components/settings/BankDetailsForm'
|
|
import { InvoiceSettingsForm } from '@/components/settings/InvoiceSettingsForm'
|
|
import { InvoiceEmailTextsSettings } from '@/components/settings/InvoiceEmailTextsSettings'
|
|
import { InvoicePreviewCard } from '@/components/settings/InvoicePreviewCard'
|
|
import { PdfPrintSettings } from '@/components/settings/PdfPrintSettings'
|
|
import { SettingsFormWrapper } from '@/components/settings/SettingsFormWrapper'
|
|
import { SettingsLoadError } from '@/components/settings/SettingsLoadError'
|
|
import { SettingsLoadingSkeleton } from '@/components/settings/SettingsLoadingSkeleton'
|
|
import { useSettings } from '@/components/settings/useSettings'
|
|
import { useToast } from '@/components/ui/use-toast'
|
|
import { normaliseSwish } from '@/lib/payments/swish'
|
|
import { formatPlusgiroNumber } from '@/lib/bankgiro/luhn'
|
|
import type { CompanySettings } from '@/types'
|
|
|
|
export function InvoicingSettingsContent() {
|
|
const t = useTranslations('settings_invoicing')
|
|
const { settings, isLoading, updateSettings, refetch } = useSettings()
|
|
const { toast } = useToast()
|
|
|
|
if (isLoading) return <SettingsLoadingSkeleton />
|
|
if (!settings) return <SettingsLoadError onRetry={refetch} />
|
|
|
|
function handleSave(formData: FormData) {
|
|
const bankErrors = validateBankFields(formData)
|
|
if (bankErrors.length > 0) {
|
|
toast({
|
|
title: t('bank_validation_title'),
|
|
description: bankErrors.map(e => e.message).join(', '),
|
|
variant: 'destructive',
|
|
})
|
|
return {}
|
|
}
|
|
|
|
const updates: Record<string, unknown> = {
|
|
bank_name: formData.get('bank_name') as string,
|
|
clearing_number: formData.get('clearing_number') as string,
|
|
account_number: formData.get('account_number') as string,
|
|
bankgiro: (formData.get('bankgiro') as string) || null,
|
|
plusgiro: (formData.get('plusgiro') as string)?.trim()
|
|
? formatPlusgiroNumber((formData.get('plusgiro') as string).trim())
|
|
: null,
|
|
swish: normaliseSwish(formData.get('swish') as string) || null,
|
|
iban: (formData.get('iban') as string || '').replace(/\s/g, '').toUpperCase() || null,
|
|
bic: (formData.get('bic') as string || '').replace(/\s/g, '').toUpperCase() || null,
|
|
invoice_prefix: (formData.get('invoice_prefix') as string) || null,
|
|
next_invoice_number: parseInt(formData.get('next_invoice_number') as string) || 1,
|
|
next_arrival_number: parseInt(formData.get('next_arrival_number') as string) || 1,
|
|
invoice_default_days: parseInt(formData.get('invoice_default_days') as string) || 30,
|
|
invoice_default_notes: (formData.get('invoice_default_notes') as string) || null,
|
|
default_our_reference: (formData.get('default_our_reference') as string) || null,
|
|
}
|
|
return {
|
|
updates,
|
|
onSuccess: (data: Record<string, unknown>) => {
|
|
updateSettings(data as Partial<CompanySettings>)
|
|
},
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-8">
|
|
<div className="flex justify-end">
|
|
<InvoicePreviewCard settings={settings} />
|
|
</div>
|
|
|
|
<SettingsFormWrapper onSave={handleSave} className="space-y-8">
|
|
<BankDetailsForm settings={settings} />
|
|
<div className="border-t border-border pt-8">
|
|
<InvoiceSettingsForm settings={settings} />
|
|
</div>
|
|
</SettingsFormWrapper>
|
|
|
|
{/* PDF settings: saves individually via toggle switches */}
|
|
<div className="border-t border-border pt-8">
|
|
<PdfPrintSettings settings={settings} onUpdate={updateSettings} />
|
|
</div>
|
|
|
|
{/* Invoice email texts: autosaves on blur */}
|
|
<div className="border-t border-border pt-8">
|
|
<InvoiceEmailTextsSettings settings={settings} onUpdate={updateSettings} />
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|