@x47base/ch-finance-engine
v1.0.2-beta2
Published
This package is an finance and accounting engine specificly made based on the swiss system.
Downloads
44
Maintainers
Readme
ch-finance-engine
Table of Contents
Introduction
ch-finance-engine is a Node.js package designed for Swiss-style accounting and finance operations. It enables double-entry bookkeeping, currency conversions, and transaction management while maintaining compliance with Swiss accounting standards.
Features
- Double-entry bookkeeping (Soll/Haben)
- Multi-currency support with configurable exchange rates
- Year-end closure of books and account management
- Supports multiple transaction types: Buchung, Sammelbuchung, Splitsammelbuchung, Rückbuchung
- Extensive unit tests for reliability
Installation
To install the latest version, run:
npm install @x47base/[email protected]Usage
Basic Example
const { Engine } = require("@x47base/ch-finance-engine");
function demo() {
const engine = new Engine("standard-config");
// Create a Book for 2025
const book2025 = engine.createBook(2025);
// Create Accounts
const bankAccount = engine.createAccount("Aktiv", 1000, "Bank", ["BankKonto"], 5000.0);
const liabilities = engine.createAccount("Passiv", 2000, "Verbindlichkeiten L+L", ["Kreditoren"], 0.0);
// Add to Book
book2025.addAccount(bankAccount);
book2025.addAccount(liabilities);
// Perform a double-entry posting (Buchung)
engine.performBuchung(1, bankAccount.code, liabilities.code, 500, "CHF", "Initial Payment");
console.log(JSON.stringify(engine.toJSON(), null, 2));
}
demo();Example with Template Accounts
const { Engine } = require("@x47base/ch-finance-engine");
function demoWithTemplateAccounts() {
const engine = new Engine("standard-config");
// Load template accounts
engine.loadTemplateAccounts();
// Create a Book for 2025
const book2025 = engine.createBook(2025);
// Get Accounts
const bankAccount = engine.getAccountByCode(1000); // Kasse
const liabilities = engine.getAccountByCode(2000); // Verbindlichkeiten aus Lieferungen und Leistungen
// Add to Book
book2025.addAccount(bankAccount);
book2025.addAccount(liabilities);
// Perform a double-entry posting (Buchung)
engine.performBuchung(1, bankAccount.code, liabilities.code, 500, "CHF", "Initial Payment");
console.log(JSON.stringify(engine.toJSON(), null, 2));
}
demoWithTemplateAccounts();Documentation
Engine Class
new Engine(configFile: string = "standard-config")
Creates an engine instance using the specified configuration file.
createBook(year: number)
Creates a new accounting book for the specified year.
createAccount(type: "Aktiv"|"Passiv"|"Aufwand"|"Ertrag", code: number, name: string, aliases: Array<string>, balance: number)
Creates an account with the given parameters.
performBuchung(id: number, accountSoll: number, accountHaben: number, amount: number, currency: string, description: string)
Performs a double-entry transaction between two accounts.
toJSON()
Returns the entire engine state as a JSON object.
License
This project is licensed under a modified MIT license. The author retains the right to modify the license terms in future versions.
