private void checkBalance( GLSession session, GLTransaction txn, GLEntry entry, String param, int[] offsets, short[] layers) throws GLException, HibernateException { Journal journal = txn.getJournal(); Account account = entry.getAccount(); session.lock(journal, account); BigDecimal balance = session.getBalance(journal, account, layers); BigDecimal minBalance = (param != null) ? new BigDecimal(param) : ZERO; BigDecimal impact = getImpact(txn, account, offsets, layers); if (isError(balance.add(impact), minBalance)) { StringBuffer sb = new StringBuffer(getRuleName()); sb.append(" rule for account "); sb.append(account.getCode()); sb.append(" failed. balance="); sb.append(balance); sb.append(", impact="); sb.append(impact); sb.append(", minimum="); sb.append(param); throw new GLException(sb.toString()); } }
private BigDecimal getImpact(GLTransaction txn, Account account, int[] offsets, short[] layers) { BigDecimal impact = ZERO; List entries = txn.getEntries(); for (int i = 0; i < offsets.length; i++) { GLEntry entry = ((GLEntry) entries.get(offsets[i])); if (account.equals(entry.getAccount()) && match(entry.getLayer(), layers)) impact = impact.add(entry.getImpact()); } return impact; }
public void check( GLSession session, GLTransaction txn, String param, Account account, int[] entryOffsets, short[] layers) throws GLException { Journal journal = txn.getJournal(); Date postDate = txn.getPostDate(); Date end = journal.getEnd(); Date start = journal.getStart(); Date lockDate = journal.getLockDate(); session.checkPermission(GLPermission.POST, journal); if (journal.isClosed()) { throw new GLException("Journal '" + journal.getName() + "' is closed"); } if (postDate == null) throw new GLException("Invalid transaction. Posting date is null"); if (start != null && postDate.compareTo(start) < 0) { throw new GLException( "Journal '" + journal.getName() + "' cannot accept transactions with a posting date less than " + start.toString()); } if (end != null && postDate.compareTo(end) > 0) { throw new GLException( "Journal '" + journal.getName() + "' cannot accept transactions with a post date greater than " + end.toString()); } if (lockDate != null && postDate.compareTo(lockDate) <= 0) { throw new GLException( "Journal '" + journal.getName() + "' has a temporary lockDate at " + lockDate.toString()); } checkEntries(txn, postDate); }
public void check( GLSession session, GLTransaction txn, String param, Account account, int[] offsets, short[] layers) throws GLException, HibernateException { List entries = txn.getEntries(); if (entries.size() == 0 || offsets.length == 0) return; for (int i = 0; i < offsets.length; i++) { GLEntry entry = ((GLEntry) entries.get(offsets[i])); if (match(entry.getLayer(), layers)) checkBalance(session, txn, entry, param, offsets, layers); } }
private void checkEntries(GLTransaction txn, Date postDate) throws GLException { List list = txn.getEntries(); Iterator iter = list.iterator(); while (iter.hasNext()) { GLEntry entry = (GLEntry) iter.next(); Account acct = entry.getAccount(); Date end = acct.getExpiration(); if (end != null && postDate.compareTo(end) > 0) { throw new GLException( "Account '" + acct.toString() + "' cannot accept transactions with a post date greater than " + end.toString()); } } }
private void checkEntries(GLTransaction txn, short layer) throws GLException { List list = txn.getEntries(); // if (list.size() < 2) // throw new GLException ("too few entries (" + list.size() + ")"); BigDecimal debits = ZERO; BigDecimal credits = ZERO; Iterator iter = list.iterator(); while (iter.hasNext()) { GLEntry entry = (GLEntry) iter.next(); if (entry.getLayer() == layer) { if (entry.isDebit()) debits = debits.add(entry.getAmount()); else credits = credits.add(entry.getAmount()); } } if (!debits.equals(credits)) { throw new GLException( "Transaction does not balance. debits=" + debits.toString() + ", credits=" + credits.toString()); } }