Search in sources :

Example 1 with ImportFilter

use of jgnash.convert.importat.ImportFilter in project jgnash by ccavanaugh.

the class ImportScriptsDialogController method loadScripts.

/**
 * Loads remain scripts that have not been enabled
 */
private void loadScripts() {
    for (final ImportFilter importFilter : ImportFilter.getImportFilters()) {
        boolean exists = false;
        for (Script script : tableView.getItems()) {
            if (script.scriptProperty.get().equals(importFilter.getScript())) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            final Script script = new Script();
            script.descriptionProperty.setValue(importFilter.getDescription());
            script.scriptProperty.setValue(importFilter.getScript());
            script.importFilter = importFilter;
            tableView.getItems().add(script);
        }
    }
}
Also used : ImportFilter(jgnash.convert.importat.ImportFilter)

Example 2 with ImportFilter

use of jgnash.convert.importat.ImportFilter 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) {
                // pass the import transaction for manipulation by the script
                importFilter.acceptTransaction(t);
                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:
                    case REINVESTDIV:
                        t.setFeesAccount(baseAccount);
                        t.setGainsAccount(baseAccount);
                        break;
                    case DIVIDEND:
                        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);
        }
        // override the classifier if an account has been specified already
        for (final ImportTransaction importTransaction : list) {
            final Account account = ImportUtils.matchAccount(importTransaction);
            if (account != null) {
                importTransaction.setAccount(account);
            }
        }
        tableView.getItems().setAll(list);
        FXCollections.sort(tableView.getItems());
        tableViewManager.restoreLayout();
    }
    JavaFXUtils.runLater(tableViewManager::packTable);
    updateDescriptor();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ImportFilter(jgnash.convert.importat.ImportFilter) Account(jgnash.engine.Account) ImportTransaction(jgnash.convert.importat.ImportTransaction) ImportTransaction(jgnash.convert.importat.ImportTransaction) Transaction(jgnash.engine.Transaction) ImportBank(jgnash.convert.importat.ImportBank) Engine(jgnash.engine.Engine)

Example 3 with ImportFilter

use of jgnash.convert.importat.ImportFilter in project jgnash by ccavanaugh.

the class ImportScriptsDialogController method setEnabledScripts.

public void setEnabledScripts(final List<ImportFilter> importFilters) {
    for (final ImportFilter importFilter : importFilters) {
        final Script script = new Script();
        script.descriptionProperty.setValue(importFilter.getDescription());
        script.scriptProperty.setValue(importFilter.getScript());
        script.importFilter = importFilter;
        script.enabledProperty.setValue(true);
        tableView.getItems().add(script);
    }
    loadScripts();
}
Also used : ImportFilter(jgnash.convert.importat.ImportFilter)

Aggregations

ImportFilter (jgnash.convert.importat.ImportFilter)3 ImportBank (jgnash.convert.importat.ImportBank)1 ImportTransaction (jgnash.convert.importat.ImportTransaction)1 Account (jgnash.engine.Account)1 CurrencyNode (jgnash.engine.CurrencyNode)1 Engine (jgnash.engine.Engine)1 Transaction (jgnash.engine.Transaction)1