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);
}
}
}
}
Aggregations