Search in sources :

Example 16 with InvestmentTransaction

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

the class InvestmentTransactionQuantityTableCell method updateItem.

@Override
protected void updateItem(final BigDecimal amount, final boolean empty) {
    // required
    super.updateItem(amount, empty);
    if (!empty && amount != null && getTableRow() != null) {
        final Transaction transaction = (Transaction) getTableRow().getItem();
        if (transaction instanceof InvestmentTransaction) {
            final NumberFormat format = CommodityFormat.getShortNumberFormat(((InvestmentTransaction) transaction).getSecurityNode());
            applyFormat(amount, format);
        } else {
            setText(null);
        }
    } else {
        setText(null);
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) NumberFormat(java.text.NumberFormat)

Example 17 with InvestmentTransaction

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

the class OfxExport method writeInvestmentTransactions.

/**
     * Writes all investment account transactions within the date range
     */
private void writeInvestmentTransactions() {
    for (final Transaction transaction : account.getTransactions(startDate, endDate)) {
        if (transaction instanceof InvestmentTransaction) {
            final InvestmentTransaction invTransaction = (InvestmentTransaction) transaction;
            switch(invTransaction.getTransactionType()) {
                case ADDSHARE:
                case BUYSHARE:
                    writeBuyStockTransaction(invTransaction);
                    break;
                case REMOVESHARE:
                case SELLSHARE:
                    writeSellStockTransaction(invTransaction);
                    break;
                case DIVIDEND:
                    writeDividendTransaction(invTransaction);
                    break;
                case REINVESTDIV:
                    writeReinvestStockTransaction(invTransaction);
                    break;
                default:
                    break;
            }
        } else {
            // bank transaction, write it
            indentedWriter.println(wrapOpen(INVBANKTRAN), indentLevel++);
            writeBankTransaction(transaction);
            indentedWriter.println(wrapClose(INVBANKTRAN), --indentLevel);
        }
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 18 with InvestmentTransaction

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

the class RegisterActions method duplicateTransaction.

static void duplicateTransaction(final Account account, final List<Transaction> transactions) {
    final ResourceBundle resourceBundle = ResourceUtils.getBundle();
    final String eftNumber = resourceBundle.getString("Item.EFT");
    for (final Transaction transaction : transactions) {
        try {
            final Transaction clone = (Transaction) transaction.clone();
            clone.setDate(LocalDate.now());
            if (!clone.getNumber().isEmpty() && !clone.getNumber().equals(eftNumber)) {
                // may return an empty string
                final String nextTransactionNumber = account.getNextTransactionNumber();
                if (!nextTransactionNumber.isEmpty()) {
                    clone.setNumber(nextTransactionNumber);
                }
            }
            if (transaction instanceof InvestmentTransaction) {
                InvestmentTransactionDialog.show(account, clone, RegisterActions::addTransaction);
            } else {
                TransactionDialog.showAndWait(account, clone, RegisterActions::addTransaction);
            }
        } catch (final CloneNotSupportedException e) {
            Logger.getLogger(RegisterActions.class.getName()).log(Level.SEVERE, e.getMessage(), e);
        }
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) ResourceBundle(java.util.ResourceBundle)

Example 19 with InvestmentTransaction

use of jgnash.engine.InvestmentTransaction 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 20 with InvestmentTransaction

use of jgnash.engine.InvestmentTransaction 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

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