Search in sources :

Example 1 with TransactionEntry

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

the class FeePanel method getTransactions.

public List<TransactionEntry> getTransactions() {
    // adjust the cash balance of the investment account
    if (feeList.isEmpty() && feeField.getDecimal().compareTo(BigDecimal.ZERO) != 0) {
        // ignore zero balance fees
        TransactionEntry fee = new TransactionEntry(account, feeField.getDecimal().abs().negate());
        fee.setTransactionTag(TransactionTag.INVESTMENT_FEE);
        feeList.add(fee);
    }
    return feeList;
}
Also used : TransactionEntry(jgnash.engine.TransactionEntry)

Example 2 with TransactionEntry

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

the class DividendPanel method modifyTransaction.

@Override
public void modifyTransaction(Transaction tran) {
    if (!(tran instanceof InvestmentTransaction)) {
        throw new IllegalArgumentException("bad tranType");
    }
    clearForm();
    datePanel.setDate(tran.getLocalDate());
    List<TransactionEntry> entries = tran.getTransactionEntries();
    assert entries.size() <= 2;
    for (TransactionEntry e : entries) {
        if (e instanceof TransactionEntryDividendX) {
            AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
            memoField.setText(e.getMemo());
            securityCombo.setSelectedNode(entry.getSecurityNode());
            incomeExchangePanel.setSelectedAccount(entry.getDebitAccount());
            incomeExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
            dividendField.setDecimal(entry.getAmount(getAccount()));
        } else if (e.getTransactionTag() == TransactionTag.INVESTMENT_CASH_TRANSFER) {
            accountExchangePanel.setSelectedAccount(e.getCreditAccount());
            accountExchangePanel.setExchangedAmount(e.getCreditAmount());
        } else {
            logger.warning("Invalid transaction");
        }
    }
    modTrans = tran;
    setReconciledState(tran.getReconciled(getAccount()));
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntryDividendX(jgnash.engine.TransactionEntryDividendX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry)

Example 3 with TransactionEntry

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

the class ReinvestDividendPanel method modifyTransaction.

@Override
public void modifyTransaction(final Transaction tran) {
    if (!(tran instanceof InvestmentTransaction)) {
        throw new IllegalArgumentException("bad tranType");
    }
    clearForm();
    datePanel.setDate(tran.getLocalDate());
    List<TransactionEntry> entries = tran.getTransactionEntries();
    feePanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentFeeEntries());
    gainsPanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentGainLossEntries());
    entries.stream().filter(e -> e instanceof TransactionEntryReinvestDivX).forEach(e -> {
        AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
        memoField.setText(e.getMemo());
        priceField.setDecimal(entry.getPrice());
        quantityField.setDecimal(entry.getQuantity());
        securityCombo.setSelectedNode(entry.getSecurityNode());
    });
    updateTotalField();
    modTrans = tran;
    setReconciledState(tran.getReconciled(getAccount()));
}
Also used : FocusListener(java.awt.event.FocusListener) Transaction(jgnash.engine.Transaction) Collection(java.util.Collection) ValidationFactory(jgnash.ui.util.ValidationFactory) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) BigDecimal(java.math.BigDecimal) FocusAdapter(java.awt.event.FocusAdapter) List(java.util.List) FormLayout(com.jgoodies.forms.layout.FormLayout) FocusEvent(java.awt.event.FocusEvent) CellConstraints(com.jgoodies.forms.layout.CellConstraints) Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) JPanel(javax.swing.JPanel) TransactionEntryReinvestDivX(jgnash.engine.TransactionEntryReinvestDivX) TransactionFactory(jgnash.engine.TransactionFactory) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntryReinvestDivX(jgnash.engine.TransactionEntryReinvestDivX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry)

Example 4 with TransactionEntry

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

the class ReturnOfCapitalPanel method modifyTransaction.

