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()));
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations