refactor(ui): record detail pages as documents, not card piles (#1739)
Bring every record detail page onto the register-detail document grammar from #1624 (DetailSection/DefRow, one status element per the list pages' chips-mark-exceptions rule, one primary next step plus Förhandsgranska visible and everything else behind a ⋯ overflow menu, line tables on the dry-table idiom with the headline total in the serif): - invoices/[id] (11 cards, 13-button toolbar): Kund | Detaljer rows, Fakturarader table + totals, Anteckningar, Betalning, Påminnelser, Utskickshistorik (InvoiceDeliveryHistory flattened); title carries the doc type, related documents become link rows - supplier-invoices/[id], bookkeeping/[id] (serif title instead of font-mono, JournalEntryAttachments variant="section", CorrectionChain flattened), invoices/[id]/credit, assets/[id]/dispose (form as Fönster rows), salary employees/[id] (edit form behind Redigera in a dialog, Ingående saldon collapsed), salary runs/[id] + run panels (Betalfil, Skattebetalning, AGI, förmåner, override) and the payslip page - DetailSection gains an optional help slot (convention 7) Styling/structure only: no API, fetch, validation, state, dialog or permission change; every action stays reachable. Co-authored-by: Jakob Wennberg <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
co-authored by
Jakob Wennberg
Claude Fable 5
parent
db14ac18cb
commit
a92c492dbe
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { use, useCallback, useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||
import { use, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
@@ -8,20 +8,18 @@ import { ArrowLeft, Loader2, Lock } from 'lucide-react'
|
||||
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { DetailSection, DefRow } from '@/components/ui/detail-section'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { PageHeader } from '@/components/ui/page-header'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import {
|
||||
SettingsInput,
|
||||
SettingsRow,
|
||||
SettingsRowNote,
|
||||
SettingsSelect,
|
||||
} from '@/components/settings/SettingsRows'
|
||||
import { assessJamkning, assessJamkningEligibility } from '@/lib/bokslut/assets/jamkning'
|
||||
import { getErrorMessage } from '@/lib/errors/get-error-message'
|
||||
import { useCanWrite } from '@/lib/hooks/use-can-write'
|
||||
@@ -39,6 +37,10 @@ interface PeriodOption {
|
||||
|
||||
const VAT_TREATMENTS = ['standard_25', 'reverse_charge', 'export', 'exempt'] as const
|
||||
|
||||
// Flat Fönster inputs are sized by the row; amounts, dates and account
|
||||
// numbers get a fixed short width so the row does not stretch them.
|
||||
const FIELD_CLASS = 'max-w-44 flex-none tabular-nums'
|
||||
|
||||
function round2(value: number): number {
|
||||
return Math.round(value * 100) / 100
|
||||
}
|
||||
@@ -246,7 +248,10 @@ export default function DisposeAssetPage({ params }: { params: Promise<{ id: str
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<PageHeader title={t('title')} />
|
||||
<Card><CardContent className="space-y-3 p-6"><Skeleton className="h-6 w-1/3" /><Skeleton className="h-4 w-2/3" /></CardContent></Card>
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-6 w-1/3" />
|
||||
<Skeleton className="h-4 w-2/3" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -255,12 +260,10 @@ export default function DisposeAssetPage({ params }: { params: Promise<{ id: str
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<PageHeader title={t('title')} />
|
||||
<Card>
|
||||
<CardContent className="space-y-4 p-6">
|
||||
<p>{!asset ? t('not_found') : t('already_disposed', { date: formatDate(asset.disposed_at!) })}</p>
|
||||
<Link href="/assets"><Button variant="secondary"><ArrowLeft className="mr-1 h-4 w-4" />{t('back')}</Button></Link>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{!asset ? t('not_found') : t('already_disposed', { date: formatDate(asset.disposed_at!) })}
|
||||
</p>
|
||||
<Link href="/assets"><Button variant="secondary"><ArrowLeft className="mr-1 h-4 w-4" />{t('back')}</Button></Link>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -269,112 +272,222 @@ export default function DisposeAssetPage({ params }: { params: Promise<{ id: str
|
||||
const missingJamkningData = possibleInvestmentGood &&
|
||||
(originalInputVat === '' || originalDeductionPercent === '')
|
||||
|
||||
// Which rows the adjustment section shows, so the last one can drop its
|
||||
// hairline and the section never ends on a dangling rule.
|
||||
const showJamkningInputs = Boolean(eligibility?.withinAdjustmentPeriod)
|
||||
const showAssessment = jamkningAssessment !== null
|
||||
const showTransferConfirm = disposalType === 'business_transfer'
|
||||
const showDocumentConfirm = showTransferConfirm && transferNeedsDocument
|
||||
const assessmentIsLast = showAssessment && !showTransferConfirm
|
||||
const inputsAreLast = showJamkningInputs && !showAssessment && !showTransferConfirm
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<PageHeader
|
||||
title={t('title')}
|
||||
action={<Link href="/assets"><Button variant="secondary"><ArrowLeft className="mr-1 h-4 w-4" />{t('back')}</Button></Link>}
|
||||
/>
|
||||
<div className="space-y-8 stagger-enter">
|
||||
{/* Back link on its own quiet row, same as the register documents */}
|
||||
<Link
|
||||
href="/assets"
|
||||
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
{t('back')}
|
||||
</Link>
|
||||
|
||||
<Card>
|
||||
{/* data-ph-mask: the asset name is user data */}
|
||||
<CardHeader><CardTitle data-ph-mask="" className="text-base">{asset.name}</CardTitle></CardHeader>
|
||||
<CardContent className="space-y-2 p-6 pt-0 text-sm">
|
||||
<SummaryRow label={t('acquisition_cost')} value={formatCurrency(Number(asset.acquisition_cost))} />
|
||||
<SummaryRow label={t('acquired')} value={formatDate(asset.acquisition_date)} />
|
||||
<SummaryRow label={t('bas_accounts')} value={`${asset.bas_asset_account} / ${asset.bas_accumulated_account} / ${asset.bas_expense_account}`} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* data-ph-mask: the asset name is user data */}
|
||||
<PageHeader title={t('title')} description={<span data-ph-mask="">{asset.name}</span>} />
|
||||
|
||||
<Card>
|
||||
<CardHeader><CardTitle className="text-base">{t('details_title')}</CardTitle></CardHeader>
|
||||
<CardContent className="grid gap-4 p-6 pt-0 md:grid-cols-2">
|
||||
<Field label={t('type_label')} htmlFor="disposalType">
|
||||
<Select value={disposalType} onValueChange={(value) => setDisposalType(value as AssetDisposalType)}>
|
||||
<SelectTrigger id="disposalType"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="sale">{t('type_sale')}</SelectItem>
|
||||
<SelectItem value="scrap">{t('type_scrap')}</SelectItem>
|
||||
<SelectItem value="business_transfer">{t('type_business_transfer')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
<Field label={t('date_label')} htmlFor="disposalDate">
|
||||
<Input id="disposalDate" type="date" value={disposalDate} onChange={(event) => setDisposalDate(event.target.value)} className="tabular-nums" />
|
||||
</Field>
|
||||
<Field label={t('period_label')} htmlFor="period">
|
||||
<Select value={periodId} onValueChange={setPeriodId}>
|
||||
<SelectTrigger id="period"><SelectValue placeholder={t('period_placeholder')} /></SelectTrigger>
|
||||
<SelectContent>{periods.map((period) => <SelectItem key={period.id} value={period.id}>{period.name}{period.is_closed || period.locked_at ? ` (${t('locked')})` : ''}</SelectItem>)}</SelectContent>
|
||||
</Select>
|
||||
{periodLocked && <p className="text-xs text-destructive">{t('period_locked')}</p>}
|
||||
</Field>
|
||||
<Field label={disposalType === 'business_transfer' ? t('consideration_label') : t('proceeds_label')} htmlFor="proceeds">
|
||||
<Input id="proceeds" inputMode="decimal" value={proceeds} onChange={(event) => setProceeds(event.target.value)} disabled={disposalType === 'scrap'} className="tabular-nums" />
|
||||
</Field>
|
||||
{disposalType !== 'scrap' && <Field label={t('proceeds_account_label')} htmlFor="proceedsAccount"><Input id="proceedsAccount" value={proceedsAccount} onChange={(event) => setProceedsAccount(event.target.value)} className="tabular-nums" /></Field>}
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* The asset being disposed: read-only context as plain rows */}
|
||||
<DetailSection kicker={t('asset_section')}>
|
||||
<DefRow label={t('acquisition_cost')}>
|
||||
<span className="tabular-nums">{formatCurrency(Number(asset.acquisition_cost))}</span>
|
||||
</DefRow>
|
||||
<DefRow label={t('acquired')}>
|
||||
<span className="tabular-nums">{formatDate(asset.acquisition_date)}</span>
|
||||
</DefRow>
|
||||
<DefRow label={t('bas_accounts')}>
|
||||
<span className="tabular-nums">
|
||||
{`${asset.bas_asset_account} / ${asset.bas_accumulated_account} / ${asset.bas_expense_account}`}
|
||||
</span>
|
||||
</DefRow>
|
||||
</DetailSection>
|
||||
|
||||
{/* The disposal itself: flat hairline rows, label left, control right */}
|
||||
<DetailSection kicker={t('details_title')}>
|
||||
<SettingsRow label={t('type_label')} htmlFor="disposalType">
|
||||
<SettingsSelect
|
||||
id="disposalType"
|
||||
value={disposalType}
|
||||
onChange={(event) => setDisposalType(event.target.value as AssetDisposalType)}
|
||||
>
|
||||
<option value="sale">{t('type_sale')}</option>
|
||||
<option value="scrap">{t('type_scrap')}</option>
|
||||
<option value="business_transfer">{t('type_business_transfer')}</option>
|
||||
</SettingsSelect>
|
||||
</SettingsRow>
|
||||
<SettingsRow label={t('date_label')} htmlFor="disposalDate" align="baseline">
|
||||
<SettingsInput
|
||||
id="disposalDate"
|
||||
type="date"
|
||||
value={disposalDate}
|
||||
onChange={(event) => setDisposalDate(event.target.value)}
|
||||
className={FIELD_CLASS}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<SettingsRow label={t('period_label')} htmlFor="period">
|
||||
<SettingsSelect id="period" value={periodId} onChange={(event) => setPeriodId(event.target.value)}>
|
||||
<option value="" disabled>{t('period_placeholder')}</option>
|
||||
{periods.map((period) => (
|
||||
<option key={period.id} value={period.id}>
|
||||
{period.name}{period.is_closed || period.locked_at ? ` (${t('locked')})` : ''}
|
||||
</option>
|
||||
))}
|
||||
</SettingsSelect>
|
||||
{periodLocked && <p className="basis-full text-xs text-destructive">{t('period_locked')}</p>}
|
||||
</SettingsRow>
|
||||
<SettingsRow
|
||||
label={disposalType === 'business_transfer' ? t('consideration_label') : t('proceeds_label')}
|
||||
htmlFor="proceeds"
|
||||
align="baseline"
|
||||
borderless={disposalType === 'scrap'}
|
||||
>
|
||||
<SettingsInput
|
||||
id="proceeds"
|
||||
inputMode="decimal"
|
||||
value={proceeds}
|
||||
onChange={(event) => setProceeds(event.target.value)}
|
||||
disabled={disposalType === 'scrap'}
|
||||
className={FIELD_CLASS}
|
||||
/>
|
||||
</SettingsRow>
|
||||
{disposalType !== 'scrap' && (
|
||||
<SettingsRow label={t('proceeds_account_label')} htmlFor="proceedsAccount" align="baseline" borderless>
|
||||
<SettingsInput
|
||||
id="proceedsAccount"
|
||||
value={proceedsAccount}
|
||||
onChange={(event) => setProceedsAccount(event.target.value)}
|
||||
className={FIELD_CLASS}
|
||||
/>
|
||||
</SettingsRow>
|
||||
)}
|
||||
</DetailSection>
|
||||
|
||||
{disposalType === 'sale' && (
|
||||
<Card>
|
||||
<CardHeader><CardTitle className="text-base">{t('vat_title')}</CardTitle></CardHeader>
|
||||
<CardContent className="space-y-4 p-6 pt-0">
|
||||
<Field label={t('vat_treatment_label')} htmlFor="vatTreatment">
|
||||
<Select value={vatTreatment} onValueChange={(value) => setVatTreatment(value as VatTreatment)}>
|
||||
<SelectTrigger id="vatTreatment"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>{VAT_TREATMENTS.map((value) => <SelectItem key={value} value={value}>{t(`vat_${value}`)}</SelectItem>)}</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
<div className="rounded-lg bg-secondary/40 p-3 text-xs">
|
||||
<SummaryRow label={t('gross')} value={formatCurrency(proceedsNumber)} />
|
||||
<SummaryRow label={t('vat')} value={formatCurrency(vatAmount)} />
|
||||
<SummaryRow label={t('net')} value={formatCurrency(netProceeds)} strong />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<DetailSection kicker={t('vat_title')}>
|
||||
<SettingsRow label={t('vat_treatment_label')} htmlFor="vatTreatment">
|
||||
<SettingsSelect
|
||||
id="vatTreatment"
|
||||
value={vatTreatment}
|
||||
onChange={(event) => setVatTreatment(event.target.value as VatTreatment)}
|
||||
>
|
||||
{VAT_TREATMENTS.map((value) => (
|
||||
<option key={value} value={value}>{t(`vat_${value}`)}</option>
|
||||
))}
|
||||
</SettingsSelect>
|
||||
</SettingsRow>
|
||||
<SettingsRow label={t('gross')}>
|
||||
<span className="tabular-nums">{formatCurrency(proceedsNumber)}</span>
|
||||
</SettingsRow>
|
||||
<SettingsRow label={t('vat')}>
|
||||
<span className="tabular-nums">{formatCurrency(vatAmount)}</span>
|
||||
</SettingsRow>
|
||||
<SettingsRow label={t('net')} borderless>
|
||||
<span className="font-medium tabular-nums">{formatCurrency(netProceeds)}</span>
|
||||
</SettingsRow>
|
||||
</DetailSection>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader><CardTitle className="text-base">{t('adjustment_title')}</CardTitle></CardHeader>
|
||||
<CardContent className="space-y-4 p-6 pt-0">
|
||||
{eligibility?.withinAdjustmentPeriod
|
||||
? <Badge variant="warning">{t('within_adjustment_period', { years: eligibility.remainingYears, total: eligibility.totalYears })}</Badge>
|
||||
: <Badge variant="secondary">{t('outside_adjustment_period')}</Badge>}
|
||||
{eligibility?.withinAdjustmentPeriod && (
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<Field label={t('original_vat_label')} htmlFor="originalInputVat" hint={t('original_vat_hint', { threshold: eligibility.threshold })}>
|
||||
<Input id="originalInputVat" inputMode="decimal" value={originalInputVat} onChange={(event) => setOriginalInputVat(event.target.value)} className="tabular-nums" />
|
||||
</Field>
|
||||
<Field label={t('original_percent_label')} htmlFor="originalDeductionPercent">
|
||||
<Input id="originalDeductionPercent" type="number" min={0} max={100} value={originalDeductionPercent} onChange={(event) => setOriginalDeductionPercent(event.target.value)} className="tabular-nums" />
|
||||
</Field>
|
||||
</div>
|
||||
)}
|
||||
{jamkningAssessment && (
|
||||
<div className="rounded-lg border border-border bg-secondary/40 p-3 text-sm">
|
||||
<SummaryRow label={t('adjustment_direction')} value={t(`direction_${jamkningAssessment.direction}`)} />
|
||||
<SummaryRow label={t('adjustment_amount')} value={formatCurrency(jamkningAssessment.amount)} strong />
|
||||
{jamkningAssessment.capped && <p className="mt-2 text-xs text-muted-foreground">{t('adjustment_capped')}</p>}
|
||||
</div>
|
||||
)}
|
||||
{disposalType === 'business_transfer' && (
|
||||
<div className="flex items-center gap-3 rounded-lg border border-border p-3">
|
||||
<Switch id="businessTransfer" checked={businessTransferConfirmed} onCheckedChange={setBusinessTransferConfirmed} />
|
||||
<Label htmlFor="businessTransfer" className="cursor-pointer">{t('business_transfer_confirm')}</Label>
|
||||
</div>
|
||||
)}
|
||||
{disposalType === 'business_transfer' && transferNeedsDocument && (
|
||||
<div className="flex items-center gap-3 rounded-lg border border-border p-3">
|
||||
<Switch id="adjustmentDocument" checked={adjustmentDocumentConfirmed} onCheckedChange={setAdjustmentDocumentConfirmed} />
|
||||
<Label htmlFor="adjustmentDocument" className="cursor-pointer">{t('adjustment_document_confirm')}</Label>
|
||||
</div>
|
||||
)}
|
||||
{missingJamkningData && <p className="text-xs text-destructive">{t('adjustment_data_required')}</p>}
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* Input VAT adjustment: the period status sits on the kicker line
|
||||
(a chip only when the asset is still inside the period), the
|
||||
underlag as rows, the assessment as read-only rows below. */}
|
||||
<DetailSection
|
||||
kicker={t('adjustment_title')}
|
||||
aside={
|
||||
eligibility?.withinAdjustmentPeriod ? (
|
||||
<Badge variant="warning">
|
||||
{t('within_adjustment_period', { years: eligibility.remainingYears, total: eligibility.totalYears })}
|
||||
</Badge>
|
||||
) : (
|
||||
<span className="text-[11px] text-muted-foreground">{t('outside_adjustment_period')}</span>
|
||||
)
|
||||
}
|
||||
>
|
||||
{showJamkningInputs && eligibility && (
|
||||
<>
|
||||
<SettingsRow
|
||||
label={t('original_vat_label')}
|
||||
htmlFor="originalInputVat"
|
||||
help={t('original_vat_hint', { threshold: eligibility.threshold })}
|
||||
align="baseline"
|
||||
>
|
||||
<SettingsInput
|
||||
id="originalInputVat"
|
||||
inputMode="decimal"
|
||||
value={originalInputVat}
|
||||
onChange={(event) => setOriginalInputVat(event.target.value)}
|
||||
className={FIELD_CLASS}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<SettingsRow
|
||||
label={t('original_percent_label')}
|
||||
htmlFor="originalDeductionPercent"
|
||||
align="baseline"
|
||||
borderless={inputsAreLast}
|
||||
>
|
||||
<SettingsInput
|
||||
id="originalDeductionPercent"
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
value={originalDeductionPercent}
|
||||
onChange={(event) => setOriginalDeductionPercent(event.target.value)}
|
||||
className={FIELD_CLASS}
|
||||
/>
|
||||
</SettingsRow>
|
||||
</>
|
||||
)}
|
||||
{jamkningAssessment && (
|
||||
<>
|
||||
<SettingsRow label={t('adjustment_direction')}>
|
||||
{t(`direction_${jamkningAssessment.direction}`)}
|
||||
</SettingsRow>
|
||||
<SettingsRow label={t('adjustment_amount')} borderless={assessmentIsLast}>
|
||||
<span className="font-medium tabular-nums">{formatCurrency(jamkningAssessment.amount)}</span>
|
||||
{jamkningAssessment.capped && (
|
||||
<SettingsRowNote className="basis-full">{t('adjustment_capped')}</SettingsRowNote>
|
||||
)}
|
||||
</SettingsRow>
|
||||
</>
|
||||
)}
|
||||
{showTransferConfirm && (
|
||||
<SettingsRow label={t('type_business_transfer')} borderless={!showDocumentConfirm}>
|
||||
<Switch
|
||||
id="businessTransfer"
|
||||
checked={businessTransferConfirmed}
|
||||
onCheckedChange={setBusinessTransferConfirmed}
|
||||
/>
|
||||
<Label htmlFor="businessTransfer" className="min-w-0 flex-1 cursor-pointer font-normal leading-5">
|
||||
{t('business_transfer_confirm')}
|
||||
</Label>
|
||||
</SettingsRow>
|
||||
)}
|
||||
{showDocumentConfirm && (
|
||||
<SettingsRow label={t('adjustment_document_label')} borderless>
|
||||
<Switch
|
||||
id="adjustmentDocument"
|
||||
checked={adjustmentDocumentConfirmed}
|
||||
onCheckedChange={setAdjustmentDocumentConfirmed}
|
||||
/>
|
||||
<Label htmlFor="adjustmentDocument" className="min-w-0 flex-1 cursor-pointer font-normal leading-5">
|
||||
{t('adjustment_document_confirm')}
|
||||
</Label>
|
||||
</SettingsRow>
|
||||
)}
|
||||
{missingJamkningData && (
|
||||
<p className="mt-3 text-xs text-destructive">{t('adjustment_data_required')}</p>
|
||||
)}
|
||||
</DetailSection>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
{/* Actions: one footer row, so the flow ends on the button it arms */}
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
<Link href="/assets"><Button variant="secondary" disabled={submitting}>{t('cancel')}</Button></Link>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
@@ -389,11 +502,3 @@ export default function DisposeAssetPage({ params }: { params: Promise<{ id: str
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Field({ label, htmlFor, hint, children }: { label: string; htmlFor: string; hint?: string; children: ReactNode }) {
|
||||
return <div className="space-y-2"><Label htmlFor={htmlFor}>{label}</Label>{children}{hint && <p className="text-xs text-muted-foreground">{hint}</p>}</div>
|
||||
}
|
||||
|
||||
function SummaryRow({ label, value, strong = false }: { label: string; value: string; strong?: boolean }) {
|
||||
return <div className={`flex justify-between gap-4 ${strong ? 'font-medium' : ''}`}><span className="text-muted-foreground">{label}</span><span className="text-right tabular-nums">{value}</span></div>
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,15 +5,17 @@ import { useRouter } from 'next/navigation'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { createClient } from '@/lib/supabase/client'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import { DetailSection, DefRow } from '@/components/ui/detail-section'
|
||||
import { TH_CLASS, TD_CLASS } from '@/components/ui/dry-table'
|
||||
import { AttnLine } from '@/components/ui/attn-line'
|
||||
import { HelpPopover } from '@/components/ui/help-popover'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { cn, formatCurrency, formatDate } from '@/lib/utils'
|
||||
import { getVatTreatmentLabel } from '@/lib/invoices/vat-rules'
|
||||
import { Loader2, ArrowLeft, AlertTriangle, Lock } from 'lucide-react'
|
||||
import { Loader2, ArrowLeft, Lock } from 'lucide-react'
|
||||
import { useCanWrite } from '@/lib/hooks/use-can-write'
|
||||
import SendInvoiceDialog from '@/components/invoices/SendInvoiceDialog'
|
||||
import { useCompany, useCapability } from '@/contexts/CompanyContext'
|
||||
@@ -182,8 +184,10 @@ export default function CreateCreditNotePage({ params }: { params: Promise<{ id:
|
||||
}
|
||||
}
|
||||
|
||||
const confirmMismatch = Boolean(confirmText) && confirmText !== invoice.invoice_number
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-3xl mx-auto">
|
||||
<div className="space-y-8 stagger-enter">
|
||||
{createdCreditNote && (
|
||||
<SendInvoiceDialog
|
||||
open={showSendPrompt}
|
||||
@@ -193,188 +197,173 @@ export default function CreateCreditNotePage({ params }: { params: Promise<{ id:
|
||||
onSuccess={() => undefined}
|
||||
/>
|
||||
)}
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-4">
|
||||
<Button variant="ghost" size="icon" onClick={() => router.back()} aria-label={t('back')}>
|
||||
<ArrowLeft className="h-5 w-5" />
|
||||
</Button>
|
||||
<div>
|
||||
|
||||
{/* Back link on its own quiet row, same as the invoice document */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => router.back()}
|
||||
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
{t('back')}
|
||||
</button>
|
||||
|
||||
{/* Header: serif title with the explanation behind "?", the credited
|
||||
invoice as the kicker, and the one attention sentence under it. */}
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<h1 className="font-display text-2xl leading-8 tracking-tight">{t('title')}</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('subtitle', { number: invoice.invoice_number ?? '' })}
|
||||
</p>
|
||||
<HelpPopover>{t('warning_description')}</HelpPopover>
|
||||
</div>
|
||||
{/* data-ph-mask: the kicker carries the invoice number */}
|
||||
<p data-ph-mask="" className="mt-1 text-sm text-muted-foreground">
|
||||
{t('subtitle', { number: invoice.invoice_number ?? '' })}
|
||||
</p>
|
||||
<AttnLine className="mt-3">{t('warning_title')}</AttnLine>
|
||||
</div>
|
||||
|
||||
{/* Warning */}
|
||||
<Card className="border-destructive/50 bg-destructive/5">
|
||||
<CardContent className="flex items-start gap-4 pt-6">
|
||||
<AlertTriangle className="h-5 w-5 text-destructive flex-shrink-0 mt-0.5" />
|
||||
<div>
|
||||
<p className="font-medium text-destructive">{t('warning_title')}</p>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{t('warning_description')}
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* Original invoice: read-only context as plain rows */}
|
||||
<DetailSection kicker={t('original_card_title')}>
|
||||
<DefRow label={t('invoice_number_label')}>
|
||||
<span className="tabular-nums">{invoice.invoice_number}</span>
|
||||
</DefRow>
|
||||
<DefRow label={t('date_label')}>
|
||||
<span className="tabular-nums">{formatDate(invoice.invoice_date)}</span>
|
||||
</DefRow>
|
||||
<DefRow label={t('customer_label')}>{customer.name}</DefRow>
|
||||
<DefRow label={t('vat_treatment_label')}>{getVatTreatmentLabel(invoice.vat_treatment)}</DefRow>
|
||||
</DetailSection>
|
||||
|
||||
{/* Original invoice info */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('original_card_title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span className="text-muted-foreground">{t('invoice_number_label')}</span>
|
||||
<span className="ml-2 font-medium">{invoice.invoice_number}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">{t('date_label')}</span>
|
||||
<span className="ml-2">{formatDate(invoice.invoice_date)}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">{t('customer_label')}</span>
|
||||
<span className="ml-2">{customer.name}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">{t('vat_treatment_label')}</span>
|
||||
<span className="ml-2">{getVatTreatmentLabel(invoice.vat_treatment)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Credit note preview */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('preview_card_title')}</CardTitle>
|
||||
{/* data-ph-mask: the invoice number is user data */}
|
||||
<CardDescription data-ph-mask="">
|
||||
{/* Credit note preview: the invoice lines negated, as the list-page
|
||||
table idiom straight on the panel, totals as a right-aligned block. */}
|
||||
<DetailSection
|
||||
kicker={t('preview_card_title')}
|
||||
aside={
|
||||
// data-ph-mask: the credit note number derives from the invoice number
|
||||
<span data-ph-mask="" className="text-[11px] tabular-nums text-muted-foreground">
|
||||
{t('preview_card_description', { number: invoice.invoice_number ?? '' })}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="grid grid-cols-12 gap-4 text-sm font-medium text-muted-foreground border-b pb-2">
|
||||
<div className="col-span-5">{t('th_description')}</div>
|
||||
<div className="col-span-2 text-right">{t('th_quantity')}</div>
|
||||
<div className="col-span-1 text-center">{t('th_unit')}</div>
|
||||
<div className="col-span-2 text-right">{t('th_unit_price')}</div>
|
||||
<div className="col-span-2 text-right">{t('th_amount')}</div>
|
||||
</div>
|
||||
|
||||
{/* Items (negated) */}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<table className="hidden w-full border-collapse text-[13px] sm:table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className={cn(TH_CLASS, 'pl-0')}>{t('th_description')}</th>
|
||||
<th className={cn(TH_CLASS, 'text-right')}>{t('th_quantity')}</th>
|
||||
<th className={TH_CLASS}>{t('th_unit')}</th>
|
||||
<th className={cn(TH_CLASS, 'text-right')}>{t('th_unit_price')}</th>
|
||||
<th className={cn(TH_CLASS, 'pr-0 text-right')}>{t('th_amount')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{invoice.items.map((item) => (
|
||||
<div key={item.id} className="grid grid-cols-12 gap-4 text-sm">
|
||||
<div className="col-span-5">{item.description}</div>
|
||||
<div className="col-span-2 text-right text-destructive">
|
||||
<tr key={item.id}>
|
||||
<td className={cn(TD_CLASS, 'pl-0')}>{item.description}</td>
|
||||
<td className={cn(TD_CLASS, 'text-right tabular-nums text-destructive')}>
|
||||
-{Math.abs(item.quantity)}
|
||||
</div>
|
||||
<div className="col-span-1 text-center">{item.unit}</div>
|
||||
<div className="col-span-2 text-right">
|
||||
</td>
|
||||
<td className={cn(TD_CLASS, 'text-muted-foreground')}>{item.unit}</td>
|
||||
<td className={cn(TD_CLASS, 'text-right tabular-nums')}>
|
||||
{formatCurrency(item.unit_price, invoice.currency)}
|
||||
</div>
|
||||
<div className="col-span-2 text-right font-medium text-destructive">
|
||||
</td>
|
||||
<td className={cn(TD_CLASS, 'pr-0 text-right tabular-nums text-destructive')}>
|
||||
{formatCurrency(-Math.abs(item.line_total), invoice.currency)}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* Totals (negated) */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('subtotal')}</span>
|
||||
<span className="text-destructive">
|
||||
{formatCurrency(-Math.abs(invoice.subtotal), invoice.currency)}
|
||||
</span>
|
||||
{/* Mobile: one flat row per line, no numeric columns to cram. */}
|
||||
<div className="divide-y divide-border text-sm sm:hidden">
|
||||
{invoice.items.map((item) => (
|
||||
<div key={item.id} className="flex items-start justify-between gap-4 py-3">
|
||||
<div className="min-w-0">
|
||||
<p>{item.description}</p>
|
||||
<p className="text-xs text-muted-foreground tabular-nums">
|
||||
-{Math.abs(item.quantity)} {item.unit} × {formatCurrency(item.unit_price, invoice.currency)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('vat_at_rate', { rate: invoice.vat_rate })}</span>
|
||||
<span className="text-destructive">
|
||||
{formatCurrency(-Math.abs(invoice.vat_amount), invoice.currency)}
|
||||
</span>
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="flex justify-between font-bold text-lg">
|
||||
<span>{t('total')}</span>
|
||||
<span className="text-destructive">
|
||||
{formatCurrency(-Math.abs(invoice.total), invoice.currency)}
|
||||
</span>
|
||||
</div>
|
||||
{invoice.currency !== 'SEK' && invoice.total_sek && (
|
||||
<div className="flex justify-between text-sm text-muted-foreground">
|
||||
<span>{t('in_sek', { rate: invoice.exchange_rate ?? 1 })}</span>
|
||||
<span className="text-destructive">
|
||||
{formatCurrency(-Math.abs(invoice.total_sek))}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<span className="shrink-0 tabular-nums text-destructive">
|
||||
{formatCurrency(-Math.abs(item.line_total), invoice.currency)}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="ml-auto mt-4 w-full max-w-xs space-y-1 text-sm tabular-nums">
|
||||
<div className="flex justify-between gap-4">
|
||||
<span className="text-muted-foreground">{t('subtotal')}</span>
|
||||
<span className="text-destructive">
|
||||
{formatCurrency(-Math.abs(invoice.subtotal), invoice.currency)}
|
||||
</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Reason */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('reason_card_title')}</CardTitle>
|
||||
<CardDescription>
|
||||
{t('reason_card_description')}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="reason">{t('reason_label')}</Label>
|
||||
<Textarea
|
||||
id="reason"
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
placeholder={t('reason_placeholder')}
|
||||
rows={3}
|
||||
/>
|
||||
<div className="flex justify-between gap-4">
|
||||
<span className="text-muted-foreground">{t('vat_at_rate', { rate: invoice.vat_rate })}</span>
|
||||
<span className="text-destructive">
|
||||
{formatCurrency(-Math.abs(invoice.vat_amount), invoice.currency)}
|
||||
</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="flex items-baseline justify-between gap-4 border-t border-border pt-2">
|
||||
<span>{t('total')}</span>
|
||||
<span className="font-display text-xl text-destructive">
|
||||
{formatCurrency(-Math.abs(invoice.total), invoice.currency)}
|
||||
</span>
|
||||
</div>
|
||||
{invoice.currency !== 'SEK' && invoice.total_sek && (
|
||||
<div className="flex justify-between gap-4 text-muted-foreground">
|
||||
<span>{t('in_sek', { rate: invoice.exchange_rate ?? 1 })}</span>
|
||||
<span className="text-destructive">{formatCurrency(-Math.abs(invoice.total_sek))}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DetailSection>
|
||||
|
||||
{/* Confirmation */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('confirm_card_title')}</CardTitle>
|
||||
<CardDescription>
|
||||
{t('confirm_card_description_1')}
|
||||
{/* data-ph-mask: the invoice number is user data */}
|
||||
<span data-ph-mask="" className="font-mono font-semibold text-foreground">{invoice.invoice_number}</span>
|
||||
{t('confirm_card_description_2')}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Input
|
||||
value={confirmText}
|
||||
onChange={(e) => setConfirmText(e.target.value)}
|
||||
placeholder={invoice.invoice_number ?? ''}
|
||||
disabled={!invoice.invoice_number}
|
||||
className={cn(
|
||||
// ph-no-capture: the placeholder carries the invoice number, and
|
||||
// replay masking covers input values, not attributes.
|
||||
'ph-no-capture',
|
||||
confirmText && confirmText !== invoice.invoice_number && 'border-destructive'
|
||||
)}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* Reason: shown on the credit note (the note lives behind the "?") */}
|
||||
<DetailSection
|
||||
kicker={t('reason_card_title')}
|
||||
help={<HelpPopover>{t('reason_card_description')}</HelpPopover>}
|
||||
>
|
||||
<Label htmlFor="reason" className="sr-only">{t('reason_label')}</Label>
|
||||
<Textarea
|
||||
id="reason"
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
placeholder={t('reason_placeholder')}
|
||||
rows={3}
|
||||
/>
|
||||
</DetailSection>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex justify-end gap-4">
|
||||
{/* Confirmation: type the invoice number to arm the action */}
|
||||
<DetailSection kicker={t('confirm_card_title')}>
|
||||
<Label htmlFor="confirm-invoice-number" className="block text-sm font-normal leading-5 text-muted-foreground">
|
||||
{t('confirm_card_description_1')}
|
||||
{/* data-ph-mask: the invoice number is user data */}
|
||||
<span data-ph-mask="" className="font-mono font-semibold text-foreground">{invoice.invoice_number}</span>
|
||||
{t('confirm_card_description_2')}
|
||||
</Label>
|
||||
<Input
|
||||
id="confirm-invoice-number"
|
||||
value={confirmText}
|
||||
onChange={(e) => setConfirmText(e.target.value)}
|
||||
placeholder={invoice.invoice_number ?? ''}
|
||||
disabled={!invoice.invoice_number}
|
||||
className={cn(
|
||||
// ph-no-capture: the placeholder carries the invoice number, and
|
||||
// replay masking covers input values, not attributes.
|
||||
'ph-no-capture mt-3 max-w-xs',
|
||||
confirmMismatch && 'border-destructive'
|
||||
)}
|
||||
/>
|
||||
</DetailSection>
|
||||
|
||||
{/* Actions: one footer row right after the confirm step, so the flow
|
||||
reads top to bottom and ends on the button it arms. */}
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => router.back()}>
|
||||
{t('cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={handleSubmit}
|
||||
disabled={
|
||||
isSubmitting ||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -4,9 +4,11 @@ import { use, useEffect, useMemo, useState } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { ArrowLeft, Calculator, Loader2 } from 'lucide-react'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DetailSection } from '@/components/ui/detail-section'
|
||||
import { HelpPopover } from '@/components/ui/help-popover'
|
||||
import { TH_CLASS, TD_CLASS } from '@/components/ui/dry-table'
|
||||
import { SalaryCalendar } from '@/components/salary/SalaryCalendar'
|
||||
import { SalaryOverridePanel } from '@/components/salary/SalaryOverridePanel'
|
||||
import { cn, formatCurrency } from '@/lib/utils'
|
||||
@@ -55,6 +57,17 @@ const LINE_ITEM_TYPE_KEYS: Record<SalaryLineItemType, string> = {
|
||||
other: 'li_other',
|
||||
}
|
||||
|
||||
// Same chip vocabulary as the Löner list and the run header (chips mark
|
||||
// exceptions): booked renders as muted text, everything else as a chip.
|
||||
const STATUS_VARIANTS: Record<string, 'default' | 'secondary' | 'success' | 'warning' | 'destructive' | 'outline'> = {
|
||||
draft: 'secondary',
|
||||
review: 'secondary',
|
||||
approved: 'secondary',
|
||||
paid: 'success',
|
||||
booked: 'success',
|
||||
corrected: 'outline',
|
||||
}
|
||||
|
||||
interface DetailResponse {
|
||||
run: SalaryRun
|
||||
runEmployee: SalaryRunEmployee & { employee: EmployeeMasked; line_items: SalaryLineItem[] }
|
||||
@@ -66,6 +79,7 @@ export default function SalaryRunEmployeeDetailPage({
|
||||
params: Promise<{ id: string; employeeId: string }>
|
||||
}) {
|
||||
const t = useTranslations('salary_run_employee')
|
||||
const tSalary = useTranslations('salary')
|
||||
const { id: runId, employeeId } = use(params)
|
||||
const [data, setData] = useState<DetailResponse | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
@@ -159,13 +173,12 @@ export default function SalaryRunEmployeeDetailPage({
|
||||
<div className="space-y-3">
|
||||
<Link
|
||||
href={`/salary/runs/${runId}`}
|
||||
className="inline-flex items-center text-sm text-muted-foreground hover:underline"
|
||||
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ArrowLeft className="mr-1 h-3.5 w-3.5" /> {t('back_to_run')}
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
{t('back_to_run')}
|
||||
</Link>
|
||||
<div className="rounded-lg bg-destructive/10 p-3 text-sm text-destructive">
|
||||
{error ?? t('error_load_employee')}
|
||||
</div>
|
||||
<p className="text-sm text-destructive">{error ?? t('error_load_employee')}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -175,63 +188,93 @@ export default function SalaryRunEmployeeDetailPage({
|
||||
const lineItems = runEmployee.line_items ?? []
|
||||
const periodLabel = `${run.period_year}-${String(run.period_month).padStart(2, '0')}`
|
||||
const readOnly = run.status !== 'draft' && run.status !== 'review'
|
||||
const statusLabel = tSalary(`status_${run.status}`)
|
||||
|
||||
const taxValue = runEmployee.tax_withheld_override ?? runEmployee.tax_withheld
|
||||
const taxOverridden = runEmployee.tax_withheld_override !== null
|
||||
const avgifterOverridden = runEmployee.avgifter_amount_override !== null
|
||||
const kpis: Array<{ label: string; value: number; accent?: boolean; overridden?: boolean }> = [
|
||||
{ label: t('gross'), value: runEmployee.gross_salary },
|
||||
{ label: t('tax'), value: taxValue, overridden: taxOverridden },
|
||||
{
|
||||
label: t('net'),
|
||||
value: runEmployee.net_salary + (runEmployee.tax_withheld - taxValue),
|
||||
accent: true,
|
||||
overridden: taxOverridden,
|
||||
},
|
||||
{
|
||||
label: t('avgifter'),
|
||||
value: runEmployee.avgifter_amount_override ?? runEmployee.avgifter_amount,
|
||||
overridden: avgifterOverridden,
|
||||
},
|
||||
]
|
||||
const absenceCounts = [
|
||||
{ label: t('sick_days'), days: liveCounts?.sick ?? runEmployee.sick_days },
|
||||
{ label: t('vab_days'), days: liveCounts?.vab ?? runEmployee.vab_days },
|
||||
{ label: t('parental_days'), days: liveCounts?.parental ?? runEmployee.parental_days },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
{/* Header */}
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-8 stagger-enter">
|
||||
{/* Back link on its own quiet row */}
|
||||
<div>
|
||||
<Link
|
||||
href={`/salary/runs/${runId}`}
|
||||
className="inline-flex items-center text-sm text-muted-foreground hover:underline"
|
||||
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ArrowLeft className="mr-1 h-3.5 w-3.5" /> {t('back_to_run')}
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
{t('back_to_run')}
|
||||
</Link>
|
||||
<div className="flex flex-wrap items-baseline justify-between gap-2">
|
||||
<div>
|
||||
<h1 className="font-display text-2xl tracking-tight">
|
||||
</div>
|
||||
|
||||
{/* Header: serif name with the run's status as the one status element,
|
||||
a quiet meta line, and the next step on the right. */}
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div className="min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<h1 className="font-display text-2xl leading-8 tracking-tight">
|
||||
{employee.first_name} {employee.last_name}
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground tabular-nums">
|
||||
{employee.personnummer_masked} · {t('payslip_period', { period: periodLabel })}
|
||||
</p>
|
||||
{run.status === 'booked' ? (
|
||||
<span className="text-sm text-muted-foreground">{statusLabel}</span>
|
||||
) : (
|
||||
<Badge variant={STATUS_VARIANTS[run.status] || 'secondary'}>{statusLabel}</Badge>
|
||||
)}
|
||||
</div>
|
||||
{run.status === 'draft' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleCalculate}
|
||||
disabled={calculating}
|
||||
>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
<span className="tabular-nums">{employee.personnummer_masked}</span>
|
||||
{' · '}
|
||||
<span className="tabular-nums">{t('payslip_period', { period: periodLabel })}</span>
|
||||
</p>
|
||||
</div>
|
||||
{run.status === 'draft' && (
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<Button onClick={handleCalculate} disabled={calculating}>
|
||||
{calculating ? (
|
||||
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Calculator className="mr-1.5 h-3.5 w-3.5" />
|
||||
<Calculator className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
{t('calculate')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Summary */}
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
|
||||
<SummaryCard label={t('gross')} value={runEmployee.gross_salary} />
|
||||
<SummaryCard
|
||||
label={t('tax')}
|
||||
value={runEmployee.tax_withheld_override ?? runEmployee.tax_withheld}
|
||||
overridden={runEmployee.tax_withheld_override !== null}
|
||||
/>
|
||||
<SummaryCard
|
||||
label={t('net')}
|
||||
value={runEmployee.net_salary + (runEmployee.tax_withheld - (runEmployee.tax_withheld_override ?? runEmployee.tax_withheld))}
|
||||
accent
|
||||
overridden={runEmployee.tax_withheld_override !== null}
|
||||
/>
|
||||
<SummaryCard
|
||||
label={t('avgifter')}
|
||||
value={runEmployee.avgifter_amount_override ?? runEmployee.avgifter_amount}
|
||||
overridden={runEmployee.avgifter_amount_override !== null}
|
||||
/>
|
||||
{/* Summary: flat label/number pairs, no tiles. The override is the
|
||||
exception, so it is a chip next to the label. */}
|
||||
<div className="flex flex-wrap gap-x-10 gap-y-4">
|
||||
{kpis.map(({ label, value, accent, overridden }) => (
|
||||
<div key={label} className="min-w-0">
|
||||
<p className="flex items-center gap-2 text-[11px] uppercase tracking-wider text-muted-foreground">
|
||||
{label}
|
||||
{overridden && <Badge variant="warning">{t('adjusted_badge')}</Badge>}
|
||||
</p>
|
||||
<p className={cn('mt-1 font-display text-xl tabular-nums leading-none', accent && 'text-success')}>
|
||||
{formatCurrency(value)}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Advanced mode: per-employee override of tax / arbetsgivaravgift */}
|
||||
@@ -251,95 +294,69 @@ export default function SalaryRunEmployeeDetailPage({
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Unified calendar: worked time (for hourly) + absence on the same grid */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('time_absence_title')}</CardTitle>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{/* Unified calendar: worked time (for hourly) + absence on the same grid.
|
||||
The how-to lives behind the kicker's "?" (convention 7). */}
|
||||
<DetailSection
|
||||
kicker={t('time_absence_title')}
|
||||
help={
|
||||
<HelpPopover>
|
||||
{employee.salary_type === 'hourly'
|
||||
? t('calendar_hint_hourly')
|
||||
: t('calendar_hint_monthly')}
|
||||
</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SalaryCalendar
|
||||
employeeId={employee.id}
|
||||
salaryType={employee.salary_type}
|
||||
periodStart={periodStart}
|
||||
periodEnd={periodEnd}
|
||||
salaryRunEmployeeId={runEmployee.id}
|
||||
readOnly={readOnly}
|
||||
onChange={load}
|
||||
onAbsenceCountsChange={setLiveCounts}
|
||||
/>
|
||||
<div className="mt-3 grid grid-cols-3 gap-2 text-xs">
|
||||
<AbsenceCount label={t('sick_days')} days={liveCounts?.sick ?? runEmployee.sick_days} />
|
||||
<AbsenceCount label={t('vab_days')} days={liveCounts?.vab ?? runEmployee.vab_days} />
|
||||
<AbsenceCount label={t('parental_days')} days={liveCounts?.parental ?? runEmployee.parental_days} />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</HelpPopover>
|
||||
}
|
||||
>
|
||||
<SalaryCalendar
|
||||
employeeId={employee.id}
|
||||
salaryType={employee.salary_type}
|
||||
periodStart={periodStart}
|
||||
periodEnd={periodEnd}
|
||||
salaryRunEmployeeId={runEmployee.id}
|
||||
readOnly={readOnly}
|
||||
onChange={load}
|
||||
onAbsenceCountsChange={setLiveCounts}
|
||||
/>
|
||||
<div className="mt-4 flex flex-wrap gap-x-10 gap-y-3">
|
||||
{absenceCounts.map(({ label, days }) => (
|
||||
<div key={label} className="min-w-0">
|
||||
<p className="text-[11px] uppercase tracking-wider text-muted-foreground">{label}</p>
|
||||
<p className="mt-1 text-sm tabular-nums">{t('days_count', { days })}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</DetailSection>
|
||||
|
||||
{/* Line items */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('line_items_title', { count: lineItems.length })}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
{lineItems.length === 0 ? (
|
||||
<p className="px-4 py-6 text-center text-sm text-muted-foreground">
|
||||
{t('no_line_items')}
|
||||
</p>
|
||||
) : (
|
||||
<table className="w-full">
|
||||
<thead className="[&_th]:font-medium [&_th]:text-[11px] [&_th]:uppercase [&_th]:tracking-wider [&_th]:text-muted-foreground">
|
||||
<tr className="border-b text-left">
|
||||
<th className="px-4 py-2">{t('th_type')}</th>
|
||||
<th className="px-4 py-2">{t('th_description')}</th>
|
||||
<th className="px-4 py-2 text-right">{t('th_quantity')}</th>
|
||||
<th className="px-4 py-2 text-right">{t('th_amount')}</th>
|
||||
{/* Line items: the list-page table idiom straight on the panel. */}
|
||||
<DetailSection kicker={t('line_items_title', { count: lineItems.length })}>
|
||||
{lineItems.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">{t('no_line_items')}</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full border-collapse text-[13px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className={cn(TH_CLASS, 'pl-0')}>{t('th_type')}</th>
|
||||
<th className={TH_CLASS}>{t('th_description')}</th>
|
||||
<th className={cn(TH_CLASS, 'text-right')}>{t('th_quantity')}</th>
|
||||
<th className={cn(TH_CLASS, 'pr-0 text-right')}>{t('th_amount')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{lineItems.map(li => (
|
||||
<tr key={li.id} className="border-b last:border-0">
|
||||
<td className="px-4 py-2 text-xs text-muted-foreground">{LINE_ITEM_TYPE_KEYS[li.item_type] ? t(LINE_ITEM_TYPE_KEYS[li.item_type]) : li.item_type}</td>
|
||||
<td className="px-4 py-2 text-sm">{li.description}</td>
|
||||
<td className="px-4 py-2 text-sm text-right tabular-nums">{li.quantity ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-right tabular-nums">{formatCurrency(li.amount)}</td>
|
||||
<tr key={li.id}>
|
||||
<td className={cn(TD_CLASS, 'pl-0 text-muted-foreground')}>
|
||||
{LINE_ITEM_TYPE_KEYS[li.item_type] ? t(LINE_ITEM_TYPE_KEYS[li.item_type]) : li.item_type}
|
||||
</td>
|
||||
<td className={TD_CLASS}>{li.description}</td>
|
||||
<td className={cn(TD_CLASS, 'text-right tabular-nums')}>{li.quantity ?? '-'}</td>
|
||||
<td className={cn(TD_CLASS, 'pr-0 text-right tabular-nums')}>{formatCurrency(li.amount)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SummaryCard({ label, value, accent, overridden }: { label: string; value: number; accent?: boolean; overridden?: boolean }) {
|
||||
const t = useTranslations('salary_run_employee')
|
||||
return (
|
||||
<div className={cn('rounded-lg border bg-card p-3', accent && 'ring-1 ring-primary/40')}>
|
||||
<div className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||
{label}
|
||||
{/* The override is an exception, so it is a chip, not a second ring:
|
||||
two ring-1 rules on one element set the same custom property and
|
||||
one of them silently loses (design.md conventions 5 and 12). */}
|
||||
{overridden && <Badge variant="warning">{t('adjusted_badge')}</Badge>}
|
||||
</div>
|
||||
<div className="mt-0.5 text-lg font-medium tabular-nums">{formatCurrency(value)}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function AbsenceCount({ label, days }: { label: string; days: number }) {
|
||||
const t = useTranslations('salary_run_employee')
|
||||
return (
|
||||
<div className="rounded-lg border bg-muted/30 px-3 py-2">
|
||||
<div className="text-[11px] text-muted-foreground">{label}</div>
|
||||
<div className="text-sm font-medium tabular-nums">{t('days_count', { days })}</div>
|
||||
</div>
|
||||
)}
|
||||
</DetailSection>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import { use, useEffect, useRef, useState } from 'react'
|
||||
import { usePathname, useRouter } from 'next/navigation'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { AttnLine } from '@/components/ui/attn-line'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { AlertTriangle, Download, Loader2 } from 'lucide-react'
|
||||
import { AlertTriangle, Loader2 } from 'lucide-react'
|
||||
import {
|
||||
DestructiveConfirmDialog,
|
||||
useDestructiveConfirm,
|
||||
@@ -768,47 +768,47 @@ export default function SalaryRunPage({ params }: { params: Promise<{ id: string
|
||||
: null
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-8 stagger-enter">
|
||||
{/* Back row + header: serif title with one status chip, the quiet meta
|
||||
line, the next step as the one default button and everything else
|
||||
behind the ⋯ menu. */}
|
||||
<RunHeader
|
||||
run={run}
|
||||
canWrite={canWrite}
|
||||
actionLoading={actionLoading}
|
||||
employeeCount={employees.length}
|
||||
onDelete={handleDelete}
|
||||
onCorrect={handleCorrect}
|
||||
/>
|
||||
|
||||
{/* Control zone: the wizard line and every action for the current stage,
|
||||
grouped in one place with a large primary target. */}
|
||||
<RunProgressBar
|
||||
run={run}
|
||||
isCalculated={isCalculated}
|
||||
noPayout={noPayout}
|
||||
agiState={agiState}
|
||||
agiKvittensnummer={agiKvittensnummer}
|
||||
canWrite={canWrite}
|
||||
actionLoading={actionLoading}
|
||||
primaryAction={primaryAction}
|
||||
onPreview={handlePreview}
|
||||
onRevert={() => handleAction('revert')}
|
||||
onUnapprove={handleUnapprove}
|
||||
onSendPayslips={handleSendPayslips}
|
||||
onDownloadPayslips={handleBulkPayslipDownload}
|
||||
onDownloadAgi={handleDownloadAgi}
|
||||
onDelete={handleDelete}
|
||||
onCorrect={handleCorrect}
|
||||
/>
|
||||
|
||||
{/* The one attention sentence on the page: an empty declaration will be
|
||||
filed for the period, which should be deliberate. */}
|
||||
{isNollkorning && (
|
||||
<AttnLine>
|
||||
{t('nollkorning_title')}: {t('nollkorning_body', { period: periodLabel })}
|
||||
</AttnLine>
|
||||
)}
|
||||
|
||||
{/* The month's steps as a flat rail: where the run stands and what the
|
||||
stage means. Actions live in the header. */}
|
||||
<RunProgressBar
|
||||
run={run}
|
||||
isCalculated={isCalculated}
|
||||
noPayout={noPayout}
|
||||
agiState={agiState}
|
||||
agiKvittensnummer={agiKvittensnummer}
|
||||
/>
|
||||
|
||||
<RunKpiCards run={run} employees={employees} />
|
||||
|
||||
{isNollkorning && (
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<p className="text-sm font-medium">{t('nollkorning_title')}</p>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{t('nollkorning_body', { period: periodLabel })}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<RunEmployeesTable
|
||||
run={run}
|
||||
runId={id}
|
||||
@@ -825,7 +825,7 @@ export default function SalaryRunPage({ params }: { params: Promise<{ id: string
|
||||
|
||||
{/* Calculation detail and the journal preview read best side by side on
|
||||
the wide canvas; they stack on smaller viewports. */}
|
||||
<div className="lg:grid lg:grid-cols-2 lg:gap-6 space-y-6 lg:space-y-0 items-start">
|
||||
<div className="grid gap-x-12 gap-y-8 lg:grid-cols-2 items-start">
|
||||
<RunCalculationDetails periodYear={run.period_year} employees={employees} />
|
||||
{preview && (
|
||||
<RunJournalPreview
|
||||
@@ -856,12 +856,10 @@ export default function SalaryRunPage({ params }: { params: Promise<{ id: string
|
||||
{/* Tax payment (skatt + arbetsgivaravgifter): once AGI has been generated */}
|
||||
{run.status === 'booked' && run.agi_generated_at && (
|
||||
taxPaymentLoading ? (
|
||||
<Card>
|
||||
<CardContent className="space-y-4 p-6">
|
||||
<Skeleton className="h-5 w-40" />
|
||||
<Skeleton className="h-20 w-full" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-5 w-40" />
|
||||
<Skeleton className="h-20 w-full" />
|
||||
</div>
|
||||
) : (
|
||||
<TaxPaymentPanel
|
||||
period={periodLabel}
|
||||
@@ -878,38 +876,20 @@ export default function SalaryRunPage({ params }: { params: Promise<{ id: string
|
||||
)
|
||||
)}
|
||||
|
||||
{/* AGI (Arbetsgivardeklaration): available once the run is booked */}
|
||||
{/* AGI (Arbetsgivardeklaration): available once the run is booked. The
|
||||
XML download for manual filing lives in the header's ⋯ menu. */}
|
||||
{run.status === 'booked' && (
|
||||
<div className="space-y-3">
|
||||
<AGIPanel
|
||||
salaryRunId={id}
|
||||
arbetsgivare={run.arbetsgivare ?? ''}
|
||||
period={`${run.period_year}${String(run.period_month).padStart(2, '0')}`}
|
||||
agiGeneratedAt={run.agi_generated_at}
|
||||
agiSubmittedAt={run.agi_submitted_at}
|
||||
submission={agiSubmission}
|
||||
onRefreshSubmission={refreshAgiSubmission}
|
||||
readOnly={!canWrite}
|
||||
onChange={loadRun}
|
||||
/>
|
||||
{canWrite && (
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleDownloadAgi}
|
||||
disabled={!!actionLoading}
|
||||
>
|
||||
{actionLoading === 'agi-download' ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Download className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
{t('action_download_agi')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<AGIPanel
|
||||
salaryRunId={id}
|
||||
arbetsgivare={run.arbetsgivare ?? ''}
|
||||
period={`${run.period_year}${String(run.period_month).padStart(2, '0')}`}
|
||||
agiGeneratedAt={run.agi_generated_at}
|
||||
agiSubmittedAt={run.agi_submitted_at}
|
||||
submission={agiSubmission}
|
||||
onRefreshSubmission={refreshAgiSubmission}
|
||||
readOnly={!canWrite}
|
||||
onChange={loadRun}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Overridable approval guard: missing bank details don't dead-end -
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user