@Override
public void modifyTransaction(Transaction tran) {
    if (!(tran instanceof InvestmentTransaction)) {
        throw new IllegalArgumentException("bad tranType");
    }
    clearForm();
    datePanel.setDate(tran.getLocalDate());
    List<TransactionEntry> entries = tran.getTransactionEntries();
    assert entries.size() <= 2;
    for (TransactionEntry e : entries) {
        if (e instanceof TransactionEntryRocX) {
            AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
            memoField.setText(e.getMemo());
            securityCombo.setSelectedNode(entry.getSecurityNode());
            incomeExchangePanel.setSelectedAccount(entry.getDebitAccount());
            incomeExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
            dividendField.setDecimal(entry.getAmount(getAccount()));
        } else if (e.getTransactionTag() == TransactionTag.INVESTMENT_CASH_TRANSFER) {
            accountExchangePanel.setSelectedAccount(e.getCreditAccount());
            accountExchangePanel.setExchangedAmount(e.getCreditAmount());
        } else {
            logger.warning("Invalid transaction");
        }
    }
    modTrans = tran;
    setReconciledState(tran.getReconciled(getAccount()));
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntryRocX(jgnash.engine.TransactionEntryRocX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry)

Example 5 with TransactionEntry

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

the class LiabilityRegisterPanel method paymentActionDebit.

/* creates the payment transaction relative to the debit account */
private void paymentActionDebit() {
    AmortizeObject ao = account.getAmortizeObject();
    if (ao != null) {
        Transaction tran = null;
        DateChkNumberDialog d = new DateChkNumberDialog(ao.getBankAccount(), rb.getString("Title.NewTrans"));
        d.setVisible(true);
        if (!d.getResult()) {
            return;
        }
        BigDecimal balance = account.getBalance().abs();
        double payment = ao.getPayment();
        double interest;
        if (ao.getUseDailyRate()) {
            LocalDate today = d.getDate();
            LocalDate last;
            if (account.getTransactionCount() > 0) {
                last = account.getTransactionAt(account.getTransactionCount() - 1).getLocalDate();
            } else {
                last = today;
            }
            // get the interest portion
            interest = ao.getIPayment(balance, last, today);
        } else {
            // get the interest portion
            interest = ao.getIPayment(balance);
        }
        // get debit account
        Account bank = ao.getBankAccount();
        if (bank != null) {
            CommodityNode n = bank.getCurrencyNode();
            Transaction transaction = new Transaction();
            transaction.setDate(d.getDate());
            transaction.setNumber(d.getNumber());
            transaction.setPayee(ao.getPayee());
            // transaction is made relative to the debit/checking account              
            TransactionEntry e = new TransactionEntry();
            // this entry is the principal payment              
            e.setCreditAccount(account);
            e.setDebitAccount(bank);
            e.setAmount(n.round(payment - interest));
            e.setMemo(ao.getMemo());
            transaction.addTransactionEntry(e);
            // handle interest portion of the payment
            Account i = ao.getInterestAccount();
            if (i != null && interest != 0.0) {
                e = new TransactionEntry();
                e.setCreditAccount(i);
                e.setDebitAccount(bank);
                e.setAmount(n.round(interest));
                e.setMemo(rb.getString("Word.Interest"));
                transaction.addTransactionEntry(e);
            //System.out.println(e.getAmount());
            }
            // a fee has been assigned
            if (ao.getFees().compareTo(BigDecimal.ZERO) != 0) {
                Account f = ao.getFeesAccount();
                if (f != null) {
                    e = new TransactionEntry();
                    e.setCreditAccount(f);
                    e.setDebitAccount(bank);
                    e.setAmount(ao.getFees());
                    e.setMemo(rb.getString("Word.Fees"));
                    transaction.addTransactionEntry(e);
                //System.out.println(e.getAmount());
                }
            }
            // the remainder of the balance should be loan principal
            tran = transaction;
        }
        if (tran != null) {
            // display the transaction in the register
            EditTransactionDialog dlg = new EditTransactionDialog(ao.getBankAccount(), PanelType.DECREASE);
            dlg.newTransaction(tran);
            dlg.setVisible(true);
        } else {
            StaticUIMethods.displayWarning(rb.getString("Message.Warn.ConfigAmortization"));
        }
    } else {
        // could not generate the transaction
        StaticUIMethods.displayWarning(rb.getString("Message.Warn.ConfigAmortization"));
    }
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) AmortizeObject(jgnash.engine.AmortizeObject) CommodityNode(jgnash.engine.CommodityNode) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) TransactionEntry(jgnash.engine.TransactionEntry)

Aggregations

TransactionEntry (jgnash.engine.TransactionEntry)55 Account (jgnash.engine.Account)16 InvestmentTransaction (jgnash.engine.InvestmentTransaction)16 Transaction (jgnash.engine.Transaction)16 BigDecimal (java.math.BigDecimal)13 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)11 Logger (java.util.logging.Logger)4 FXML (javafx.fxml.FXML)4 NotNull (jgnash.util.NotNull)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 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JPanel (javax.swing.JPanel)3 Engine (jgnash.engine.Engine)3 TransactionFactory (jgnash.engine.TransactionFactory)3