Search in sources :

Example 91 with Account

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

the class BasicRegisterTableController method getBalanceAt.

private BigDecimal getBalanceAt(final Transaction transaction) {
    BigDecimal balance = BigDecimal.ZERO;
    final Account account = this.account.get();
    if (account != null) {
        final int index = sortedList.indexOf(transaction);
        for (int i = 0; i <= index; i++) {
            balance = balance.add(sortedList.get(i).getAmount(account));
        }
    }
    return balance;
}
Also used : Account(jgnash.engine.Account) BigDecimal(java.math.BigDecimal)

Example 92 with Account

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

the class AbstractSumByTypeReport method getAccountList.

private static List<Account> getAccountList(final Set<AccountType> types) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Set<Account> accountSet = engine.getAccountList().stream().filter(a -> types.contains(a.getAccountType())).collect(Collectors.toCollection(TreeSet::new));
    return new ArrayList<>(accountSet);
}
Also used : ColumnStyle(jgnash.ui.report.jasper.ColumnStyle) Engine(jgnash.engine.Engine) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) EngineFactory(jgnash.engine.EngineFactory) IconUtils(jgnash.ui.util.IconUtils) ResourceUtils(jgnash.util.ResourceUtils) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) ColumnHeaderStyle(jgnash.ui.report.jasper.ColumnHeaderStyle) ResourceBundle(java.util.ResourceBundle) AccountType(jgnash.engine.AccountType) CurrencyNode(jgnash.engine.CurrencyNode) DateUtils(jgnash.time.DateUtils) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JButton(javax.swing.JButton) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) DynamicJasperReport(jgnash.ui.report.jasper.DynamicJasperReport) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) List(java.util.List) AbstractAction(javax.swing.AbstractAction) DatePanel(jgnash.ui.components.DatePanel) FormLayout(com.jgoodies.forms.layout.FormLayout) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) JCheckBox(javax.swing.JCheckBox) Account(jgnash.engine.Account) AbstractReportTableModel(jgnash.ui.report.jasper.AbstractReportTableModel) Collections(java.util.Collections) JPanel(javax.swing.JPanel) Borders(com.jgoodies.forms.factories.Borders) Account(jgnash.engine.Account) ArrayList(java.util.ArrayList) Engine(jgnash.engine.Engine)

Example 93 with Account

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

the class PayeePieChart method createPanel.

