Search in sources :

Example 36 with Account

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

the class MonthlyAccountBalanceChart method createPanel.

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);
    startDateField.setDate(start);
    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));
    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);
    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));
    Account a = combo.getSelectedAccount();
    JFreeChart chart = createVerticalXYBarChart(a);
    final ChartPanel chartPanel = new ChartPanel(chart);
    FormLayout layout = new FormLayout("p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);
    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);
    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);
    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);
    builder.append(rb.getString("Label.Account"), combo);
    builder.nextLine();
    builder.append(" ");
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);
    final JPanel panel = builder.getPanel();
    ActionListener listener = e -> {
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }
            updateSubAccountBox();
            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    };
    combo.addActionListener(listener);
    hideLockedAccountCheckBox.addActionListener(e -> {
        combo.setHideLocked(hideLockedAccountCheckBox.isSelected());
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }
            updateSubAccountBox();
            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    });
    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }
            updateSubAccountBox();
            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    });
    refreshButton.addActionListener(listener);
    updateSubAccountBox();
    return panel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) ActionListener(java.awt.event.ActionListener) AccountBalanceDisplayManager(jgnash.ui.register.AccountBalanceDisplayManager) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Date(java.util.Date) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) IconUtils(jgnash.ui.util.IconUtils) ResourceUtils(jgnash.util.ResourceUtils) SimpleDateFormat(java.text.SimpleDateFormat) NumberAxis(org.jfree.chart.axis.NumberAxis) NumberFormat(java.text.NumberFormat) Level(java.util.logging.Level) BigDecimal(java.math.BigDecimal) TimeSeries(org.jfree.data.time.TimeSeries) ResourceBundle(java.util.ResourceBundle) JFreeChart(org.jfree.chart.JFreeChart) AccountType(jgnash.engine.AccountType) DateTickMarkPosition(org.jfree.chart.axis.DateTickMarkPosition) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) DateFormat(java.text.DateFormat) CurrencyNode(jgnash.engine.CurrencyNode) EventQueue(java.awt.EventQueue) FilteredAccountListComboBox(jgnash.ui.components.FilteredAccountListComboBox) DateUtils(jgnash.time.DateUtils) DateTickUnit(org.jfree.chart.axis.DateTickUnit) JButton(javax.swing.JButton) Comparators(jgnash.engine.Comparators) RowSpec(com.jgoodies.forms.layout.RowSpec) XYPlot(org.jfree.chart.plot.XYPlot) Logger(java.util.logging.Logger) GenericCloseDialog(jgnash.ui.components.GenericCloseDialog) List(java.util.List) DateAxis(org.jfree.chart.axis.DateAxis) DatePanel(jgnash.ui.components.DatePanel) FormLayout(com.jgoodies.forms.layout.FormLayout) LocalDate(java.time.LocalDate) JCheckBox(javax.swing.JCheckBox) Account(jgnash.engine.Account) TemporalAdjusters(java.time.temporal.TemporalAdjusters) ChartPanel(org.jfree.chart.ChartPanel) Collections(java.util.Collections) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) Month(org.jfree.data.time.Month) JPanel(javax.swing.JPanel) DateTickUnitType(org.jfree.chart.axis.DateTickUnitType) Account(jgnash.engine.Account) JPanel(javax.swing.JPanel) ChartPanel(org.jfree.chart.ChartPanel) JButton(javax.swing.JButton) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder)

Example 37 with Account

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

