Search in sources :

Example 21 with CurrencyNode

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

Example 22 with CurrencyNode

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);
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) CSVFormat(org.apache.commons.csv.CSVFormat) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) LocalDate(java.time.LocalDate) BufferedWriter(java.io.BufferedWriter)

Example 23 with CurrencyNode

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;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) Set(java.util.Set) HashSet(java.util.HashSet) SecurityNode(jgnash.engine.SecurityNode) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 24 with CurrencyNode

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);
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) Engine(jgnash.engine.Engine)

Example 25 with CurrencyNode

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

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