Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add account balance to Content Provider #68

Closed
gasko opened this issue Apr 10, 2011 · 4 comments
Closed

Add account balance to Content Provider #68

gasko opened this issue Apr 10, 2011 · 4 comments
Labels

Comments

@gasko
Copy link

gasko commented Apr 10, 2011

Today you only can get the transaction amount via the content provider. But you can't get the account balance.
So I suggest that you add account balance to the category "BANK_ACCOUNTS_CAT"

@magnusart
Copy link
Contributor

Short answer: This will cause tight coupling. Instead account balance should be exposed!

Long answer:
The bank balance is calculated on the fly and only saved in the database for the purpose to trigger notifications and update the database if and only if the balance have changed.

The bank balance is not a part of the domain/datamodel per se, it is actually a saved state calculated from the accounts. When UID is implemented the bank balance value does not need to be saved in the database anymore. Exposing it would cause tight coupling with any application that uses it.

Therefore the AccountBalance column should be exposed instead. I actually happen to need that as well so I will implement it.

Below is the code that uses the balance (the diff variable):

currentBalance = bank.getBalance();
accounts.clear();
for (final Account account : bank.getAccounts()) {
    accounts.put(account.getId(), account);
}
bank.update();
diff = currentBalance.subtract(bank.getBalance());

The balance itself is calculated on the fly

    public BigDecimal getBalance() {
        if (STATIC_BALANCE) {
            return balance;
        }
        else {
            BigDecimal bal = new BigDecimal(0); 
            for (Account account : accounts) {
                if (account.getType() == Account.REGULAR || account.getType() == Account.CCARD) {
                    if (!account.isHidden() || (account.getAliasfor() == null || account.getAliasfor().length() == 0)) {
                        bal = bal.add(account.getBalance());
                    }
                }
            }
            return bal;
        }
    }

@magnusart
Copy link
Contributor

Hmmm.... very tired and misread the original question. Embarrasing but anyhow, I'm almost done implementing it.

@magnusart
Copy link
Contributor

This is implemented in a pending pull request: #89

liato added a commit that referenced this issue Jun 11, 2011
Fix for issue #68: Add account balance to Content Provider
@liato
Copy link
Owner

liato commented Jul 10, 2011

Thanks magnusart!

@liato liato closed this as completed Jul 10, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants