Search in sources :

Example 6 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class BudgetPanel method showBudgetPane.

private void showBudgetPane() {
    logger.entering(BudgetPanel.class.getName(), "showBudgetPane");
    // unregister the listener so we don't leak by listening to stale models
    if (tableModel != null) {
        tableModel.removeMessageListener(this);
    }
    activeBudget = budgetCombo.getSelectedBudget();
    if (activeBudget != null) {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        final CurrencyNode baseCurrency = engine.getDefaultCurrency();
        resultsModel = new BudgetResultsModel(activeBudget, budgetYear, baseCurrency, false);
        tableModel = new ExpandingBudgetTableModel(resultsModel);
        // register the listener
        tableModel.addMessageListener(this);
        activeBudget.setWorkingYear(budgetYear);
        preferences.put(LAST_BUDGET, activeBudget.getUuid());
        List<BudgetPeriodPanel> newPanels = buildPeriodPanels();
        JPanel budgetPanel = getBudgetPanel(newPanels);
        AccountRowHeaderPanel accountPanel = new AccountRowHeaderPanel(activeBudget, tableModel);
        BudgetColumnHeader header = new BudgetColumnHeader(newPanels);
        panels = newPanels;
        for (BudgetPeriodPanel periodPanel : panels) {
            periodPanel.setRowHeight(accountPanel.getRowHeight());
        }
        scrollPane.setViewportView(budgetPanel);
        scrollPane.setRowHeaderView(accountPanel);
        scrollPane.setColumnHeaderView(header);
        scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, accountPanel.getTableHeader());
        if (summaryRowVisibleCheckBox.isSelected()) {
            addSummaryRows();
        }
        if (activeBudget.getBudgetPeriod() != Period.YEARLY && summaryColVisibleCheckBox.isSelected()) {
            // summary is redundant for a yearly view
            addSummaryColumn();
            if (summaryRowVisibleCheckBox.isSelected()) {
                addSummaryCorner();
            }
        }
        rowHeaderResizeHandler.attachListeners();
        showCurrentPeriod();
        overviewPanel.updateSparkLines();
    }
    logger.exiting(BudgetPanel.class.getName(), "showBudgetPane");
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) JPanel(javax.swing.JPanel) Engine(jgnash.engine.Engine) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel)

Example 7 with CurrencyNode

use of jgnash.engine.CurrencyNode 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 8 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class AbstractCrosstabReport method createTableModel.

