Search in sources :

Example 76 with Transaction

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

the class ReturnOfCapitalSlipController method buildTransaction.

@NotNull
@Override
public Transaction buildTransaction() {
    BigDecimal incomeExchangedAmount = decimalTextField.getDecimal().negate();
    BigDecimal accountExchangedAmount = decimalTextField.getDecimal();
    if (!incomeExchangePane.getSelectedAccount().getCurrencyNode().equals(accountProperty().get().getCurrencyNode())) {
        incomeExchangedAmount = incomeExchangePane.exchangeAmountProperty().get().negate();
    }
    if (!accountExchangePane.getSelectedAccount().getCurrencyNode().equals(accountProperty().get().getCurrencyNode())) {
        accountExchangedAmount = accountExchangePane.exchangeAmountProperty().get();
    }
    final Transaction transaction = TransactionFactory.generateRocXTransaction(incomeExchangePane.getSelectedAccount(), accountProperty().get(), accountExchangePane.getSelectedAccount(), securityComboBox.getValue(), decimalTextField.getDecimal(), incomeExchangedAmount, accountExchangedAmount, datePicker.getValue(), memoTextField.getText());
    transaction.setNumber(numberComboBox.getValue());
    return transaction;
}
Also used : Transaction(jgnash.engine.Transaction) BigDecimal(java.math.BigDecimal) NotNull(jgnash.util.NotNull)

Example 77 with Transaction

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

the class SellShareSlipController method buildTransaction.

@NotNull
@Override
public Transaction buildTransaction() {
    final BigDecimal exchangeRate = accountExchangePane.getExchangeRate();
    final List<TransactionEntry> gains = gainLossPane.getTransactions();
    final List<TransactionEntry> fees = feePane.getTransactions();
    final Transaction transaction = TransactionFactory.generateSellXTransaction(accountExchangePane.getSelectedAccount(), accountProperty().get(), securityComboBox.getValue(), priceField.getDecimal(), quantityField.getDecimal(), exchangeRate, datePicker.getValue(), memoTextField.getText(), fees, gains);
    transaction.setNumber(numberComboBox.getValue());
    return attachmentPane.buildTransaction(transaction);
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) NotNull(jgnash.util.NotNull)

Example 78 with Transaction

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

the class AbstractRegisterPanel method jumpAction.

/**
     * Displays a register dialog for the opposite account and places the opposite side of the transaction in edit mode.
     */
void jumpAction() {
    Transaction t = getSelectedTransaction();
    if (t != null) {
        if (t.getTransactionType() == TransactionType.DOUBLEENTRY) {
            final Set<Account> set = t.getAccounts();
            set.stream().filter(a -> !getAccount().equals(a)).forEach(a -> RegisterFrame.showDialog(a, t));
        } else if (t.getTransactionType() == TransactionType.SPLITENTRY) {
            final Account common = t.getCommonAccount();
            if (!getAccount().equals(common)) {
                RegisterFrame.showDialog(common, t);
            }
        } else if (t instanceof InvestmentTransaction) {
            final Account invest = ((InvestmentTransaction) t).getInvestmentAccount();
            if (!getAccount().equals(invest)) {
                RegisterFrame.showDialog(invest, t);
            }
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) Engine(jgnash.engine.Engine) KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) ResourceUtils(jgnash.util.ResourceUtils) SecurityNode(jgnash.engine.SecurityNode) StaticUIMethods(jgnash.ui.StaticUIMethods) AbstractRegisterTableModel(jgnash.ui.register.table.AbstractRegisterTableModel) ChannelEvent(jgnash.engine.message.ChannelEvent) EncodeDecode(jgnash.util.EncodeDecode) MessageProperty(jgnash.engine.message.MessageProperty) ResourceBundle(java.util.ResourceBundle) JMenuItem(javax.swing.JMenuItem) MouseAdapter(java.awt.event.MouseAdapter) InvestmentTransaction(jgnash.engine.InvestmentTransaction) RecurringEntryDialog(jgnash.ui.recurring.RecurringEntryDialog) MessageListener(jgnash.engine.message.MessageListener) EventQueue(java.awt.EventQueue) ReconciledState(jgnash.engine.ReconciledState) ButtonGroup(javax.swing.ButtonGroup) RegisterTable(jgnash.ui.register.table.RegisterTable) JPopupMenu(javax.swing.JPopupMenu) Set(java.util.Set) JMenu(javax.swing.JMenu) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) Reminder(jgnash.engine.recurring.Reminder) JTableUtils(jgnash.ui.util.JTableUtils) Preferences(java.util.prefs.Preferences) TransactionType(jgnash.engine.TransactionType) Objects(java.util.Objects) CommodityNode(jgnash.engine.CommodityNode) YesNoDialog(jgnash.ui.components.YesNoDialog) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) Account(jgnash.engine.Account) JTable(javax.swing.JTable) UIApplication(jgnash.ui.UIApplication) JPanel(javax.swing.JPanel) Message(jgnash.engine.message.Message) Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 79 with Transaction

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

