Search in sources :

Example 1 with ImportFilter

use of jgnash.convert.imports.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.imports.ImportFilter)

Example 2 with ImportFilter

use of jgnash.convert.imports.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) {
                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)

Example 3 with ImportFilter

use of jgnash.convert.imports.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.imports.ImportFilter)

Aggregations

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