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());
    }
  }
Exemple #2
0
  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);
  }