the class AbstractReconcileTableModel method messagePosted.

@Override
public void messagePosted(final Message event) {
    if (event.getObject(MessageProperty.ACCOUNT).equals(account)) {
        rwl.writeLock().lock();
        try {
            final Transaction transaction = event.getObject(MessageProperty.TRANSACTION);
            EventQueue.invokeLater(() -> {
                switch(event.getEvent()) {
                    case TRANSACTION_REMOVE:
                        RecTransaction trans = findTransaction(transaction);
                        if (trans != null) {
                            int index = list.indexOf(trans);
                            list.remove(index);
                            fireTableRowsDeleted(index, index);
                        }
                        break;
                    case TRANSACTION_ADD:
                        if (isVisible(transaction)) {
                            RecTransaction newTran = new RecTransaction(transaction, transaction.getReconciled(account));
                            int index = Collections.binarySearch(list, newTran);
                            if (index < 0) {
                                index = -index - 1;
                                list.add(index, newTran);
                                fireTableRowsInserted(index, index);
                            }
                        }
                        break;
                    default:
                        break;
                }
            });
        } finally {
            rwl.writeLock().unlock();
        }
    }
}
Also used : Transaction(jgnash.engine.Transaction) RecTransaction(jgnash.engine.RecTransaction) RecTransaction(jgnash.engine.RecTransaction)

Example 80 with Transaction

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

the class AbstractBankTransactionPanel method enterAction.

/**
     * Method that is called when the enter button is used
     */
@Override
public void enterAction() {
    if (validateForm()) {
        if (modTrans == null) {
            Transaction newTrans = buildTransaction();
            ReconcileManager.reconcileTransaction(getAccount(), newTrans, getReconciledState());
            // chain the transaction build
            newTrans = attachmentPanel.buildTransaction(newTrans);
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            if (engine != null) {
                engine.addTransaction(newTrans);
            }
        } else {
            Transaction newTrans = buildTransaction();
            // restore the reconciled state of the previous old transaction
            for (Account a : modTrans.getAccounts()) {
                if (!a.equals(getAccount())) {
                    ReconcileManager.reconcileTransaction(a, newTrans, modTrans.getReconciled(a));
                }
            }
            /*
                 * Reconcile the modified transaction for this account.
                 * This must be performed last to ensure consistent results per the ReconcileManager rules
                 */
            ReconcileManager.reconcileTransaction(getAccount(), newTrans, getReconciledState());
            // chain the transaction build
            newTrans = attachmentPanel.buildTransaction(newTrans);
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            if (engine != null && engine.removeTransaction(modTrans)) {
                engine.addTransaction(newTrans);
            }
        }
        clearForm();
        fireOkAction();
        focusFirstComponent();
    }
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) Engine(jgnash.engine.Engine)

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