Search in sources :

Example 31 with Account

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

the class ExpandingBudgetTableModel method getVisibleDepth.

/**
     * @see AbstractExpandingTableModel#getVisibleDepth(Comparable)
     */
@Override
public int getVisibleDepth(final Account account) {
    int depth = 0;
    Account parent = account.getParent();
    while (parent != null) {
        if (!parent.isExcludedFromBudget()) {
            depth++;
        }
        parent = parent.getParent();
    }
    return depth;
}
Also used : Account(jgnash.engine.Account)

Example 32 with Account

use of jgnash.engine.Account 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 33 with Account

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

the class MainRegisterPanel method exportAction.

private void exportAction() {
    if (getActiveTable() != null) {
        final Account account = registerTree.getSelectedAccount();
        if (account != null && account.getTransactionCount() > 1) {
            LocalDate startDate = account.getTransactionAt(0).getLocalDate();
            LocalDate endDate = account.getTransactionAt(account.getTransactionCount() - 1).getLocalDate();
            // fetch selected rows
            final int[] rows = getActiveTable().getSelectedRows();
            if (rows.length > 1) {
                startDate = account.getTransactionAt(rows[0]).getLocalDate();
                endDate = account.getTransactionAt(rows[rows.length - 1]).getLocalDate();
            }
            ExportTransactionsAction.exportTransactions(account, startDate, endDate);
        }
    }
}
Also used : Account(jgnash.engine.Account) LocalDate(java.time.LocalDate)

Example 34 with Account

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

the class MainRegisterPanel method printAction.

/**
     * Display a register print report
     */
private void printAction() {
    if (getActiveTable() != null) {
        // fetch selected accounts
        final int[] rows = getActiveTable().getSelectedRows();
        Account a = registerTree.getSelectedAccount();
        if (a != null && rows.length < 2) {
            new AccountRegisterReport(a).showReport();
        } else if (a != null) {
            // display the selected rows
            new AccountRegisterReport(registerTree.getSelectedAccount(), rows[0], rows[rows.length - 1]).showReport();
        }
    }
}
Also used : Account(jgnash.engine.Account) AccountRegisterReport(jgnash.ui.report.compiled.AccountRegisterReport)

Example 35 with Account

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

the class MonthlyAccountBalanceChart method calculateTotal.

private static BigDecimal calculateTotal(final LocalDate start, final LocalDate end, final Account account, final CurrencyNode baseCurrency) {
    BigDecimal amount;
    AccountType type = account.getAccountType();
    // get the amount for the account                
    amount = AccountBalanceDisplayManager.convertToSelectedBalanceMode(type, account.getBalance(start, end, baseCurrency));
    // add the amount of every sub accounts
    for (final Account child : account.getChildren(Comparators.getAccountByCode())) {
        amount = amount.add(calculateTotal(start, end, child, baseCurrency));
    }
    return amount;
}
Also used : Account(jgnash.engine.Account) AccountType(jgnash.engine.AccountType) BigDecimal(java.math.BigDecimal)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9