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");
}
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;
}
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);
}
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;
}
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;
}
Aggregations