Search in sources :

Example 26 with InvestmentTransaction

use of jgnash.engine.InvestmentTransaction in project jgnash by ccavanaugh.

the class OfxImport method importTransactions.

public static void importTransactions(final OfxBank ofxBank, final Account baseAccount) {
    Objects.requireNonNull(ofxBank.getTransactions());
    Objects.requireNonNull(baseAccount);
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final ImportTransaction tran : ofxBank.getTransactions()) {
        // do not import matched transactions
        if (tran.getState() == ImportState.NEW || tran.getState() == ImportState.NOT_EQUAL) {
            Transaction transaction = null;
            if (tran.isInvestmentTransaction()) {
                if (baseAccount.getAccountType().getAccountGroup() == AccountGroup.INVEST) {
                    transaction = importInvestmentTransaction(ofxBank, tran, baseAccount);
                    if (transaction != null) {
                        // check and add the security node to the account if not present
                        if (!baseAccount.containsSecurity(((InvestmentTransaction) transaction).getSecurityNode())) {
                            engine.addAccountSecurity(((InvestmentTransaction) transaction).getInvestmentAccount(), ((InvestmentTransaction) transaction).getSecurityNode());
                        }
                    }
                } else {
                    // Signal an error
                    System.out.println("Base account was not an investment account type");
                }
            } else {
                if (baseAccount.equals(tran.getAccount())) {
                    // single entry oTran
                    transaction = TransactionFactory.generateSingleEntryTransaction(baseAccount, tran.getAmount(), tran.getDatePosted(), tran.getMemo(), tran.getPayee(), tran.getCheckNumber());
                } else {
                    // double entry
                    if (tran.getAmount().signum() >= 0) {
                        transaction = TransactionFactory.generateDoubleEntryTransaction(baseAccount, tran.getAccount(), tran.getAmount().abs(), tran.getDatePosted(), tran.getMemo(), tran.getPayee(), tran.getCheckNumber());
                    } else {
                        transaction = TransactionFactory.generateDoubleEntryTransaction(tran.getAccount(), baseAccount, tran.getAmount().abs(), tran.getDatePosted(), tran.getMemo(), tran.getPayee(), tran.getCheckNumber());
                    }
                }
            }
            // add the new transaction
            if (transaction != null) {
                transaction.setFitid(tran.getFITID());
                engine.addTransaction(transaction);
            }
        }
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) ImportTransaction(jgnash.convert.imports.ImportTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Engine(jgnash.engine.Engine) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Aggregations

InvestmentTransaction (jgnash.engine.InvestmentTransaction)26 Transaction (jgnash.engine.Transaction)17 TransactionEntry (jgnash.engine.TransactionEntry)12 BigDecimal (java.math.BigDecimal)11 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)8 Account (jgnash.engine.Account)8 List (java.util.List)7 TransactionFactory (jgnash.engine.TransactionFactory)6 ChangeListener (javafx.beans.value.ChangeListener)4 FXML (javafx.fxml.FXML)4 Engine (jgnash.engine.Engine)4 TransactionType (jgnash.engine.TransactionType)4 CellConstraints (com.jgoodies.forms.layout.CellConstraints)3 FormLayout (com.jgoodies.forms.layout.FormLayout)3 FocusAdapter (java.awt.event.FocusAdapter)3 FocusEvent (java.awt.event.FocusEvent)3 FocusListener (java.awt.event.FocusListener)3 NumberFormat (java.text.NumberFormat)3 ResourceBundle (java.util.ResourceBundle)3 Logger (java.util.logging.Logger)3