Search in sources :

Example 46 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class BayesImportClassifier method generateClassifier.

private static BayesClassifier<Account> generateClassifier(List<Transaction> transactions, final Account baseAccount) {
    final BayesClassifier<Account> classifier = new BayesClassifier<>(baseAccount);
    for (final Transaction t : transactions) {
        final Set<Account> accountSet = t.getAccounts();
        accountSet.remove(baseAccount);
        for (final Account account : accountSet) {
            if (!t.getPayee().isEmpty()) {
                classifier.train(t.getPayee(), account);
            }
            if (!t.getMemo().isEmpty()) {
                classifier.train(t.getMemo(), account);
            }
        }
    }
    return classifier;
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) BayesClassifier(jgnash.bayes.BayesClassifier)

Example 47 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class GenericImport method findFirstAvailableAccount.

public static Account findFirstAvailableAccount() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final Account account : engine.getAccountList()) {
        if (!account.isPlaceHolder() && !account.isLocked()) {
            return account;
        }
    }
    return null;
}
Also used : Account(jgnash.engine.Account) Engine(jgnash.engine.Engine)

Example 48 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class QifImport method addAccounts.

/**
     * All of the accounts must be added before the transactions are added because the category (account) must exist
     * first
     */
private void addAccounts() {
    logger.info("*** Importing Accounts ***");
    List<QifAccount> list = parser.accountList;
    // add all of the accounts first
    for (QifAccount qAcc : list) {
        Account acc;
        if (!accountMap.containsKey(qAcc.name)) {
            // add the account if it does not exist
            acc = generateAccount(qAcc);
            if (acc != null) {
                engine.addAccount(engine.getRootAccount(), acc);
                loadAccountMap(acc);
            }
        }
    }
    logger.info("*** Importing Transactions ***");
    // go back and add the transactions;
    for (QifAccount qAcc : list) {
        Account acc = accountMap.get(qAcc.name);
        // try and match the closest
        if (acc == null) {
            acc = engine.getAccountByName(qAcc.name);
        }
        // TODO Correct import of investment transactions
        if (acc != null && acc.getAccountType() != AccountType.INVEST) {
            addTransactions(qAcc, acc);
        } else {
            if (acc != null) {
                logger.severe("Investment transactions not fully supported");
            } else {
                logger.log(Level.SEVERE, "Lost the account: {0}", qAcc.name);
            }
        }
    }
}
Also used : Account(jgnash.engine.Account)

Example 49 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class QifImport method findBestParent.

/**
     * Returns the Account of the best possible parent account for the supplied QifCategory
     *
     * @param cat imported QifCategory to match
     * @param map cached account map
     * @return best Account match
     */
private Account findBestParent(final QifCategory cat, final Map<String, Account> map) {
    int i = cat.name.lastIndexOf(':');
    if (i != -1) {
        String pathName = cat.name.substring(0, i);
        while (true) {
            if (map.containsKey(pathName)) {
                return map.get(pathName);
            }
            int j = pathName.lastIndexOf(':');
            if (j != -1) {
                pathName = pathName.substring(0, j);
            } else {
                break;
            }
        }
    }
    Account parent;
    if (cat.type.equals("E")) {
        parent = ImportUtils.getRootExpenseAccount();
    } else {
        parent = ImportUtils.getRootIncomeAccount();
    }
    if (parent != null) {
        return parent;
    }
    return engine.getRootAccount();
}
Also used : Account(jgnash.engine.Account)

Example 50 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class QifImport method addCategories.

private void addCategories() {
    List<QifCategory> list = parser.categories;
    Map<String, Account> map;
    for (QifCategory cat : list) {
        Account acc = generateAccount(cat);
        if (acc.getAccountType() == AccountType.EXPENSE) {
            map = expenseMap;
        } else {
            map = incomeMap;
        }
        Account parent = findBestParent(cat, map);
        engine.addAccount(parent, acc);
        loadCategoryMap(acc, map);
    }
}
Also used : Account(jgnash.engine.Account)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9