Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get accountdetail options #78

Merged
merged 4 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions modules/minigl/src/main/java/org/jpos/gl/AccountDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,50 @@ public class AccountDetail {
* Constructs an AccountDetail.
* @param journal the Journal.
* @param account the account.
* @param initialBalance initial balance (reporting currency).
* @param balance balance (reporting currency), could be initial if naturalOrder or final if not.
* @param start start date (inclusive).
* @param end end date (inclusive).
* @param entries list of GLEntries.
* @param layers the layers involved in this detail
* @param ascendingOrder if we should compute balance normally or inverted
*/
public AccountDetail(
Journal journal, Account account,
BigDecimal initialBalance,
Date start, Date end, List<GLEntry> entries, short[] layers)
BigDecimal balance,
Date start, Date end, List<GLEntry> entries, short[] layers, boolean ascendingOrder)
{
super();
this.journal = journal;
this.account = account;
this.initialBalance = initialBalance;
this.start = start;
this.end = end;
this.entries = entries;
this.layers = layers;
computeBalances();
if (ascendingOrder) {
this.initialBalance = balance;
computeBalances();
} else {
this.finalBalance = balance;
computeReverseBalances(balance);
}
}

/**
* Constructs an AccountDetail.
* @param journal the Journal.
* @param account the account.
* @param balance balance (reporting currency), could be initial if naturalOrder or final if not.
* @param start start date (inclusive).
* @param end end date (inclusive).
* @param entries list of GLEntries.
* @param layers the layers involved in this detail
*/
public AccountDetail(
Journal journal, Account account,
BigDecimal balance,
Date start, Date end, List<GLEntry> entries, short[] layers)
{
this(journal, account, balance, start, end, entries, layers, true);
}

/**
Expand All @@ -79,13 +103,7 @@ public AccountDetail(
BigDecimal balance,
List<GLEntry> entries, short[] layers)
{
super();
this.journal = journal;
this.account = account;
this.finalBalance = balance;
this.entries = entries;
this.layers = layers;
computeReverseBalances(balance);
this(journal, account, balance, null, null, entries, layers, false);
}

public Journal getJournal() {
Expand Down
100 changes: 52 additions & 48 deletions modules/minigl/src/main/java/org/jpos/gl/GLSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1092,17 +1092,17 @@ public List<FinalAccount> getDeepFinalChildren(Account acct) throws HibernateExc
* @param acct the account.
* @param start date (inclusive).
* @param end date (inclusive).
* @param layers array of the layers included.
* @param ascendingOrder boolean.
* @param maxResults int.
* @return Account detail for given period.
* @throws GLException if user doesn't have READ permission on this journal.
*/
public AccountDetail getAccountDetail
(Journal journal, Account acct, Date start, Date end, short[] layers)
(Journal journal, Account acct, Date start, Date end, short[] layers, boolean ascendingOrder, int maxResults)
throws HibernateException, GLException
{
checkPermission (GLPermission.READ);
start = Util.floor (start);
end = Util.ceil (end);

Criteria crit = session.createCriteria (GLEntry.class);

boolean hasChildren = false;
Expand All @@ -1123,21 +1123,55 @@ public List<FinalAccount> getDeepFinalChildren(Account acct) throws HibernateExc

crit.add (Restrictions.in ("layer", (Object[])toShortArray (layers)));
crit = crit.createCriteria ("transaction")
.add (Restrictions.eq ("journal", journal))
.add (Restrictions.ge ("postDate", start))
.add (Restrictions.le ("postDate", end));
.add (Restrictions.eq ("journal", journal));
if (start != null || (start == null && ascendingOrder)) {
start = Util.floor(start);
crit.add (Restrictions.ge ("postDate", start));
}
if (end != null || (end == null && ascendingOrder)) {
end = Util.ceil(end);
crit.add (Restrictions.le ("postDate", end));
}

BigDecimal initialBalance[] = getBalances (journal, acct, start, false, layers, 0L);
crit.addOrder (Order.asc ("postDate"));
crit.addOrder (Order.asc ("timestamp"));
crit.addOrder (Order.asc ("id"));
List entries = crit.list();
// BigDecimal finalBalance = applyEntries (initialBalance[0], entries);
if (maxResults > 0)
crit.setMaxResults(maxResults);

long maxEntry = 0L;
List <GLEntry> entries;
BigDecimal initialBalance[];
if (ascendingOrder) {
crit.addOrder (Order.asc ("postDate"));
crit.addOrder (Order.asc ("timestamp"));
crit.addOrder (Order.asc ("id"));
entries = crit.list();
initialBalance = getBalances(journal, acct, start, false, layers, maxEntry);
} else {
crit.addOrder (Order.desc ("postDate"));
crit.addOrder (Order.desc ("timestamp"));
crit.addOrder (Order.desc ("id"));
entries = crit.list();
if (entries.size() > 0) {
maxEntry = entries.get(0).getId();
}
initialBalance = getBalances(journal, acct, end, true, layers, maxEntry);
}
return new AccountDetail(journal, acct, initialBalance[0], start, end, entries, layers, ascendingOrder);
}

return new AccountDetail (
journal, acct,
initialBalance[0],
start, end, entries, layers );
/**
* AccountDetail for date range
* @param journal the journal.
* @param acct the account.
* @param start date (inclusive).
* @param end date (inclusive).
* @return Account detail for given period.
* @throws GLException if user doesn't have READ permission on this journal.
*/
public AccountDetail getAccountDetail
(Journal journal, Account acct, Date start, Date end, short[] layers)
throws HibernateException, GLException
{
return getAccountDetail(journal, acct, start, end, layers, true, 0);
}

/**
Expand All @@ -1153,37 +1187,7 @@ public List<FinalAccount> getDeepFinalChildren(Account acct) throws HibernateExc
(Journal journal, Account acct, short[] layers, int maxResults)
throws HibernateException, GLException
{
checkPermission (GLPermission.READ);
Criteria crit = session.createCriteria (GLEntry.class);

boolean hasChildren = false;
if (acct.isCompositeAccount()) {
Disjunction dis = Restrictions.disjunction();
for (Long l : getChildren (acct)) {
hasChildren = true;
dis.add (Restrictions.idEq(l));
}
if (hasChildren) {
Criteria subCrit = crit.createCriteria(("account"));
subCrit.add (dis);
}
}
if (!hasChildren) {
crit.add (Restrictions.eq ("account", acct));
}

crit.add (Restrictions.in ("layer", (Object[])toShortArray (layers)));
crit = crit.createCriteria ("transaction")
.add (Restrictions.eq ("journal", journal));

crit.addOrder (Order.desc ("id"));
crit.setMaxResults(maxResults);
List<GLEntry> entries = crit.list();
BigDecimal balance = ZERO;
if (entries.size() > 0)
balance = getBalances(journal, acct, (Date) null, true, layers, entries.get(0).getId())[0];

return new AccountDetail(journal, acct, balance, entries, layers);
return getAccountDetail(journal, acct, null, null, layers, false, maxResults);
}


Expand Down