Search in sources :

Example 6 with TransactionEntry

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

the class TransactionPanel method enterAction.

@Override
public void enterAction() {
    if (validateForm()) {
        if (modEntry != null && modTrans != null) {
            try {
                final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
                Objects.requireNonNull(engine);
                // clone the transaction
                Transaction t = (Transaction) modTrans.clone();
                // remove the modifying entry from the clone
                t.removeTransactionEntry(modEntry);
                // generate new TransactionEntry
                TransactionEntry e = buildTransactionEntry();
                // add it to the clone
                t.addTransactionEntry(e);
                ReconcileManager.reconcileTransaction(getAccount(), t, getReconciledState());
                engine.removeTransaction(modTrans);
                engine.addTransaction(t);
                clearForm();
                fireOkAction();
                focusFirstComponent();
            } catch (CloneNotSupportedException e) {
                Logger.getLogger(TransactionPanel.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        } else {
            super.enterAction();
        }
    }
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Engine(jgnash.engine.Engine) TransactionEntry(jgnash.engine.TransactionEntry)

Example 7 with TransactionEntry

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

the class SplitTransactionEntryPanel method buildTransactionEntry.

@Override
protected TransactionEntry buildTransactionEntry() {
    TransactionEntry entry = new TransactionEntry();
    entry.setMemo(memoField.getText());
    int signum = amountField.getDecimal().signum();
    if ((panelType == PanelType.DECREASE && signum >= 0) || (panelType == PanelType.INCREASE && signum < 0)) {
        entry.setCreditAccount(accountPanel.getSelectedAccount());
        entry.setDebitAccount(getAccount());
        if (hasEqualCurrencies()) {
            entry.setAmount(amountField.getDecimal().abs());
        } else {
            entry.setDebitAmount(amountField.getDecimal().abs().negate());
            entry.setCreditAmount(accountPanel.getExchangedAmount().abs());
        }
    } else {
        entry.setCreditAccount(getAccount());
        entry.setDebitAccount(accountPanel.getSelectedAccount());
        if (hasEqualCurrencies()) {
            entry.setAmount(amountField.getDecimal().abs());
        } else {
            entry.setCreditAmount(amountField.getDecimal().abs());
            entry.setDebitAmount(accountPanel.getExchangedAmount().abs().negate());
        }
    }
    entry.setReconciled(account, getReconciledState());
    return entry;
}
Also used : TransactionEntry(jgnash.engine.TransactionEntry)

Example 8 with TransactionEntry

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

the class AdjustmentPanel method newTransaction.

private void newTransaction(final Transaction t) {
    TransactionEntry entry = t.getTransactionEntries().get(0);
    memoField.setText(entry.getMemo());
    amountField.setDecimal(entry.getCreditAmount());
    datePanel.setDate(t.getLocalDate());
    numberField.setText(t.getNumber());
    payeeField.setText(t.getPayee());
    setReconciledState(t.getReconciled(getAccount()));
}
Also used : TransactionEntry(jgnash.engine.TransactionEntry)

Example 9 with TransactionEntry

use of jgnash.engine.TransactionEntry 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 10 with TransactionEntry

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

the class BuyShareSlipController method modifyTransaction.

@Override
public void modifyTransaction(@NotNull final Transaction transaction) {
    if (transaction.getTransactionType() != TransactionType.BUYSHARE || !(transaction instanceof InvestmentTransaction)) {
        throw new IllegalArgumentException(resources.getString("Message.Error.InvalidTransactionType"));
    }
    clearForm();
    datePicker.setValue(transaction.getLocalDate());
    numberComboBox.setValue(transaction.getNumber());
    List<TransactionEntry> entries = transaction.getTransactionEntries();
    feePane.setTransactionEntries(((InvestmentTransaction) transaction).getInvestmentFeeEntries());
    entries.stream().filter(e -> e instanceof TransactionEntryBuyX).forEach(e -> {
        final AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
        memoTextField.setText(e.getMemo());
        priceField.setDecimal(entry.getPrice());
        quantityField.setDecimal(entry.getQuantity());
        securityComboBox.setSecurityNode(entry.getSecurityNode());
        if (entry.getCreditAccount().equals(accountProperty().get())) {
            accountExchangePane.setSelectedAccount(entry.getDebitAccount());
            accountExchangePane.setExchangedAmount(entry.getDebitAmount().abs());
        } else {
            accountExchangePane.setSelectedAccount(entry.getCreditAccount());
            accountExchangePane.setExchangedAmount(entry.getCreditAmount());
        }
    });
    modTrans = transaction;
    modTrans = attachmentPane.modifyTransaction(modTrans);
    setReconciledState(transaction.getReconciled(accountProperty().get()));
}
Also used : FXML(javafx.fxml.FXML) BigDecimal(java.math.BigDecimal) List(java.util.List) NotNull(jgnash.util.NotNull) Transaction(jgnash.engine.Transaction) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX) InvestmentTransaction(jgnash.engine.InvestmentTransaction) ChangeListener(javafx.beans.value.ChangeListener) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionFactory(jgnash.engine.TransactionFactory) TransactionType(jgnash.engine.TransactionType) InvestmentTransaction(jgnash.engine.InvestmentTransaction) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX)

Aggregations

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