Search in sources :

Example 1 with ImportBank

use of jgnash.convert.imports.ImportBank in project jgnash by ccavanaugh.

the class ImportTwo method getSettings.

@Override
@SuppressWarnings("unchecked")
public void getSettings(final Map<Enum<?>, Object> map) {
    ImportBank<ImportTransaction> bank = (ImportBank<ImportTransaction>) map.get(ImportDialog.Settings.BANK);
    if (bank != null) {
        List<ImportTransaction> list = bank.getTransactions();
        Account account = (Account) map.get(ImportDialog.Settings.ACCOUNT);
        // set to sane account assuming it's going to be a single entry
        for (ImportTransaction t : list) {
            t.setAccount(account);
            t.setState(ImportState.NEW);
        }
        // match up any pre-existing transactions
        GenericImport.matchTransactions(list, account);
        // classify the transactions
        BayesImportClassifier.classifyTransactions(list, account.getSortedTransactionList(), account);
        table.setTransactions(list);
        refreshInfo();
    }
}
Also used : Account(jgnash.engine.Account) ImportBank(jgnash.convert.imports.ImportBank) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Example 2 with ImportBank

use of jgnash.convert.imports.ImportBank in project jgnash by ccavanaugh.

the class ImportPageTwoController method getSettings.

@Override
public void getSettings(final Map<ImportWizard.Settings, Object> map) {
    @SuppressWarnings("unchecked") final ImportBank<ImportTransaction> bank = (ImportBank<ImportTransaction>) map.get(ImportWizard.Settings.BANK);
    if (bank != null) {
        final List<ImportTransaction> list = bank.getTransactions();
        baseAccount = (Account) map.get(ImportWizard.Settings.ACCOUNT);
        final CurrencyNode currencyNode = baseAccount.getCurrencyNode();
        // rescale for consistency
        numberFormat.setMinimumFractionDigits(currencyNode.getScale());
        numberFormat.setMaximumFractionDigits(currencyNode.getScale());
        // List of enabled import filters
        final List<ImportFilter> importFilterList = ImportFilter.getEnabledImportFilters();
        // set to sane account assuming it's going to be a single entry
        for (final ImportTransaction t : list) {
            // Process transactions with the import filter
            for (final ImportFilter importFilter : importFilterList) {
                t.setMemo(importFilter.processMemo(t.getMemo()));
                t.setPayee(importFilter.processPayee(t.getPayee()));
            }
            if (t.getTransactionType() != TransactionType.REINVESTDIV) {
                t.setAccount(baseAccount);
            }
            if (t.isInvestmentTransaction()) {
                switch(t.getTransactionType()) {
                    case BUYSHARE:
                        t.setFeesAccount(baseAccount);
                        break;
                    case SELLSHARE:
                        t.setFeesAccount(baseAccount);
                        t.setGainsAccount(baseAccount);
                        break;
                    case DIVIDEND:
                        t.setGainsAccount(baseAccount);
                        break;
                    case REINVESTDIV:
                        t.setFeesAccount(baseAccount);
                        t.setGainsAccount(baseAccount);
                        break;
                    default:
                }
            }
            // force reset
            t.setState(ImportState.NEW);
        }
        incomeAccountColumn.setVisible(bank.isInvestmentAccount());
        expenseAccountColumn.setVisible(bank.isInvestmentAccount());
        typeColumn.setVisible(bank.isInvestmentAccount());
        // match up any pre-existing transactions
        GenericImport.matchTransactions(list, baseAccount);
        // classify the transactions
        if (Options.globalBayesProperty().get()) {
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            Objects.requireNonNull(engine);
            final List<Transaction> transactions = engine.getTransactions();
            transactions.sort(null);
            BayesImportClassifier.classifyTransactions(list, transactions, baseAccount);
        } else {
            BayesImportClassifier.classifyTransactions(list, baseAccount.getSortedTransactionList(), baseAccount);
        }
        tableView.getItems().setAll(list);
        FXCollections.sort(tableView.getItems());
        tableViewManager.restoreLayout();
    }
    Platform.runLater(tableViewManager::packTable);
    updateDescriptor();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ImportFilter(jgnash.convert.imports.ImportFilter) Transaction(jgnash.engine.Transaction) ImportTransaction(jgnash.convert.imports.ImportTransaction) ImportBank(jgnash.convert.imports.ImportBank) Engine(jgnash.engine.Engine) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Aggregations

ImportBank (jgnash.convert.imports.ImportBank)2 ImportTransaction (jgnash.convert.imports.ImportTransaction)2 ImportFilter (jgnash.convert.imports.ImportFilter)1 Account (jgnash.engine.Account)1 CurrencyNode (jgnash.engine.CurrencyNode)1 Engine (jgnash.engine.Engine)1 Transaction (jgnash.engine.Transaction)1