Search in sources :

Example 61 with Transaction

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

Example 62 with Transaction

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

the class ClippingDecorator method findStopIndex.

private void findStopIndex(final LocalDate date) {
    endDate = date;
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        Transaction t = model.getTransactionAt(i);
        if (DateUtils.before(t.getLocalDate(), date)) {
            endIndex = i;
            return;
        }
    }
    endIndex = model.getRowCount() - 1;
}
Also used : Transaction(jgnash.engine.Transaction)

Example 63 with Transaction

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

the class ClippingDecorator method findStartIndex.

private void findStartIndex(final LocalDate date) {
    startDate = date;
    for (int i = 0; i < model.getRowCount(); i++) {
        Transaction t = model.getTransactionAt(i);
        if (DateUtils.after(t.getLocalDate(), date)) {
            startIndex = i;
            return;
        }
    }
    startIndex = model.getRowCount() - 1;
}
Also used : Transaction(jgnash.engine.Transaction)

Example 64 with Transaction

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

the class RegisterTable method prepareRenderer.

/**
     * Override prepareRenderer instead of using a custom renderer so the look and feel is preserved
     *
     * @see javax.swing.JTable#prepareRenderer(javax.swing.table.TableCellRenderer, int, int)
     */
@Override
public Component prepareRenderer(final TableCellRenderer renderer, final int row, final int column) {
    Component c = super.prepareRenderer(renderer, row, column);
    // column may have been reordered
    final Object value = getModel().getValueAt(row, convertColumnIndexToModel(column));
    if (getModel() instanceof AbstractRegisterTableModel) {
        Transaction t = ((AbstractRegisterTableModel) getModel()).getTransactionAt(row);
        if (t.getLocalDate().isAfter(LocalDate.now())) {
            c.setFont(c.getFont().deriveFont(Font.ITALIC));
        }
        if (QuantityStyle.class.isAssignableFrom(getColumnClass(column)) && t instanceof InvestmentTransaction && c instanceof JLabel) {
            ((JLabel) c).setHorizontalAlignment(SwingConstants.RIGHT);
            if (value != null && value instanceof Number) {
                final NumberFormat numberFormat = CommodityFormat.getShortNumberFormat(((InvestmentTransaction) t).getSecurityNode());
                ((JLabel) c).setText(numberFormat.format(value));
            } else {
                ((JLabel) c).setText("");
            }
        }
    }
    if (LocalDate.class.isAssignableFrom(getColumnClass(column)) && c instanceof JLabel) {
        if (value != null && value instanceof LocalDate) {
            ((JLabel) c).setText(dateFormatter.format((TemporalAccessor) value));
        }
    } else if (FullCommodityStyle.class.isAssignableFrom(getColumnClass(column)) && c instanceof JLabel) {
        ((JLabel) c).setHorizontalAlignment(SwingConstants.RIGHT);
        if (value != null && value instanceof Number) {
            if (!isRowSelected(row) && ((BigDecimal) value).signum() < 0) {
                c.setForeground(Color.RED);
            }
            ((JLabel) c).setText(fullFormat.format(value));
        } else {
            ((JLabel) c).setText("");
        }
    } else if (ShortCommodityStyle.class.isAssignableFrom(getColumnClass(column)) && c instanceof JLabel) {
        ((JLabel) c).setHorizontalAlignment(SwingConstants.RIGHT);
        if (value != null && value instanceof Number) {
            ((JLabel) c).setText(shortFormat.format(value));
        } else {
            ((JLabel) c).setText("");
        }
    }
    return c;
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) TemporalAccessor(java.time.temporal.TemporalAccessor) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) JLabel(javax.swing.JLabel) Component(java.awt.Component) LocalDate(java.time.LocalDate) NumberFormat(java.text.NumberFormat)

Example 65 with Transaction

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

the class ApiTest method testTransactionAPI.

@Test
public void testTransactionAPI() {
    final String ACCOUNT_NAME = "testAccount";
    final CurrencyNode node = e.getDefaultCurrency();
    final Account a = new Account(AccountType.BANK, node);
    a.setName(ACCOUNT_NAME);
    e.addAccount(e.getRootAccount(), a);
    // Test single entry transaction
    final Transaction transaction = TransactionFactory.generateSingleEntryTransaction(a, BigDecimal.TEN, LocalDate.now(), "memo", "payee", "1");
    e.addTransaction(transaction);
    assertEquals(TransactionType.SINGLENTRY, transaction.getTransactionType());
    for (final TransactionEntry transactionEntry : transaction.getTransactionEntries()) {
        assertFalse(transactionEntry.isMultiCurrency());
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) TransactionEntry(jgnash.engine.TransactionEntry) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.Test)

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