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 CsvExport method exportAccountTree.
public static void exportAccountTree(@NotNull final Engine engine, @NotNull final Path path) {
Objects.requireNonNull(engine);
Objects.requireNonNull(path);
// force a correct file extension
final String fileName = FileUtils.stripFileExtension(path.toString()) + ".csv";
final CSVFormat csvFormat = CSVFormat.EXCEL.withQuoteMode(QuoteMode.ALL);
try (final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(Paths.get(fileName)), StandardCharsets.UTF_8);
final CSVPrinter writer = new CSVPrinter(new BufferedWriter(outputStreamWriter), csvFormat)) {
// write UTF-8 byte order mark to the file for easier imports
outputStreamWriter.write(BYTE_ORDER_MARK);
writer.printRecord(ResourceUtils.getString("Column.Account"), ResourceUtils.getString("Column.Code"), ResourceUtils.getString("Column.Entries"), ResourceUtils.getString("Column.Balance"), ResourceUtils.getString("Column.ReconciledBalance"), ResourceUtils.getString("Column.Currency"), ResourceUtils.getString("Column.Type"));
// Create a list sorted by depth and account code and then name if code is not specified
final List<Account> accountList = engine.getAccountList();
accountList.sort(Comparators.getAccountByTreePosition(Comparators.getAccountByCode()));
final CurrencyNode currencyNode = engine.getDefaultCurrency();
final LocalDate today = LocalDate.now();
for (final Account account : accountList) {
final String indentedName = SPACE.repeat((account.getDepth() - 1) * INDENT) + account.getName();
final String balance = account.getTreeBalance(today, currencyNode).toPlainString();
final String reconcileBalance = account.getReconciledTreeBalance().toPlainString();
writer.printRecord(indentedName, String.valueOf(account.getAccountCode()), String.valueOf(account.getTransactionCount()), balance, reconcileBalance, account.getCurrencyNode().getSymbol(), account.getAccountType().toString());
}
} catch (final IOException e) {
Logger.getLogger(CsvExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class JpaCommodityDAO method getActiveCurrencies.
/*
* @see jgnash.engine.CommodityDAOInterface#getActiveAccountCommodities()
*/
@Override
public Set<CurrencyNode> getActiveCurrencies() {
Set<CurrencyNode> currencyNodeSet = Collections.emptySet();
try {
Future<Set<CurrencyNode>> future = executorService.submit(() -> {
emLock.lock();
try {
final TypedQuery<Account> q = em.createQuery("SELECT a FROM Account a WHERE a.markedForRemoval = false", Account.class);
final List<Account> accountList = q.getResultList();
final Set<CurrencyNode> currencies = new HashSet<>();
for (final Account account : accountList) {
currencies.add(account.getCurrencyNode());
currencies.addAll(account.getSecurities().parallelStream().map(SecurityNode::getReportedCurrencyNode).collect(Collectors.toList()));
}
return currencies;
} finally {
emLock.unlock();
}
});
currencyNodeSet = future.get();
} catch (final InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return currencyNodeSet;
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class NewFileUtility method buildNewFile.
public static void buildNewFile(final String fileName, final DataStoreType dataStoreType, final char[] password, final CurrencyNode currencyNode, final Collection<CurrencyNode> currencyNodes, final Collection<RootAccount> rootAccountCollection) throws IOException {
final ResourceBundle resources = ResourceUtils.getBundle();
// have to close the engine first
EngineFactory.closeEngine(EngineFactory.DEFAULT);
// try to delete any existing database
if (Files.exists(Paths.get(fileName))) {
if (!EngineFactory.deleteDatabase(fileName)) {
throw new IOException(ResourceUtils.getString("Message.Error.DeleteExistingFile", fileName));
}
}
// create the directory if needed
Files.createDirectories(Paths.get(fileName).getParent());
final Engine e = EngineFactory.bootLocalEngine(fileName, EngineFactory.DEFAULT, password, dataStoreType);
CurrencyNode defaultCurrency = currencyNode;
// creation of a duplicate currency
if (e.getDefaultCurrency().matches(defaultCurrency)) {
defaultCurrency = e.getDefaultCurrency();
}
// make sure a duplicate default is not added
for (final CurrencyNode node : currencyNodes) {
if (!node.matches(defaultCurrency)) {
e.addCurrency(node);
}
}
if (!defaultCurrency.equals(e.getDefaultCurrency())) {
e.setDefaultCurrency(defaultCurrency);
}
if (!rootAccountCollection.isEmpty()) {
// import account sets
for (final RootAccount root : rootAccountCollection) {
AccountTreeXMLFactory.importAccountTree(e, root);
}
} else {
// none selected, create a very basic account set
final RootAccount root = e.getRootAccount();
final Account bank = new Account(AccountType.BANK, defaultCurrency);
bank.setDescription(resources.getString("Name.BankAccounts"));
bank.setName(resources.getString("Name.BankAccounts"));
e.addAccount(root, bank);
final Account income = new Account(AccountType.INCOME, defaultCurrency);
income.setDescription(resources.getString("Name.IncomeAccounts"));
income.setName(resources.getString("Name.IncomeAccounts"));
e.addAccount(root, income);
final Account expense = new Account(AccountType.EXPENSE, defaultCurrency);
expense.setDescription(resources.getString("Name.ExpenseAccounts"));
expense.setName(resources.getString("Name.ExpenseAccounts"));
e.addAccount(root, expense);
}
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class CurrencyComboBox method messagePosted.
@Override
public void messagePosted(final Message event) {
if (event.getObject(MessageProperty.COMMODITY) instanceof CurrencyNode) {
final CurrencyNode node = event.getObject(MessageProperty.COMMODITY);
JavaFXUtils.runLater(() -> {
switch(event.getEvent()) {
case CURRENCY_REMOVE:
items.removeAll(node);
break;
case CURRENCY_ADD:
items.add(node);
break;
case CURRENCY_MODIFY:
items.removeAll(node);
items.add(node);
break;
case FILE_CLOSING:
items.clear();
default:
break;
}
});
}
}
Aggregations