Search in sources :

Example 1 with ImportTransaction

use of jgnash.convert.imports.ImportTransaction in project jgnash by ccavanaugh.

the class ImportTwo method getSettings.

@Override
@SuppressWarnings("unchecked")
public void getSettings(final Map<Enum<?>, Object> map) {
    ImportBank<ImportTransaction> bank = (ImportBank<ImportTransaction>) map.get(ImportDialog.Settings.BANK);
    if (bank != null) {
        List<ImportTransaction> list = bank.getTransactions();
        Account account = (Account) map.get(ImportDialog.Settings.ACCOUNT);
        // set to sane account assuming it's going to be a single entry
        for (ImportTransaction t : list) {
            t.setAccount(account);
            t.setState(ImportState.NEW);
        }
        // match up any pre-existing transactions
        GenericImport.matchTransactions(list, account);
        // classify the transactions
        BayesImportClassifier.classifyTransactions(list, account.getSortedTransactionList(), account);
        table.setTransactions(list);
        refreshInfo();
    }
}
Also used : Account(jgnash.engine.Account) ImportBank(jgnash.convert.imports.ImportBank) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Example 2 with ImportTransaction

use of jgnash.convert.imports.ImportTransaction in project jgnash by ccavanaugh.

the class ImportPageTwoController method buildTableView.

private void buildTableView() {
    final TableColumn<ImportTransaction, ImportState> stateColumn = new TableColumn<>();
    stateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getState()));
    stateColumn.setCellFactory(param -> {
        TableCell<ImportTransaction, ImportState> cell = new ImportStateTableCell();
        cell.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
            if (event.getClickCount() > 1) {
                final ImportTransaction t = tableView.getItems().get(((TableCell<?, ?>) event.getSource()).getTableRow().getIndex());
                if (t.getState() == ImportState.EQUAL) {
                    t.setState(ImportState.NOT_EQUAL);
                } else if (t.getState() == ImportState.NOT_EQUAL) {
                    t.setState(ImportState.EQUAL);
                } else if (t.getState() == ImportState.NEW) {
                    t.setState(ImportState.IGNORE);
                } else if (t.getState() == ImportState.IGNORE) {
                    t.setState(ImportState.NEW);
                }
                Platform.runLater(tableView::refresh);
            }
        });
        return cell;
    });
    tableView.getColumns().add(stateColumn);
    final TableColumn<ImportTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDatePosted()));
    dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
    tableView.getColumns().add(dateColumn);
    final TableColumn<ImportTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCheckNumber()));
    tableView.getColumns().add(numberColumn);
    final TableColumn<ImportTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    tableView.getColumns().add(payeeColumn);
    final TableColumn<ImportTransaction, String> memoColumn = new TableColumn<>(resources.getString("Column.Memo"));
    memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
    tableView.getColumns().add(memoColumn);
    final TableColumn<ImportTransaction, Account> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
    accountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getAccount());
        }
        return null;
    });
    accountColumn.setCellFactory(param -> new AccountComboBoxTableCell<>());
    accountColumn.setEditable(true);
    accountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setAccount(event.getNewValue());
        lastAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(accountColumn);
    incomeAccountColumn = new TableColumn<>(resources.getString("Column.Income"));
    incomeAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getGainsAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getGainsAccount());
        }
        return null;
    });
    incomeAccountColumn.setCellFactory(param -> new IncomeAccountComboBoxTableCell<>());
    incomeAccountColumn.setEditable(true);
    incomeAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setGainsAccount(event.getNewValue());
        lastGainsAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(incomeAccountColumn);
    expenseAccountColumn = new TableColumn<>(resources.getString("Column.Expense"));
    expenseAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getFeesAccount() != null) {
            if (param.getValue().getFees().compareTo(BigDecimal.ZERO) != 0) {
                return new SimpleObjectProperty<>(param.getValue().getFeesAccount());
            } else {
                return new SimpleObjectProperty<>(NOP_EXPENSE_ACCOUNT);
            }
        }
        return null;
    });
    expenseAccountColumn.setCellFactory(param -> new ExpenseAccountComboBoxTableCell<>());
    expenseAccountColumn.setEditable(true);
    expenseAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setFeesAccount(event.getNewValue());
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(expenseAccountColumn);
    final TableColumn<ImportTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getAmount()));
    amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(numberFormat));
    amountColumn.setCellFactory(param -> {
        final TableCell<ImportTransaction, BigDecimal> cell = new BigDecimalTableCell<>(numberFormat);
        cell.indexProperty().addListener((observable, oldValue, newValue) -> {
            final int index = newValue.intValue();
            if (index >= 0 && index < tableView.itemsProperty().get().size()) {
                cell.setTooltip(new Tooltip(tableView.itemsProperty().get().get(index).getToolTip()));
            }
        });
        return cell;
    });
    tableView.getColumns().add(amountColumn);
    typeColumn = new TableColumn<>(resources.getString("Column.Type"));
    typeColumn.setCellValueFactory(param -> {
        TransactionType transactionType = TransactionType.SINGLENTRY;
        if (param.getValue().isInvestmentTransaction()) {
            transactionType = param.getValue().getTransactionType();
        } else if (!param.getValue().getAccount().equals(baseAccount)) {
            transactionType = TransactionType.DOUBLEENTRY;
        }
        return new SimpleStringProperty(transactionType.toString());
    });
    tableView.getColumns().add(typeColumn);
}
Also used : Account(jgnash.engine.Account) TransactionType(jgnash.engine.TransactionType) ImportState(jgnash.convert.imports.ImportState) LocalDate(java.time.LocalDate) ImportTransaction(jgnash.convert.imports.ImportTransaction) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TableCell(javafx.scene.control.TableCell) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) Tooltip(javafx.scene.control.Tooltip) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty)

