Search in sources :

Example 26 with CurrencyNode

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);
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Engine(jgnash.engine.Engine)

Example 27 with CurrencyNode

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));
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Path(java.nio.file.Path) Account(jgnash.engine.Account) Budget(jgnash.engine.budget.Budget) Engine(jgnash.engine.Engine) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel) Test(org.junit.jupiter.api.Test)

Example 28 with CurrencyNode

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));
}
Also used : Locale(java.util.Locale) CurrencyNode(jgnash.engine.CurrencyNode) NumberFormat(java.text.NumberFormat) Test(org.junit.jupiter.api.Test)

Example 29 with CurrencyNode

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);
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) NumberFormat(java.text.NumberFormat) Test(org.junit.jupiter.api.Test)

Example 30 with CurrencyNode

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;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountGroup(jgnash.engine.AccountGroup) Engine(jgnash.engine.Engine)

Aggregations

CurrencyNode (jgnash.engine.CurrencyNode)58 Account (jgnash.engine.Account)28 Engine (jgnash.engine.Engine)28 BigDecimal (java.math.BigDecimal)10 ArrayList (java.util.ArrayList)10 LocalDate (java.time.LocalDate)8 NumberFormat (java.text.NumberFormat)7 List (java.util.List)7 FXML (javafx.fxml.FXML)7 AccountGroup (jgnash.engine.AccountGroup)7 Transaction (jgnash.engine.Transaction)6 ResourceBundle (java.util.ResourceBundle)5 SecurityNode (jgnash.engine.SecurityNode)5 InjectFXML (jgnash.uifx.util.InjectFXML)5 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 ExecutionException (java.util.concurrent.ExecutionException)3