private JPanel createPanel() {
    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    JButton addFilterButton = new JButton(rb.getString("Button.AddFilter"));
    final JButton saveButton = new JButton(rb.getString("Button.SaveFilters"));
    JButton deleteFilterButton = new JButton(rb.getString("Button.DeleteFilter"));
    JButton clearPrefButton = new JButton(rb.getString("Button.MasterDelete"));
    filterCombo = new JComboBox<>();
    startField = new DatePanel();
    endField = new DatePanel();
    txtAddFilter = new TextField();
    filterList = new ArrayList<>();
    filtersChanged = false;
    useFilters = new JCheckBox(rb.getString("Label.UseFilters"));
    useFilters.setSelected(true);
    showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
    combo = AccountListComboBox.getFullInstance();
    final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now().minusYears(DEBIT));
    long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
    startField.setDate(DateUtils.asLocalDate(start));
    currentAccount = combo.getSelectedAccount();
    PieDataset[] data = createPieDataSet(currentAccount);
    JFreeChart chartCredit = createPieChart(currentAccount, data, CREDIT);
    chartPanelCredit = new ChartPanel(chartCredit, true, true, true, false, true);
    //                         (chart, properties, save, print, zoom, tooltips)
    JFreeChart chartDebit = createPieChart(currentAccount, data, DEBIT);
    chartPanelDebit = new ChartPanel(chartDebit, true, true, true, false, true);
    FormLayout layout = new FormLayout("p, $lcgap, 70dlu, 8dlu, p, $lcgap, 70dlu, $ugap, p, $lcgap:g, left:p", "d, $rgap, d, $ugap, f:p:g, $rgap, d");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    layout.setRowGroups(new int[][] { { DEBIT, 3 } });
    // row 1
    builder.append(combo, 9);
    builder.append(useFilters);
    builder.nextLine();
    builder.nextLine();
    // row 3
    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(refreshButton);
    builder.append(showPercentCheck);
    builder.nextLine();
    builder.nextLine();
    // row 5
    FormLayout subLayout = new FormLayout("180dlu:g, 1dlu, 180dlu:g", "f:180dlu:g");
    DefaultFormBuilder subBuilder = new DefaultFormBuilder(subLayout);
    subBuilder.append(chartPanelCredit);
    subBuilder.append(chartPanelDebit);
    builder.append(subBuilder.getPanel(), 11);
    builder.nextLine();
    builder.nextLine();
    // row 7
    builder.append(txtAddFilter, 3);
    builder.append(addFilterButton, 3);
    builder.append(saveButton);
    builder.nextLine();
    // row
    builder.append(filterCombo, 3);
    builder.append(deleteFilterButton, 3);
    builder.append(clearPrefButton);
    builder.nextLine();
    JPanel panel = builder.getPanel();
    combo.addActionListener(e -> {
        Account newAccount = combo.getSelectedAccount();
        if (filtersChanged) {
            int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.SaveFilters"), "Warning", JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION) {
                saveButton.doClick();
            }
        }
        filtersChanged = false;
        String[] list = POUND_DELIMITER_PATTERN.split(pref.get(FILTER_TAG + newAccount.hashCode(), ""));
        filterList.clear();
        for (String filter : list) {
            if (!filter.isEmpty()) {
                filterList.add(filter);
            }
        }
        refreshFilters();
        setCurrentAccount(newAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });
    refreshButton.addActionListener(e -> {
        setCurrentAccount(currentAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });
    clearPrefButton.addActionListener(e -> {
        int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.MasterDelete"), "Warning", JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            try {
                pref.clear();
            } catch (Exception ex) {
                System.out.println("Exception clearing preferences" + ex);
            }
        }
    });
    saveButton.addActionListener(e -> {
        final StringBuilder sb = new StringBuilder();
        for (String filter : filterList) {
            sb.append(filter);
            sb.append('#');
        }
        pref.put(FILTER_TAG + currentAccount.hashCode(), sb.toString());
        filtersChanged = false;
    });
    addFilterButton.addActionListener(e -> {
        String newFilter = txtAddFilter.getText();
        filterList.remove(newFilter);
        if (!newFilter.isEmpty()) {
            filterList.add(newFilter);
            filtersChanged = true;
            txtAddFilter.setText("");
        }
        refreshFilters();
    });
    deleteFilterButton.addActionListener(e -> {
        if (!filterList.isEmpty()) {
            String filter = (String) filterCombo.getSelectedItem();
            filterList.remove(filter);
            filtersChanged = true;
        }
        refreshFilters();
    });
    useFilters.addActionListener(e -> setCurrentAccount(currentAccount));
    showPercentCheck.addActionListener(e -> {
        ((PiePlot) chartPanelCredit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
        ((PiePlot) chartPanelDebit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
    });
    return panel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JPanel(javax.swing.JPanel) Account(jgnash.engine.Account) ChartPanel(org.jfree.chart.ChartPanel) JButton(javax.swing.JButton) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) JCheckBox(javax.swing.JCheckBox) PieDataset(org.jfree.data.general.PieDataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) DatePanel(jgnash.ui.components.DatePanel) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) TextField(java.awt.TextField) PiePlot(org.jfree.chart.plot.PiePlot)

Example 94 with Account

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

the class PayeePieChart method getTransactions.

private List<TranTuple> getTransactions(final Account account, final List<TranTuple> transactions, final LocalDate startDate, final LocalDate endDate) {
    for (final Transaction t : account.getTransactions(startDate, endDate)) {
        TranTuple tuple = new TranTuple(account, t);
        transactions.add(tuple);
    }
    for (final Account child : account.getChildren(Comparators.getAccountByCode())) {
        getTransactions(child, transactions, startDate, endDate);
    }
    return transactions;
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction)

Example 95 with Account

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

the class PortfolioReport method createJasperPrint.

/**
     * Creates a JasperPrint object.
     *
     * @return JasperPrint object
     */
@Override
public JasperPrint createJasperPrint(final boolean formatForCSV) {
    logger.info(rb.getString("Message.CollectingReportData"));
    Account account = accountCombo.getSelectedAccount();
    PortfolioReportTableModel model = new PortfolioReportTableModel(account.getCurrencyNode());
    model.verbose = verboseCheckBox.isSelected();
    return createJasperPrint(model, formatForCSV);
}
Also used : Account(jgnash.engine.Account)

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