Search in sources :

Example 6 with AccountGroup

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;
}
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 7 with AccountGroup

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));
}
Also used : AccountGroup(jgnash.engine.AccountGroup) BudgetPeriodResults(jgnash.engine.budget.BudgetPeriodResults)

Example 8 with AccountGroup

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;
}
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 9 with AccountGroup

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);
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) JasperPrint(net.sf.jasperreports.engine.JasperPrint) LinkedList(java.util.LinkedList) AccountGroup(jgnash.engine.AccountGroup)

Aggregations

AccountGroup (jgnash.engine.AccountGroup)9 ArrayList (java.util.ArrayList)6 Account (jgnash.engine.Account)6 BigDecimal (java.math.BigDecimal)4 CurrencyNode (jgnash.engine.CurrencyNode)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)4 LocalDate (java.time.LocalDate)3 TableColumn (javafx.scene.control.TableColumn)3 TreeTableColumn (javafx.scene.control.TreeTableColumn)3 Engine (jgnash.engine.Engine)3 LinkedList (java.util.LinkedList)2 ResourceBundle (java.util.ResourceBundle)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 BudgetPeriodDescriptor (jgnash.engine.budget.BudgetPeriodDescriptor)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 List (java.util.List)1