Search in sources :

Example 46 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 47 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 48 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 49 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)

Example 50 with Transaction

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

the class AbstractSlipController method modifyTransactionForAutoComplete.

/**
     * Modify a transaction before it is used to complete the panel for auto fill. The supplied transaction must be a
     * new or cloned transaction. It can't be a transaction that lives in the map. The returned transaction can be the
     * supplied reference or may be a new instance
     *
     * @param t The transaction to modify
     * @return the modified transaction
     */
private Transaction modifyTransactionForAutoComplete(final Transaction t) {
    // tweak the transaction
    t.setNumber(null);
    // clear both sides
    t.setReconciled(ReconciledState.NOT_RECONCILED);
    // set the last date as required
    if (!Options.rememberLastDateProperty().get()) {
        t.setDate(LocalDate.now());
    } else {
        t.setDate(datePicker.getValue());
    }
    // preserve any transaction entries that may have been entered first
    if (amountField.getLength() > 0) {
        Transaction newTrans = buildTransaction();
        t.clearTransactionEntries();
        t.addTransactionEntries(newTrans.getTransactionEntries());
    }
    // preserve any preexisting memo field info
    if (memoTextField.getLength() > 0) {
        t.setMemo(memoTextField.getText());
    }
    // Do not copy over attachments
    t.setAttachment(null);
    return t;
}
Also used : Transaction(jgnash.engine.Transaction)

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