import type * as plugins from './plugins.js'; import type { TReverseChargeParagraph } from './core/core.types.js'; export type TAccountType = | 'asset' | 'liability' | 'equity' | 'revenue' | 'expense'; export type TSKRType = 'SKR03' | 'SKR04'; export type TTransactionStatus = 'pending' | 'posted' | 'reversed'; /** * DATEV posting keys (Buchungsschlüssel) for German accounting * These keys control automatic VAT booking and are checked in tax audits */ export type TPostingKey = | 3 // Payment with 19% VAT | 8 // 7% input VAT | 9 // 19% input VAT | 19 // 19% input VAT (intra-EU) | 40 // Tax-free (disables VAT automatism) | 94; // 19% input/output VAT (reverse charge) export type TReportType = | 'trial_balance' | 'income_statement' | 'balance_sheet' | 'general_ledger' | 'cash_flow'; /** * Posting key validation rule */ export interface IPostingKeyRule { key: TPostingKey; description: string; vatRate?: number; // Expected VAT rate (if applicable) requiresVAT: boolean; // Whether VAT entry is required disablesVATAutomatism: boolean; // Whether this key disables automatic VAT allowedScenarios?: string[]; // Allowed tax scenarios (e.g., 'reverse_charge') } export interface IAccountData { accountNumber: string; accountName: string; accountClass: number; accountType: TAccountType; skrType: TSKRType; description?: string; vatRate?: number; isActive?: boolean; isAutomaticAccount?: boolean; // Automatikkonto (e.g., 1400, 1600) - cannot be posted to directly /** * An individual account of the books (Individualkonto, declared with * `ChartOfAccounts.declareIndividualAccount`): the DATEV account it belongs * to; unset = an account of the chart or a custom account */ parentAccountNumber?: string; /** the securities role an individual account's declaration names; unset = none */ securitiesRole?: plugins.chartdata.TSecuritiesRole; /** what an individual account's declaration changes of what it takes from its parent; unset = nothing */ overrides?: plugins.chartdata.IIndividualAccountOverrides; } export interface ITransactionData { date: Date; debitAccount: string; creditAccount: string; amount: number; description: string; reference?: string; skrType: TSKRType; vatAmount?: number; costCenter?: string; } export interface IJournalEntry { date: Date; description: string; reference?: string; lines: IJournalEntryLine[]; skrType: TSKRType; } export interface IJournalEntryLine { accountNumber: string; debit?: number; credit?: number; description?: string; costCenter?: string; /** v1 numeric DATEV posting key; optional since schemaVersion 2 (see buKey) */ postingKey?: TPostingKey; // --- schemaVersion 2 fields (exact cents, explicit side and Gegenkonto) --- side?: 'debit' | 'credit'; amountCents?: number; counterAccount?: string; /** string-typed DATEV BU-Schlüssel ('' = none) */ buKey?: string; buchungstext?: string; belegfeld1?: string; costCenter1?: string; docLink?: string; /** informational VAT share carried on the line (v1 compatibility) */ vatAmountCents?: number; /** * the paragraph of § 13b UStG the line's keyed base falls under * (`IJournalLineDraft.reverseChargeParagraph`); hashed only where present, * so an entry posted without it keeps its hash */ reverseChargeParagraph?: TReverseChargeParagraph; } /** * Transaction-shaped projection of a v2 journal entry (or one of its lines). * The Transaction collection is frozen in v2 — reads go through these views. */ export interface ITransactionView { id: string; transactionNumber: string; date: Date; debitAccount: string; creditAccount: string; amount: number; vatAmount: number; description: string; reference: string; skrType: TSKRType; status: string; period: string; fiscalYear: number; costCenter?: string; /** id of the entry this one reverses (Storno linkage) */ reversalOf?: string; } export interface ITrialBalanceEntry { accountNumber: string; accountName: string; debitBalance: number; creditBalance: number; netBalance: number; } export interface ITrialBalanceReport { date: Date; skrType: TSKRType; entries: ITrialBalanceEntry[]; totalDebits: number; totalCredits: number; isBalanced: boolean; } export interface IIncomeStatementEntry { accountNumber: string; accountName: string; amount: number; percentage?: number; } export interface IIncomeStatement { date: Date; skrType: TSKRType; revenue: IIncomeStatementEntry[]; expenses: IIncomeStatementEntry[]; totalRevenue: number; totalExpenses: number; netIncome: number; } export interface IBalanceSheetEntry { accountNumber: string; accountName: string; amount: number; } export interface IBalanceSheet { date: Date; skrType: TSKRType; assets: { current: IBalanceSheetEntry[]; fixed: IBalanceSheetEntry[]; totalAssets: number; }; liabilities: { current: IBalanceSheetEntry[]; longTerm: IBalanceSheetEntry[]; totalLiabilities: number; }; equity: { entries: IBalanceSheetEntry[]; totalEquity: number; }; isBalanced: boolean; } export interface IAccountFilter { skrType?: TSKRType; accountClass?: number; accountType?: TAccountType; isActive?: boolean; searchTerm?: string; } export interface ITransactionFilter { skrType?: TSKRType; dateFrom?: Date; dateTo?: Date; accountNumber?: string; minAmount?: number; maxAmount?: number; searchTerm?: string; } interface IDatabaseConfigBase { /** Directory the invoice storage writes to (default `./exports/invoices`). */ invoiceExportPath?: string; } /** skr opens, owns and closes its own connection to this database. */ export interface IDatabaseConnectionConfig extends IDatabaseConfigBase { mongoDbUrl: string; dbName?: string; db?: never; } /** * skr uses a database the caller connected (`init()` already awaited) and * owns: it prepares its collections in it and never closes it. */ export interface IDatabaseInstanceConfig extends IDatabaseConfigBase { db: plugins.nosqldb.SmartdataDb; mongoDbUrl?: never; dbName?: never; } export type TDatabaseConfig = IDatabaseConnectionConfig | IDatabaseInstanceConfig; export interface IReportParams { dateFrom?: Date; dateTo?: Date; skrType: TSKRType; format?: 'json' | 'csv' | 'datev'; } export interface IAccountBalance { accountNumber: string; debitTotal: number; creditTotal: number; balance: number; lastUpdated: Date; }