@SuppressWarnings("ConstantConditions")
private ReportModel createTableModel() {
    logger.info(rb.getString("Message.CollectingReportData"));
    CurrencyNode baseCurrency = EngineFactory.getEngine(EngineFactory.DEFAULT).getDefaultCurrency();
    List<Account> accounts = new ArrayList<>();
    String sortOrder = sortOrderList.getSelectedItem().toString();
    boolean needPercentiles = SORT_ORDER_BALANCE_DESC_WITH_PERCENTILE.equals(sortOrder);
    for (AccountGroup group : getAccountGroups()) {
        List<Account> list = getAccountList(AccountType.getAccountTypes(group));
        boolean ascendingSortOrder = true;
        if (!list.isEmpty()) {
            if (list.get(0).getAccountType() == AccountType.EXPENSE) {
                ascendingSortOrder = false;
            }
        }
        if (SORT_ORDER_NAME.equals(sortOrder)) {
            if (!showLongNamesCheckBox.isSelected()) {
                list.sort(Comparators.getAccountByName());
            } else {
                list.sort(Comparators.getAccountByPathName());
            }
        } else if (SORT_ORDER_BALANCE_DESC.equals(sortOrder) || SORT_ORDER_BALANCE_DESC_WITH_PERCENTILE.equals(sortOrder)) {
            list.sort(Comparators.getAccountByBalance(startDateField.getLocalDate(), endDateField.getLocalDate(), baseCurrency, ascendingSortOrder));
        }
        if (needPercentiles) {
            BigDecimal groupTotal = BigDecimal.ZERO;
            for (Account a : list) {
                groupTotal = groupTotal.add(a.getBalance(startDateField.getLocalDate(), endDateField.getLocalDate(), baseCurrency));
            }
            BigDecimal sumSoFar = BigDecimal.ZERO;
            for (Account a : list) {
                sumSoFar = sumSoFar.add(a.getBalance(startDateField.getLocalDate(), endDateField.getLocalDate(), baseCurrency));
                percentileMap.put(a, sumSoFar.doubleValue() / groupTotal.doubleValue());
            }
        }
        accounts.addAll(list);
    }
    updateResolution();
    // remove any account that will report a zero balance for all periods
    if (hideZeroBalanceAccounts.isSelected()) {
        Iterator<Account> i = accounts.iterator();
        while (i.hasNext()) {
            Account account = i.next();
            boolean remove = true;
            for (int j = 0; j < endDates.size(); j++) {
                if (account.getBalance(startDates.get(j), endDates.get(j)).compareTo(BigDecimal.ZERO) != 0) {
                    remove = false;
                    break;
                }
            }
            if (remove) {
                i.remove();
            }
        }
    }
    // configure columns
    List<ColumnInfo> columnsList = new LinkedList<>();
    // accounts column
    ColumnInfo ci = new AccountNameColumnInfo(accounts);
    ci.columnName = rb.getString("Column.Account");
    ci.headerStyle = ColumnHeaderStyle.LEFT;
    ci.columnClass = String.class;
    ci.columnStyle = ColumnStyle.STRING;
    ci.isFixedWidth = false;
    columnsList.add(ci);
    for (int i = 0; i < dateLabels.size(); ++i) {
        ci = new DateRangeBalanceColumnInfo(accounts, startDates.get(i), endDates.get(i), baseCurrency);
        ci.columnName = dateLabels.get(i);
        ci.headerStyle = ColumnHeaderStyle.RIGHT;
        ci.columnClass = BigDecimal.class;
        ci.columnStyle = ColumnStyle.BALANCE_WITH_SUM_AND_GLOBAL;
        ci.isFixedWidth = true;
        columnsList.add(ci);
    }
    // cross-tab total column
    ci = new CrossTabAmountColumnInfo(accounts, baseCurrency);
    ci.columnName = "";
    ci.headerStyle = ColumnHeaderStyle.RIGHT;
    ci.columnClass = BigDecimal.class;
    ci.columnStyle = ColumnStyle.CROSSTAB_TOTAL;
    ci.isFixedWidth = true;
    columnsList.add(ci);
    if (needPercentiles) {
        ci = new PercentileColumnInfo(accounts);
        ci.columnName = "Percentile";
        ci.headerStyle = ColumnHeaderStyle.RIGHT;
        ci.columnClass = String.class;
        ci.columnStyle = ColumnStyle.CROSSTAB_TOTAL;
        ci.isFixedWidth = true;
        columnsList.add(ci);
    }
    // grouping column (last column)
    ci = new GroupColumnInfo(accounts);
    ci.columnName = "Type";
    ci.headerStyle = ColumnHeaderStyle.CENTER;
    ci.columnClass = String.class;
    ci.columnStyle = ColumnStyle.GROUP;
    ci.isFixedWidth = false;
    columnsList.add(ci);
    columns = columnsList.toArray(new ColumnInfo[columnsList.size()]);
    return new ReportModel(accounts, baseCurrency);
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) JasperPrint(net.sf.jasperreports.engine.JasperPrint) LinkedList(java.util.LinkedList) AccountGroup(jgnash.engine.AccountGroup)

Example 9 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class IncomeExpensePieChart method createPieChart.

