use of jgnash.engine.CurrencyNode 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.CurrencyNode in project jgnash by ccavanaugh.
the class OfxImport method matchAccount.
public static Account matchAccount(final OfxBank bank) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final String number = bank.accountId;
final CurrencyNode node = engine.getCurrency(bank.currency);
Account account = null;
if (node != null) {
for (Account a : engine.getAccountList()) {
if (a.getAccountNumber() != null && a.getAccountNumber().equals(number) && a.getCurrencyNode().equals(node)) {
account = a;
break;
}
}
} else if (number != null) {
for (Account a : engine.getAccountList()) {
if (a.getAccountNumber().equals(number)) {
account = a;
break;
}
}
}
return account;
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class QifImport method generateAccount.
/*
* Creates and returns an Account of the correct type given a QifCategory
*/
private Account generateAccount(final QifCategory cat) {
Account account;
CurrencyNode defaultCurrency = engine.getDefaultCurrency();
if (cat.type.equals("E")) {
account = new Account(AccountType.EXPENSE, defaultCurrency);
// account.setTaxRelated(cat.taxRelated);
// account.setTaxSchedule(cat.taxSchedule);
} else {
account = new Account(AccountType.INCOME, defaultCurrency);
// account.setTaxRelated(cat.taxRelated);
// account.setTaxSchedule(cat.taxSchedule);
}
// trim off the leading parent account
int index = cat.name.lastIndexOf(':');
if (index != -1) {
account.setName(cat.name.substring(index + 1));
} else {
account.setName(cat.name);
}
account.setDescription(cat.description);
return account;
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class QifImport method generateAccount.
private Account generateAccount(final QifAccount acc) {
Account account;
CurrencyNode defaultCurrency = engine.getDefaultCurrency();
switch(acc.type) {
case "Bank":
account = new Account(AccountType.BANK, defaultCurrency);
break;
case "CCard":
account = new Account(AccountType.CREDIT, defaultCurrency);
break;
case "Cash":
account = new Account(AccountType.CASH, defaultCurrency);
break;
case "Invst":
case "Port":
account = new Account(AccountType.INVEST, defaultCurrency);
break;
case "Oth A":
account = new Account(AccountType.ASSET, defaultCurrency);
break;
case "Oth L":
account = new Account(AccountType.LIABILITY, defaultCurrency);
break;
default:
logger.log(Level.SEVERE, "Could not generate an account for:\n{0}", acc.toString());
return null;
}
account.setName(acc.name);
account.setDescription(acc.description);
return account;
}
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"));
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