Search in sources :

Example 1 with AccountType

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);
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) SecurityNode(jgnash.engine.SecurityNode) ResourceBundle(java.util.ResourceBundle) AccountType(jgnash.engine.AccountType) Engine(jgnash.engine.Engine)

Example 2 with AccountType

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);
    }
}
Also used : AccountType(jgnash.engine.AccountType)

Example 3 with AccountType

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);
    }
}
Also used : AccountType(jgnash.engine.AccountType)

Example 4 with AccountType

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;
}
Also used : Account(jgnash.engine.Account) AccountType(jgnash.engine.AccountType) BigDecimal(java.math.BigDecimal)

Example 5 with AccountType

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);
}
Also used : Month(org.jfree.data.time.Month) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) LocalDate(java.time.LocalDate) AccountType(jgnash.engine.AccountType) BigDecimal(java.math.BigDecimal)

Aggregations

AccountType (jgnash.engine.AccountType)16 Account (jgnash.engine.Account)10 BigDecimal (java.math.BigDecimal)8 LocalDate (java.time.LocalDate)7 Engine (jgnash.engine.Engine)7 ResourceBundle (java.util.ResourceBundle)4 CurrencyNode (jgnash.engine.CurrencyNode)4 DateUtils (jgnash.time.DateUtils)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AccountGroup (jgnash.engine.AccountGroup)3 EngineFactory (jgnash.engine.EngineFactory)3 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2