use of jgnash.convert.importat.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) {
// 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();
}
Aggregations