private JFreeChart createPieChart(final Account a) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Objects.requireNonNull(a);
    PieDataset data = createPieDataSet(a);
    PiePlot plot = new PiePlot(data);
    // rebuilt each time because they're based on the account's commodity
    CurrencyNode defaultCurrency = engine.getDefaultCurrency();
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);
    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
    plot.setLabelGap(.02);
    plot.setInteriorGap(.1);
    // own transactions, not just child accounts), separate it from children.
    if (data.getIndex(a) != -1) {
        plot.setExplodePercent(a, .10);
    }
    String title;
    // pick an appropriate title
    if (a.getAccountType() == AccountType.EXPENSE) {
        title = rb.getString("Title.PercentExpense");
    } else if (a.getAccountType() == AccountType.INCOME) {
        title = rb.getString("Title.PercentIncome");
    } else {
        title = rb.getString("Title.PercentDist");
    }
    title = title + " - " + a.getPathName();
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    BigDecimal total = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();
    String subtitle = valueFormat.format(total);
    if (!defaultCurrency.equals(a.getCurrencyNode())) {
        BigDecimal totalDefaultCurrency = total.multiply(a.getCurrencyNode().getExchangeRate(defaultCurrency));
        NumberFormat defaultValueFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
        subtitle += "  -  " + defaultValueFormat.format(totalDefaultCurrency);
    }
    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);
    return chart;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) TextTitle(org.jfree.chart.title.TextTitle) PieDataset(org.jfree.data.general.PieDataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) Engine(jgnash.engine.Engine) JFreeChart(org.jfree.chart.JFreeChart) BigDecimal(java.math.BigDecimal) NumberFormat(java.text.NumberFormat)

Example 10 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class AbstractSumByTypeReport method createReportModel.

ReportModel createReportModel(final LocalDate startDate, final LocalDate endDate) {
    logger.info(rb.getString("Message.CollectingReportData"));
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    // generate the date information
    if (runningTotal) {
        dates = DateUtils.getLastDayOfTheMonths(startDate, endDate);
    } else {
        dates = DateUtils.getFirstDayOfTheMonths(startDate, endDate);
        dates.set(0, startDate);
        if (DateUtils.after(endDate, dates.get(dates.size() - 1))) {
            dates.add(endDate);
        }
    }
    final CurrencyNode baseCurrency = engine.getDefaultCurrency();
    List<Account> accounts = new ArrayList<>();
    for (AccountGroup group : getAccountGroups()) {
        accounts.addAll(getAccountList(AccountType.getAccountTypes(group)));
    }
    // remove any account that will report a zero balance for all periods
    if (hideZeroBalanceAccounts.isSelected()) {
        Iterator<Account> i = accounts.iterator();
        while (i.hasNext()) {
            Account account = i.next();
            boolean remove = true;
            if (runningTotal) {
                for (LocalDate date : dates) {
                    if (account.getBalance(date).compareTo(BigDecimal.ZERO) != 0) {
                        remove = false;
                        break;
                    }
                }
            } else {
                for (int j = 0; j < dates.size() - 1; j++) {
                    final LocalDate sDate = dates.get(j);
                    final LocalDate eDate = dates.get(j + 1).minusDays(1);
                    if (account.getBalance(sDate, eDate).compareTo(BigDecimal.ZERO) != 0) {
                        remove = false;
                        break;
                    }
                }
            }
            if (remove) {
                i.remove();
            }
        }
    }
    ReportModel model = new ReportModel(baseCurrency);
    model.addAccounts(accounts);
    return model;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) AccountGroup(jgnash.engine.AccountGroup) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Engine(jgnash.engine.Engine) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Aggregations

CurrencyNode (jgnash.engine.CurrencyNode)58 Account (jgnash.engine.Account)28 Engine (jgnash.engine.Engine)28 BigDecimal (java.math.BigDecimal)10 ArrayList (java.util.ArrayList)10 LocalDate (java.time.LocalDate)8 NumberFormat (java.text.NumberFormat)7 List (java.util.List)7 FXML (javafx.fxml.FXML)7 AccountGroup (jgnash.engine.AccountGroup)7 Transaction (jgnash.engine.Transaction)6 ResourceBundle (java.util.ResourceBundle)5 SecurityNode (jgnash.engine.SecurityNode)5 InjectFXML (jgnash.uifx.util.InjectFXML)5 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 ExecutionException (java.util.concurrent.ExecutionException)3