use of jgnash.convert.importat.ImportTransaction in project jgnash by ccavanaugh.
the class ImportPageTwoController method initialize.
@FXML
private void initialize() {
textFlow.getChildren().addAll(new Text(TextResource.getString("ImportTwo.txt")));
deleteButton.disableProperty().bind(tableView.getSelectionModel().selectedItemProperty().isNull());
tableView.setTableMenuButtonVisible(false);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setEditable(true);
tableView.getItems().addListener((ListChangeListener<ImportTransaction>) c -> valid.set(tableView.getItems().size() > 0));
buildTableView();
tableViewManager = new TableViewManager<>(tableView, PREF_NODE);
tableViewManager.setColumnWeightFactory(column -> PREF_COLUMN_WEIGHTS[column]);
tableViewManager.setMinimumColumnWidthFactory(column -> MIN_COLUMN_WIDTHS[column]);
updateDescriptor();
}
use of jgnash.convert.importat.ImportTransaction 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();
}
use of jgnash.convert.importat.ImportTransaction in project jgnash by ccavanaugh.
the class ImportPageThreeController method getSettings.
@Override
@SuppressWarnings("unchecked")
public void getSettings(final Map<ImportWizard.Settings, Object> map) {
final Account account = (Account) map.get(ImportWizard.Settings.ACCOUNT);
final List<ImportTransaction> transactions = (List<ImportTransaction>) map.get(ImportWizard.Settings.TRANSACTIONS);
JavaFXUtils.runLater(() -> destLabel.setText(account.getName()));
final AtomicInteger count = new AtomicInteger();
transactions.stream().filter(tran -> tran.getState() == ImportState.NEW || tran.getState() == ImportState.NOT_EQUAL).forEach(tran -> count.incrementAndGet());
JavaFXUtils.runLater(() -> transCountLabel.setText(Integer.toString(count.get())));
updateDescriptor();
}
use of jgnash.convert.importat.ImportTransaction in project jgnash by ccavanaugh.
the class Mt940Exporter method convert.
/**
* Convert a single Mt940-entry to a jGnash-Transaction
*
* @param entry Mt940Entry to convert
* @return new import transaction
*/
private static ImportTransaction convert(Mt940Entry entry) {
BigDecimal amount;
if (entry.getSollHabenKennung() == SollHabenKennung.CREDIT) {
// The bank account is credited, so we gained income
amount = entry.getBetrag();
} else if (entry.getSollHabenKennung() == SollHabenKennung.DEBIT) {
// The bank account is debited, so we made expenses
// withdrawals have a negative 'amount'
amount = BigDecimal.valueOf(0L).subtract(entry.getBetrag());
} else {
throw new UnsupportedOperationException("SollHabenKennung " + entry.getSollHabenKennung() + " not supported");
}
ImportTransaction tran = new ImportTransaction();
tran.setAmount(amount);
tran.setDatePosted(entry.getValutaDatum());
tran.setMemo(entry.getMehrzweckfeld());
tran.setAccount(null);
return tran;
}
Aggregations