Fix/build (#1041)
* fix(bookkeeping): harden correction account changes * feat(tax): enhance tax deadline generation with new settings and filing methods - Added new company settings: tax_turnover_over_40m, vat_has_eu_trade, vat_filing_method, periodisk_sammanstallning_enabled, and periodisk_sammanstallning_filing_method. - Updated deadline generation logic to accommodate new settings affecting VAT and employer declaration deadlines. - Implemented tests for new functionality, ensuring that completed obligations are preserved and not replaced by new pending rows. - Introduced a cron job to backfill missing tax deadlines for companies with settings but no upcoming deadlines. - Updated API routes for generating tax deadlines and handling cron jobs. - Modified database schema to include new columns for tax filing profiles and constraints for filing methods. * fix(invoices): record credit note reconciliation guard * fix(tax): correct automatic deadline settings * fix(tax): key AGI deadline to VAT taxable base and add storforetag payment deadline The 26th filing day for the skattedeklaration (AGI and VAT together) hinges on one statutory measure, a VAT taxable base above SEK 40 million (SFL 26 kap.), not a separate employer turnover. Drop employer_turnover_over_40m and derive the AGI schedule from vat_registered plus vat_taxable_base_over_40m, so a non-VAT-reporting employer is never shown the 26th when its binding date is the 12th. Also: - add a skatteinbetalning deadline row (12th, 17 January) for storforetag, whose deducted tax and employer contributions are due before the 26th filing date - normalize legally incoherent over-40m flag combinations to the earlier small-company schedule in a follow-up migration - replace hardcoded 27 December dates with the banking-day adjustment - extend the 40m help text to cover the SKV-decided early filing election and the payment-still-on-the-12th rule - document the regeneration race repaired by the daily backfill cron Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(migrations): add AGI and VAT filing logic with employer column removal * feat(settings): implement VAT registration logic and update related flags; enhance deadline handling --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
1443235cec
commit
a5e37d3510
@@ -0,0 +1,134 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
changeCorrectionLineAccount,
|
||||
getSelectableCorrectionCatalog,
|
||||
} from '../correction-line-account'
|
||||
|
||||
const accounts = [
|
||||
{
|
||||
account_number: '2393',
|
||||
account_name: 'Lån från närstående personer, långfristig del',
|
||||
},
|
||||
{
|
||||
account_number: '2893',
|
||||
account_name: 'Skulder till närstående personer, kortfristig del',
|
||||
},
|
||||
]
|
||||
|
||||
describe('changeCorrectionLineAccount', () => {
|
||||
it('replaces a stale account-derived description when the account changes', () => {
|
||||
const result = changeCorrectionLineAccount(
|
||||
{
|
||||
account_number: '2393',
|
||||
line_description: 'Lån från närstående personer, långfristig del',
|
||||
debit_amount: '',
|
||||
credit_amount: '1000',
|
||||
},
|
||||
'2893',
|
||||
accounts,
|
||||
)
|
||||
|
||||
expect(result).toEqual({
|
||||
account_number: '2893',
|
||||
line_description: 'Skulder till närstående personer, kortfristig del',
|
||||
debit_amount: '',
|
||||
credit_amount: '1000',
|
||||
})
|
||||
})
|
||||
|
||||
it('preserves a user-authored line description', () => {
|
||||
const result = changeCorrectionLineAccount(
|
||||
{
|
||||
account_number: '2393',
|
||||
line_description: 'Lån enligt avtal 2026-07-01',
|
||||
},
|
||||
'2893',
|
||||
accounts,
|
||||
)
|
||||
|
||||
expect(result.line_description).toBe('Lån enligt avtal 2026-07-01')
|
||||
})
|
||||
|
||||
it('uses the BAS catalogue when the new account is not active', () => {
|
||||
const result = changeCorrectionLineAccount(
|
||||
{
|
||||
account_number: '2393',
|
||||
line_description: 'Lån från närstående personer, långfristig del',
|
||||
},
|
||||
'2893',
|
||||
accounts,
|
||||
)
|
||||
|
||||
expect(result.line_description).toBe('Skulder till närstående personer, kortfristig del')
|
||||
})
|
||||
|
||||
it('recognizes an account-derived description from a deactivated custom account', () => {
|
||||
const result = changeCorrectionLineAccount(
|
||||
{
|
||||
account_number: '2997',
|
||||
line_description: 'Avräkning projektägare',
|
||||
},
|
||||
'2893',
|
||||
[
|
||||
{ account_number: '2997', account_name: 'Avräkning projektägare' },
|
||||
accounts[1],
|
||||
],
|
||||
)
|
||||
|
||||
expect(result.line_description).toBe('Skulder till närstående personer, kortfristig del')
|
||||
})
|
||||
|
||||
it('prefers the company account name over a duplicate BAS catalogue name', () => {
|
||||
const result = changeCorrectionLineAccount(
|
||||
{
|
||||
account_number: '2393',
|
||||
line_description: 'Lån från närstående personer, långfristig del',
|
||||
},
|
||||
'2893',
|
||||
[
|
||||
accounts[0],
|
||||
{ account_number: '2893', account_name: 'Avräkning ägare' },
|
||||
accounts[1],
|
||||
],
|
||||
)
|
||||
|
||||
expect(result.line_description).toBe('Avräkning ägare')
|
||||
})
|
||||
|
||||
it('fills a blank description from the selected account', () => {
|
||||
const result = changeCorrectionLineAccount(
|
||||
{ account_number: '2393', line_description: '' },
|
||||
'2893',
|
||||
accounts,
|
||||
)
|
||||
|
||||
expect(result.line_description).toBe('Skulder till närstående personer, kortfristig del')
|
||||
})
|
||||
|
||||
it('clears a derived description when the new account has no known name', () => {
|
||||
const result = changeCorrectionLineAccount(
|
||||
{
|
||||
account_number: '2393',
|
||||
line_description: 'Lån från närstående personer, långfristig del',
|
||||
},
|
||||
'9999',
|
||||
accounts,
|
||||
)
|
||||
|
||||
expect(result.line_description).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getSelectableCorrectionCatalog', () => {
|
||||
it('excludes deliberately deactivated company accounts from catalogue choices', () => {
|
||||
const result = getSelectableCorrectionCatalog(
|
||||
[
|
||||
{ account_number: '2393', account_name: 'Långfristigt lån', is_active: true },
|
||||
{ account_number: '2893', account_name: 'Kortfristigt lån', is_active: false },
|
||||
],
|
||||
accounts,
|
||||
)
|
||||
|
||||
expect(result).toEqual([accounts[0]])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,67 @@
|
||||
import { foldText } from './account-search'
|
||||
|
||||
interface NamedAccount {
|
||||
account_number: string
|
||||
account_name: string
|
||||
}
|
||||
|
||||
interface CompanyAccount extends NamedAccount {
|
||||
is_active: boolean
|
||||
}
|
||||
|
||||
interface CorrectionLineAccountFields {
|
||||
account_number: string
|
||||
line_description: string
|
||||
}
|
||||
|
||||
function findAccountName(accountNumber: string, accounts: NamedAccount[]): string | undefined {
|
||||
return accounts.find((account) => account.account_number === accountNumber)?.account_name
|
||||
}
|
||||
|
||||
function namesMatch(left: string, right: string): boolean {
|
||||
return foldText(left.trim()) === foldText(right.trim())
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep deliberately deactivated company accounts out of catalogue-backed
|
||||
* picker results. The correction service will seed missing BAS accounts, but
|
||||
* it intentionally refuses to reactivate accounts the company disabled.
|
||||
*/
|
||||
export function getSelectableCorrectionCatalog<T extends NamedAccount>(
|
||||
companyAccounts: CompanyAccount[],
|
||||
catalog: T[],
|
||||
): T[] {
|
||||
const inactiveNumbers = new Set(
|
||||
companyAccounts
|
||||
.filter((account) => !account.is_active)
|
||||
.map((account) => account.account_number),
|
||||
)
|
||||
return catalog.filter((account) => !inactiveNumbers.has(account.account_number))
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the account on a correction line without carrying a stale account
|
||||
* name into the posted replacement entry. Descriptions that do not match the
|
||||
* previous account name are user-authored voucher text and stay untouched.
|
||||
*/
|
||||
export function changeCorrectionLineAccount<T extends CorrectionLineAccountFields>(
|
||||
line: T,
|
||||
nextAccountNumber: string,
|
||||
accounts: NamedAccount[],
|
||||
): T {
|
||||
const currentDescription = line.line_description.trim()
|
||||
const previousNames = accounts
|
||||
.filter((account) => account.account_number === line.account_number)
|
||||
.map((account) => account.account_name)
|
||||
|
||||
const descriptionIsAccountName = currentDescription.length === 0
|
||||
|| previousNames.some((name) => namesMatch(currentDescription, name))
|
||||
|
||||
return {
|
||||
...line,
|
||||
account_number: nextAccountNumber,
|
||||
line_description: descriptionIsAccountName
|
||||
? findAccountName(nextAccountNumber, accounts) ?? ''
|
||||
: line.line_description,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user