Search in sources :

Example 6 with InvestmentTransaction

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

the class InvestmentRegisterTableModel method getInternalValueAt.

@Override
public Object getInternalValueAt(int row, int col) {
    InvestmentTransaction _t = null;
    Transaction t = getTransactionAt(row);
    if (t instanceof InvestmentTransaction) {
        _t = (InvestmentTransaction) t;
    }
    switch(col) {
        case 0:
            return t.getLocalDate();
        case 1:
            if (_t != null) {
                return _t.getTransactionType().toString();
            } else if (t.getAmount(account).signum() > 0) {
                return rb.getString("Item.CashDeposit");
            }
            return rb.getString("Item.CashWithdrawal");
        case 2:
            if (_t != null) {
                return _t.getSecurityNode().getSymbol();
            }
            return t.getMemo();
        case 3:
            return t.getReconciled(account).toString();
        case // quantity
        4:
            if (_t != null) {
                BigDecimal quantity = _t.getQuantity();
                if (quantity.compareTo(BigDecimal.ZERO) != 0) {
                    return quantity;
                }
            }
            return null;
        case // price
        5:
            if (_t != null) {
                BigDecimal price = _t.getPrice();
                if (price.compareTo(BigDecimal.ZERO) != 0) {
                    return price;
                }
            }
            return null;
        case // net cash amount
        6:
            if (_t != null) {
                return _t.getNetCashValue();
            }
            return t.getAmount(account);
        default:
            return ERROR;
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal)

Example 7 with InvestmentTransaction

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

the class RegisterTableModel method getInternalValueAt.

@Override
protected Object getInternalValueAt(int row, int col) {
    Transaction t = getTransactionAt(row);
    BigDecimal amount = t.getAmount(account);
    int signum = amount.signum();
    switch(col) {
        case 0:
            return t.getLocalDate();
        case 1:
            return t.getNumber();
        case 2:
            return t.getPayee();
        case 3:
            return t.getMemo();
        case 4:
            if (t instanceof InvestmentTransaction) {
                return ((InvestmentTransaction) t).getInvestmentAccount().getName();
            }
            int count = t.size();
            if (count > 1) {
                return "[ " + count + " " + split + " ]";
            }
            Account creditAccount = t.getTransactionEntries().get(0).getCreditAccount();
            if (creditAccount != account) {
                return creditAccount.getName();
            }
            return t.getTransactionEntries().get(0).getDebitAccount().getName();
        case 5:
            return t.getReconciled(account).toString();
        case 6:
            if (signum >= 0) {
                return amount;
            }
            return null;
        case 7:
            if (signum < 0) {
                return amount.abs();
            }
            return null;
        case 8:
            return getBalanceAt(row);
        default:
            return ERROR;
    }
}
Also used : Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal)

Example 8 with InvestmentTransaction

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

the class RegisterTableWithSplitEntriesModel method getInternalValueAt.

