Search in sources :

Example 41 with Transaction

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

the class InvestmentRegisterPanel method modifyTransaction.

@Override
protected void modifyTransaction(int index) {
    Transaction t = model.getTransactionAt(index);
    transactionPanel.modifyTransaction(t);
}
Also used : Transaction(jgnash.engine.Transaction)

Example 42 with Transaction

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

the class RegisterTableWithSplitEntriesModel method updateData.

/**
     * Update the internal data from the specified index. Note that this index is not relative to the account
     * transaction list but to the internal data.
     *
     * @param startIndex internal data index from which transactions need to updated.
     */
private void updateData(final int startIndex) {
    if (data == null) {
        data = new ArrayList<>(0);
    }
    while (data.size() > startIndex) {
        data.remove(startIndex);
    }
    for (Transaction t : account.getSortedTransactionList()) {
        if (data.size() >= startIndex) {
            data.add(new TransactionWrapper(t));
            if (t.getTransactionType() == TransactionType.SPLITENTRY && showSplitDetails) {
                /* Only detail split entries if 2 or more entries impact this account */
                int splitImpact = 0;
                // count the number of impacting entry(s)
                for (TransactionEntry e : t.getTransactionEntries()) {
                    if (e.getAmount(account).signum() != 0) {
                        splitImpact++;
                    }
                }
                // load only the entries that impact this account
                if (splitImpact > 1) {
                    data.addAll(t.getTransactionEntries().stream().filter(e -> e.getAmount(account).signum() != 0).map(e -> new TransactionWrapper(t, e)).collect(Collectors.toList()));
                }
            }
        }
    }
    // updating the balance cache too
    balanceCache.ensureCapacity(data.size());
    balanceCache.clear(startIndex);
}
Also used : EventQueue(java.awt.EventQueue) BigDecimal(java.math.BigDecimal) MessageProperty(jgnash.engine.message.MessageProperty) AccountBalanceDisplayManager(jgnash.ui.register.AccountBalanceDisplayManager) Transaction(jgnash.engine.Transaction) Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntry(jgnash.engine.TransactionEntry) Collectors(java.util.stream.Collectors) Message(jgnash.engine.message.Message) ArrayList(java.util.ArrayList) TransactionType(jgnash.engine.TransactionType) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntry(jgnash.engine.TransactionEntry)

Example 43 with Transaction

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

the class RegisterTableWithSplitEntriesModel method getBalanceAt.

@Override
BigDecimal getBalanceAt(final int index) {
    if (balanceCache.get(index) != null) {
        return AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), balanceCache.get(index));
    }
    // cannot rely on account.getBalanceAt()
    BigDecimal balance = null;
    Transaction t = data.get(index).transaction;
    if (account.contains(t) && data.get(index).entry == null) {
        // top level only
        balance = BigDecimal.ZERO;
        for (int i = 0; i <= index; i++) {
            Transaction tran = data.get(i).transaction;
            if (data.get(i).entry == null && account.contains(tran)) {
                balance = balance.add(tran.getAmount(account));
            }
        }
    }
    balanceCache.set(index, balance);
    return AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), balance);
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal)

Example 44 with Transaction

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

the class RegisterTableWithSplitEntriesModel method messagePosted.

@Override
public void messagePosted(final Message event) {
    if (account.equals(event.getObject(MessageProperty.ACCOUNT))) {
        EventQueue.invokeLater(() -> {
            switch(event.getEvent()) {
                case FILE_CLOSING:
                    unregister();
                    break;
                case TRANSACTION_ADD:
                    Transaction t = event.getObject(MessageProperty.TRANSACTION);
                    updateData();
                    int index = indexOfWrapper(t);
                    if (index >= 0) {
                        fireTableRowsInserted(index, index);
                    }
                    break;
                case TRANSACTION_REMOVE:
                    updateData();
                    fireTableDataChanged();
                    break;
                default:
                    break;
            }
        });
    }
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 45 with Transaction

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

the class SellSharePanel 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 TransactionEntrySellX).forEach(e -> {
        final AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
        memoField.setText(e.getMemo());
        priceField.setDecimal(entry.getPrice());
        quantityField.setDecimal(entry.getQuantity());
        securityCombo.setSelectedNode(entry.getSecurityNode());
        accountExchangePanel.setSelectedAccount(entry.getDebitAccount());
        accountExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
    });
    updateTotalField();
    modTrans = tran;
    setReconciledState(tran.getReconciled(getAccount()));
}
Also used : FocusListener(java.awt.event.FocusListener) ActionListener(java.awt.event.ActionListener) Transaction(jgnash.engine.Transaction) Collection(java.util.Collection) ValidationFactory(jgnash.ui.util.ValidationFactory) TransactionEntry(jgnash.engine.TransactionEntry) ActionEvent(java.awt.event.ActionEvent) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) BigDecimal(java.math.BigDecimal) FocusAdapter(java.awt.event.FocusAdapter) List(java.util.List) TransactionEntrySellX(jgnash.engine.TransactionEntrySellX) 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) AccountExchangePanel(jgnash.ui.register.AccountExchangePanel) JPanel(javax.swing.JPanel) TransactionFactory(jgnash.engine.TransactionFactory) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntrySellX(jgnash.engine.TransactionEntrySellX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry)

Aggregations

Transaction (jgnash.engine.Transaction)81 InvestmentTransaction (jgnash.engine.InvestmentTransaction)39 Account (jgnash.engine.Account)27 BigDecimal (java.math.BigDecimal)24 Engine (jgnash.engine.Engine)22 TransactionEntry (jgnash.engine.TransactionEntry)18 NotNull (jgnash.util.NotNull)13 List (java.util.List)10 LocalDate (java.time.LocalDate)9 FXML (javafx.fxml.FXML)9 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)9 ArrayList (java.util.ArrayList)7 TransactionType (jgnash.engine.TransactionType)7 ResourceBundle (java.util.ResourceBundle)6 TransactionFactory (jgnash.engine.TransactionFactory)6 NumberFormat (java.text.NumberFormat)5 Objects (java.util.Objects)5 ChangeListener (javafx.beans.value.ChangeListener)5 EngineFactory (jgnash.engine.EngineFactory)5 Message (jgnash.engine.message.Message)5