Search in sources :

Example 6 with Transaction

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

the class ClippingDecorator method getRowCount.

/**
     * @see javax.swing.table.TableModel#getRowCount()
     */
@Override
public int getRowCount() {
    if (model.getAccount().getTransactionCount() == 0) {
        return 0;
    }
    if (endIndex == startIndex) {
        Transaction t = getAccount().getTransactionAt(getAccount().getTransactionCount() - 1);
        if (DateUtils.before(t.getLocalDate(), startDate, false)) {
            return 0;
        }
        t = model.getTransactionAt(startIndex);
        if (DateUtils.after(t.getLocalDate(), startDate) && DateUtils.before(t.getLocalDate(), endDate, true)) {
            return 1;
        }
        return 0;
    }
    return endIndex - startIndex + 1;
}
Also used : Transaction(jgnash.engine.Transaction)

Example 7 with Transaction

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

the class BudgetPeriodModel method processTransactionEvent.

private void processTransactionEvent(final Message message) {
    final Transaction transaction = message.getObject(MessageProperty.TRANSACTION);
    if (isBetween(transaction.getLocalDate())) {
        // don't update unless needed
        // build a list of accounts include ancestors that will be impacted by the transaction changes
        final Set<Account> accounts = new HashSet<>();
        for (Account account : transaction.getAccounts()) {
            accounts.addAll(account.getAncestors());
        }
        fireUpdate(accounts);
    }
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) HashSet(java.util.HashSet)

Example 8 with Transaction

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

the class DuplicateTransactionDialog method okAction.

@Override
public void okAction() {
    // get a clone
    Transaction clone = null;
    try {
        clone = (Transaction) transaction.clone();
        final LocalDate today = LocalDate.now();
        if (today.equals(datePanel.getLocalDate())) {
            // maintain entry order
            clone.setDate(today);
        } else {
            // set the new date
            clone.setDate(datePanel.getLocalDate());
        }
        // set the transaction number
        clone.setNumber(numberCombo.getText());
        // clear the reconciled state of the transaction
        clone.setReconciled(ReconciledState.NOT_RECONCILED);
    } catch (final CloneNotSupportedException e) {
        Logger.getLogger(DuplicateTransactionDialog.class.getName()).log(Level.SEVERE, e.toString(), e);
    }
    if (clone != null) {
        final Engine e = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(e);
        // add the transaction
        e.addTransaction(clone);
        newTransaction = e.getTransactionByUuid(clone.getUuid());
    }
    super.okAction();
}
Also used : Transaction(jgnash.engine.Transaction) LocalDate(java.time.LocalDate) Engine(jgnash.engine.Engine)

Example 9 with Transaction

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

the class LiabilityRegisterPanel method paymentActionDebit.

/* creates the payment transaction relative to the debit account */
private void paymentActionDebit() {
    AmortizeObject ao = account.getAmortizeObject();
    if (ao != null) {
        Transaction tran = null;
        DateChkNumberDialog d = new DateChkNumberDialog(ao.getBankAccount(), rb.getString("Title.NewTrans"));
        d.setVisible(true);
        if (!d.getResult()) {
            return;
        }
        BigDecimal balance = account.getBalance().abs();
        double payment = ao.getPayment();
        double interest;
        if (ao.getUseDailyRate()) {
            LocalDate today = d.getDate();
            LocalDate last;
            if (account.getTransactionCount() > 0) {
                last = account.getTransactionAt(account.getTransactionCount() - 1).getLocalDate();
            } else {
                last = today;
            }
            // get the interest portion
            interest = ao.getIPayment(balance, last, today);
        } else {
            // get the interest portion
            interest = ao.getIPayment(balance);
        }
        // get debit account
        Account bank = ao.getBankAccount();
        if (bank != null) {
            CommodityNode n = bank.getCurrencyNode();
            Transaction transaction = new Transaction();
            transaction.setDate(d.getDate());
            transaction.setNumber(d.getNumber());
            transaction.setPayee(ao.getPayee());
            // transaction is made relative to the debit/checking account              
            TransactionEntry e = new TransactionEntry();
            // this entry is the principal payment              
            e.setCreditAccount(account);
            e.setDebitAccount(bank);
            e.setAmount(n.round(payment - interest));
            e.setMemo(ao.getMemo());
            transaction.addTransactionEntry(e);
            // handle interest portion of the payment
            Account i = ao.getInterestAccount();
            if (i != null && interest != 0.0) {
                e = new TransactionEntry();
                e.setCreditAccount(i);
                e.setDebitAccount(bank);
                e.setAmount(n.round(interest));
                e.setMemo(rb.getString("Word.Interest"));
                transaction.addTransactionEntry(e);
            //System.out.println(e.getAmount());
            }
            // a fee has been assigned
            if (ao.getFees().compareTo(BigDecimal.ZERO) != 0) {
                Account f = ao.getFeesAccount();
                if (f != null) {
                    e = new TransactionEntry();
                    e.setCreditAccount(f);
                    e.setDebitAccount(bank);
                    e.setAmount(ao.getFees());
                    e.setMemo(rb.getString("Word.Fees"));
                    transaction.addTransactionEntry(e);
                //System.out.println(e.getAmount());
                }
            }
            // the remainder of the balance should be loan principal
            tran = transaction;
        }
        if (tran != null) {
            // display the transaction in the register
            EditTransactionDialog dlg = new EditTransactionDialog(ao.getBankAccount(), PanelType.DECREASE);
            dlg.newTransaction(tran);
            dlg.setVisible(true);
        } else {
            StaticUIMethods.displayWarning(rb.getString("Message.Warn.ConfigAmortization"));
        }
    } else {
        // could not generate the transaction
        StaticUIMethods.displayWarning(rb.getString("Message.Warn.ConfigAmortization"));
    }
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) AmortizeObject(jgnash.engine.AmortizeObject) CommodityNode(jgnash.engine.CommodityNode) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) TransactionEntry(jgnash.engine.TransactionEntry)

Example 10 with Transaction

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

the class TransactionPanel method enterAction.

@Override
public void enterAction() {
    if (validateForm()) {
        if (modEntry != null && modTrans != null) {
            try {
                final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
                Objects.requireNonNull(engine);
                // clone the transaction
                Transaction t = (Transaction) modTrans.clone();
                // remove the modifying entry from the clone
                t.removeTransactionEntry(modEntry);
                // generate new TransactionEntry
                TransactionEntry e = buildTransactionEntry();
                // add it to the clone
                t.addTransactionEntry(e);
                ReconcileManager.reconcileTransaction(getAccount(), t, getReconciledState());
                engine.removeTransaction(modTrans);
                engine.addTransaction(t);
                clearForm();
                fireOkAction();
                focusFirstComponent();
            } catch (CloneNotSupportedException e) {
                Logger.getLogger(TransactionPanel.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        } else {
            super.enterAction();
        }
    }
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Engine(jgnash.engine.Engine) TransactionEntry(jgnash.engine.TransactionEntry)

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