Giter Club home page Giter Club logo

double-entry-bookkeeping-api's Introduction

Build Status codecov Codacy Badge Maven Central PRs Welcome License: MIT

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.

Description

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:

  • An account MUST NOT be overdrawn, i.e. have a negative balance.
  • A monetary transaction MAY support multiple currencies as long as the total balance for the transaction legs with the same currency is zero.
  • The concepts of debit and credit are simplified by specifying that monetary transactions towards an account can have either a positive or negative value.

API

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();

Build

mvn package

Contributing

If you would like to help making this project better, see the CONTRIBUTING.md.

Maintainers

Send any other comments and suggestions to Yani Metaxas.

License

This project is distributed under the MIT License.

double-entry-bookkeeping-api's People

Contributors

imetaxas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

double-entry-bookkeeping-api's Issues

Implement an account list method

Ledger ledger = new LedgerBuilder(chartOfAccounts)
.name("JDBC H2")
.options(options)
.build()
.init();
List accounts = ledger.list();

License

Hello,
I'm trying your code ... it seems really well done!
I'm planning to use part of it in a project, I will have to change various parts beauce I use guice and not spring.
Could you add a license? the most useful for the purposes of development would be the MIT ...
thank you very much!

Validate TransferRequest reference

Throw a proper exception message:

at com.yanimetaxas.bookkeeping.dao.TransactionDaoImpl.storeTransaction(TransactionDaoImpl.java:42)
at com.yanimetaxas.bookkeeping.service.TransferServiceImpl.storeTransaction(TransferServiceImpl.java:56)
at com.yanimetaxas.bookkeeping.service.TransferServiceImpl.transferFunds(TransferServiceImpl.java:40)
at com.yanimetaxas.bookkeeping.model.Ledger.commit(Ledger.java:36)
at com.yanimetaxas.bookkeeping.model.LedgerTest.accountBalancesUpdatedAfterTransferUsingJdbcMysql(LedgerTest.java:216)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'Client_1530466126023-T1' for key 'PRIMARY'

Schema:
PRIMARY KEY(client_ref, transaction_ref)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.