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.
This commit is contained in:
@@ -9,6 +9,18 @@ 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'
|
||||
@@ -16,6 +28,18 @@ export type TReportType =
|
||||
| '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;
|
||||
@@ -25,6 +49,7 @@ export interface IAccountData {
|
||||
description?: string;
|
||||
vatRate?: number;
|
||||
isActive?: boolean;
|
||||
isAutomaticAccount?: boolean; // Automatikkonto (e.g., 1400, 1600) - cannot be posted to directly
|
||||
}
|
||||
|
||||
export interface ITransactionData {
|
||||
@@ -53,6 +78,7 @@ export interface IJournalEntryLine {
|
||||
credit?: number;
|
||||
description?: string;
|
||||
costCenter?: string;
|
||||
postingKey: TPostingKey; // REQUIRED: DATEV posting key for VAT automation control
|
||||
}
|
||||
|
||||
export interface ITrialBalanceEntry {
|
||||
|
||||
Reference in New Issue
Block a user