Search in sources :

Example 1 with PayeeMatcher

use of jgnash.engine.search.PayeeMatcher in project jgnash by ccavanaugh.

the class PayeePieChart method createPieDataSet.

private PieDataset[] createPieDataSet(final Account a) {
    final DefaultPieDataset[] returnValue = new DefaultPieDataset[2];
    returnValue[CREDIT] = new DefaultPieDataset();
    returnValue[DEBIT] = new DefaultPieDataset();
    if (a != null) {
        //System.out.print("Account = "); System.out.println(a);
        Map<String, BigDecimal> names = new HashMap<>();
        List<TranTuple> list = getTransactions(a, new ArrayList<>(), startField.getLocalDate(), endField.getLocalDate());
        CurrencyNode currency = a.getCurrencyNode();
        for (final TranTuple tranTuple : list) {
            Transaction tran = tranTuple.transaction;
            Account account = tranTuple.account;
            String payee = tran.getPayee();
            BigDecimal sum = tran.getAmount(account);
            sum = sum.multiply(account.getCurrencyNode().getExchangeRate(currency));
            if (useFilters.isSelected()) {
                for (String aFilterList : filterList) {
                    PayeeMatcher pm = new PayeeMatcher(aFilterList, false);
                    if (pm.matches(tran)) {
                        payee = aFilterList;
                        //System.out.println(filterList.get(i));
                        break;
                    }
                }
            }
            if (names.containsKey(payee)) {
                sum = sum.add(names.get(payee));
            }
            names.put(payee, sum);
        }
        for (final Map.Entry<String, BigDecimal> entry : names.entrySet()) {
            BigDecimal value = entry.getValue();
            if (value.compareTo(BigDecimal.ZERO) == -1) {
                value = value.negate();
                returnValue[DEBIT].setValue(entry.getKey(), value);
            } else {
                returnValue[CREDIT].setValue(entry.getKey(), value);
            }
        }
    }
    return returnValue;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) HashMap(java.util.HashMap) PayeeMatcher(jgnash.engine.search.PayeeMatcher) BigDecimal(java.math.BigDecimal) Transaction(jgnash.engine.Transaction) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with PayeeMatcher

use of jgnash.engine.search.PayeeMatcher in project jgnash by ccavanaugh.

the class FilterDecorator method setFilter.

@Override
public void setFilter(final String filter) {
    this.filter = filter;
    pm = new PayeeMatcher(filter, false);
    updateMatches();
}
Also used : PayeeMatcher(jgnash.engine.search.PayeeMatcher)

Aggregations

PayeeMatcher (jgnash.engine.search.PayeeMatcher)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Account (jgnash.engine.Account)1 CurrencyNode (jgnash.engine.CurrencyNode)1 Transaction (jgnash.engine.Transaction)1 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)1