Fix/bank sync bas (#1284)
* fix(year-end): stop revaluing FX items that were not on the balance sheet The year-end close ran currency revaluation as an unconditional step before the irreversible close, and the revaluation queried LIVE open invoices with no date scoping. An invoice issued after balansdagen, settled before it, or never booked at all was therefore revalued into the year being closed, writing down a 1510/2440 that stood at zero. Because the entry lands inside the same run that closes the period, the only remedy left was a rattelse in the following year. The population is now measured as of balansdagen, reusing the reconstruction the reskontra reports already use (fetchPaymentsAsOf / outstandingAsOf): the invoice_date ceiling is unconditional (post-dated invoices make the bug reachable for a current period too) and the widening to 'paid' applies only to a historical date, where a since-settled invoice was still open then. Rows that carry no balance-sheet exposure are skipped per row rather than per company: an unbooked registration is not on 1510/2440. Deliberately NOT keyed on accounting_method, since BFL 5 kap 2 § 3 st requires kontantmetoden companies to book their outstanding fordringar/skulder at balansdagen, and those converted rows are genuine exposure that ARL 4 kap. 13 § must value. The readiness warning stays ungated on purpose: an unbooked FX row is exactly what deserves a warning, because /book still posts it into the year about to close and lockPeriod/closePeriod then removes that remedy for good. The wizard preview now lists the per-invoice revaluation rows it will post instead of three aggregate numbers, so the user approves line-level content before the close. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(bookkeeping): reach accounts outside BAS 2026 from a verifikat rattelse A user could not move a verifikat line to konto 8022: the picker reported no such account and offered no way forward. 8022 was dropped from BAS 2026 (it is in BAS 2018), so it is a legitimate company-specific underkonto rather than a catalog gap. Verified against the official bas.se kontoplan that our BAS reference already matches BAS 2026, so 8022 is deliberately NOT added to it: seeding a retired account would push it onto every company. StrikeLinesDialog and CorrectionEntryDialog were the only account pickers in the app that never passed onCreateAccount, so their combobox rendered a dead empty state. Both now open AddAccountDialog prefilled, then refetch the chart and select the new account on the initiating line, leaving the half-finished rattelse intact. AccountCombobox closed its dropdown on the fourth digit of any committed number, which hid the empty state before it was ever painted and made the create affordance unreachable for exactly the numbers that need it. It now closes only when the number matches something, so focus still advances to the belopp field for real accounts. No change to posting rules: correct_entry_lines_inline validates chart membership, not BAS membership, and account creation already required the same write role. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(vacation): adjust vacation accrual calculations for mid-year hires and update related logic --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
108f348c84
commit
3bbf2a051b
@@ -216,9 +216,20 @@ export default function AccountCombobox({ value, accounts, onChange, onCommit, o
|
||||
// editing an already-committed number doesn't keep stealing focus. On
|
||||
// commit, close the dropdown too: focus advances to the amount field, so
|
||||
// a lingering open list would just cover the rows below.
|
||||
//
|
||||
// Unless the number matches nothing. Then the dropdown is showing the
|
||||
// empty state, which carries the only way forward for a number outside
|
||||
// BAS (a retired account such as 8022, or a company-specific
|
||||
// underkonto): the "Skapa konto" affordance. Closing on the fourth
|
||||
// keystroke used to hide it before it was ever painted, which made the
|
||||
// affordance unreachable for exactly the numbers that need it.
|
||||
if (newValue !== value) {
|
||||
onCommit?.(newValue)
|
||||
setIsOpen(false)
|
||||
if (searchAccounts(accountIndex, newValue).length > 0) {
|
||||
setIsOpen(false)
|
||||
return
|
||||
}
|
||||
setIsOpen(true)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import AccountCombobox from '@/components/bookkeeping/AccountCombobox'
|
||||
import { AddAccountDialog } from '@/components/bookkeeping/AddAccountDialog'
|
||||
import CorrectionPreview from '@/components/bookkeeping/CorrectionPreview'
|
||||
import {
|
||||
autoCorrectionDescription,
|
||||
@@ -29,6 +30,7 @@ import {
|
||||
changeCorrectionLineAccount,
|
||||
getSelectableCorrectionCatalog,
|
||||
} from '@/lib/bookkeeping/correction-line-account'
|
||||
import { splitCreateAccountPrefill } from '@/lib/bookkeeping/create-account-prefill'
|
||||
import { loadBasCatalog, type CatalogAccount } from '@/lib/bookkeeping/bas-catalog-client'
|
||||
import type { JournalEntry, JournalEntryLine, BASAccount } from '@/types'
|
||||
|
||||
@@ -56,6 +58,10 @@ export default function CorrectionEntryDialog({ entry, open, onOpenChange, onCor
|
||||
const [lines, setLines] = useState<CorrectionLine[]>([])
|
||||
const [description, setDescription] = useState('')
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
// Index of the line whose combobox opened the create dialog, and the search
|
||||
// string it was showing. Null index = the dialog is closed.
|
||||
const [creatingAccountForLine, setCreatingAccountForLine] = useState<number | null>(null)
|
||||
const [createAccountPrefill, setCreateAccountPrefill] = useState('')
|
||||
|
||||
const activeAccounts = useMemo(
|
||||
() => accounts.filter((account) => account.is_active),
|
||||
@@ -149,6 +155,34 @@ export default function CorrectionEntryDialog({ entry, open, onOpenChange, onCor
|
||||
setLines((prev) => prev.filter((_, i) => i !== index))
|
||||
}
|
||||
|
||||
const closeCreateAccount = () => {
|
||||
setCreatingAccountForLine(null)
|
||||
setCreateAccountPrefill('')
|
||||
}
|
||||
|
||||
// A number that is neither in the company chart nor in BAS 2026 (a retired
|
||||
// account such as 8022, or a company-specific underkonto) would otherwise be
|
||||
// a dead end here: the rättelse can only post to accounts that exist in the
|
||||
// chart. Creating it inline keeps the half-finished rättelse intact.
|
||||
const handleAccountCreated = async (account: { account_number: string; account_name?: string }) => {
|
||||
await fetchAccounts()
|
||||
if (creatingAccountForLine != null) {
|
||||
// fetchAccounts' state update is not visible in this closure, so the
|
||||
// fresh account's own name is passed alongside the stale sources. The
|
||||
// reactivate path reports no name, but that account is already in
|
||||
// `accounts` (the fetch includes deactivated rows).
|
||||
const created = account.account_name
|
||||
? [{ account_number: account.account_number, account_name: account.account_name }]
|
||||
: []
|
||||
setLines((prev) => prev.map((line, index) => (
|
||||
index === creatingAccountForLine
|
||||
? changeCorrectionLineAccount(line, account.account_number, [...accountNameSources, ...created])
|
||||
: line
|
||||
)))
|
||||
}
|
||||
closeCreateAccount()
|
||||
}
|
||||
|
||||
const totalDebit = lines.reduce((sum, l) => sum + (parseFloat(l.debit_amount) || 0), 0)
|
||||
const totalCredit = lines.reduce((sum, l) => sum + (parseFloat(l.credit_amount) || 0), 0)
|
||||
const roundedDebit = Math.round(totalDebit * 100) / 100
|
||||
@@ -298,6 +332,10 @@ export default function CorrectionEntryDialog({ entry, open, onOpenChange, onCor
|
||||
accounts={activeAccounts}
|
||||
catalog={selectableCatalog}
|
||||
onChange={(v) => updateLineAccount(index, v)}
|
||||
onCreateAccount={(prefill) => {
|
||||
setCreatingAccountForLine(index)
|
||||
setCreateAccountPrefill(prefill)
|
||||
}}
|
||||
disabled={accountsStatus !== 'ready'}
|
||||
/>
|
||||
<Button
|
||||
@@ -380,6 +418,17 @@ export default function CorrectionEntryDialog({ entry, open, onOpenChange, onCor
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
{/* Nested on purpose: closing this one (Esc, click-outside, Avbryt) must
|
||||
leave the half-filled ändringsverifikation behind it untouched. */}
|
||||
<AddAccountDialog
|
||||
open={creatingAccountForLine != null}
|
||||
onOpenChange={(next) => {
|
||||
if (!next) closeCreateAccount()
|
||||
}}
|
||||
onCreated={handleAccountCreated}
|
||||
{...splitCreateAccountPrefill(createAccountPrefill)}
|
||||
/>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import { TemplateForm } from '@/components/settings/TemplateForm'
|
||||
import CreatePeriodDialog from '@/components/bookkeeping/CreatePeriodDialog'
|
||||
import { ActivateAccountsDialog } from '@/components/bookkeeping/ActivateAccountsDialog'
|
||||
import { AddAccountDialog } from '@/components/bookkeeping/AddAccountDialog'
|
||||
import { splitCreateAccountPrefill } from '@/lib/bookkeeping/create-account-prefill'
|
||||
import DuplicateBookingDialog, { type DuplicateMatchTransaction } from '@/components/transactions/DuplicateBookingDialog'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import {
|
||||
@@ -2004,8 +2005,7 @@ export default function JournalEntryForm({
|
||||
setCreateAccountPrefill('')
|
||||
}
|
||||
}}
|
||||
initialAccountNumber={/^\d{1,4}$/.test(createAccountPrefill) ? createAccountPrefill : undefined}
|
||||
initialAccountName={/^\d{1,4}$/.test(createAccountPrefill) ? undefined : createAccountPrefill}
|
||||
{...splitCreateAccountPrefill(createAccountPrefill)}
|
||||
onCreated={handleAccountCreated}
|
||||
/>
|
||||
|
||||
|
||||
@@ -13,10 +13,12 @@ import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import AccountCombobox from '@/components/bookkeeping/AccountCombobox'
|
||||
import { AddAccountDialog } from '@/components/bookkeeping/AddAccountDialog'
|
||||
import { AccountNumber } from '@/components/ui/account-number'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { getErrorMessage } from '@/lib/errors/get-error-message'
|
||||
import { changeCorrectionLineAccount, getSelectableCorrectionCatalog } from '@/lib/bookkeeping/correction-line-account'
|
||||
import { splitCreateAccountPrefill } from '@/lib/bookkeeping/create-account-prefill'
|
||||
import { loadBasCatalog, type CatalogAccount } from '@/lib/bookkeeping/bas-catalog-client'
|
||||
import { Loader2, Plus, Trash2 } from 'lucide-react'
|
||||
import type { JournalEntry, JournalEntryLine, BASAccount } from '@/types'
|
||||
@@ -51,6 +53,10 @@ export default function StrikeLinesDialog({ entry, open, onOpenChange, onCorrect
|
||||
const [strikeIds, setStrikeIds] = useState<Set<string>>(new Set())
|
||||
const [newLines, setNewLines] = useState<NewLine[]>([])
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
// Index of the replacement line whose combobox opened the create dialog, and
|
||||
// the search string it was showing. Null index = the dialog is closed.
|
||||
const [creatingAccountForLine, setCreatingAccountForLine] = useState<number | null>(null)
|
||||
const [createAccountPrefill, setCreateAccountPrefill] = useState('')
|
||||
|
||||
const activeAccounts = useMemo(
|
||||
() => accounts.filter((account) => account.is_active),
|
||||
@@ -121,6 +127,34 @@ export default function StrikeLinesDialog({ entry, open, onOpenChange, onCorrect
|
||||
setNewLines((prev) => prev.filter((_, i) => i !== index))
|
||||
}
|
||||
|
||||
const closeCreateAccount = () => {
|
||||
setCreatingAccountForLine(null)
|
||||
setCreateAccountPrefill('')
|
||||
}
|
||||
|
||||
// A number that is neither in the company chart nor in BAS 2026 (a retired
|
||||
// account such as 8022, or a company-specific underkonto) would otherwise be
|
||||
// a dead end here: the rättelse can only post to accounts that exist in the
|
||||
// chart. Creating it inline keeps the half-finished rättelse intact.
|
||||
const handleAccountCreated = async (account: { account_number: string; account_name?: string }) => {
|
||||
await fetchAccounts()
|
||||
if (creatingAccountForLine != null) {
|
||||
// fetchAccounts' state update is not visible in this closure, so the
|
||||
// fresh account's own name is passed alongside the stale sources. The
|
||||
// reactivate path reports no name, but that account is already in
|
||||
// `accounts` (the fetch includes deactivated rows).
|
||||
const created = account.account_name
|
||||
? [{ account_number: account.account_number, account_name: account.account_name }]
|
||||
: []
|
||||
setNewLines((prev) => prev.map((line, index) => (
|
||||
index === creatingAccountForLine
|
||||
? changeCorrectionLineAccount(line, account.account_number, [...accounts, ...catalog, ...created])
|
||||
: line
|
||||
)))
|
||||
}
|
||||
closeCreateAccount()
|
||||
}
|
||||
|
||||
// Effective verifikat after the rättelse: remaining original lines + new lines.
|
||||
const remaining = originalLines.filter((l) => !strikeIds.has(l.id))
|
||||
const remainingDebit = remaining.reduce((sum, l) => sum + (Number(l.debit_amount) || 0), 0)
|
||||
@@ -268,6 +302,10 @@ export default function StrikeLinesDialog({ entry, open, onOpenChange, onCorrect
|
||||
accounts={activeAccounts}
|
||||
catalog={selectableCatalog}
|
||||
onChange={(v) => updateNewLineAccount(index, v)}
|
||||
onCreateAccount={(prefill) => {
|
||||
setCreatingAccountForLine(index)
|
||||
setCreateAccountPrefill(prefill)
|
||||
}}
|
||||
disabled={accountsStatus !== 'ready'}
|
||||
/>
|
||||
<Button
|
||||
@@ -352,6 +390,17 @@ export default function StrikeLinesDialog({ entry, open, onOpenChange, onCorrect
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
{/* Nested on purpose: closing this one (Esc, click-outside, Avbryt) must
|
||||
leave the rättelse behind it untouched. */}
|
||||
<AddAccountDialog
|
||||
open={creatingAccountForLine != null}
|
||||
onOpenChange={(next) => {
|
||||
if (!next) closeCreateAccount()
|
||||
}}
|
||||
onCreated={handleAccountCreated}
|
||||
{...splitCreateAccountPrefill(createAccountPrefill)}
|
||||
/>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -82,8 +82,9 @@ export function PreviewStep({ preview, isLoading, error, onBack, onContinue }: P
|
||||
<div className="h-px flex-1 bg-border/60" />
|
||||
</div>
|
||||
<p className="px-1 text-xs leading-5 text-muted-foreground">
|
||||
Öppna fordringar/skulder i utländsk valuta värderas om till balansdagens kurs innan
|
||||
bokslut. Detta sker automatiskt som en del av verkställandet.
|
||||
Fordringar/skulder i utländsk valuta som var öppna på balansdagen värderas om till
|
||||
balansdagens kurs. Raderna nedan bokförs som en del av verkställandet: kontrollera
|
||||
dem innan du går vidare.
|
||||
</p>
|
||||
<div className="px-1 pt-4">
|
||||
<div className="grid grid-cols-3 gap-4 text-sm">
|
||||
@@ -107,6 +108,42 @@ export function PreviewStep({ preview, isLoading, error, onBack, onContinue }: P
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* Capped height: a company with hundreds of open FX invoices must
|
||||
not push the wizard's own actions off the screen. */}
|
||||
<div className="max-h-80 overflow-y-auto px-1 pt-4">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Faktura</TableHead>
|
||||
<TableHead>Typ</TableHead>
|
||||
<TableHead className="text-right">Belopp</TableHead>
|
||||
<TableHead className="text-right">Kurs → balansdag</TableHead>
|
||||
<TableHead className="text-right">Differens</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{preview.currencyRevaluation.items.map((item) => (
|
||||
<TableRow key={`${item.type}-${item.source_id}`}>
|
||||
<TableCell className="text-sm">{item.reference || '-'}</TableCell>
|
||||
<TableCell className="text-sm text-muted-foreground">
|
||||
{item.type === 'receivable' ? 'Kundfordran' : 'Leverantörsskuld'}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">
|
||||
{formatCurrency(item.amount_in_currency, item.currency)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums text-sm text-muted-foreground">
|
||||
{item.original_rate.toFixed(4)} → {item.closing_rate.toFixed(4)}
|
||||
</TableCell>
|
||||
<TableCell
|
||||
className={`text-right tabular-nums ${item.difference_sek < 0 ? 'text-destructive' : ''}`}
|
||||
>
|
||||
{formatCurrency(item.difference_sek)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
|
||||
@@ -150,6 +150,16 @@ export function PaymentFilePanel({
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* The flow looked clean all the way until the bank said no: the
|
||||
file downloads fine and only fails at upload, on the pay date.
|
||||
Say the delivery precondition up front instead. */}
|
||||
{format === 'pain001' && (
|
||||
<div className="flex items-start gap-2 rounded-md border border-border p-3 text-xs">
|
||||
<AlertTriangle className="h-3.5 w-3.5 mt-0.5 shrink-0" />
|
||||
<span className="text-muted-foreground">{t('pain001_agreement_warning')}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{format === 'bg_lb' && (
|
||||
<div className="flex items-start gap-2 rounded-md border border-border p-3 text-xs">
|
||||
<AlertTriangle className="h-3.5 w-3.5 mt-0.5 shrink-0" />
|
||||
|
||||
Reference in New Issue
Block a user