use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class CurrencyComboBox method loadModel.
private void loadModel() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final List<CurrencyNode> nodeList = engine.getCurrencies();
// extract and reuse the default model
items = getItems();
// warp in a sorted list
setItems(new SortedList<>(items, null));
items.addAll(nodeList);
final CurrencyNode defaultCurrency = engine.getDefaultCurrency();
setValue(defaultCurrency);
MessageBus.getInstance().registerListener(this, MessageChannel.COMMODITY, MessageChannel.SYSTEM);
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class BudgetResultsExportTest method testExportBudgetResultsModel.
@Test
void testExportBudgetResultsModel() throws Exception {
final String file = Files.createTempFile("budget-", DataStoreType.XML.getDataStore().getFileExt()).toString();
EngineFactory.deleteDatabase(file);
Engine e = EngineFactory.bootLocalEngine(file, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD, DataStoreType.XML);
e.setCreateBackups(false);
CurrencyNode node = e.getDefaultCurrency();
Account account1 = new Account(AccountType.EXPENSE, node);
account1.setName("Expense 1");
e.addAccount(e.getRootAccount(), account1);
Account account2 = new Account(AccountType.EXPENSE, node);
account2.setName("Expense 2");
e.addAccount(e.getRootAccount(), account2);
Budget budget = new Budget();
budget.setName("My Budget");
budget.setDescription("Test");
budget.setBudgetPeriod(Period.MONTHLY);
assertTrue(e.addBudget(budget));
BudgetResultsModel model = new BudgetResultsModel(budget, 2012, node, false);
final Path exportFile = Files.createTempFile("testworkbook", ".xls");
final String errors = BudgetResultsExport.exportBudgetResultsModel(exportFile, model);
assertNull(errors);
assertTrue(Files.exists(exportFile));
Files.delete(exportFile);
EngineFactory.closeEngine(EngineFactory.DEFAULT);
Files.deleteIfExists(Paths.get(file));
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class NumericFormatsTests method localeTest.
@Test
void localeTest() {
Locale.setDefault(new Locale("el", "GR"));
CurrencyNode currencyNode = new CurrencyNode();
currencyNode.setSymbol("EUR");
currencyNode.setScale((byte) 2);
currencyNode.setPrefix("€");
final NumberFormat numberFormat = NumericFormats.getFullCommodityFormat(currencyNode);
assertEquals("EUR", numberFormat.getCurrency().getCurrencyCode());
assertThrows(NullPointerException.class, () -> NumericFormats.getFullCommodityFormat(null));
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class NumericFormatsTests method testFormats.
@Test
void testFormats() {
Locale.setDefault(Locale.US);
final CurrencyNode node = new CurrencyNode();
node.setSymbol("USD");
node.setScale((byte) 2);
node.setPrefix("$");
// preserve the configured format
final String oldShortPattern = NumericFormats.getShortFormatPattern();
final String oldFullPattern = NumericFormats.getFullFormatPattern();
NumericFormats.setFullFormatPattern("\u00A4#,##0.00;(\u00A4#,##0.00)");
NumericFormats.setShortFormatPattern("\u00A4#,##0.00;-\u00A4#,##0.00");
NumberFormat shortFormat = NumericFormats.getShortCommodityFormat(node);
NumberFormat fullFormat = NumericFormats.getFullCommodityFormat(node);
assertNotNull(fullFormat);
assertNotNull(shortFormat);
assertEquals("$10.00", shortFormat.format(BigDecimal.TEN));
assertEquals("$10.00 ", fullFormat.format(BigDecimal.TEN));
assertEquals("-$10.00", shortFormat.format(BigDecimal.TEN.negate()));
assertEquals("($10.00)", fullFormat.format(BigDecimal.TEN.negate()));
NumericFormats.setShortFormatPattern("#,##0.00;-#,##0.00");
shortFormat = NumericFormats.getShortCommodityFormat(node);
assertEquals("10.00", shortFormat.format(BigDecimal.TEN));
assertEquals("-10.00", shortFormat.format(BigDecimal.TEN.negate()));
// restore the old patterns
NumericFormats.setShortFormatPattern(oldShortPattern);
NumericFormats.setFullFormatPattern(oldFullPattern);
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class AbstractSumByTypeReport method createReportModel.
ReportModel createReportModel(final LocalDate startDate, final LocalDate endDate, final boolean hideZeroBalanceAccounts) {
percentileMap.clear();
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
// update the subtitle
final MessageFormat format = new MessageFormat(rb.getString("Pattern.DateRange"));
subTitle = format.format(new Object[] { DateUtils.asDate(startDate), DateUtils.asDate(endDate) });
// generate the required date and label arrays
updateResolution(startDate, endDate);
final CurrencyNode baseCurrency = engine.getDefaultCurrency();
List<Account> accounts = new ArrayList<>();
for (final AccountGroup group : getAccountGroups()) {
accounts.addAll(getAccountList(AccountType.getAccountTypes(group)));
}
// remove any account that will report a zero balance for all periods
if (hideZeroBalanceAccounts) {
final Iterator<Account> i = accounts.iterator();
while (i.hasNext()) {
final Account account = i.next();
boolean remove = true;
if (runningTotal) {
for (final LocalDate date : startDates) {
if (account.getBalance(date).compareTo(BigDecimal.ZERO) != 0) {
remove = false;
break;
}
}
for (final LocalDate date : endDates) {
if (account.getBalance(date).compareTo(BigDecimal.ZERO) != 0) {
remove = false;
break;
}
}
} else {
for (int j = 0; j < startDates.size(); j++) {
if (account.getBalance(startDates.get(j), endDates.get(j)).compareTo(BigDecimal.ZERO) != 0) {
remove = false;
break;
}
}
}
if (remove) {
i.remove();
}
}
}
switch(// sort the accounts
sortOrder) {
case BY_NAME:
accounts.sort(showFullAccountPath ? Comparators.getAccountByPathName() : Comparators.getAccountByName());
break;
case BY_BALANCE:
accounts.sort(Comparators.getAccountByBalance(startDate, endDate, baseCurrency, true));
break;
default:
accounts.sort(Comparators.getAccountByName());
}
// cross tabulate account percentages by group
if (addPercentileColumn) {
for (final AccountGroup group : getAccountGroups()) {
// sum the group
BigDecimal groupTotal = BigDecimal.ZERO;
for (final Account a : accounts) {
if (a.getAccountType().getAccountGroup() == group) {
groupTotal = groupTotal.add(a.getBalance(startDate, endDate, baseCurrency));
}
}
// calculate the percentage
for (final Account a : accounts) {
if (a.getAccountType().getAccountGroup() == group) {
BigDecimal sum = a.getBalance(startDate, endDate, baseCurrency);
percentileMap.put(a, sum.divide(groupTotal, MathConstants.mathContext));
}
}
}
}
final ReportModel model = new ReportModel(baseCurrency);
model.addAccounts(accounts);
return model;
}
Aggregations