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