Search in sources :

Example 1 with Transaction

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);
    });
}
Also used : Engine(jgnash.engine.Engine) RootAccount(jgnash.engine.RootAccount) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) MessageProxy(jgnash.engine.message.MessageProxy) MathConstants(jgnash.engine.MathConstants) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MessageBus(jgnash.engine.message.MessageBus) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) MessageProperty(jgnash.engine.message.MessageProperty) MessageChannel(jgnash.engine.message.MessageChannel) Map(java.util.Map) AccountType(jgnash.engine.AccountType) EnumSet(java.util.EnumSet) CurrencyNode(jgnash.engine.CurrencyNode) MessageListener(jgnash.engine.message.MessageListener) ReentrantLock(java.util.concurrent.locks.ReentrantLock) EnumMap(java.util.EnumMap) Comparators(jgnash.engine.Comparators) Set(java.util.Set) Collectors(java.util.stream.Collectors) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) List(java.util.List) Account(jgnash.engine.Account) Message(jgnash.engine.message.Message) RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) HashSet(java.util.HashSet)

Example 2 with Transaction

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();
}
Also used : Transaction(jgnash.engine.Transaction) Engine(jgnash.engine.Engine)

Example 3 with Transaction

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;
}
Also used : Transaction(jgnash.engine.Transaction)

Example 4 with 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()));
}
Also used : FocusListener(java.awt.event.FocusListener) Transaction(jgnash.engine.Transaction) Collection(java.util.Collection) ValidationFactory(jgnash.ui.util.ValidationFactory) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) BigDecimal(java.math.BigDecimal) FocusAdapter(java.awt.event.FocusAdapter) List(java.util.List) 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) JPanel(javax.swing.JPanel) TransactionEntryReinvestDivX(jgnash.engine.TransactionEntryReinvestDivX) TransactionFactory(jgnash.engine.TransactionFactory) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntryReinvestDivX(jgnash.engine.TransactionEntryReinvestDivX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry)

Example 5 with Transaction

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