Search in sources :

Example 41 with Account

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

the class IncomeExpensePieChart method setChartCursor.

private void setChartCursor(final ChartPanel chartPanel, final ChartEntity e, final Point point) {
    lastPoint = point;
    EventQueue.invokeLater(new Runnable() {

        ChartEntity entity = e;

        @Override
        public void run() {
            if (entity == null && point != null) {
                entity = chartPanel.getEntityForPoint(lastPoint.x, lastPoint.y);
            }
            Account parent = currentAccount;
            if (entity instanceof PieSectionEntity) {
                // change cursor if section is interesting
                Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
                if (a.getChildCount() > 0 && a != parent) {
                    chartPanel.setCursor(ZOOM_IN);
                } else {
                    chartPanel.setCursor(Cursor.getDefaultCursor());
                }
                return;
            } else if (entity == null && parent != null) {
                parent = parent.getParent();
                if (parent != null && !(parent instanceof RootAccount)) {
                    chartPanel.setCursor(ZOOM_OUT);
                    return;
                }
            }
            chartPanel.setCursor(Cursor.getDefaultCursor());
        }
    });
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount) ChartEntity(org.jfree.chart.entity.ChartEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 42 with Account

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

Example 43 with Account

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

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

the class RegisterTableModel method getInternalValueAt.

@Override
protected Object getInternalValueAt(int row, int col) {
    Transaction t = getTransactionAt(row);
    BigDecimal amount = t.getAmount(account);
    int signum = amount.signum();
    switch(col) {
        case 0:
            return t.getLocalDate();
        case 1:
            return t.getNumber();
        case 2:
            return t.getPayee();
        case 3:
            return t.getMemo();
        case 4:
            if (t instanceof InvestmentTransaction) {
                return ((InvestmentTransaction) t).getInvestmentAccount().getName();
            }
            int count = t.size();
            if (count > 1) {
                return "[ " + count + " " + split + " ]";
            }
            Account creditAccount = t.getTransactionEntries().get(0).getCreditAccount();
            if (creditAccount != account) {
                return creditAccount.getName();
            }
            return t.getTransactionEntries().get(0).getDebitAccount().getName();
        case 5:
            return t.getReconciled(account).toString();
        case 6:
            if (signum >= 0) {
                return amount;
            }
            return null;
        case 7:
            if (signum < 0) {
                return amount.abs();
            }
            return null;
        case 8:
            return getBalanceAt(row);
        default:
            return ERROR;
    }
}
Also used : Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal)

Example 45 with Account

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

the class AccountExport method getAccountColumnValue.

private static String getAccountColumnValue(final Transaction transaction, final Account account) {
    if (transaction instanceof InvestmentTransaction) {
        return ((InvestmentTransaction) transaction).getInvestmentAccount().getName();
    }
    int count = transaction.size();
    if (count > 1) {
        return "[ " + count + " " + ResourceUtils.getString("Button.Splits") + " ]";
    }
    final Account creditAccount = transaction.getTransactionEntries().get(0).getCreditAccount();
    if (creditAccount != account) {
        return creditAccount.getName();
    }
    return transaction.getTransactionEntries().get(0).getDebitAccount().getName();
}
Also used : Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

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