Search in sources :

Example 11 with ImportTransaction

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();
}
Also used : Button(javafx.scene.control.Button) ImportFilter(jgnash.convert.importat.ImportFilter) Engine(jgnash.engine.Engine) TableViewManager(jgnash.uifx.util.TableViewManager) StackPane(javafx.scene.layout.StackPane) AccountComboBox(jgnash.uifx.control.AccountComboBox) 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) ImportTransaction(jgnash.convert.importat.ImportTransaction) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) TransactionType(jgnash.engine.TransactionType) Objects(java.util.Objects) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) List(java.util.List) LocalDate(java.time.LocalDate) TextResource(jgnash.resource.util.TextResource) ImportUtils(jgnash.convert.importat.ImportUtils) BayesImportClassifier(jgnash.convert.importat.BayesImportClassifier) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Transaction(jgnash.engine.Transaction) MouseEvent(javafx.scene.input.MouseEvent) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TextFlow(javafx.scene.text.TextFlow) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) GenericImport(jgnash.convert.importat.GenericImport) TableCell(javafx.scene.control.TableCell) ResourceBundle(java.util.ResourceBundle) Tooltip(javafx.scene.control.Tooltip) CurrencyNode(jgnash.engine.CurrencyNode) Label(javafx.scene.control.Label) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) TableRow(javafx.scene.control.TableRow) ImportBank(jgnash.convert.importat.ImportBank) MaterialDesignLabel(jgnash.uifx.resource.font.MaterialDesignLabel) ResourceUtils(jgnash.resource.util.ResourceUtils) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ImportState(jgnash.convert.importat.ImportState) 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.importat.ImportTransaction) FXML(javafx.fxml.FXML)

Example 12 with ImportTransaction

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();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ImportFilter(jgnash.convert.importat.ImportFilter) Account(jgnash.engine.Account) ImportTransaction(jgnash.convert.importat.ImportTransaction) ImportTransaction(jgnash.convert.importat.ImportTransaction) Transaction(jgnash.engine.Transaction) ImportBank(jgnash.convert.importat.ImportBank) Engine(jgnash.engine.Engine)

Example 13 with ImportTransaction

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

Example 14 with ImportTransaction

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;
}
Also used : BigDecimal(java.math.BigDecimal) ImportTransaction(jgnash.convert.importat.ImportTransaction)

Aggregations

ImportTransaction (jgnash.convert.importat.ImportTransaction)14 BigDecimal (java.math.BigDecimal)5 InputStream (java.io.InputStream)4 Account (jgnash.engine.Account)4 Transaction (jgnash.engine.Transaction)4 Test (org.junit.jupiter.api.Test)4 InputStreamReader (java.io.InputStreamReader)3 LocalDate (java.time.LocalDate)3 List (java.util.List)3 QName (javax.xml.namespace.QName)3 ImportState (jgnash.convert.importat.ImportState)3 Engine (jgnash.engine.Engine)3 TransactionType (jgnash.engine.TransactionType)3 ResourceUtils (jgnash.resource.util.ResourceUtils)3 IOException (java.io.IOException)2 LineNumberReader (java.io.LineNumberReader)2 Charset (java.nio.charset.Charset)2 Path (java.nio.file.Path)2 NumberFormat (java.text.NumberFormat)2 Map (java.util.Map)2