* feat(bookkeeping): per-account default VAT, oresavrundning momsfri Add a per-account "Standard moms" setting to the chart of accounts and use it to auto-fill the moms on a leverantorsfaktura-rad when that konto is picked. Oresavrundning (3740) ships as "Ingen moms", so a rounding line no longer inherits the 25 % rad-default and skews the moms. - chart_of_accounts.default_vat_rate (0/0.06/0.12/0.25, CHECK-constrained) - BEFORE INSERT trigger ships 3740 momsfri on every insert path; backfills existing 3740 rows - kontoplan editor: dead free-text momskod replaced with a Standard moms select - supplier-invoice rad auto-fills the rate from the konto default Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(supplier-invoices): configurable start number for the ankomstnummer series Add a company_settings.next_arrival_number start floor so a company can continue its leverantorsfaktura numbering from a previous system (e.g. Fortnox) instead of restarting the ankomstnummer at 1. get_next_arrival_number now floors the series via GREATEST(MAX(arrival_number)+1, next_arrival_number), so the floor can never move the series backwards or collide with the (company_id, arrival_number) unique index. The RPC is hardened while rewritten: SET search_path to empty, schema-qualified refs, and an auth.uid() membership check matching generate_invoice_number. Includes the settings UI field, sv/en strings, migration, and pg-real coverage. The CompanySettings type and Zod schema field for this feature landed earlier in 1bf3b641 (swept into the per-account VAT commit). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(dependabot): reduce open pull requests limit and group updates for better management --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
86 lines
3.6 KiB
TypeScript
86 lines
3.6 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,
|
|
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>
|
|
)
|
|
}
|