use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class BudgetResultsModel method processTransactionEvent.
private void processTransactionEvent(final Message message) {
final Transaction transaction = message.getObject(MessageProperty.TRANSACTION);
descriptorList.stream().filter(descriptor -> descriptor.isBetween(transaction.getLocalDate())).forEach(descriptor -> {
final Set<Account> accountSet = new HashSet<>();
for (Account account : transaction.getAccounts()) {
accountSet.addAll(account.getAncestors());
}
accountSet.forEach(this::clearCached);
});
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class AbstractInvSlipController method handleEnterAction.
@Override
public void handleEnterAction() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
if (modTrans == null) {
final Transaction newTrans = buildTransaction();
// Need to set the reconciled state
ReconcileManager.reconcileTransaction(accountProperty().get(), newTrans, getReconciledState());
engine.addTransaction(newTrans);
} else {
final Transaction newTrans = buildTransaction();
/* Need to preserve the reconciled state of the opposite side
* if both sides are not automatically reconciled
*/
ReconcileManager.reconcileTransaction(accountProperty().get(), newTrans, getReconciledState());
if (engine.isTransactionValid(newTrans)) {
if (engine.removeTransaction(modTrans)) {
engine.addTransaction(newTrans);
}
}
}
clearForm();
focusFirstComponent();
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class TransferPanel method buildTransaction.
/**
* TODO: The memo payee and number should be user configurable by the user
*/
@Override
protected Transaction buildTransaction() {
String number = "TRAN";
String payee = rb.getString("Tab.Transfer");
Transaction transaction;
final int signum = amountField.getDecimal().signum();
if (panelType == PanelType.DECREASE && signum >= 0 || signum == -1) {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(accountPanel.getSelectedAccount(), getAccount(), amountField.getDecimal().abs(), datePanel.getLocalDate(), memoField.getText(), payee, number);
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(accountPanel.getSelectedAccount(), getAccount(), accountPanel.getExchangedAmount().abs(), amountField.getDecimal().abs().negate(), datePanel.getLocalDate(), memoField.getText(), payee, number);
}
} else {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(getAccount(), accountPanel.getSelectedAccount(), amountField.getDecimal().abs(), datePanel.getLocalDate(), memoField.getText(), payee, number);
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(getAccount(), accountPanel.getSelectedAccount(), amountField.getDecimal().abs(), accountPanel.getExchangedAmount().abs().negate(), datePanel.getLocalDate(), memoField.getText(), payee, number);
}
}
ReconcileManager.reconcileTransaction(getAccount(), transaction, getReconciledState());
return transaction;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class ReinvestDividendPanel 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 TransactionEntryReinvestDivX).forEach(e -> {
AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
memoField.setText(e.getMemo());
priceField.setDecimal(entry.getPrice());
quantityField.setDecimal(entry.getQuantity());
securityCombo.setSelectedNode(entry.getSecurityNode());
});
updateTotalField();
modTrans = tran;
setReconciledState(tran.getReconciled(getAccount()));
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class AbstractRegisterTableModel method messagePosted.
@Override
public void messagePosted(final Message event) {
if (event.getEvent() == ChannelEvent.CURRENCY_MODIFY || event.getEvent() == ChannelEvent.SECURITY_MODIFY) {
EventQueue.invokeLater(AbstractRegisterTableModel.this::fireTableDataChanged);
}
if (account.equals(event.getObject(MessageProperty.ACCOUNT))) {
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case FILE_CLOSING:
unregister();
return;
case TRANSACTION_ADD:
Transaction t = event.getObject(MessageProperty.TRANSACTION);
int index = account.indexOf(t);
balanceCache.ensureCapacity(account.getTransactionCount());
balanceCache.clear(index);
fireTableRowsInserted(index, index);
break;
case TRANSACTION_REMOVE:
balanceCache.clear();
fireTableDataChanged();
break;
default:
break;
}
});
}
}
Aggregations