import * as plugins from './plugins.js'; import { Account } from './skr.classes.account.js'; import { JournalEntry } from './skr.classes.journalentry.js'; import { type IExportOptions } from './skr.export.js'; import * as core from './core/index.js'; import { type IPostDraftOptions } from './skr.posting.js'; import { type ILedgerPeriodState } from './skr.period.js'; import { type IChainVerificationResult } from './skr.verify.js'; import { type IBalanceQueryOptions, type ITrialBalanceCents, type IAccountBalanceCents } from './skr.balances.js'; import { type ISkrMigrationRecord } from '../dist_ts_migration/index.js'; import { type IBookingOptions, type IBookingResult } from './skr.invoice.booking.js'; import type { IInvoice, IInvoiceFilter, IInvoiceImportOptions, IInvoiceExportOptions, IBookingRules, TInvoiceDirection } from './skr.invoice.entity.js'; import type { TDatabaseConfig, TSKRType, IAccountData, IAccountFilter, ITransactionData, ITransactionFilter, IJournalEntry, IReportParams, ITrialBalanceReport, IIncomeStatement, IBalanceSheet, IAccountBalance, ITransactionView } from './skr.types.js'; /** * Main API class for SKR accounting operations */ export declare class SkrApi { private config; private chartOfAccounts; private ledger; private reports; private logger; private initialized; private currentSKRType; private invoiceAdapter; private invoiceStorage; private invoiceBookingEngine; private journalPoster; /** the books' individual accounts as stored, read on `initialize` and after every change through this API; the default policy carries them */ private individualAccounts; constructor(config: TDatabaseConfig); /** * Initialize the API with specified SKR type */ initialize(skrType: TSKRType): Promise; /** * Ensure API is initialized */ private ensureInitialized; /** * Create a new account */ createAccount(accountData: Partial): Promise; /** * Get account by number */ getAccount(accountNumber: string): Promise; /** * Update an account */ updateAccount(accountNumber: string, updates: Partial): Promise; /** * Delete an account */ deleteAccount(accountNumber: string): Promise; /** * Declare an individual account of the books (Individualkonto) on a number * DATEV leaves free after the account it belongs to; the default policy * (`getDefaultPolicy`) carries it from then on. @fin.cx/chartdata checks it * together with the individual accounts already declared and refuses it * with its `IndividualAccountsError` (`problems`); nothing is stored then. */ declareIndividualAccount(declaration: plugins.chartdata.IIndividualAccountDeclaration): Promise; /** * The declarations of the books' individual accounts as stored, by account * number. Reading them also refreshes the ones the default policy carries, * so declarations stored by another instance are taken. */ getIndividualAccounts(): Promise; /** * List accounts with optional filter */ listAccounts(filter?: IAccountFilter): Promise; /** * Search accounts by term */ searchAccounts(searchTerm: string): Promise; /** * Get accounts by class */ getAccountsByClass(accountClass: number): Promise; /** * Get accounts by type */ getAccountsByType(accountType: IAccountData['accountType']): Promise; /** * Post a simple transaction. Since v2 this creates a hashed two-line * journal entry (exact cents) — the Transaction collection is frozen. */ postTransaction(transactionData: ITransactionData): Promise; /** * Post a journal entry. Since v2 the entry is hashed, sequenced, and * immutable; float inputs are converted to exact cents with a drift guard. */ postJournalEntry(journalData: IJournalEntry): Promise; /** * Get a transaction view by id (two-line v2 entries project 1:1). */ getTransaction(transactionId: string): Promise; /** * List transaction views with optional filter (two-line v2 entries). */ listTransactions(filter?: ITransactionFilter): Promise; /** * Get per-line transaction views for one account. */ getAccountTransactions(accountNumber: string): Promise; /** * Reverse via Storno — the original entry is never mutated (GoBD). */ reverseTransaction(transactionId: string): Promise; /** * Reverse a journal entry via Storno. */ reverseJournalEntry(journalId: string): Promise; /** * Generate trial balance */ generateTrialBalance(params?: IReportParams): Promise; /** * Generate income statement */ generateIncomeStatement(params?: IReportParams): Promise; /** * Generate balance sheet */ generateBalanceSheet(params?: IReportParams): Promise; /** * Generate general ledger */ generateGeneralLedger(params?: IReportParams): Promise; /** * Generate cash flow statement */ generateCashFlowStatement(params?: IReportParams): Promise; /** * Export report to CSV */ exportReportToCSV(reportType: 'trial_balance' | 'income_statement' | 'balance_sheet', params?: IReportParams): Promise; /** * Export to DATEV format (EXTF 700 Buchungsstapel over v2 entries). * For a fully parameterized export use exportDatevBuchungsstapel(). */ exportToDATEV(params?: IReportParams): Promise; /** * Close accounting period: post P&L-zeroing entries (v2) into the period. * Locking is a separate deliberate act — call festschreibePeriod() after. */ closePeriod(period: string, closingAccountNumber?: string): Promise; /** * Get account balance (aggregated from v2 entries, exact cents inside). */ getAccountBalance(accountNumber: string, asOfDate?: Date): Promise; /** * Refresh the (informational) balance caches on Account documents from the * aggregated v2 ledger. */ recalculateBalances(): Promise; /** * Import accounts from CSV */ importAccountsFromCSV(csvContent: string): Promise; /** * Export accounts to CSV */ exportAccountsToCSV(): Promise; /** * Export Jahresabschluss in GoBD-compliant BagIt format * Creates a revision-safe export for 10-year archival */ exportJahresabschluss(options: IExportOptions): Promise; /** * Export ledger data in NDJSON format */ private exportLedgerData; /** * Export account data in CSV format */ private exportAccountData; /** * Export balance data in CSV format */ private exportBalanceData; /** * Generate PDF reports for the export */ private generatePdfReports; /** * Sign the export with CAdES signature */ private signExport; /** * Default account policy for the active chart, with the books' individual * accounts (`individualAccounts`) where they declare any: the drafts this * API validates and the recipes built on it see an individual account as * its parent. */ getDefaultPolicy(): core.IAccountPolicy; /** * Post a validated journal draft atomically (v2 path: exact cents, * gapless sequence, hash chain). Use the recipes in `core` to build drafts. */ postDraft(draft: core.IJournalDraft, options?: IPostDraftOptions): Promise; /** * Reverse a hashed entry via Storno — the original is never mutated. */ postStorno(entry: JournalEntry, options?: IPostDraftOptions & { date?: Date; description?: string; }): Promise; /** * Festschreibung: finalize all posted v2 entries of a period and lock it * against further postings (GoBD). */ festschreibePeriod(period: string, lockedBy?: string): Promise<{ finalizedEntries: number; }>; getPeriodState(period: string): Promise; /** * Recompute the whole hash chain for a fiscal year and compare it against * the stored chain head — the audit-trail integrity check. */ verifyAuditChain(fiscalYear: number): Promise; /** * Exact trial balance in integer cents, aggregated from v2 entries. */ getTrialBalanceCents(options?: IBalanceQueryOptions): Promise; getAccountBalanceCents(accountNumber: string, options?: IBalanceQueryOptions): Promise; /** * DATEV Buchungsstapel (EXTF 700 / v13) over the v2 entries of a date * range. Returns the CSV string (persist as CP1252!) and filename. */ exportDatevBuchungsstapel(options: { dateFrom: Date; dateTo: Date; consultantNumber: number; clientNumber: number; fiscalYearStart: Date; label?: string; festschreibung?: boolean; createdAt?: Date; }): Promise<{ csv: string; filename: string; rowCount: number; }>; /** * The migration steps applied to this database, oldest first, each with its * report (Verfahrensdokumentation artifact). `initialize()` runs pending * steps before anything else touches the ledger. */ getMigrationRecords(): Promise; listOpenItems(options?: { kind?: import('./skr.opos.js').TOposKind; accountNumber?: string; asOf?: Date; includeSettled?: boolean; }): Promise; getOposAging(kind: import('./skr.opos.js').TOposKind, asOf: Date, bucketDays?: number[]): Promise; getControlTotals(asOf?: Date): Promise; /** * One period's movements + exact igE/§13b scenario bases, with the books' * individual accounts, shaped for @fin.cx/tax `computeUstva()`. Review * `warnings` before filing. */ getUstvaPeriodData(dateFrom: Date, dateTo: Date): Promise; setDunning(params: { accountNumber: string; reference: string; dunningLevel?: number; dueDate?: string; }): Promise; /** * Settle an open item with a bank payment (Skonto and small-difference * write-offs via the core recipe); ordinary v2 posting, fully audited. * * An item with a NEGATIVE openCents is a credit in the counterparty's * favour — what a customer credit note leaves behind on an invoice that was * already paid. It is settled by paying the money back, so the direction * flips (see planOpenItemSettlement); the refund repeats the item's * reference and therefore clears the same open item. */ settleOpenItem(params: { item: import('./skr.opos.js').IOpenItem; paidCents: number; date: Date; bankAccount?: string; /** the Skonto at one rate, or split over the rates of the invoice (see core.bookBankPayment) */ skonto?: core.TBankPaymentSkonto; diffToleranceCents?: number; description?: string; }): Promise; /** * Get current SKR type */ getSKRType(): TSKRType | null; /** * Get account class description */ getAccountClassDescription(accountClass: number): string; /** * Validate double-entry rules */ validateDoubleEntry(debitAmount: number, creditAmount: number): boolean; /** * Get unbalanced transactions (for audit) */ getUnbalancedTransactions(): Promise; /** * Close the API and database connection */ close(): Promise; /** * Post multiple transactions */ postBatchTransactions(transactions: ITransactionData[]): Promise; /** * Create multiple accounts */ createBatchAccounts(accounts: IAccountData[]): Promise; /** * Get paginated accounts */ getAccountsPaginated(page?: number, pageSize?: number, filter?: IAccountFilter): Promise<{ data: Account[]; total: number; page: number; pageSize: number; totalPages: number; }>; /** * Get paginated transactions */ getTransactionsPaginated(page?: number, pageSize?: number, filter?: ITransactionFilter): Promise<{ data: ITransactionView[]; total: number; page: number; pageSize: number; totalPages: number; }>; /** * Import an invoice from file or buffer * Parses, validates, and optionally books the invoice */ importInvoice(file: Buffer | string, direction: TInvoiceDirection, options?: IInvoiceImportOptions): Promise; /** * Book an invoice to the ledger */ bookInvoice(invoice: IInvoice, bookingRules?: Partial, options?: IBookingOptions): Promise; /** * Export an invoice in a different format */ exportInvoice(invoice: IInvoice, options: IInvoiceExportOptions): Promise<{ xml: string; pdf?: Buffer; }>; /** * Search invoices by filter */ searchInvoices(filter: IInvoiceFilter): Promise; /** * Get invoice by content hash */ getInvoice(contentHash: string): Promise; /** * Get invoice storage statistics */ getInvoiceStatistics(): Promise; /** * Create EN16931 compliance report for invoices */ createInvoiceComplianceReport(): Promise; /** * Generate an invoice from internal data */ generateInvoice(invoiceData: Partial, format: IInvoiceExportOptions['format']): Promise<{ xml: string; pdf?: Buffer; }>; }