Search in sources :

Example 11 with TransactionEntry

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

the class SlipController method newTransaction.

private void newTransaction(final Transaction t) {
    clearForm();
    amountField.setDecimal(t.getAmount(accountProperty().get()).abs());
    // Must consider if this is a concatenated memo to set the field correctly
    memoTextField.setText(t.isMemoConcatenated() ? t.getMemo() : t.getTransactionMemo());
    payeeTextField.setText(t.getPayee());
    numberComboBox.setValue(t.getNumber());
    datePicker.setValue(t.getLocalDate());
    setReconciledState(t.getReconciled(accountProperty().get()));
    if (t.getTransactionType() == TransactionType.SPLITENTRY) {
        if (canModifyTransaction(t)) {
            // split common account is the same as the base account
            //  clone the splits for modification
            transactionEntries.clear();
            for (final TransactionEntry entry : t.getTransactionEntries()) {
                try {
                    transactionEntries.add((TransactionEntry) entry.clone());
                } catch (final CloneNotSupportedException e) {
                    Logger.getLogger(SlipController.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
                }
            }
            amountField.setDecimal(t.getAmount(accountProperty().get()).abs());
        } else {
            // not the same common account, can only modify the entry
            splitsButton.setDisable(true);
            payeeTextField.setEditable(false);
            numberComboBox.setDisable(true);
            datePicker.setEditable(false);
            // Override
            memoTextField.setText(t.getMemo(account.get()));
            amountField.setDecimal(t.getAmount(accountProperty().get()).abs());
            for (final TransactionEntry entry : t.getTransactionEntries()) {
                if (entry.getCreditAccount() == accountProperty().get()) {
                    accountExchangePane.setExchangedAmount(entry.getDebitAmount().abs());
                    break;
                } else if (entry.getDebitAccount() == accountProperty().get()) {
                    accountExchangePane.setExchangedAmount(entry.getCreditAmount());
                    break;
                }
            }
        }
    } else if (t instanceof InvestmentTransaction) {
        Logger logger = Logger.getLogger(SlipController.class.getName());
        logger.warning("unsupported transaction type");
    } else {
        // DoubleEntryTransaction
        datePicker.setEditable(true);
    }
    // setup the accountCombo correctly
    if (t.getTransactionType() == TransactionType.DOUBLEENTRY) {
        TransactionEntry entry = t.getTransactionEntries().get(0);
        if (slipType == SlipType.DECREASE) {
            accountExchangePane.setSelectedAccount(entry.getCreditAccount());
            accountExchangePane.setExchangedAmount(entry.getCreditAmount());
        } else {
            accountExchangePane.setSelectedAccount(entry.getDebitAccount());
            accountExchangePane.setExchangedAmount(entry.getDebitAmount().abs());
        }
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Logger(java.util.logging.Logger) TransactionEntry(jgnash.engine.TransactionEntry)

Example 12 with TransactionEntry

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

the class SlipController method buildTransactionEntry.

private TransactionEntry buildTransactionEntry() {
    final TransactionEntry entry = new TransactionEntry();
    entry.setMemo(memoTextField.getText());
    final int signum = amountField.getDecimal().signum();
    if (slipType == SlipType.DECREASE && signum >= 0 || slipType == SlipType.INCREASE && signum < 0) {
        entry.setCreditAccount(accountExchangePane.getSelectedAccount());
        entry.setDebitAccount(account.get());
        if (hasEqualCurrencies()) {
            entry.setAmount(amountField.getDecimal().abs());
        } else {
            entry.setDebitAmount(accountExchangePane.exchangeAmountProperty().get().abs().negate());
        }
    } else {
        entry.setCreditAccount(account.get());
        entry.setDebitAccount(accountExchangePane.getSelectedAccount());
        if (hasEqualCurrencies()) {
            entry.setAmount(amountField.getDecimal().abs());
        } else {
            entry.setCreditAmount(accountExchangePane.exchangeAmountProperty().get().abs());
        }
    }
    entry.setReconciled(account.get(), getReconciledState());
    return entry;
}
Also used : TransactionEntry(jgnash.engine.TransactionEntry)

Example 13 with TransactionEntry

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

the class SlipController method handleEnterAction.

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

Example 14 with TransactionEntry

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

the class GainLossPane method getTransactions.

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

Example 15 with TransactionEntry

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

the class GainLossTransactionEntrySlipController method buildTransactionEntry.

@Override
TransactionEntry buildTransactionEntry() {
    final TransactionEntry entry = super.buildTransactionEntry();
    entry.setTransactionTag(TransactionTag.GAIN_LOSS);
    return entry;
}
Also used : TransactionEntry(jgnash.engine.TransactionEntry)

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