A library of the Double-entry bookkeeping concept which is downloadable from the Central Repository.
View the Project on GitHub imetaxas/double-entry-bookkeeping-api
A library of the Double-entry bookkeeping concept which is downloadable from the Central Repository.
It uses Spring 5 and the Java Transaction API internally.
It supports H2, HSQL and Derby databases in embedded mode.
And H2, MySQL and Postgres using JDBC.
Double-entry bookkeeping involves making at least two entries or legs for every transaction. A debit in one account and a corresponding credit in another account. The sum of all debits should always equal the sum of all credits, providing a simple way to check for errors. The following rules MUST apply:
Using embedded H2
ChartOfAccounts chartOfAccounts = new ChartOfAccountsBuilder()
.create("CASH_ACCOUNT_1", "1000.00", "EUR")
.create("REVENUE_ACCOUNT_1", "0.00", "EUR")
.build();
Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("My Embedded H2 ledger")
.build()
.init();
Using Embedded HSQL
ChartOfAccounts chartOfAccounts = new ChartOfAccountsBuilder()
.create("CASH_ACCOUNT_1", "1000.00", "EUR")
.create("REVENUE_ACCOUNT_1", "0.00", "EUR")
.build();
Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("My Embedded HSQL ledger")
.options(ConnectionOptions.EMBEDDED_HSQL_CONNECTION)
.build()
.init();
Using Embedded Derby
ChartOfAccounts chartOfAccounts = new ChartOfAccountsBuilder()
.create("CASH_ACCOUNT_1", "1000.00", "EUR")
.create("REVENUE_ACCOUNT_1", "0.00", "EUR")
.build();
Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("My Embedded Derby ledger")
.options(ConnectionOptions.EMBEDDED_DERBY_CONNECTION)
.build()
.init();
Using JDBC H2
ConnectionOptions options = new ConnectionOptions(DataSourceDriver.JDBC_H2)
.url("URL")
.username("USERNAME")
.password("PASSWORD");
Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("My JDBC H2 ledger")
.options(options)
.build()
.init();
Using JDBC MySQL
ConnectionOptions options = new ConnectionOptions(DataSourceDriver.JDBC_MYSQL)
.url("URL")
.username("USERNAME")
.password("PASSWORD");
Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("My JDBC MYSQL ledger")
.options(options)
.build()
.init();
Using JDBC Postgres
ConnectionOptions options = new ConnectionOptions(DataSourceDriver.JDBC_POSTGRES)
.url("URL")
.username("USERNAME")
.password("PASSWORD");
Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("My JDBC POSTGRES ledger")
.options(options)
.build()
.init();
Create new accounts and include already created ones in the ledger
ChartOfAccounts chartOfAccounts = new ChartOfAccountsBuilder()
.create("CASH_ACCOUNT_1", "1000.00", "EUR")
.create("REVENUE_ACCOUNT_1", "0.00", "EUR")
.includeExisted("ACCOUNT_1")
.includeExisted("ACCOUNT_2")
.build();
Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("Ledger with both new and already created accounts")
.options(options)
.build()
.init();
Commit Transfer Requests
TransferRequest transferRequest1 = ledger.createTransferRequest()
.reference("T1")
.type("testing1")
.account("CASH_ACCOUNT_1").debit("5.00", "EUR")
.account("REVENUE_ACCOUNT_1").credit("5.00", "EUR")
.build();
ledger.commit(transferRequest1);
TransferRequest transferRequest2 = ledger.createTransferRequest()
.reference("T2")
.type("testing2")
.account("CASH_ACCOUNT_1").debit("10.50", "EUR")
.account("REVENUE_ACCOUNT_1").credit("10.50", "EUR")
.build();
ledger.commit(transferRequest2);
Search the Ledger for committed Transactions
List<Transaction> cashAccountTransactionList = ledger.findTransactions("CASH_ACCOUNT_1");
List<Transaction> revenueAccountTransactionList = ledger.findTransactions("REVENUE_ACCOUNT_1");
Transaction transaction1 = ledger.getTransactionByRef("T1");
Transaction transaction2 = ledger.getTransactionByRef("T2");
Print the Ledger’s history of operations
ledger.printHistoryLog();
mvn package
If you would like to help making this project better, see the CONTRIBUTING.md.
Send any other comments and suggestions to Yani Metaxas.
This project is distributed under the MIT License.