the class MonthlyAccountBalanceChartCompare method createPanel.

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);
    startDateField.setDate(start);
    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));
    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);
    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));
    jcb_compare = new JCheckBox(rb.getString("Button.Compare"));
    jcb_compare.setSelected(true);
    Account a = combo1.getSelectedAccount();
    Account a2 = combo2.getSelectedAccount();
    JFreeChart chart = createVerticalXYBarChart(a, a2);
    final ChartPanel chartPanel = new ChartPanel(chart);
    FormLayout layout = new FormLayout("p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);
    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);
    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);
    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);
    builder.append(rb.getString("Label.Account"), combo1);
    builder.nextLine();
    builder.append(rb.getString("Label.Compare"), combo2);
    builder.nextLine();
    builder.append(jcb_compare);
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);
    final JPanel panel = builder.getPanel();
    ActionListener listener = e -> {
        try {
            if (e.getSource() == jcb_compare) {
                combo2.setEnabled(jcb_compare.isSelected());
            }
            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }
            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }
            updateSubAccountBox();
            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    };
    combo1.addActionListener(listener);
    combo2.addActionListener(listener);
    jcb_compare.addActionListener(listener);
    subAccountCheckBox.addActionListener(listener);
    hideLockedAccountCheckBox.addActionListener(e -> {
        combo1.setHideLocked(hideLockedAccountCheckBox.isSelected());
        combo2.setHideLocked(hideLockedAccountCheckBox.isSelected());
        try {
            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }
            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }
            updateSubAccountBox();
            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    });
    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo1.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        combo2.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        try {
            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }
            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }
            updateSubAccountBox();
            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    });
    refreshButton.addActionListener(listener);
    updateSubAccountBox();
    return panel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) ActionListener(java.awt.event.ActionListener) AccountBalanceDisplayManager(jgnash.ui.register.AccountBalanceDisplayManager) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Date(java.util.Date) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) IconUtils(jgnash.ui.util.IconUtils) ResourceUtils(jgnash.util.ResourceUtils) SimpleDateFormat(java.text.SimpleDateFormat) NumberAxis(org.jfree.chart.axis.NumberAxis) NumberFormat(java.text.NumberFormat) Level(java.util.logging.Level) BigDecimal(java.math.BigDecimal) TimeSeries(org.jfree.data.time.TimeSeries) ResourceBundle(java.util.ResourceBundle) JFreeChart(org.jfree.chart.JFreeChart) AccountType(jgnash.engine.AccountType) DateTickMarkPosition(org.jfree.chart.axis.DateTickMarkPosition) DateFormat(java.text.DateFormat) CurrencyNode(jgnash.engine.CurrencyNode) EventQueue(java.awt.EventQueue) FilteredAccountListComboBox(jgnash.ui.components.FilteredAccountListComboBox) DateUtils(jgnash.time.DateUtils) DateTickUnit(org.jfree.chart.axis.DateTickUnit) JButton(javax.swing.JButton) Comparators(jgnash.engine.Comparators) RowSpec(com.jgoodies.forms.layout.RowSpec) XYPlot(org.jfree.chart.plot.XYPlot) Logger(java.util.logging.Logger) GenericCloseDialog(jgnash.ui.components.GenericCloseDialog) List(java.util.List) DateAxis(org.jfree.chart.axis.DateAxis) DatePanel(jgnash.ui.components.DatePanel) FormLayout(com.jgoodies.forms.layout.FormLayout) LocalDate(java.time.LocalDate) JCheckBox(javax.swing.JCheckBox) Account(jgnash.engine.Account) ClusteredXYBarRenderer(org.jfree.chart.renderer.xy.ClusteredXYBarRenderer) TemporalAdjusters(java.time.temporal.TemporalAdjusters) ChartPanel(org.jfree.chart.ChartPanel) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) Month(org.jfree.data.time.Month) JPanel(javax.swing.JPanel) DateTickUnitType(org.jfree.chart.axis.DateTickUnitType) Account(jgnash.engine.Account) JPanel(javax.swing.JPanel) ChartPanel(org.jfree.chart.ChartPanel) JButton(javax.swing.JButton) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder)

Example 38 with Account

use of jgnash.engine.Account 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 39 with Account

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

the class AbstractCrosstabReport method getAccountList.

private static List<Account> getAccountList(final Set<AccountType> types) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    List<Account> accounts = engine.getAccountList();
    Iterator<Account> i = accounts.iterator();
    search: while (i.hasNext()) {
        Account a = i.next();
        if (a.getTransactionCount() == 0) {
            i.remove();
        } else {
            for (AccountType t : types) {
                if (a.getAccountType() == t) {
                    continue search;
                }
            }
            // made it here.. remove it
            i.remove();
        }
    }
    return accounts;
}
Also used : Account(jgnash.engine.Account) AccountType(jgnash.engine.AccountType) Engine(jgnash.engine.Engine)

Example 40 with Account

use of jgnash.engine.Account 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)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9