Files
skr/ts/skr.types.ts
Juergen Kunz 4f1066da2e feat: Enhance journal entry and transaction handling with posting keys
- Added posting key support to SKR03 and SKR04 journal entries and transactions to ensure DATEV compliance.
- Implemented validation for posting keys in journal entries, ensuring all lines have a posting key and that they are consistent across the entry.
- Introduced automatic account checks to prevent posting to accounts that cannot be directly posted to (e.g., 1400, 1600).
- Updated account validation to include checks for debtor and creditor ranges.
- Enhanced invoice booking logic to include appropriate posting keys based on VAT rates and scenarios.
- Created a new module for posting key definitions and validation rules, including functions for validating posting keys and suggesting appropriate keys based on transaction parameters.
- Updated tests to cover new posting key functionality and ensure compliance with accounting rules.
2025-10-27 08:34:28 +00:00

182 lines
4.0 KiB
TypeScript

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
}
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;
postingKey: TPostingKey; // REQUIRED: DATEV posting key for VAT automation control
}
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;
}
export interface IDatabaseConfig {
mongoDbUrl: string;
dbName?: string;
invoiceExportPath?: string; // Optional path for invoice storage
}
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;
}