use of jgnash.engine.AccountGroup 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;
}
use of jgnash.engine.AccountGroup in project jgnash by ccavanaugh.
the class BudgetTableController method calculateMinColumnWidth.
private double calculateMinColumnWidth(final BudgetPeriodDescriptor descriptor) {
double max = 0;
double min = 0;
for (final AccountGroup accountGroup : accountGroupList) {
BudgetPeriodResults budgetPeriodResults = budgetResultsModel.getResults(descriptor, accountGroup);
max = Math.max(max, budgetPeriodResults.getBudgeted().doubleValue());
max = Math.max(max, budgetPeriodResults.getChange().doubleValue());
max = Math.max(max, budgetPeriodResults.getRemaining().doubleValue());
min = Math.min(min, budgetPeriodResults.getBudgeted().doubleValue());
min = Math.min(min, budgetPeriodResults.getChange().doubleValue());
min = Math.min(min, budgetPeriodResults.getRemaining().doubleValue());
}
return Math.max(JavaFXUtils.getDisplayedTextWidth(CommodityFormat.getFullNumberFormat(budgetResultsModel.getBaseCurrency()).format(max) + BORDER_MARGIN, null), JavaFXUtils.getDisplayedTextWidth(CommodityFormat.getFullNumberFormat(budgetResultsModel.getBaseCurrency()).format(min) + BORDER_MARGIN, null));
}
use of jgnash.engine.AccountGroup in project jgnash by ccavanaugh.
the class AbstractSumByTypeReport method createReportModel.
protected 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;
}
use of jgnash.engine.AccountGroup in project jgnash by ccavanaugh.
the class AbstractCrosstabReport method createTableModel.
@SuppressWarnings("ConstantConditions")
private ReportModel createTableModel() {
logger.info(rb.getString("Message.CollectingReportData"));
final CurrencyNode baseCurrency = EngineFactory.getEngine(EngineFactory.DEFAULT).getDefaultCurrency();
final List<Account> accounts = new ArrayList<>();
final String sortOrder = sortOrderComboBox.getValue();
final boolean needPercentiles = SORT_ORDER_BALANCE_DESC_WITH_PERCENTILE.equals(sortOrder);
for (final 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(startDatePicker.getValue(), endDatePicker.getValue(), baseCurrency, ascendingSortOrder));
}
if (needPercentiles) {
BigDecimal groupTotal = BigDecimal.ZERO;
for (final Account a : list) {
groupTotal = groupTotal.add(a.getBalance(startDatePicker.getValue(), endDatePicker.getValue(), baseCurrency));
}
BigDecimal sumSoFar = BigDecimal.ZERO;
for (final Account a : list) {
sumSoFar = sumSoFar.add(a.getBalance(startDatePicker.getValue(), endDatePicker.getValue(), 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