/** * Account policy: which accounts a booking recipe uses for a given SKR chart. * Defaults reflect the DATEV standard charts; entries marked PROVISIONAL are * pattern-derived and get verified against the full chart data in M-A * (@fin.cx/chartdata). Everything is overridable per call. */ import type * as plugins from './core.plugins.js'; import type { TSKRType } from './core.types.js'; import { CHART_AUTOMATIK_ACCOUNTS } from './core.chartaccounts.js'; import { RecipeRefusalError } from './core.errors.js'; import { assertSkrType, chartOf } from './core.chart.js'; export interface IAccountPolicy { skrType: TSKRType; bank: string; cash: string; /** Sammelkonten — direct postings are blocked; use personal accounts. */ debtorsControl: string; creditorsControl: string; /** * Suspense for unclear payments: a movement nothing explains yet is parked * here until it is matched (`bookToSuspense`, `resolveSuspense`). DATEV's * interim account, "Sonstige Verrechnungskonten (Interimskonto)", SKR 03 * 1792 and SKR 04 3630 (DATEV Kontenrahmen gültig für 2026, pp. 11 and * 13); durchlaufende Posten are another account (`passThrough`). */ clearing: string; /** * Durchlaufende Posten (§ 10 Abs. 1 Satz 6 UStG): amounts received and spent * in the name and for the account of another, such as court fees passed on. * They are no part of the consideration, bear no VAT and stand outside the * UStVA. A document's `passThroughCents` is booked here, never on `clearing`, * which parks what is not yet known. DATEV Kontenrahmen SKR 03 (Art.-Nr. * 11174) 1590 and SKR 04 (Art.-Nr. 11175) 1370, gültig für 2026: balance-sheet * accounts without tax function. Optional, so a policy written before this * role stays a policy; a document with durchlaufende Posten is refused * without it (`pass_through_account_missing`). */ passThrough?: string; /** Interim account for bank-to-bank transfers. */ geldtransit: string; vat: { outputStandard: string; outputReduced: string; inputStandard: string; inputReduced: string; intraEuAcqInput: string; intraEuAcqOutput: string; reverseChargeInput: string; reverseChargeOutput: string; /** VAT owed to another EU member state on a sale taxable there — not German VAT, outside the UStVA */ otherEuStateGoods: string; otherEuStateServices: string; otherEuStateElectronicServices: string; }; revenue: { domesticStandard: string; domesticReduced: string; intraEuSupply: string; export: string; /** * a supply taxable at 0 % (§ 12 Abs. 3 UStG, UStVA Kz 87): SKR03 8290, * SKR04 4290. Optional, so a policy made before stays a policy; a * zero-rated sale that names no account refuses without it * (`zero_rate_account_missing`). */ domesticZeroRate?: string; reverseCharge: string; /** * Revenue taxable in another EU member state (UStVA Kz 45): goods, * electronic services, and other services and Werklieferungen. For the * last the DATEV Kontenrahmen 2026 has no account of its own; the account * of "im anderen EU-Land steuerbaren Leistungen, im Inland nicht steuerbare * Umsätze" (SKR03 8339, SKR04 4339) takes them, the account `notTaxableHereEu` * takes too, and their VAT goes on `vat.otherEuStateServices`. */ otherEuStateGoods: string; otherEuStateElectronicServices: string; otherEuStateServices: string; /** a § 3a Abs. 2 service whose recipient owes the tax in another member state (UStVA Kz 21) */ otherEuStateRecipientLiable: string; /** turnover not taxable here (UStVA Kz 45), its place in another member state or a third country */ notTaxableHereEu: string; notTaxableHereThirdCountry: string; }; expenseDefault: string; skonto: { /** erhaltene Skonti (purchases) — Automatikkonten with VSt correction */ receivedStandard: string; receivedReduced: string; /** gewährte Skonti (sales) — Automatikkonten with USt correction */ grantedStandard: string; grantedReduced: string; }; fx: { gain: string; loss: string }; /** * Income that is no consideration of a supply and so bears no VAT and has * no UStVA line, booked when it is received (§ 252 Abs. 1 Nr. 4 HGB; § 11 * EStG in a cash-basis year), for example as the `excess` of a bank payment: * - `damages`: damages received, such as a reminder fee or the lump sum of * § 288 Abs. 5 BGB a debtor in default pays (§§ 280 Abs. 2, 286 BGB): * "Versicherungsentschädigungen und Schadenersatzleistungen", SKR 03 * 2742, SKR 04 4970; * - `interest`: interest received, such as default interest (§ 288 Abs. 1 * and 2 BGB): "Sonstige Zinsen und ähnliche Erträge", SKR 03 2650, * SKR 04 7100. * DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174) and SKR 04 (Art.-Nr. 11175), * gültig für 2026, without tax function. Optional, so a policy written * before this role stays a policy; `otherIncomeAccount` refuses without it * (`other_income_accounts_missing`). */ otherIncome?: { damages: string; interest: string }; /** * Nebenkosten des Geldverkehrs: the fees a bank or a payment provider (PayPal, * Wise) charges for moving money, among them a fee a provider keeps from the * balance it holds (`bookPaymentFee`). An expense without input VAT: a * payment service is exempt (§ 4 Nr. 8 UStG); a fee with its tax names it * (`IPaymentFeeInput.scenario`). DATEV Kontenrahmen SKR 03 * (Art.-Nr. 11174) 4970 and SKR 04 (Art.-Nr. 11175) 6855, gültig für 2026, * without tax function. Optional, so a policy written before this role stays * a policy; `paymentFeesAccount` refuses without it * (`payment_fees_account_missing`). */ paymentFees?: string; /** * Saldenvortragskonten: the counter accounts of the opening balances * (EB-Werte) of the general-ledger accounts, the debtors and the creditors. */ openingBalance: { generalLedger: string; debtors: string; creditors: string }; /** * Privatentnahmen and Privateinlagen of a sole trader or a partner. A * company has none; its owners' movements go to their own accounts. */ privateAccounts: { withdrawal: string; deposit: string }; /** * Umsatzsteuer-Vorauszahlungen, and those of the Sondervorauszahlung (1/11); * `previousYear` and `earlierYears`, the Umsatzsteuerverbindlichkeiten of the * previous year and of earlier years, which the carry-forward opens a * closed year's VAT on (`vatOfPastYearsReclassified`). Optional, so a * policy made before them stays a policy; that helper refuses without them * (`vat_year_accounts_missing`). */ vatSettlement: { prepayment: string; specialPrepayment: string; previousYear?: string; earlierYears?: string }; /** where a company's year result is carried: Gewinnvortrag and Verlustvortrag vor Verwendung */ resultCarryForward: { profit: string; loss: string }; /** * Anzahlungen: money paid or received before the supply. `paid`: geleistete * Anzahlungen auf Vorräte (§ 266 Abs. 2 B.I.4 HGB), `untaxed` for one whose * input tax is not deducted with it (no invoice at hand yet, § 15 Abs. 1 * Satz 1 Nr. 1 Satz 3 UStG, or none to deduct), `reduced` and `standard` * with the DATEV automatism AV of 7 % and 19 % input tax. `received`: * erhaltene Anzahlungen auf Bestellungen (§ 266 Abs. 3 C.3 HGB), `untaxed` * for one whose tax does not arise with it (a supply without German VAT), * `reduced` and `standard` the "versteuerte" accounts with the automatism * AM of 7 % and 19 % output tax, whose tax arises when they are received * (§ 13 Abs. 1 Nr. 1 Buchst. a Satz 4 UStG). Optional, so a policy made * before these roles stays a policy; the advance recipes refuse without * them (`advance_accounts_missing`). */ advances?: { paid: { untaxed: string; reduced: string; standard: string }; received: { untaxed: string; reduced: string; standard: string }; }; /** * Goods bought for resale, where the purchases are booked as an expense * (Wareneingang) and the stock only at the year's end: `stock`, "Waren * (Bestand)" under the inventories (§ 266 Abs. 2 B.I.3 HGB); `stockChange`, * "Bestandsveränderungen Waren", where the difference between the stock the * Inventar values and the stock the books carry is booked, part of the * Materialaufwand (§ 275 Abs. 2 Nr. 5 HGB); `customs`, "Zölle und * Einfuhrabgaben", part of the cost of the goods bought (§ 255 Abs. 1 * Satz 2 HGB). DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174, p. 21) 3980, 3950, * 3850 and SKR 04 (Art.-Nr. 11175, pp. 3 and 20) 1140, 5881, 5840, gültig * für 2026: accounts without tax function. Optional, so a policy made * before this role stays a policy; `bookInventoryChange` refuses without it * (`goods_accounts_missing`). */ goods?: { stock: string; stockChange: string; customs: string }; /** Small payment-difference write-offs (PROVISIONAL: generic sonstige Erträge/Aufwendungen). */ roundingDiff: { gain: string; loss: string }; debtorRange: [number, number]; creditorRange: [number, number]; /** * Accounts with built-in DATEV tax automatism. Lines on these accounts must * carry no BU key ('' — automatism applies) or key 40 (automatism cancelled). * The default policies list the chart's (`CHART_AUTOMATIK_ACCOUNTS`, from * @fin.cx/chartdata). `isAutomatikAccount` takes every Automatikkonto of the * chart as one whatever a policy lists, since DATEV applies the chart's * automatism on import; a policy adds accounts set up as Automatikkonten * beyond the chart. */ automatikkonten: string[]; /** * The books' individual accounts (Individualkonten): accounts on the * numbers DATEV leaves free after one of its accounts, which they belong to * and take their type, HGB position, UStVA and Anlage EÜR mapping and tax * rule from, without its DATEV tax automatism (@fin.cx/chartdata * `IIndividualAccountDeclaration`). The core's checks of what an account is * read them through `booksChartOf`, which refuses declarations chartdata * refuses (`IndividualAccountsError`). An individual account that names a * securities role is the account the securities recipes book that role on. * Optional: a policy without them keeps the chart's accounts only. */ individualAccounts?: readonly plugins.chartdata.IIndividualAccountDeclaration[]; } export const SKR03_DEFAULT_POLICY: IAccountPolicy = { skrType: 'SKR03', bank: '1200', cash: '1000', debtorsControl: '1400', creditorsControl: '1600', // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174, p. 11), gültig für 2026 clearing: '1792', // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174, p. 9), gültig für 2026 passThrough: '1590', geldtransit: '1360', vat: { outputStandard: '1776', outputReduced: '1771', inputStandard: '1576', inputReduced: '1571', intraEuAcqInput: '1574', // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174), gültig für 2026: 1774 "Umsatzsteuer aus innergemeinschaftlichem // Erwerb 19 %"; 1784 is the igE of new vehicles from suppliers without a VAT ID intraEuAcqOutput: '1774', reverseChargeInput: '1577', reverseChargeOutput: '1787', // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174), gültig für 2026 otherEuStateGoods: '1767', otherEuStateServices: '1768', otherEuStateElectronicServices: '1728', }, revenue: { domesticStandard: '8400', domesticReduced: '8300', intraEuSupply: '8125', export: '8120', domesticZeroRate: '8290', reverseCharge: '8337', otherEuStateGoods: '8320', otherEuStateElectronicServices: '8331', otherEuStateServices: '8339', otherEuStateRecipientLiable: '8336', notTaxableHereEu: '8339', notTaxableHereThirdCountry: '8338', }, expenseDefault: '4900', skonto: { receivedStandard: '3736', receivedReduced: '3731', // PROVISIONAL grantedStandard: '8736', grantedReduced: '8731', // PROVISIONAL }, fx: { gain: '2660', loss: '2150' }, // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174), gültig für 2026 openingBalance: { generalLedger: '9000', debtors: '9008', creditors: '9009' }, privateAccounts: { withdrawal: '1800', deposit: '1890' }, // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174, p. 11), gültig für 2026 vatSettlement: { prepayment: '1780', specialPrepayment: '1781', previousYear: '1790', earlierYears: '1791' }, resultCarryForward: { profit: '0860', loss: '0868' }, // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174), gültig für 2026 advances: { paid: { untaxed: '1510', reduced: '1511', standard: '1518' }, received: { untaxed: '1710', reduced: '1711', standard: '1718' }, }, // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174, p. 17), gültig für 2026 otherIncome: { damages: '2742', interest: '2650' }, paymentFees: '4970', // DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174, p. 21), gültig für 2026 goods: { stock: '3980', stockChange: '3950', customs: '3850' }, roundingDiff: { gain: '2700', loss: '2300' }, // PROVISIONAL debtorRange: [10000, 69999], creditorRange: [70000, 99999], automatikkonten: [...CHART_AUTOMATIK_ACCOUNTS.SKR03], }; export const SKR04_DEFAULT_POLICY: IAccountPolicy = { skrType: 'SKR04', bank: '1800', cash: '1600', debtorsControl: '1200', creditorsControl: '3300', // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175, p. 13), gültig für 2026 clearing: '3630', // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175, p. 4), gültig für 2026 passThrough: '1370', geldtransit: '1460', vat: { outputStandard: '3806', outputReduced: '3801', inputStandard: '1406', inputReduced: '1401', intraEuAcqInput: '1404', intraEuAcqOutput: '3804', reverseChargeInput: '1407', reverseChargeOutput: '3837', // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175), gültig für 2026 otherEuStateGoods: '3817', otherEuStateServices: '3818', otherEuStateElectronicServices: '3798', }, revenue: { domesticStandard: '4400', domesticReduced: '4300', intraEuSupply: '4125', export: '4120', domesticZeroRate: '4290', reverseCharge: '4337', otherEuStateGoods: '4320', otherEuStateElectronicServices: '4331', otherEuStateServices: '4339', otherEuStateRecipientLiable: '4336', notTaxableHereEu: '4339', notTaxableHereThirdCountry: '4338', }, expenseDefault: '6300', skonto: { receivedStandard: '5736', receivedReduced: '5731', // PROVISIONAL grantedStandard: '4736', grantedReduced: '4731', // PROVISIONAL }, fx: { gain: '4840', loss: '6880' }, // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175), gültig für 2026 openingBalance: { generalLedger: '9000', debtors: '9008', creditors: '9009' }, privateAccounts: { withdrawal: '2100', deposit: '2180' }, // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175, p. 14), gültig für 2026 vatSettlement: { prepayment: '3820', specialPrepayment: '3830', previousYear: '3841', earlierYears: '3845' }, resultCarryForward: { profit: '2970', loss: '2978' }, // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175), gültig für 2026 advances: { paid: { untaxed: '1180', reduced: '1181', standard: '1186' }, received: { untaxed: '3250', reduced: '3260', standard: '3272' }, }, // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175, pp. 18, 26), gültig für 2026 otherIncome: { damages: '4970', interest: '7100' }, paymentFees: '6855', // DATEV Kontenrahmen SKR 04 (Art.-Nr. 11175, pp. 3 and 20), gültig für 2026 goods: { stock: '1140', stockChange: '5881', customs: '5840' }, roundingDiff: { gain: '4830', loss: '6300' }, // PROVISIONAL debtorRange: [10000, 69999], creditorRange: [70000, 99999], automatikkonten: [...CHART_AUTOMATIK_ACCOUNTS.SKR04], }; /** * The account of income that is no consideration of a supply (`otherIncome`): * `damages` for damages received, such as a reminder fee or the lump sum of * § 288 Abs. 5 BGB, `interest` for interest received, such as default * interest. Refused when the policy names no such accounts * (`other_income_accounts_missing`). */ export function otherIncomeAccount(policy: IAccountPolicy, kind: 'damages' | 'interest'): string { if (!policy.otherIncome) { throw new RecipeRefusalError( 'other_income_accounts_missing', 'the policy names no otherIncome accounts, where damages and interest received are booked', { field: 'otherIncome' }, ); } return policy.otherIncome[kind]; } /** * The account of Nebenkosten des Geldverkehrs (`paymentFees`), where a fee a * bank or a payment provider charges is booked. Refused when the policy names * none (`payment_fees_account_missing`). */ export function paymentFeesAccount(policy: IAccountPolicy): string { if (!policy.paymentFees) { throw new RecipeRefusalError( 'payment_fees_account_missing', 'the policy names no paymentFees account, where the fees of moving money are booked', { field: 'paymentFees' }, ); } return policy.paymentFees; } /** The default policy of a chart skr keeps; another name, another spelling or none is refused (`UnknownChartError`). */ export function getDefaultPolicy(skrType: TSKRType): IAccountPolicy { assertSkrType(skrType); return skrType === 'SKR03' ? SKR03_DEFAULT_POLICY : SKR04_DEFAULT_POLICY; } /** * Whose company holds a claim against a shareholder, by the legal form and, * of a KGaA, by who the shareholder is: * - `gmbh`, `ug`: a GmbH or an UG (haftungsbeschränkt), a GmbH of its own form; * - `ag`, `se`: an AG or a Societas Europaea; * - `kgaa_general_partner`: a KGaA, against a persönlich haftender * Gesellschafter; * - `kgaa_limited_shareholder`: a KGaA, against a Kommanditaktionär; * - `eg`: a cooperative (eingetragene Genossenschaft). */ export type TShareholderClaimForm = 'gmbh' | 'ug' | 'ag' | 'se' | 'kgaa_general_partner' | 'kgaa_limited_shareholder' | 'eg'; export const SHAREHOLDER_CLAIM_FORMS: readonly TShareholderClaimForm[] = ['gmbh', 'ug', 'ag', 'se', 'kgaa_general_partner', 'kgaa_limited_shareholder', 'eg']; /** * The account a company books a claim against a shareholder on, by its form * (`TShareholderClaimForm`), in the DATEV Kontenrahmen SKR 03 (Art.-Nr. 11174) * and SKR 04 (Art.-Nr. 11175), gültig für 2026: among other things what a * shareholder received for the company and owes it, such as a customer's * payment into the shareholder's private account * (`bookReceivableSettledOutside`). All under the other assets (§ 266 Abs. 2 * B.II.4 HGB), without tax function. * - A GmbH or UG: "Forderungen gegen GmbH-Gesellschafter", stated apart or * noted (§ 42 Abs. 3 GmbHG): SKR 03 1381, SKR 04 1307. * - An AG or SE, and a KGaA against a Kommanditaktionär: "Forderungen gegen * sonstige Gesellschafter": SKR 03 1507 (DATEV's first account of the * group, with a remaining term of up to one year; there is none for the * whole claim), SKR 04 1330. * - A KGaA against a persönlich haftender Gesellschafter, stated apart (§ 286 * Abs. 2 Satz 4 HGB): "Forderungen gegen persönlich haftende * Gesellschafter": SKR 03 1385, SKR 04 1317. * - A cooperative: the other assets, SKR 03 1500, SKR 04 1300. * A sole trader or a partnership has no such claim: what its owner received * is a withdrawal (`privateAccounts.withdrawal`). A chart default beside the * policy, not a field of it; `@fin.cx/chartdata` 2.8.0 holds every account. */ export const SHAREHOLDER_CLAIM_ACCOUNTS: Readonly>>> = { SKR03: { gmbh: '1381', ug: '1381', ag: '1507', se: '1507', kgaa_general_partner: '1385', kgaa_limited_shareholder: '1507', eg: '1500' }, SKR04: { gmbh: '1307', ug: '1307', ag: '1330', se: '1330', kgaa_general_partner: '1317', kgaa_limited_shareholder: '1330', eg: '1300' }, }; /** The account a company of `formArg` books a claim against a shareholder on in `skrTypeArg` (`SHAREHOLDER_CLAIM_ACCOUNTS`). */ export function shareholderClaimAccount(skrTypeArg: TSKRType, formArg: TShareholderClaimForm): string { assertSkrType(skrTypeArg); const account = SHAREHOLDER_CLAIM_ACCOUNTS[skrTypeArg]?.[formArg]; if (account === undefined) { throw new Error(`no claim against a shareholder is known for ${String(formArg)} in ${String(skrTypeArg)}`); } return account; } /** * Whether DATEV applies a tax automatism to a line on the account: an * Automatikkonto of the chart in use (`CHART_AUTOMATIK_ACCOUNTS`), or one the * policy lists. */ export function isAutomatikAccount(policy: IAccountPolicy, accountNumber: string): boolean { return CHART_AUTOMATIK_ACCOUNTS[chartOf(policy)].includes(accountNumber) || policy.automatikkonten.includes(accountNumber); } export function isDebtorAccount(policy: IAccountPolicy, accountNumber: string): boolean { const parsed = Number.parseInt(accountNumber, 10); return Number.isInteger(parsed) && parsed >= policy.debtorRange[0] && parsed <= policy.debtorRange[1]; } export function isCreditorAccount(policy: IAccountPolicy, accountNumber: string): boolean { const parsed = Number.parseInt(accountNumber, 10); return ( Number.isInteger(parsed) && parsed >= policy.creditorRange[0] && parsed <= policy.creditorRange[1] ); }