use of jgnash.engine.AccountType in project jgnash by ccavanaugh.
the class AccountTools method createAccount.
static void createAccount(final Account account) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
Account parentAccount = account;
final ResourceBundle rb = ResourceUtils.getBundle();
if (parentAccount == null) {
parentAccount = engine.getRootAccount();
if (parentAccount == null) {
// no root account at all, file was closed
return;
}
}
AccountDialog dlg = new AccountDialog();
dlg.setParentAccount(parentAccount);
dlg.setAccountType(parentAccount.getAccountType());
dlg.setTitle(rb.getString("Title.NewAccount"));
dlg.setVisible(true);
if (dlg.returnStatus()) {
CurrencyNode currency = dlg.getCurrency();
AccountType accType = dlg.getAccountType();
if (currency == null) {
currency = engine.getRootAccount().getCurrencyNode();
Logger.getLogger(AccountTools.class.getName()).warning("Forcing use of the default currency");
}
Account newAccount = new Account(accType, currency);
if (accType.getAccountGroup() == AccountGroup.INVEST) {
Collection<SecurityNode> collection = dlg.getAccountSecurities();
collection.forEach(newAccount::addSecurity);
}
newAccount.setName(dlg.getAccountName());
newAccount.setAccountCode(dlg.getAccountCode());
newAccount.setAccountNumber(dlg.getAccountNumber());
newAccount.setBankId(dlg.getBankId());
newAccount.setDescription(dlg.getAccountDescription());
newAccount.setNotes(dlg.getAccountNotes());
newAccount.setLocked(dlg.isAccountLocked());
newAccount.setPlaceHolder(dlg.isAccountPlaceholder());
newAccount.setVisible(dlg.isAccountVisible());
newAccount.setExcludedFromBudget(dlg.isExcludedFromBudget());
engine.addAccount(dlg.getParentAccount(), newAccount);
}
}
use of jgnash.engine.AccountType in project jgnash by ccavanaugh.
the class AccountPanel method updateCommodityButton.
private void updateCommodityButton() {
AccountType type = getAccountType();
if (type == AccountType.INVEST || type == AccountType.MUTUAL) {
securityButton.setEnabled(true);
updateCommodityText();
} else {
securityButton.setEnabled(false);
}
}
use of jgnash.engine.AccountType in project jgnash by ccavanaugh.
the class AccountPanel method disableAccountType.
void disableAccountType(final AccountType type) {
if (type.isMutable()) {
for (AccountType t : AccountType.values()) {
if (!t.isMutable()) {
accountTypeModel.removeElement(t);
}
}
} else {
accountTypeCombo.setSelectedItem(type);
accountTypeCombo.setEnabled(false);
}
}
use of jgnash.engine.AccountType 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;
}
use of jgnash.engine.AccountType in project jgnash by ccavanaugh.
the class MonthlyAccountBalanceChart method createTimeSeriesCollection.
private TimeSeriesCollection createTimeSeriesCollection(final Account account) {
List<LocalDate> dates = Collections.emptyList();
if (subAccountCheckBox.isSelected()) {
// Getting the dates to calculate
final LocalDate start = startDateField.getLocalDate().with(TemporalAdjusters.firstDayOfMonth());
final LocalDate stop = endDateField.getLocalDate().with(TemporalAdjusters.lastDayOfMonth());
dates = DateUtils.getLastDayOfTheMonths(start, stop);
TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance"));
// For every month, calculate the total amount
for (LocalDate date : dates) {
final LocalDate d = date.with(TemporalAdjusters.lastDayOfMonth());
final LocalDate s = date.with(TemporalAdjusters.firstDayOfMonth());
// Get the total amount for the account and every sub accounts for the specified date
// and include it in the chart
t.add(new Month(DateUtils.asDate(date)), calculateTotal(s, d, account, account.getCurrencyNode()));
}
return new TimeSeriesCollection(t);
}
int count = account.getTransactionCount();
if (count > 0) {
LocalDate start = account.getTransactionAt(0).getLocalDate();
LocalDate stop = account.getTransactionAt(count - 1).getLocalDate();
dates = DateUtils.getLastDayOfTheMonths(start, stop);
}
TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance"));
AccountType type = account.getAccountType();
for (LocalDate localDate : dates) {
// get balance for the whole month
LocalDate d = localDate.with(TemporalAdjusters.lastDayOfMonth());
LocalDate s = localDate.with(TemporalAdjusters.firstDayOfMonth());
BigDecimal balance = AccountBalanceDisplayManager.convertToSelectedBalanceMode(type, account.getBalance(s, d));
t.add(new Month(DateUtils.asDate(localDate)), balance);
}
return new TimeSeriesCollection(t);
}
Aggregations