Search in sources :

Example 1 with AmortizeObject

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

the class AmortizeDialog method getAmortizeObject.

/**
     * Returns a new AmortizeObject created with the form data
     *
     * @return a new AmortizeObject
     */
public AmortizeObject getAmortizeObject() {
    AmortizeObject o = new AmortizeObject();
    o.setDate(dateField.getLocalDate());
    o.setFees(feesField.getDecimal());
    o.setInterestPeriods(intPeriodsField.intValue());
    o.setPaymentPeriods(payPeriodsField.intValue());
    o.setPrincipal(loanAmountField.getDecimal());
    o.setRate(interestField.getDecimal());
    o.setLength(loanTermField.intValue());
    o.setPayee(payeeField.getText());
    o.setMemo(memoField.getText());
    o.setUseDailyRate(useDaysButton.isSelected());
    o.setDaysPerYear(daysField.getDecimal());
    if (bankAccount != null) {
        o.setBankAccount(bankAccount);
    }
    if (interestAccount != null) {
        o.setInterestAccount(interestAccount);
    }
    if (feesAccount != null) {
        o.setFeesAccount(feesAccount);
    }
    return o;
}
Also used : AmortizeObject(jgnash.engine.AmortizeObject)

Example 2 with AmortizeObject

use of jgnash.engine.AmortizeObject 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 3 with AmortizeObject

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

the class AmortizeDialog method generateDefault.

private static AmortizeObject generateDefault() {
    AmortizeObject o = new AmortizeObject();
    // make up some reasonable numbers
    o.setLength(360);
    o.setPaymentPeriods(12);
    o.setRate(new BigDecimal("5.75"));
    o.setPrincipal(new BigDecimal("80000.00"));
    o.setUseDailyRate(false);
    o.setDaysPerYear(new BigDecimal("365"));
    // Defaults for US and CA are known... not sure about others
    if (Locale.getDefault().getCountry().equals("CA")) {
        o.setInterestPeriods(4);
    } else {
        o.setInterestPeriods(12);
    }
    return o;
}
Also used : AmortizeObject(jgnash.engine.AmortizeObject) BigDecimal(java.math.BigDecimal)

Example 4 with AmortizeObject

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

the class LiabilityRegisterPanel method amortizeAction.

/**
     * Displays the Amortize dialog
     */
private void amortizeAction() {
    AmortizeObject ao = account.getAmortizeObject();
    AmortizeDialog d = new AmortizeDialog(ao);
    d.setVisible(true);
    if (d.getResult()) {
        if (!engine.setAmortizeObject(account, d.getAmortizeObject())) {
            StaticUIMethods.displayError(rb.getString("Message.Error.AmortizationSave"));
        }
    }
}
Also used : AmortizeDialog(jgnash.ui.account.AmortizeDialog) AmortizeObject(jgnash.engine.AmortizeObject)

Aggregations

AmortizeObject (jgnash.engine.AmortizeObject)4 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)1 Account (jgnash.engine.Account)1 CommodityNode (jgnash.engine.CommodityNode)1 Transaction (jgnash.engine.Transaction)1 TransactionEntry (jgnash.engine.TransactionEntry)1 AmortizeDialog (jgnash.ui.account.AmortizeDialog)1