use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class OfxImport method importInvestmentTransaction.
private static InvestmentTransaction importInvestmentTransaction(final OfxBank ofxBank, final ImportTransaction ofxTransaction, final Account investmentAccount) {
final SecurityNode securityNode = matchSecurity(ofxBank, ofxTransaction.getSecurityId());
final String memo = ofxTransaction.getMemo();
final LocalDate datePosted = ofxTransaction.getDatePosted();
final BigDecimal units = ofxTransaction.getUnits();
final BigDecimal unitPrice = ofxTransaction.getUnitPrice();
final Account incomeAccount = ofxTransaction.getGainsAccount();
final Account fessAccount = ofxTransaction.getFeesAccount();
Account cashAccount = ofxTransaction.getAccount();
// force use of cash balance
if (OfxTags.CASH.equals(ofxTransaction.getSubAccount())) {
cashAccount = investmentAccount;
}
final List<TransactionEntry> fees = new ArrayList<>();
final List<TransactionEntry> gains = new ArrayList<>();
if (!ofxTransaction.getCommission().equals(BigDecimal.ZERO)) {
final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getCommission().negate());
transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
fees.add(transactionEntry);
}
if (!ofxTransaction.getFees().equals(BigDecimal.ZERO)) {
final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getFees().negate());
transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
fees.add(transactionEntry);
}
InvestmentTransaction transaction = null;
if (securityNode != null) {
switch(ofxTransaction.getTransactionType()) {
case DIVIDEND:
final BigDecimal dividend = ofxTransaction.getAmount();
transaction = TransactionFactory.generateDividendXTransaction(incomeAccount, investmentAccount, cashAccount, securityNode, dividend, dividend, dividend, datePosted, memo);
break;
case REINVESTDIV:
// Create a gains entry of an account other than the investment account has been selected
if (incomeAccount != investmentAccount) {
final TransactionEntry gainsEntry = TransactionFactory.createTransactionEntry(incomeAccount, investmentAccount, ofxTransaction.getAmount().negate(), memo, TransactionTag.GAIN_LOSS);
gains.add(gainsEntry);
}
transaction = TransactionFactory.generateReinvestDividendXTransaction(investmentAccount, securityNode, unitPrice, units, datePosted, memo, fees, gains);
break;
case BUYSHARE:
transaction = TransactionFactory.generateBuyXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees);
break;
case SELLSHARE:
transaction = TransactionFactory.generateSellXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees, gains);
break;
default:
}
}
return transaction;
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class QifImport method generateSplitTransaction.
/**
* Generates a Transaction given a QifSplitTransaction
*
* @param qTran split qif transaction to convert
* @param acc base Account
* @return generated TransactionEntry
*/
private TransactionEntry generateSplitTransaction(final QifSplitTransaction qTran, final Account acc) {
TransactionEntry tran = new TransactionEntry();
Account account = findBestAccount(qTran.category);
/* Verify that the splits category is not assigned to the parent account. This is
* allowed within Quicken, but violates double entry and is not allowed in jGnash.
* Wipe the resulting account and default to the unassigned accounts to maintain
* integrity.
*/
if (account == acc) {
logger.warning("Detected an invalid split transactions entry, correcting problem");
account = null;
}
/* If a valid account is found at this point, then it should have a duplicate
* entry in another account that needs to be removed
*/
if (account != null && isAccount(qTran.category)) {
removeMirrorSplitTransaction(qTran);
}
if (account == null) {
// unassigned split transaction.... fix it with a default
if (qTran.amount.signum() == -1) {
// need an expense account
if (unassignedExpense == null) {
unassignedExpense = new Account(AccountType.EXPENSE, engine.getDefaultCurrency());
unassignedExpense.setName("** QIF Import - Unassigned Expense Account");
unassignedExpense.setDescription("Fix transactions and delete this account");
engine.addAccount(engine.getRootAccount(), unassignedExpense);
logger.info("Created an account for unassigned expense account");
}
account = unassignedExpense;
} else {
if (unassignedIncome == null) {
unassignedIncome = new Account(AccountType.INCOME, engine.getDefaultCurrency());
unassignedIncome.setName("** QIF Import - Unassigned Income Account");
unassignedIncome.setDescription("Fix transactions and delete this account");
engine.addAccount(engine.getRootAccount(), unassignedIncome);
logger.info("Created an account for unassigned income account");
}
account = unassignedIncome;
}
}
if (qTran.amount.signum() == -1) {
tran.setDebitAccount(acc);
tran.setCreditAccount(account);
} else {
tran.setDebitAccount(account);
tran.setCreditAccount(acc);
}
tran.setAmount(qTran.amount.abs());
tran.setMemo(qTran.memo);
return tran;
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class QifImport method generateTransaction.
/**
* Generates a transaction
* <p>
* Notes: If a QifTransaction does not specify an account, then assume it is a single
* entry transaction for the supplied Account. The transaction most likely came from a online banking source.
*
* @param qTran Qif transaction to generate Transaction for
* @param acc base Account
* @return new Transaction
*/
private Transaction generateTransaction(final QifTransaction qTran, final Account acc) {
Objects.requireNonNull(acc);
boolean reconciled = "x".equalsIgnoreCase(qTran.status);
Transaction tran;
Account cAcc;
if (qTran.getAccount() != null) {
cAcc = qTran.getAccount();
} else {
cAcc = findBestAccount(qTran.category);
}
if (qTran.hasSplits()) {
tran = new Transaction();
// create a double entry transaction with splits
List<QifSplitTransaction> splits = qTran.splits;
for (QifSplitTransaction splitTransaction : splits) {
TransactionEntry split = generateSplitTransaction(splitTransaction, acc);
if (split != null) {
tran.addTransactionEntry(split);
}
}
ReconcileManager.reconcileTransaction(acc, tran, reconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
} else if (acc == cAcc && !qTran.hasSplits() || cAcc == null) {
// create single entry transaction without splits
tran = TransactionFactory.generateSingleEntryTransaction(acc, qTran.getAmount(), qTran.getDatePosted(), qTran.getMemo(), qTran.getPayee(), qTran.getCheckNumber());
ReconcileManager.reconcileTransaction(acc, tran, reconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
} else if (!qTran.hasSplits()) {
// create a double entry transaction without splits
if (qTran.getAmount().signum() == -1) {
tran = TransactionFactory.generateDoubleEntryTransaction(cAcc, acc, qTran.getAmount(), qTran.getDatePosted(), qTran.getMemo(), qTran.getPayee(), qTran.getCheckNumber());
} else {
tran = TransactionFactory.generateDoubleEntryTransaction(acc, cAcc, qTran.getAmount(), qTran.getDatePosted(), qTran.getMemo(), qTran.getPayee(), qTran.getCheckNumber());
}
ReconcileManager.reconcileTransaction(cAcc, tran, reconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
ReconcileManager.reconcileTransaction(acc, tran, reconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
if (isAccount(qTran.category)) {
// remove the mirror transaction
removeMirrorTransaction(qTran, acc);
}
} else {
// could not find the account this transaction belongs to
logger.log(Level.WARNING, "Could not create following transaction:" + "\n{0}", qTran.toString());
return null;
}
tran.setDate(qTran.getDatePosted());
tran.setPayee(qTran.getPayee());
tran.setNumber(qTran.getCheckNumber());
return tran;
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class GainLossDialog method deleteAction.
@Override
void deleteAction() {
final TransactionEntry entry = tableView.getSelectionModel().getSelectedItem();
if (entry != null) {
tableView.getSelectionModel().clearSelection();
gainLossController.clearForm();
getTransactionEntries().remove(entry);
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class GainLossPane method setTransactionEntries.
/**
* Clones a {@code List} of {@code TransactionEntry(s)}.
*
* @param fees {@code List} of fees to clone
*/
void setTransactionEntries(final List<TransactionEntry> fees) {
final List<TransactionEntry> transactionEntries = gainLossDialog.getTransactionEntries();
if (fees.size() == 1) {
TransactionEntry e = fees.get(0);
if (e.getCreditAccount().equals(e.getDebitAccount())) {
setDecimal(e.getAmount(accountProperty().get()).abs());
} else {
try {
// copy over the provided set's entry
transactionEntries.add((TransactionEntry) e.clone());
} catch (CloneNotSupportedException e1) {
Logger.getLogger(GainLossPane.class.getName()).log(Level.SEVERE, e1.getLocalizedMessage(), e1);
}
setDecimal(sumGains().abs());
}
} else {
for (final TransactionEntry entry : fees) {
// clone the provided set's entries
try {
transactionEntries.add((TransactionEntry) entry.clone());
} catch (CloneNotSupportedException e) {
Logger.getLogger(GainLossPane.class.getName()).log(Level.SEVERE, e.toString(), e);
}
}
setDecimal(sumGains().abs());
}
setEditable(transactionEntries.size() < 1);
}
Aggregations