use of jgnash.convert.imports.ImportTransaction in project jgnash by ccavanaugh.
the class OfxV2Parser method parseBankTransaction.
/**
* Parses a STMTTRN element
*
* @param reader shared XMLStreamReader
* @throws XMLStreamException XML parsing error has occurred
*/
private void parseBankTransaction(final XMLStreamReader reader) throws XMLStreamException {
logger.entering(OfxV2Parser.class.getName(), "parseBankTransaction");
final QName parsingElement = reader.getName();
final ImportTransaction tran = new ImportTransaction();
parse: while (reader.hasNext()) {
final int event = reader.next();
switch(event) {
case XMLStreamConstants.START_ELEMENT:
switch(reader.getLocalName()) {
case TRNTYPE:
tran.setTransactionTypeDescription(reader.getElementText());
break;
case DTPOSTED:
tran.setDatePosted(parseDate(reader.getElementText()));
break;
case DTUSER:
tran.setDateUser(parseDate(reader.getElementText()));
break;
case TRNAMT:
tran.setAmount(parseAmount(reader.getElementText()));
break;
case FITID:
tran.setFITID(reader.getElementText());
break;
case CHECKNUM:
tran.setCheckNumber(reader.getElementText());
break;
case NAME:
case // either PAYEE or NAME will be used
PAYEE:
tran.setPayee(reader.getElementText().replaceAll(EXTRA_SPACE_REGEX, " ").trim());
break;
case MEMO:
tran.setMemo(reader.getElementText().replaceAll(EXTRA_SPACE_REGEX, " ").trim());
break;
case // Chase bank mucking up the OFX standard
CATEGORY:
break;
case SIC:
tran.setSIC(reader.getElementText());
break;
case REFNUM:
tran.setRefNum(reader.getElementText());
break;
case PAYEEID:
tran.setPayeeId(reader.getElementText().replaceAll(EXTRA_SPACE_REGEX, " ").trim());
break;
case CURRENCY:
tran.setCurrency(reader.getElementText());
break;
case ORIGCURRENCY:
tran.setCurrency(reader.getElementText());
break;
case // transfer into / out off an investment account
SUBACCTFUND:
tran.setSubAccount(reader.getElementText());
break;
case // consume, occurs with an investment account transfer
STMTTRN:
break;
default:
logger.log(Level.WARNING, "Unknown STMTTRN element: {0}", reader.getLocalName());
break;
}
break;
case XMLStreamConstants.END_ELEMENT:
if (reader.getName().equals(parsingElement)) {
logger.fine("Found the end of the bank transaction");
break parse;
}
default:
}
}
bank.addTransaction(tran);
logger.exiting(OfxV2Parser.class.getName(), "parseBankTransaction");
}
use of jgnash.convert.imports.ImportTransaction in project jgnash by ccavanaugh.
the class ImportSummary method refreshInfo.
private void refreshInfo() {
destLabel.setText(account.getPathName());
int count = 0;
for (ImportTransaction tran : transactions) {
if (tran.getState() == ImportState.NEW || tran.getState() == ImportState.NOT_EQUAL) {
//
count++;
}
}
transCount.setText(Integer.toString(count));
}
use of jgnash.convert.imports.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);
Platform.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());
Platform.runLater(() -> transCountLabel.setText(Integer.toString(count.get())));
updateDescriptor();
}
use of jgnash.convert.imports.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) {
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();
}
use of jgnash.convert.imports.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();
}
Aggregations