Search in sources :

Example 11 with ImportTransaction

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");
}
Also used : QName(javax.xml.namespace.QName) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Example 12 with ImportTransaction

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));
}
Also used : ImportTransaction(jgnash.convert.imports.ImportTransaction)

Example 13 with ImportTransaction

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();
}
Also used : Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) ImportTransaction(jgnash.convert.imports.ImportTransaction) List(java.util.List) Label(javafx.scene.control.Label) ResourceBundle(java.util.ResourceBundle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractWizardPaneController(jgnash.uifx.control.wizard.AbstractWizardPaneController) Map(java.util.Map) Account(jgnash.engine.Account) ResourceUtils(jgnash.util.ResourceUtils) ImportState(jgnash.convert.imports.ImportState) Account(jgnash.engine.Account) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Example 14 with ImportTransaction

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();
}
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 15 with ImportTransaction

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();
}
Also used : Button(javafx.scene.control.Button) Engine(jgnash.engine.Engine) TableViewManager(jgnash.uifx.util.TableViewManager) StackPane(javafx.scene.layout.StackPane) AccountComboBox(jgnash.uifx.control.AccountComboBox) ImportFilter(jgnash.convert.imports.ImportFilter) BigDecimal(java.math.BigDecimal) Nullable(jgnash.util.Nullable) ListChangeListener(javafx.collections.ListChangeListener) Map(java.util.Map) AccountType(jgnash.engine.AccountType) TableView(javafx.scene.control.TableView) GenericImport(jgnash.convert.imports.GenericImport) TransactionType(jgnash.engine.TransactionType) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) List(java.util.List) LocalDate(java.time.LocalDate) BayesImportClassifier(jgnash.convert.imports.BayesImportClassifier) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ImportBank(jgnash.convert.imports.ImportBank) Transaction(jgnash.engine.Transaction) MouseEvent(javafx.scene.input.MouseEvent) EngineFactory(jgnash.engine.EngineFactory) ResourceUtils(jgnash.util.ResourceUtils) TextResource(jgnash.util.TextResource) FXCollections(javafx.collections.FXCollections) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TextFlow(javafx.scene.text.TextFlow) ImportState(jgnash.convert.imports.ImportState) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) ResourceBundle(java.util.ResourceBundle) Tooltip(javafx.scene.control.Tooltip) FontAwesomeLabel(jgnash.resource.font.FontAwesomeLabel) CurrencyNode(jgnash.engine.CurrencyNode) ImportTransaction(jgnash.convert.imports.ImportTransaction) Label(javafx.scene.control.Label) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) TableRow(javafx.scene.control.TableRow) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) AbstractWizardPaneController(jgnash.uifx.control.wizard.AbstractWizardPaneController) Account(jgnash.engine.Account) ContentDisplay(javafx.scene.control.ContentDisplay) Options(jgnash.uifx.Options) Text(javafx.scene.text.Text) ImportTransaction(jgnash.convert.imports.ImportTransaction) FXML(javafx.fxml.FXML)

Aggregations

ImportTransaction (jgnash.convert.imports.ImportTransaction)15 BigDecimal (java.math.BigDecimal)5 InputStream (java.io.InputStream)4 Account (jgnash.engine.Account)4 LocalDate (java.time.LocalDate)3 List (java.util.List)3 QName (javax.xml.namespace.QName)3 ImportBank (jgnash.convert.imports.ImportBank)3 ImportState (jgnash.convert.imports.ImportState)3 Engine (jgnash.engine.Engine)3 Transaction (jgnash.engine.Transaction)3 TransactionType (jgnash.engine.TransactionType)3 ResourceUtils (jgnash.util.ResourceUtils)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 NumberFormat (java.text.NumberFormat)2 Map (java.util.Map)2 ResourceBundle (java.util.ResourceBundle)2