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;
}
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"));
}
}
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);
}
}
}
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();
}
}
}
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;
}
Aggregations