Example 3 with ImportTransaction

use of jgnash.convert.imports.ImportTransaction in project jgnash by ccavanaugh.

the class OfxBank method toString.

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    b.append("statusCode: ").append(statusCode).append('\n');
    b.append("statusSeverity: ").append(statusSeverity).append('\n');
    b.append("statusMessage: ").append(statusMessage).append('\n');
    b.append("currency: ").append(currency).append('\n');
    b.append("bankId: ").append(bankId).append('\n');
    b.append("branchId: ").append(branchId).append('\n');
    b.append("accountId: ").append(accountId).append('\n');
    b.append("accountType: ").append(accountType).append('\n');
    b.append("dateStart: ").append(dateStart).append('\n');
    b.append("dateEnd: ").append(dateEnd).append('\n');
    b.append("ledgerBalance: ").append(ledgerBalance).append('\n');
    b.append("ledgerBalanceDate: ").append(ledgerBalanceDate).append('\n');
    if (availBalance != null) {
        b.append("availBalance: ").append(availBalance).append('\n');
    }
    if (availBalanceDate != null) {
        b.append("availBalanceDate: ").append(availBalanceDate).append('\n');
    }
    for (final ImportTransaction t : getTransactions()) {
        b.append(t).append('\n');
    }
    for (final ImportSecurity importSecurity : securityList) {
        b.append(importSecurity.toString()).append('\n');
    }
    return b.toString();
}
Also used : ImportSecurity(jgnash.convert.imports.ImportSecurity) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Example 4 with ImportTransaction

use of jgnash.convert.imports.ImportTransaction in project jgnash by ccavanaugh.

the class Ofx2Test method parseBankOneCommas.

/**
     * Test for amounts that use a comma as a decimal separator
     */
@Test
public void parseBankOneCommas() {
    final String testFile = "/bank1-commas.ofx";
    URL url = Object.class.getResource(testFile);
    String encoding;
    try {
        encoding = FileMagic.getOfxV1Encoding(Paths.get(url.toURI()));
        try (InputStream stream = Object.class.getResourceAsStream(testFile)) {
            parser.parse(OfxV1ToV2.convertToXML(stream), encoding);
            assertEquals("ENG", parser.getLanguage());
            assertEquals("INFO", parser.getStatusSeverity());
            assertEquals(0, parser.getStatusCode());
            assertEquals(0, parser.getBank().statusCode);
            assertEquals("INFO", parser.getBank().statusSeverity);
            assertEquals(null, parser.getBank().statusMessage);
            assertEquals(new BigDecimal("524.10"), parser.getBank().ledgerBalance);
            assertEquals(new BigDecimal("519.10"), parser.getBank().availBalance);
            List<ImportTransaction> transactions = parser.getBank().getTransactions();
            assertEquals(new BigDecimal("-130.00"), transactions.get(0).getAmount());
            assertEquals(new BigDecimal("-120.00"), transactions.get(1).getAmount());
            assertEquals(new BigDecimal("300.01"), transactions.get(2).getAmount());
            assertEquals(new BigDecimal("160.50"), transactions.get(3).getAmount());
            assertFalse(parser.getBank().isInvestmentAccount());
        } catch (IOException e) {
            logSevere(Ofx2Test.class, e);
            fail();
        }
    } catch (URISyntaxException e) {
        logSevere(Ofx2Test.class, e);
        fail();
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) BigDecimal(java.math.BigDecimal) ImportTransaction(jgnash.convert.imports.ImportTransaction) Test(org.junit.Test)

Example 5 with ImportTransaction

use of jgnash.convert.imports.ImportTransaction in project jgnash by ccavanaugh.

the class Mt940Test method testMt940Rabobank.

/**
     * Test parsing an (anonimized) mt940 file as produced by the Rabobank
     * online bank
     * 
     * @throws ParseException thrown if a parse exception occurs while reading the file
     * @throws IOException thrown if an IO exception occurs while reading the file
     */
@Test
public void testMt940Rabobank() throws IOException, ParseException {
    int nTransactions = 6;
    Mt940Parser parser = new Mt940Parser();
    InputStream inputStream = this.getClass().getResourceAsStream("/rabobank.swi");
    try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(inputStream))) {
        Mt940File file = parser.parse(reader);
        assertEquals(nTransactions, file.getEntries().size());
        ImportBank<ImportTransaction> bank = Mt940Exporter.convert(file);
        assertEquals(nTransactions, bank.getTransactions().size());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Mt940Parser(net.bzzt.swift.mt940.parser.Mt940Parser) LineNumberReader(java.io.LineNumberReader) ImportTransaction(jgnash.convert.imports.ImportTransaction) Test(org.junit.Test)

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