Skip to content

Commit

Permalink
Added classes to supprt Journalized entry workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ghacupha committed Mar 21, 2018
1 parent 9c14d63 commit 7581789
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 73 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ Changelog for ghacupha book-keeper.

[c366bc1cdb1e91f](https://github.com/ghacupha/book-keeper/commit/c366bc1cdb1e91f) ghacupha *2018-03-18 09:02:18*

**amended wrong type in the account**
**amended wrong type in the journal**


[9f80fed5aabbb7d](https://github.com/ghacupha/book-keeper/commit/9f80fed5aabbb7d) ghacupha *2018-03-18 08:58:38*

**added tests for the account**
**added tests for the journal**


[23bbdf320d952d3](https://github.com/ghacupha/book-keeper/commit/23bbdf320d952d3) ghacupha *2018-03-18 08:57:42*
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ The book-keeper can also track entire transactions, each of which may contain se
```java
public class AccountingTransactionTest {

// Subscriptions expense account
// Subscriptions expense journal
Account subscriptionExpenseAccount;
AccountAttributes subscriptionExpenseAccountAttributes;
EntryAttributes subscriptionAccountEntryDetails;

// Withhoding tax account
// Withhoding tax journal
Account withholdingTaxAccount;
AccountAttributes withholdingTaxAccountAttributes;
EntryAttributes withholdingTaxDetailsEntry;

// Banker's cheque suspense account
// Banker's cheque suspense journal
Account bankersChqAccountSuspense;
AccountAttributes bankersChequeAccountDetails;
EntryAttributes bankersChequeAccountEntry;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/github/ghacupha/keeper/book/api/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.github.ghacupha.keeper.book.api;

import io.github.ghacupha.keeper.book.base.Account;
import io.github.ghacupha.keeper.book.base.EntryDetails;
import io.github.ghacupha.keeper.book.unit.money.Cash;
import io.github.ghacupha.keeper.book.unit.time.TimePoint;
Expand All @@ -33,7 +32,7 @@
*/
public interface Entry {

Entry newEntry(Account account, EntryAttributes entryAttributes, Cash amount, TimePoint bookingDate);
Entry newEntry(Account journal, EntryAttributes entryAttributes, Cash amount, TimePoint bookingDate);

EntryAttributes getEntryAttributes();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2018 Edwin Njeru
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.ghacupha.keeper.book.api;

import io.github.ghacupha.keeper.book.balance.JournalSide;
import io.github.ghacupha.keeper.book.unit.money.Cash;
import io.github.ghacupha.keeper.book.util.ImmutableEntryException;
import io.github.ghacupha.keeper.book.util.MismatchedCurrencyException;
import io.github.ghacupha.keeper.book.util.UnableToPostException;

import java.util.Currency;

public interface JournalizedTransaction {

/**
* This method creates a {@link Entry} and adds that to the {@link Account} in the parameter
* and also adds it to this {@link Transaction} provided the {@link Transaction} is not already posted
*
* @param amount {@link Cash} amount being posted to the journal
* @param account {@link Account} into which the {@link Entry} is being added
* @param attributes {@link EntryAttributes} related to the Entry being added to the {@link Account} that is
* being created in this method.
* @throws ImmutableEntryException Thrown if the {@link Transaction} is already posted when this method is running
* @throws MismatchedCurrencyException Thrown if the {@link Currency} of the {@link Entry} or {@link Account}
* is mismatched with the {@link Currency} of this {@link Transaction}
*/
void add(JournalSide journalSide,Cash amount, Account account, EntryAttributes attributes) throws ImmutableEntryException, MismatchedCurrencyException;

/**
* Posts the transactions into respective {@link Account} items
*
* @throws UnableToPostException {@link UnableToPostException} thrown when the transaction is not balanced
* That is if the items posted on the debit are more than those posted on the credit or vice versa.
*/
void post() throws UnableToPostException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.ghacupha.keeper.book.api;

import io.github.ghacupha.keeper.book.base.Journal;
import io.github.ghacupha.keeper.book.unit.money.Cash;
import io.github.ghacupha.keeper.book.util.ImmutableEntryException;
import io.github.ghacupha.keeper.book.util.MismatchedCurrencyException;
Expand All @@ -35,15 +36,15 @@ public interface Transaction {
* This method creates a {@link Entry} and adds that to the {@link Account} in the parameter
* and also adds it to this {@link Transaction} provided the {@link Transaction} is not already posted
*
* @param amount {@link Cash} amount being posted to the account
* @param amount {@link Cash} amount being posted to the journal
* @param account {@link Account} into which the {@link Entry} is being added
* @param attributes {@link EntryAttributes} related to the Entry being added to the {@link Account} that is
* being created in this method.
* @throws ImmutableEntryException Thrown if the {@link Transaction} is already posted when this method is running
* @throws MismatchedCurrencyException Thrown if the {@link Currency} of the {@link Entry} or {@link Account}
* is mismatched with the {@link Currency} of this {@link Transaction}
*/
void add(Cash amount, io.github.ghacupha.keeper.book.base.Account account, EntryAttributes attributes) throws ImmutableEntryException, MismatchedCurrencyException;
void add(Cash amount, Account account, EntryAttributes attributes) throws ImmutableEntryException, MismatchedCurrencyException;

/**
* Posts the transactions into respective {@link Account} items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ public class AccountBalance {
private static final Logger log = LoggerFactory.getLogger(AccountBalance.class);

private final Cash amount;
private final AccountBalanceType accountBalanceType;
private final JournalSide journalSide;

public AccountBalance(Cash amount, AccountBalanceType accountBalanceType) {
public AccountBalance(Cash amount, JournalSide journalSide) {
this.amount = amount;
this.accountBalanceType = accountBalanceType;
this.journalSide = journalSide;

log.debug("AccountBalance created : {}", this);
}

public static AccountBalance newBalance(Cash amount, AccountBalanceType accountBalanceType) {
public static AccountBalance newBalance(Cash amount, JournalSide journalSide) {

return new AccountBalance(amount, accountBalanceType);
return new AccountBalance(amount, journalSide);
}

private String balance() {

return amount.getNumber().doubleValue() + " " + accountBalanceType;
return amount.getNumber().doubleValue() + " " + journalSide;
}

public Cash getAmount() {
return amount;
}

public AccountBalanceType getAccountBalanceType() {
return accountBalanceType;
public JournalSide getJournalSide() {
return journalSide;
}

@Override
Expand All @@ -71,18 +71,18 @@ public boolean equals(Object o) {
if (!amount.equals(that.amount)) {
return false;
}
return accountBalanceType == that.accountBalanceType;
return journalSide == that.journalSide;
}

@Override
public int hashCode() {
int result = amount.hashCode();
result = 31 * result + accountBalanceType.hashCode();
result = 31 * result + journalSide.hashCode();
return result;
}

@Override
public String toString() {
return amount.getNumber().doubleValue() + " " + accountBalanceType;
return amount.getNumber().doubleValue() + " " + journalSide;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@

package io.github.ghacupha.keeper.book.balance;

import io.github.ghacupha.keeper.book.api.Account;
import io.github.ghacupha.keeper.book.api.Entry;

/**
* Denotes the side to which a transaction belongs on the balance sheet. Either the debit side or credit side
* of the Journal entry. It also show the "default" that an {@link Account} belongs to before any {@link Entry}
* items are posted
*
* @author edwin.njeru
*/
public enum AccountBalanceType {
public enum JournalSide {

/**
* Debit side of the balance sheet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.concurrent.ConcurrentSkipListMap;

/**
* Encapsulates information concerning the nature of an {@link Account} to which
* Encapsulates information concerning the nature of an {@link Journal} to which
* it belongs
*
* @author edwin.njeru
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package io.github.ghacupha.keeper.book.base;

import io.github.ghacupha.keeper.book.api.Account;
import io.github.ghacupha.keeper.book.api.Entry;
import io.github.ghacupha.keeper.book.api.EntryAttributes;
import io.github.ghacupha.keeper.book.unit.money.Cash;
import io.github.ghacupha.keeper.book.unit.money.HardCash;
import io.github.ghacupha.keeper.book.unit.time.TimePoint;
import io.github.ghacupha.keeper.book.util.ImmutableEntryException;
import org.slf4j.Logger;
Expand All @@ -38,10 +38,10 @@ public class AccountingEntry implements Entry {
private EntryAttributes entryAttributes;
private boolean open;
private TimePoint bookingDate;
private io.github.ghacupha.keeper.book.api.Account forAccount;
private Account forAccount;
private Cash amount;

public AccountingEntry(Account forAccount, EntryAttributes entryAttributes, Cash amount, TimePoint bookingDate) {
public AccountingEntry(Account account, EntryAttributes entryAttributes, Cash amount, TimePoint bookingDate) {
this.bookingDate = bookingDate;
this.open = true;
this.amount = amount;
Expand All @@ -50,7 +50,7 @@ public AccountingEntry(Account forAccount, EntryAttributes entryAttributes, Cash
} catch (ImmutableEntryException e) {
e.printStackTrace();
}
this.forAccount = forAccount;
this.forAccount = account;
this.bookingDate = bookingDate;

log.debug("Accounting entry created : {}", this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public AccountingTransaction(TimePoint date, Currency currency) {
* The add method adds entries to the transaction provided the transaction has not already
* been posted
*
* @param amount {@link Cash} amount being posted to the account
* @param amount {@link Cash} amount being posted to the journal
* @param account {@link Account} into which the {@link Entry} is being added
*/
@Override
public void add(Cash amount, io.github.ghacupha.keeper.book.base.Account account, EntryAttributes attributes) throws ImmutableEntryException, MismatchedCurrencyException {
public void add(Cash amount, Account account, EntryAttributes attributes) throws ImmutableEntryException, MismatchedCurrencyException {

if (wasPosted) {
throw new ImmutableEntryException("Cannot add entry to a transaction that's already posted");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2018 Edwin Njeru
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.ghacupha.keeper.book.base;

import io.github.ghacupha.keeper.book.api.Transaction;
import io.github.ghacupha.keeper.book.unit.time.TimePoint;

import java.util.Currency;

public class AccountingTransactionDecorator extends AccountingTransaction implements Transaction {

public AccountingTransactionDecorator(TimePoint date, Currency currency) {
super(date, currency);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.ghacupha.keeper.book.base;

import io.github.ghacupha.keeper.book.api.Account;
import io.github.ghacupha.keeper.book.api.Entry;
import io.github.ghacupha.keeper.book.api.EntryAttributes;
import io.github.ghacupha.keeper.book.unit.money.Cash;
Expand All @@ -29,7 +30,7 @@
*/
public class AccoutingEntryDecorator extends AccountingEntry implements Entry {

public AccoutingEntryDecorator(Account forAccount, EntryAttributes entryAttributes, Cash amount, TimePoint bookingDate) {
super(forAccount, entryAttributes, amount, bookingDate);
public AccoutingEntryDecorator(Account account, EntryAttributes entryAttributes, Cash amount, TimePoint bookingDate) {
super(account, entryAttributes, amount, bookingDate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2018 Edwin Njeru
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.ghacupha.keeper.book.base;

import io.github.ghacupha.keeper.book.api.Transaction;

public class FixedJournalTransaction extends AccountingTransactionDecorator implements Transaction {

//TODO override add method in super and implement add method in JournalizedTransaction interface
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package io.github.ghacupha.keeper.book.base;

import io.github.ghacupha.keeper.book.api.Account;
import io.github.ghacupha.keeper.book.api.AccountAttributes;
import io.github.ghacupha.keeper.book.api.Entry;
import io.github.ghacupha.keeper.book.balance.AccountBalance;
import io.github.ghacupha.keeper.book.balance.AccountBalanceType;
import io.github.ghacupha.keeper.book.balance.JournalSide;
import io.github.ghacupha.keeper.book.unit.money.Cash;
import io.github.ghacupha.keeper.book.unit.money.HardCash;
import io.github.ghacupha.keeper.book.unit.time.DateRange;
Expand All @@ -40,22 +41,22 @@
*
* @author edwin.njeru
*/
public class Account implements io.github.ghacupha.keeper.book.api.Account {
public class Journal implements Account {

private static final Logger log = LoggerFactory.getLogger(Account.class);
private static final Logger log = LoggerFactory.getLogger(Journal.class);

private final AccountBalanceType accountBalanceType;
private final JournalSide journalSide;
private final Currency currency;
private final AccountAttributes accountAttributes;
private Collection<Entry> entries = new HashSet<>();


public Account(AccountBalanceType accountBalanceType, Currency currency, AccountAttributes accountAttributes) {
this.accountBalanceType = accountBalanceType;
public Journal(JournalSide journalSide, Currency currency, AccountAttributes accountAttributes) {
this.journalSide = journalSide;
this.currency = currency;
this.accountAttributes = accountAttributes;

log.debug("Account created : {}", this);
log.debug("Journal created : {}", this);
}

@Override
Expand Down Expand Up @@ -111,9 +112,9 @@ private AccountBalance balance(DateRange dateRange) {
result[0] = result[0].plus(orderedAmount);
});

log.debug("Returning balance of amount : {} on the {} side", result[0], accountBalanceType);
log.debug("Returning balance of amount : {} on the {} side", result[0], journalSide);

return new AccountBalance(result[0], accountBalanceType);
return new AccountBalance(result[0], journalSide);
}

@Override
Expand Down
Loading

0 comments on commit 7581789

Please sign in to comment.