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:
2025-10-27 08:34:28 +00:00
parent 73b46f7857
commit 4f1066da2e
13 changed files with 758 additions and 229 deletions

View File

@@ -29,8 +29,8 @@ tap.test('should enforce double-entry bookkeeping rules', async () => {
description: 'Unbalanced entry',
reference: 'TEST-001',
lines: [
{ accountNumber: '1000', debit: 100 },
{ accountNumber: '4000', credit: 50 }, // Unbalanced!
{ accountNumber: '1000', debit: 100, postingKey: 40 },
{ accountNumber: '4000', credit: 50, postingKey: 40 }, // Unbalanced!
],
skrType: 'SKR03',
});
@@ -99,10 +99,10 @@ tap.test(
description: 'Complex distribution',
reference: 'COMPLEX-001',
lines: [
{ accountNumber: '5000', debit: 500, description: 'Materials' },
{ accountNumber: '6000', debit: 300, description: 'Wages' },
{ accountNumber: '7100', debit: 200, description: 'Rent' },
{ accountNumber: '1200', credit: 1000, description: 'Bank payment' },
{ accountNumber: '5000', debit: 500, description: 'Materials', postingKey: 40 },
{ accountNumber: '6000', debit: 300, description: 'Wages', postingKey: 40 },
{ accountNumber: '7100', debit: 200, description: 'Rent', postingKey: 40 },
{ accountNumber: '1200', credit: 1000, description: 'Bank payment', postingKey: 40 },
],
skrType: 'SKR03',
});
@@ -220,10 +220,19 @@ tap.test('should handle batch transaction posting', async () => {
});
tap.test('should handle transaction with VAT', async () => {
// Create creditor account for supplier
await api.createAccount({
accountNumber: '70001',
accountName: 'Lieferant Test GmbH',
accountClass: 7,
accountType: 'liability',
skrType: 'SKR03',
});
const transaction = await api.postTransaction({
date: new Date(),
debitAccount: '5400', // Goods with 19% VAT
creditAccount: '1600', // Trade payables
creditAccount: '70001', // Creditor account (supplier)
amount: 119,
description: 'Purchase including VAT',
skrType: 'SKR03',