@Override
protected Object getInternalValueAt(final int row, final int col) {
    final TransactionWrapper wrapper = data.get(row);
    BigDecimal amount;
    if (wrapper.entry == null) {
        amount = wrapper.transaction.getAmount(account);
    } else {
        amount = wrapper.entry.getAmount(account);
    }
    int signum = amount.signum();
    /* only show details if showSplitDetails is true and account
         * does not directly contain the transaction */
    boolean showDetail = wrapper.entry != null && showSplitDetails;
    switch(col) {
        case 0:
            if (showDetail) {
                return null;
            }
            return wrapper.transaction.getLocalDate();
        case 1:
            if (showDetail) {
                return null;
            }
            return wrapper.transaction.getNumber();
        case 2:
            if (showDetail) {
                return null;
            }
            return wrapper.transaction.getPayee();
        case 3:
            if (showDetail) {
                return null;
            }
            return wrapper.transaction.getMemo(getAccount());
        case 4:
            if (wrapper.entry != null && showDetail) {
                TransactionEntry _t = wrapper.entry;
                if (_t.getCreditAccount() != account) {
                    return "   - " + _t.getCreditAccount().getName();
                }
                return "   - " + _t.getDebitAccount().getName();
            } else if (wrapper.entry == null && wrapper.transaction.getTransactionType() == TransactionType.DOUBLEENTRY) {
                TransactionEntry _t = wrapper.transaction.getTransactionEntries().get(0);
                if (_t.getCreditAccount() != account) {
                    return _t.getCreditAccount().getName();
                }
                return _t.getDebitAccount().getName();
            } else if (wrapper.entry == null && wrapper.transaction.getTransactionType() == TransactionType.SINGLENTRY) {
                TransactionEntry _t = wrapper.transaction.getTransactionEntries().get(0);
                return _t.getCreditAccount().getName();
            } else if (wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY) {
                Transaction _t = wrapper.transaction;
                return "[ " + _t.size() + " " + split + " ]";
            } else if (wrapper.transaction instanceof InvestmentTransaction) {
                return ((InvestmentTransaction) wrapper.transaction).getInvestmentAccount().getName();
            } else {
                return ERROR;
            }
        case 5:
            if (wrapper.entry == null) {
                return wrapper.transaction.getReconciled(account).toString();
            }
            return wrapper.entry.getReconciled(account).toString();
        case 6:
            // Don't show amount if the split details are going to be shown, otherwise totals will be wrong
            if (showSplitDetails && wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY && wrapper.entry == null) {
                return null;
            }
            if (signum >= 0) {
                return amount;
            }
            return null;
        case 7:
            // Don't show amount if the split details are going to be shown, otherwise totals will be wrong
            if (showSplitDetails && wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY && wrapper.entry == null) {
                return null;
            }
            if (signum < 0) {
                return amount.abs();
            }
            return null;
        case 8:
            if (showDetail) {
                return null;
            }
            return getBalanceAt(row);
        default:
            return ERROR;
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal) TransactionEntry(jgnash.engine.TransactionEntry)

Example 9 with InvestmentTransaction

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

the class AccountExport method getAccountColumnValue.

private static String getAccountColumnValue(final Transaction transaction, final Account account) {
    if (transaction instanceof InvestmentTransaction) {
        return ((InvestmentTransaction) transaction).getInvestmentAccount().getName();
    }
    int count = transaction.size();
    if (count > 1) {
        return "[ " + count + " " + ResourceUtils.getString("Button.Splits") + " ]";
    }
    final Account creditAccount = transaction.getTransactionEntries().get(0).getCreditAccount();
    if (creditAccount != account) {
        return creditAccount.getName();
    }
    return transaction.getTransactionEntries().get(0).getDebitAccount().getName();
}
Also used : Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 10 with InvestmentTransaction

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

the class BankRegisterPaneController method modifyTransaction.

@Override
protected void modifyTransaction(@NotNull final Transaction transaction) {
    if (!(transaction instanceof InvestmentTransaction)) {
        if (transaction.getTransactionType() == TransactionType.SINGLENTRY) {
            transactionForms.getSelectionModel().select(adjustTab);
            ((Slip) adjustTab.getUserData()).modifyTransaction(transaction);
        } else if (transaction.getAmount(accountProperty().get()).signum() >= 0) {
            transactionForms.getSelectionModel().select(creditTab);
            ((Slip) creditTab.getUserData()).modifyTransaction(transaction);
        } else {
            transactionForms.getSelectionModel().select(debitTab);
            ((Slip) debitTab.getUserData()).modifyTransaction(transaction);
        }
    } else {
        // pop a dialog to modify the transaction
        InvestmentTransactionDialog.show(((InvestmentTransaction) transaction).getInvestmentAccount(), transaction, newTransaction -> {
            if (newTransaction != null) {
                final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
                Objects.requireNonNull(engine);
                engine.removeTransaction(transaction);
                engine.addTransaction(newTransaction);
            }
        });
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Engine(jgnash.engine.Engine)

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