use of jgnash.engine.InvestmentTransaction 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.InvestmentTransaction in project jgnash by ccavanaugh.
the class BuySharePanel 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());
entries.stream().filter(e -> e instanceof TransactionEntryBuyX).forEach(e -> {
AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
memoField.setText(e.getMemo());
priceField.setDecimal(entry.getPrice());
quantityField.setDecimal(entry.getQuantity());
securityCombo.setSelectedNode(entry.getSecurityNode());
if (entry.getCreditAccount().equals(account)) {
accountExchangePanel.setSelectedAccount(entry.getDebitAccount());
accountExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
} else {
accountExchangePanel.setSelectedAccount(entry.getCreditAccount());
accountExchangePanel.setExchangedAmount(entry.getCreditAmount());
}
});
updateTotalField();
modTrans = tran;
setReconciledState(tran.getReconciled(getAccount()));
}
use of jgnash.engine.InvestmentTransaction in project jgnash by ccavanaugh.
the class TransactionPanel method newTransaction.
void newTransaction(final Transaction t) {
clearForm();
splits = null;
// handles any exchange rate that may exist
amountField.setDecimal(t.getAmount(getAccount()).abs());
// Must consider if this is a concatenated memo to set the field correctly
memoField.setText(t.isMemoConcatenated() ? t.getMemo() : t.getTransactionMemo());
payeeField.setText(t.getPayee());
numberField.setText(t.getNumber());
datePanel.setDate(t.getLocalDate());
setReconciledState(t.getReconciled(getAccount()));
if (t.getTransactionType() == TransactionType.SPLITENTRY) {
// display common account
accountPanel.setSelectedAccount(t.getCommonAccount());
accountPanel.setEnabled(false);
if (canModifyTransaction(t)) {
// split as the same base account
// clone the splits for modification
splits = new ArrayList<>();
for (TransactionEntry entry : t.getTransactionEntries()) {
try {
splits.add((TransactionEntry) entry.clone());
} catch (CloneNotSupportedException e) {
Logger.getLogger(TransactionPanel.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
amountField.setEditable(false);
amountField.setDecimal(t.getAmount(this.getAccount()).abs());
} else {
// not the same common account, can only modify the entry
splitsButton.setEnabled(false);
payeeField.setEditable(false);
numberField.setEnabled(false);
datePanel.setEditable(false);
// Override
memoField.setText(t.getMemo(getAccount()));
//memoField.setEnabled(true);
amountField.setEditable(true);
amountField.setDecimal(t.getAmount(this.getAccount()).abs());
for (TransactionEntry entry : t.getTransactionEntries()) {
if (entry.getCreditAccount() == this.getAccount()) {
accountPanel.setExchangedAmount(entry.getDebitAmount().abs());
break;
} else if (entry.getDebitAccount() == this.getAccount()) {
accountPanel.setExchangedAmount(entry.getCreditAmount());
break;
}
}
}
} else if (t instanceof InvestmentTransaction) {
Logger logger = Logger.getLogger(TransactionPanel.class.getName());
logger.warning("unsupported transaction type");
} else {
// DoubleEntryTransaction
accountPanel.setEnabled(!t.areAccountsHidden());
amountField.setEnabled(true);
datePanel.setEditable(true);
}
// setup the accountCombo correctly
if (t.getTransactionType() == TransactionType.DOUBLEENTRY) {
TransactionEntry entry = t.getTransactionEntries().get(0);
if (panelType == PanelType.DECREASE) {
accountPanel.setSelectedAccount(entry.getCreditAccount());
accountPanel.setExchangedAmount(entry.getCreditAmount());
} else {
accountPanel.setSelectedAccount(entry.getDebitAccount());
accountPanel.setExchangedAmount(entry.getDebitAmount().abs());
}
}
}
use of jgnash.engine.InvestmentTransaction in project jgnash by ccavanaugh.
the class AddRemoveSharePanel method modifyTransaction.
@Override
public void modifyTransaction(Transaction tran) {
assert tran instanceof InvestmentTransaction;
assert tran.getTransactionType() == TransactionType.ADDSHARE || tran.getTransactionType() == TransactionType.REMOVESHARE;
InvestmentTransaction _tran = (InvestmentTransaction) tran;
clearForm();
modTrans = tran;
datePanel.setDate(tran.getLocalDate());
memoField.setText(tran.getTransactionMemo());
priceField.setDecimal(_tran.getPrice());
quantityField.setDecimal(_tran.getQuantity());
securityCombo.setSelectedNode(_tran.getSecurityNode());
setReconciledState(tran.getReconciled(getAccount()));
updateTotalField();
}
use of jgnash.engine.InvestmentTransaction in project jgnash by ccavanaugh.
the class OfxImport method importInvestmentTransaction.
private static InvestmentTransaction importInvestmentTransaction(final OfxBank ofxBank, final ImportTransaction ofxTransaction, final Account investmentAccount) {
final SecurityNode securityNode = matchSecurity(ofxBank, ofxTransaction.getSecurityId());
final String memo = ofxTransaction.getMemo();
final LocalDate datePosted = ofxTransaction.getDatePosted();
final BigDecimal units = ofxTransaction.getUnits();
final BigDecimal unitPrice = ofxTransaction.getUnitPrice();
final Account incomeAccount = ofxTransaction.getGainsAccount();
final Account fessAccount = ofxTransaction.getFeesAccount();
Account cashAccount = ofxTransaction.getAccount();
// force use of cash balance
if (OfxTags.CASH.equals(ofxTransaction.getSubAccount())) {
cashAccount = investmentAccount;
}
final List<TransactionEntry> fees = new ArrayList<>();
final List<TransactionEntry> gains = new ArrayList<>();
if (!ofxTransaction.getCommission().equals(BigDecimal.ZERO)) {
final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getCommission().negate());
transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
fees.add(transactionEntry);
}
if (!ofxTransaction.getFees().equals(BigDecimal.ZERO)) {
final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getFees().negate());
transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
fees.add(transactionEntry);
}
InvestmentTransaction transaction = null;
if (securityNode != null) {
switch(ofxTransaction.getTransactionType()) {
case DIVIDEND:
final BigDecimal dividend = ofxTransaction.getAmount();
transaction = TransactionFactory.generateDividendXTransaction(incomeAccount, investmentAccount, cashAccount, securityNode, dividend, dividend, dividend, datePosted, memo);
break;
case REINVESTDIV:
// Create a gains entry of an account other than the investment account has been selected
if (incomeAccount != investmentAccount) {
final TransactionEntry gainsEntry = TransactionFactory.createTransactionEntry(incomeAccount, investmentAccount, ofxTransaction.getAmount().negate(), memo, TransactionTag.GAIN_LOSS);
gains.add(gainsEntry);
}
transaction = TransactionFactory.generateReinvestDividendXTransaction(investmentAccount, securityNode, unitPrice, units, datePosted, memo, fees, gains);
break;
case BUYSHARE:
transaction = TransactionFactory.generateBuyXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees);
break;
case SELLSHARE:
transaction = TransactionFactory.generateSellXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees, gains);
break;
default:
}
}
return transaction;
}
Aggregations