/** * The refusal of a booking recipe: the recipe cannot book what it was asked, * because of the input — an amount, an account, a missing number, a * difference beyond the tolerance — not because of a defect of the code. A * caller shows or resolves a refusal; every other Error a recipe throws is a * programming error (an impossible state, a broken invariant). */ import type { TTaxScenario } from './core.types.js'; /** What a recipe refuses; stable, for callers to branch on. */ export type TRecipeRefusalCode = // amounts /** an amount that must be positive integer cents is not (`details.field`, `details.amountCents`) */ | 'amount_not_positive' /** an amount that must be whole cents is not (`details.field`, `details.amountCents`) */ | 'amount_not_whole_cents' // documents /** the scenario has no default revenue account in the policy; name one (`details.scenario`) */ | 'revenue_account_required' /** a credit note without the number of the invoice it corrects (§ 31 Abs. 5 UStDV) */ | 'corrected_invoice_required' /** a credit note without its own number (§ 14 Abs. 4 Satz 1 Nr. 4 UStG) */ | 'credit_note_number_required' /** a credit note dated before the invoice it corrects: its own date (`issueDate`, else the entry's `date`) */ | 'credit_note_predates_invoice' /** a credit note's own date (`issueDate`) that is given and is no day: an Invalid Date, or no Date at all (`details.field`) */ | 'credit_note_issue_date_invalid' /** a document without VAT groups */ | 'document_groups_missing' /** a document whose VAT groups are all 0 and that has no durchlaufende Posten */ | 'document_without_amount' /** a group's stated tax (`vatCents`) that differs from the tax of its rate by more than a cent, has another sign than its amount, or is not 0 on a scenario without German VAT (`details.field`, `.amountCents`, `.differenceCents`, `.toleranceCents`, `.ratePercent`, `.scenario`) */ | 'vat_amount_off_rate' /** `otherIncomeAccount` under a policy without the `otherIncome` accounts (`details.field`) */ | 'other_income_accounts_missing' /** `paymentFeesAccount` or `bookPaymentFee` under a policy without the `paymentFees` account (`details.field`) */ | 'payment_fees_account_missing' /** `bookPaymentFee` under a scenario no fee is taxed under, or a rate on a fee without German VAT (`details.field`, `.scenario`, `.ratePercent`) */ | 'payment_fee_input_invalid' /** a document with durchlaufende Posten (`passThroughCents`) under a policy without the `passThrough` account (`details.field`) */ | 'pass_through_account_missing' /** the policy's `passThrough` account has a DATEV tax automatism or is marked for the UStVA (`details.account`) */ | 'pass_through_account_not_allowed' /** a purchase's tax excluded from the deduction (`nonDeductibleVatCents`) that is no whole cents, beyond the tax, of another sign than the group's amount, on a scenario without German VAT, or on a sale; a Skonto share's `nonDeductible` without `selfAssessed`; a key of a part deducted (`deductiblePercent`) that is not above 0 and below 100 with up to two places, on a sale's Skonto, beside `nonDeductible`, on a part without German VAT, or on a fee beside `nonDeductibleVatCents`; a fee's `nonDeductible` beside `deductiblePercent` or `nonDeductibleVatCents`, on a fee without German VAT, or other than `true` (`details.field`, `.amountCents`, `.scenario`) */ | 'non_deductible_vat_invalid' /** a `reverseChargeParagraph` that is none of `TReverseChargeParagraph`, on a part, group or fee not under § 13b UStG (a Skonto share without `selfAssessed: 'reverse_charge_13b'`), or `abs_2_nr_3` on a fee, which is no Umsatz under the GrEStG (`details.field`, `.scenario`) */ | 'reverse_charge_paragraph_invalid' /** a revenue or expense account whose DATEV automatism books German VAT at a rate, for a booking without German VAT; any Automatikkonto as the expense account of a purchase, fee or Skonto share whose recipient owes the tax (§ 13b UStG, intra-Community acquisition), whose base would carry key 40 there (`details.field`, `.account`, `.scenario`, `.ratePercent` where the automatism has a rate) */ | 'automatik_account_not_allowed' /** a domestic booking at 19 or 7 % on an account the chart ties to another rate or to no German VAT (`details.field`, `.account`, `.scenario`, `.ratePercent`) */ | 'account_rate_mismatch' /** a vendor document under a scenario of sales only (`details.scenario`) */ | 'scenario_not_for_purchases' /** a sale taxable in another member state without that state's rate, or with one below 0 (`details.field`, `.scenario`, `.ratePercent`) */ | 'other_eu_state_rate_required' /** a sale taxable in another member state without the kind of its supply (`details.field`, `.scenario`) */ | 'other_eu_state_supply_required' /** a sale not taxable here without where it has its place (`details.field`, `.scenario`) */ | 'place_of_supply_required' // bank payments /** the payment falls short of the open amount by more than the tolerance, without Skonto (`details.direction`, `.differenceCents`, `.toleranceCents`) */ | 'shortfall_beyond_tolerance' /** the payment exceeds the open amount by more than the tolerance, without `excess` (`details.direction`, `.differenceCents`, `.toleranceCents`) */ | 'excess_beyond_tolerance' /** `excess.account` names no account */ | 'excess_account_required' /** `excess.account` cannot take the excess (`details.account`) */ | 'excess_account_not_allowed' /** `excess` is named, but nothing moved beyond the expected amount */ | 'excess_not_applicable' /** a Skonto on a refund to a debtor or on a payment from a creditor (`details.direction`, `.account`) */ | 'skonto_wrong_counterparty' /** a Skonto at a rate the policy holds no accounts for (`details.field`, `.ratePercent`) */ | 'skonto_rate_unsupported' /** `skonto.shares` names no share */ | 'skonto_shares_missing' /** a part of a Skonto that must name its account names none (`details.field`) */ | 'skonto_account_required' /** a part of a Skonto names an account it cannot book on (`details.field`, `.account`) */ | 'skonto_account_not_allowed' /** a part of a Skonto is named twice (`details.field`) */ | 'skonto_share_duplicate' /** the Skonto is larger than the shares it was granted on (`details.amountCents`) */ | 'skonto_exceeds_shares' /** a Skonto on a § 13b or intra-Community acquisition invoice in `InvoiceBookingEngine`, which does not book the self-assessed tax's correction; `bookBankPayment` does, with a share `selfAssessed` (`details.field`) */ | 'skonto_scenario_unsupported' /** the lines of an invoice's VAT group went to several accounts, so the account its Skonto reduces is not known (`details.accounts`) */ | 'skonto_account_ambiguous' /** a part at 0 % on revenue taxed in another member state without that state's rate (`details.field`, `.account`) */ | 'skonto_other_eu_state_required' /** a part at 0 % on an account that takes both services taxed in another member state and turnover not taxable here, stating neither or both of `otherEuState` and `notTaxableHere`, or `notTaxableHere` on a part at a German rate (`details.field`, `.account`) */ | 'skonto_other_eu_state_case_required' /** a part taxed in another member state in the Skonto of a purchase (`details.field`, `.direction`) */ | 'skonto_other_eu_state_on_purchase' /** a part taxed in another member state given at a German rate (`details.field`, `.ratePercent`) */ | 'skonto_other_eu_state_with_german_rate' /** a part whose recipient owes the German tax (`selfAssessed`) in the Skonto of a sale (`details.field`, `.direction`) */ | 'skonto_self_assessed_on_sale' /** a part whose recipient owes the German tax that also names `otherEuState` or `notTaxableHere`, or an unknown `selfAssessed` (`details.field`) */ | 'skonto_self_assessed_conflict' // opening balances and the carry-forward /** an opening balance on a Saldenvortragskonto or a control account (`details.account`) */ | 'opening_balance_account_not_allowed' /** the same account or open item given twice (`details.account`) */ | 'opening_balance_duplicate' /** every opening balance is 0, or none was given */ | 'opening_balances_empty' /** a Saldenvortragskonto closes with a balance: the year's opening balances did not balance (`details.account`) */ | 'saldenvortrag_not_cleared' /** the closing balances do not sum to 0 (`details.differenceCents`) */ | 'closing_balances_unbalanced' /** the VAT of past years reclassified on a policy that names no accounts for it (`vatSettlement.previousYear`, `.earlierYears`) */ | 'vat_year_accounts_missing' /** a VAT account given per open item for the VAT of past years, which carries an account's balance whole (`details.account`) */ | 'vat_account_per_open_item' /** private accounts given for a company (`details.accounts`) */ | 'private_accounts_of_company' /** the partners' shares do not sum to the year's result (`details.differenceCents`) */ | 'partner_shares_mismatch' /** a private account no partner holds (`details.account`) */ | 'private_account_without_partner' /** the account that takes the result is given per open item (`details.account`) */ | 'result_account_per_open_item' /** the open items of an account do not sum to its balance (`details.account`, `.differenceCents`) */ | 'open_items_mismatch' // chart /** the chart in use lacks accounts the booking needs (`details.accounts`) */ | 'chart_account_missing' | 'shareholder_liability_kind_required' | 'shareholder_liability_account_required' | 'shareholder_liability_account_not_allowed' // offsets between personal accounts /** a side of an offset between personal accounts names no personal account of a customer or supplier (`details.field`, `.account`) */ | 'personal_account_required' /** an offset between personal accounts names one open item on both sides (one account, the same number or none): the claims meet on it already (`details.accounts`) */ | 'offset_same_account' /** a side of an offset between personal accounts gives its open item's number but blank (`details.field`) */ | 'offset_reference_required' // reversals /** the entry to reverse has no id */ | 'reversal_entry_without_id' /** the entry to reverse is not a valid entry (`details.errors`) */ | 'reversal_entry_invalid' /** a line to reverse is not as posted: not positive whole cents (`details.field`, `.amountCents`) */ | 'reversal_line_not_positive' // open items /** a receivable settled outside names no personal account of a customer (`details.field`, `.account`) */ | 'debtor_account_required' /** a receivable settled outside names no account the money went to (`details.field`) */ | 'settlement_account_required' /** a receivable settled outside names an account other than the till, the Privatentnahmen or the claim against a shareholder on its form's account, or a claim account without its form (`details.field` `account` or `shareholderForm`, `.account`) */ | 'settlement_account_not_allowed' /** a receivable settled outside with a reference given but blank: the invoice number that settles the open item, or none at all (`details.field`) */ | 'settlement_reference_required' /** a receivable settled outside with a Skonto or a tolerance but no open item they are measured against (`details.field`) */ | 'settlement_open_item_required' /** the open item is already settled: nothing to pay or refund (`details.account`) */ | 'open_item_settled' // advances /** the policy names no accounts of advances (`IAccountPolicy.advances`) */ | 'advance_accounts_missing' /** an advance at a rate other than 0, 7 or 19 % (`details.ratePercent`) */ | 'advance_rate_unsupported' /** the clearing of an advance names no personal account of the right kind: a customer's for a received one, a supplier's for a paid one (`details.field`, `.account`) */ | 'advance_party_account_required' /** an advance's input tax deducted for more than was paid of it (`details.field`, `.amountCents`, `.differenceCents`) */ | 'advance_deduction_beyond_payment' // the zero rate /** a zero-rated sale (`domestic_zero_rate`) that names no account, on a policy that names none (`IAccountPolicy.revenue.domesticZeroRate`; `details.scenario`) */ | 'zero_rate_account_missing' // goods /** the change in the stock of goods on a policy that names no accounts of goods (`IAccountPolicy.goods`; `details.field`) */ | 'goods_accounts_missing' /** the policy's stock or stock-change account has a DATEV tax automatism or is marked for the UStVA (`details.field`, `.account`) */ | 'goods_account_not_allowed' /** the stock the Inventar values is the stock the books carry: there is no change to book */ | 'inventory_unchanged' /** a stock valued or booked below 0 (`details.field`, `.amountCents`) */ | 'inventory_value_negative' // securities /** * a securities role the books keep no account for: DATEV's chart holds none, the books declare no individual * account with it, and the core books it on no account of its position, because the law keeps it apart (the * results of Termingeschäfte and of short sales; `details.field` the role, `.account` the parent an individual * account suggested for it follows, `.accounts` the numbers free after that parent) */ | 'securities_account_missing' /** amounts of a securities booking that do not fit together or a choice that does not fit the booking (`details.field`, `.amountCents`) */ | 'securities_input_invalid' // payroll /** a payroll role the books' chart keeps no account for (`details.field` the role) */ | 'payroll_account_missing' /** a payroll run whose costs are not its debts, its benefit in kind and what it leaves on the clearing account (`details.differenceCents`: costs less the rest) */ | 'payroll_run_unbalanced' /** an amount or a choice of a payroll booking that does not fit it (`details.field`, `.amountCents`) */ | 'payroll_input_invalid' // expense claims /** an expense role the books' chart keeps no account for (`details.field` the role) */ | 'expense_account_missing' /** an amount, a number or a choice of an expense claim's booking that does not fit it (`details.field`, `.amountCents`, `.account`, `.scenario`) */ | 'expense_claim_input_invalid' /** * the part of a vendor document's expense that is not deductible (`nondeductibleExpense`) on an account that is no * expense account of the chart or books a tax of its own, of no positive whole cents, beyond the document's * expense, or on a document with a correction's group or one whose recipient owes the tax (`details.field`, * `.account`, `.amountCents`, `.differenceCents`, `.scenario`) */ | 'nondeductible_expense_invalid'; /** What a refusal is about, where it helps a caller to show or resolve it. */ export interface IRecipeRefusalDetails { /** the input field refused, as the message names it, e.g. `expectedCents` or `skonto.shares[1].account` */ field?: string; /** the account refused */ account?: string; /** the accounts refused or missing */ accounts?: readonly string[]; /** the amount refused, as given */ amountCents?: number; /** the difference the refusal is about, in cents */ differenceCents?: number; /** the tolerance a difference exceeded, in cents */ toleranceCents?: number; /** the direction of the payment */ direction?: 'incoming' | 'outgoing'; /** the VAT rate refused */ ratePercent?: number; /** the tax scenario */ scenario?: TTaxScenario; /** the validation errors of an entry */ errors?: readonly string[]; } export class RecipeRefusalError extends Error { public readonly code: TRecipeRefusalCode; public readonly details: IRecipeRefusalDetails; constructor(code: TRecipeRefusalCode, message: string, details: IRecipeRefusalDetails = {}) { super(message); this.name = 'RecipeRefusalError'; this.code = code; this.details = details; } } /** * A chart of accounts skr does not keep: another name, another spelling, or * none, where SKR03 or SKR04 is required (`assertSkrType`, `chartOf`). skr * never reads such a value as either chart. `details.chart` is the value as * it was given. */ export class UnknownChartError extends Error { public readonly code = 'chart_unknown' as const; public readonly details: { readonly chart: unknown }; constructor(chartArg: unknown) { super(`unknown chart of accounts ${typeof chartArg === 'string' ? `'${chartArg}'` : String(chartArg)}: skr keeps SKR03 and SKR04`); this.name = 'UnknownChartError'; this.details = { chart: chartArg }; } }