* feat(api): implement commit functionality for journal entries * fix(extensions): make ExtensionSettings.clear() a real delete so disconnect flows work The 2026-03-30 multi-tenant refactor dropped all RLS policies on extension_data and recreated only SELECT/INSERT/UPDATE. Combined with `value jsonb NOT NULL`, every extension that called `settings.set(key, null)` to clear stored state (cloud-backup disconnect, skatteverket OAuth/AGI cleanup, arcim-migration consent reset) silently failed — the upsert hit the NOT NULL constraint and the error was swallowed, leaving users stuck with stale connection rows. Adds an `extension_data_delete` RLS policy, a `clear(key)` method backed by a real DELETE, switches the four affected handlers, and makes `set()` throw on Supabase error so this class of silent failure can't recur. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(journal-entries): add draft saving functionality to journal entry form * feat: add periodisk sammanställning report generation and CSV export - Implemented period date helpers in `period-dates.ts` for calculating start and end dates based on period type (monthly, quarterly, yearly). - Created `periodisk-sammanstallning.ts` to generate the periodisk sammanställning report, including data fetching, validation, and warning handling. - Developed CSV serializer in `periodisk-sammanstallning-csv.ts` for exporting the report in SKV574008 format. - Added new columns to `company_settings` for storing periodisk sammanställning settings and tax contact information via migration. - Introduced a new migration to add a `paid_with_private_funds` flag to `supplier_invoices` for tracking out-of-pocket expenses. - Updated journal entries to include the new source type for privately paid supplier invoices. * feat(migrations): add paid_with_private_funds flag to supplier_invoices and expand journal_entries.source_type CHECK * fix(ai_requests): drop existing policies and trigger before creating new ones * fix(migrations): ensure extension_data has a proper DELETE policy for ExtensionSettings.clear() * fix(supplier-invoices): update error handling for invalid input in POST request * fix: correct capitalization in project title * fix(migrations): resolve duplicate version 20260513120000 Two migrations shared the same timestamp prefix, causing schema_migrations_pkey collision on Supabase preview branches. Bump extension_data_delete_policy to 20260513120001. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
257 lines
9.8 KiB
TypeScript
257 lines
9.8 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { Input } from '@/components/ui/input'
|
|
import { Label } from '@/components/ui/label'
|
|
import { Checkbox } from '@/components/ui/checkbox'
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
import { Badge } from '@/components/ui/badge'
|
|
import type { CompanySettings } from '@/types'
|
|
|
|
interface TaxSettingsFormProps {
|
|
settings: CompanySettings
|
|
}
|
|
|
|
export function TaxSettingsForm({ settings }: TaxSettingsFormProps) {
|
|
const [vatRegistered, setVatRegistered] = useState(settings.vat_registered ?? false)
|
|
const [fSkatt, setFSkatt] = useState(settings.f_skatt ?? true)
|
|
const [paysSalaries, setPaysSalaries] = useState(settings.pays_salaries ?? false)
|
|
|
|
const isEnskildFirma = settings.entity_type === 'enskild_firma'
|
|
|
|
return (
|
|
<div className="space-y-8">
|
|
{/* Entity type — read-only */}
|
|
<section className="space-y-4">
|
|
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
|
Företagsform
|
|
</h2>
|
|
<div className="flex items-center gap-3">
|
|
<Badge variant="secondary" className="text-sm">
|
|
{settings.entity_type === 'aktiebolag' ? 'Aktiebolag' : 'Enskild firma'}
|
|
</Badge>
|
|
<p className="text-xs text-muted-foreground">
|
|
Företagsform kan inte ändras. Kontakta support vid behov.
|
|
</p>
|
|
</div>
|
|
</section>
|
|
|
|
{/* F-skatt */}
|
|
<section className="border-t border-border/8 pt-8 space-y-4">
|
|
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
|
Skatt & moms
|
|
</h2>
|
|
|
|
<div className="space-y-4">
|
|
<div className="flex items-start space-x-3">
|
|
<Checkbox
|
|
id="f_skatt"
|
|
checked={fSkatt}
|
|
onCheckedChange={(v) => setFSkatt(v === true)}
|
|
/>
|
|
<input type="hidden" name="f_skatt" value={fSkatt ? 'true' : 'false'} />
|
|
<div className="space-y-1">
|
|
<Label htmlFor="f_skatt" className="cursor-pointer">F-skattsedel</Label>
|
|
<p className="text-xs text-muted-foreground">
|
|
Godkänd för F-skatt (självständig näringsverksamhet).
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex items-start space-x-3">
|
|
<Checkbox
|
|
id="vat_registered"
|
|
checked={vatRegistered}
|
|
onCheckedChange={(v) => setVatRegistered(v === true)}
|
|
/>
|
|
<input type="hidden" name="vat_registered" value={vatRegistered ? 'true' : 'false'} />
|
|
<div className="space-y-1">
|
|
<Label htmlFor="vat_registered" className="cursor-pointer">Momsregistrerad</Label>
|
|
<p className="text-xs text-muted-foreground">
|
|
Obligatoriskt om omsättningen överstiger 120 000 kr per år.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
{vatRegistered && (
|
|
<div className="space-y-4 pl-7">
|
|
<div className="max-w-xs space-y-2">
|
|
<Label htmlFor="vat_number">Momsregistreringsnummer</Label>
|
|
<Input
|
|
id="vat_number"
|
|
name="vat_number"
|
|
placeholder="SE123456789001"
|
|
defaultValue={settings.vat_number || ''}
|
|
/>
|
|
<p className="text-xs text-muted-foreground">
|
|
Format: SE + organisationsnummer + 01
|
|
</p>
|
|
</div>
|
|
|
|
<div className="max-w-xs space-y-2">
|
|
<Label>Momsredovisningsperiod</Label>
|
|
<Select
|
|
name="moms_period"
|
|
defaultValue={settings.moms_period || undefined}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue placeholder="Välj period" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="monthly">Månad</SelectItem>
|
|
<SelectItem value="quarterly">Kvartal</SelectItem>
|
|
<SelectItem value="yearly">År</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
<p className="text-xs text-muted-foreground">
|
|
Enligt beslut från Skatteverket.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="max-w-xs space-y-2">
|
|
<Label>Period för periodisk sammanställning</Label>
|
|
<Select
|
|
name="periodisk_sammanstallning_period"
|
|
defaultValue={settings.periodisk_sammanstallning_period || 'monthly'}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue placeholder="Välj period" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="monthly">Månad</SelectItem>
|
|
<SelectItem value="quarterly">Kvartal</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
<p className="text-xs text-muted-foreground">
|
|
Varuförsäljning till EU ska normalt rapporteras månadsvis (35 kap. 2 § SFL).
|
|
Kvartal kräver tillstånd från Skatteverket och gäller endast tjänsteförsäljning.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</section>
|
|
|
|
{/* Tax contact — required for SKV-filings */}
|
|
<section className="border-t border-border/8 pt-8 space-y-4">
|
|
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
|
Kontaktperson för skatteärenden
|
|
</h2>
|
|
<p className="text-xs text-muted-foreground -mt-2">
|
|
Används som avsändare på filer till Skatteverket (periodisk sammanställning m.m.).
|
|
</p>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 max-w-2xl">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="tax_contact_name">Namn</Label>
|
|
<Input
|
|
id="tax_contact_name"
|
|
name="tax_contact_name"
|
|
defaultValue={settings.tax_contact_name || ''}
|
|
placeholder="Anna Andersson"
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="tax_contact_phone">Telefon</Label>
|
|
<Input
|
|
id="tax_contact_phone"
|
|
name="tax_contact_phone"
|
|
defaultValue={settings.tax_contact_phone || ''}
|
|
placeholder="08-123 45 67"
|
|
/>
|
|
</div>
|
|
<div className="space-y-2 sm:col-span-2">
|
|
<Label htmlFor="tax_contact_email">E-post</Label>
|
|
<Input
|
|
id="tax_contact_email"
|
|
name="tax_contact_email"
|
|
type="email"
|
|
defaultValue={settings.tax_contact_email || ''}
|
|
placeholder="anna@foretaget.se"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
{/* Fiscal year & salaries */}
|
|
<section className="border-t border-border/8 pt-8 space-y-4">
|
|
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
|
Räkenskapsår & löner
|
|
</h2>
|
|
|
|
<div className="max-w-xs space-y-2">
|
|
<Label>Räkenskapsårets startmånad</Label>
|
|
{isEnskildFirma ? (
|
|
<>
|
|
<Input value="Januari" disabled />
|
|
<input type="hidden" name="fiscal_year_start_month" value="1" />
|
|
<p className="text-xs text-muted-foreground">
|
|
Enskild firma måste använda kalenderår (BFL 3 kap.).
|
|
</p>
|
|
</>
|
|
) : (
|
|
<>
|
|
<Select
|
|
name="fiscal_year_start_month"
|
|
defaultValue={String(settings.fiscal_year_start_month || 1)}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{[
|
|
'Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni',
|
|
'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December',
|
|
].map((month, i) => (
|
|
<SelectItem key={i + 1} value={String(i + 1)}>{month}</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
<p className="text-xs text-muted-foreground">
|
|
Ändring påverkar framtida räkenskapsår.
|
|
</p>
|
|
</>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex items-start space-x-3">
|
|
<Checkbox
|
|
id="pays_salaries"
|
|
checked={paysSalaries}
|
|
onCheckedChange={(v) => setPaysSalaries(v === true)}
|
|
/>
|
|
<input type="hidden" name="pays_salaries" value={paysSalaries ? 'true' : 'false'} />
|
|
<div className="space-y-1">
|
|
<Label htmlFor="pays_salaries" className="cursor-pointer">Betalar löner</Label>
|
|
<p className="text-xs text-muted-foreground">
|
|
Påverkar vilka skattedeadlines som visas (arbetsgivardeklaration m.m.).
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
{/* Preliminary tax */}
|
|
<section className="border-t border-border/8 pt-8 space-y-4">
|
|
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
|
Preliminärskatt
|
|
</h2>
|
|
|
|
<div className="max-w-xs space-y-2">
|
|
<Label htmlFor="preliminary_tax_monthly">
|
|
Månatlig preliminärskatt (F-skatt)
|
|
</Label>
|
|
<Input
|
|
id="preliminary_tax_monthly"
|
|
name="preliminary_tax_monthly"
|
|
type="number"
|
|
defaultValue={settings.preliminary_tax_monthly || ''}
|
|
/>
|
|
<p className="text-xs text-muted-foreground">
|
|
Belopp i SEK som betalas varje månad.
|
|
</p>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
)
|
|
}
|