Search in sources :

Example 6 with AccountType

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

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

the class IncomeExpensePieChart method createPanel.

private JPanel createPanel() {
    EnumSet<AccountType> set = EnumSet.of(AccountType.INCOME, AccountType.EXPENSE);
    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    startField = new DatePanel();
    endField = new DatePanel();
    showEmptyCheck = new JCheckBox(rb.getString("Label.ShowEmptyAccounts"));
    showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    combo = AccountListComboBox.getParentTypeInstance(engine.getRootAccount(), set);
    final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now()).minusYears(1);
    long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
    startField.setDate(DateUtils.asLocalDate(start));
    currentAccount = combo.getSelectedAccount();
    JFreeChart chart = createPieChart(currentAccount);
    chartPanel = new ChartPanel(chart, true, true, true, false, true);
    //                         (chart, properties, save, print, zoom, tooltips)
    FormLayout layout = new FormLayout("p, 4dlu, 70dlu, 8dlu, p, 4dlu, 70dlu, 8dlu, p, 4dlu:g, left:p", "f:d, 3dlu, f:d, 6dlu, f:p:g");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    layout.setRowGroups(new int[][] { { 1, 3 } });
    builder.append(combo, 9);
    builder.append(showEmptyCheck);
    builder.nextLine();
    builder.nextLine();
    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(refreshButton);
    builder.append(showPercentCheck);
    builder.nextLine();
    builder.nextLine();
    builder.append(chartPanel, 11);
    JPanel panel = builder.getPanel();
    combo.addActionListener(e -> {
        setCurrentAccount(combo.getSelectedAccount());
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });
    refreshButton.addActionListener(e -> {
        setCurrentAccount(currentAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });
    showEmptyCheck.addActionListener(e -> setCurrentAccount(currentAccount));
    showPercentCheck.addActionListener(e -> ((PiePlot) chartPanel.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels));
    ChartMouseListener mouseListener = new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent event) {
            MouseEvent me = event.getTrigger();
            if (me.getID() == MouseEvent.MOUSE_CLICKED && me.getClickCount() == 1) {
                try {
                    ChartEntity entity = event.getEntity();
                    // expand sections if interesting, back out if in nothing
                    if (entity instanceof PieSectionEntity) {
                        Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
                        if (a.getChildCount() > 0) {
                            setCurrentAccount(a);
                        }
                    } else if (entity == null) {
                        Account parent = currentAccount;
                        if (parent == null) {
                            return;
                        }
                        parent = parent.getParent();
                        if (parent == null || parent instanceof RootAccount) {
                            return;
                        }
                        setCurrentAccount(parent);
                    }
                } catch (final Exception e) {
                    Logger.getLogger(IncomeExpensePieChart.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            setChartCursor(chartPanel, event.getEntity(), event.getTrigger().getPoint());
        }
    };
    chartPanel.addChartMouseListener(mouseListener);
    return panel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JPanel(javax.swing.JPanel) RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) ChartPanel(org.jfree.chart.ChartPanel) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) MouseEvent(java.awt.event.MouseEvent) JButton(javax.swing.JButton) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) AccountType(jgnash.engine.AccountType) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) ChartMouseListener(org.jfree.chart.ChartMouseListener) JCheckBox(javax.swing.JCheckBox) RootAccount(jgnash.engine.RootAccount) DatePanel(jgnash.ui.components.DatePanel) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) ChartEntity(org.jfree.chart.entity.ChartEntity) Engine(jgnash.engine.Engine) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 8 with AccountType

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

the class RunningAccountBalanceChart method createTimeSeriesCollection.

private TimeSeriesCollection createTimeSeriesCollection(final Account account) {
    if (subAccountCheckBox.isSelected()) {
        LocalDate start = DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate());
        LocalDate stop = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
        List<LocalDate> list = DateUtils.getLastDayOfTheMonths(start, stop);
        TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance"));
        // For every month, calculate the total amount
        for (LocalDate date : list) {
            LocalDate d = DateUtils.getLastDayOfTheMonth(date);
            // Get the total amount for the account and every sub accounts
            // for the specified date
            BigDecimal bd_TotalAmount = calculateTotal(d, account, account.getCurrencyNode());
            // Include it in the graph
            t.add(new Month(DateUtils.asDate(date)), bd_TotalAmount);
        }
        return new TimeSeriesCollection(t);
    }
    List<LocalDate> list = Collections.emptyList();
    int count = account.getTransactionCount();
    if (count > 0) {
        final LocalDate start = account.getTransactionAt(0).getLocalDate();
        final LocalDate stop = account.getTransactionAt(count - 1).getLocalDate();
        list = DateUtils.getLastDayOfTheMonths(start, stop);
    }
    TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance"));
    AccountType type = account.getAccountType();
    for (final LocalDate date : list) {
        // get balance for the whole month
        LocalDate d = DateUtils.getLastDayOfTheMonth(date);
        BigDecimal balance = AccountBalanceDisplayManager.convertToSelectedBalanceMode(type, account.getBalance(d));
        t.add(new Month(DateUtils.asDate(date)), balance);
    }
    return new TimeSeriesCollection(t);
}
Also used : Month(org.jfree.data.time.Month) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) LocalDate(java.time.LocalDate) AccountType(jgnash.engine.AccountType) BigDecimal(java.math.BigDecimal)

Example 9 with AccountType

use of jgnash.engine.AccountType 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 10 with AccountType

use of jgnash.engine.AccountType 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) EngineFactory(jgnash.engine.EngineFactory) 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) Iterator(java.util.Iterator) Collection(java.util.Collection) CheckBox(javafx.scene.control.CheckBox) Set(java.util.Set) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) FXML(javafx.fxml.FXML) List(java.util.List) Row(jgnash.ui.report.Row) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Account(jgnash.engine.Account) AbstractReportTableModel(jgnash.ui.report.jasper.AbstractReportTableModel) Collections(java.util.Collections) DatePickerEx(jgnash.uifx.control.DatePickerEx) Account(jgnash.engine.Account) ArrayList(java.util.ArrayList) Engine(jgnash.engine.Engine)

Aggregations

AccountType (jgnash.engine.AccountType)15 Account (jgnash.engine.Account)8 BigDecimal (java.math.BigDecimal)7 LocalDate (java.time.LocalDate)6 Engine (jgnash.engine.Engine)6 ResourceBundle (java.util.ResourceBundle)3 CurrencyNode (jgnash.engine.CurrencyNode)3 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Preferences (java.util.prefs.Preferences)2 Collectors (java.util.stream.Collectors)2