I have Bank table and transaction table. The relationship is one-to-many, so a bank may have many transactions. Transaction table has the bank foreign key(bank_id). and each transaction has a column 'type' which is either credit or debit. I want to show each bank balance based on its transactions.
Here are my questions:
- How to select a specific bank?
- How to calculate the balance for a bank?
- Should I calculate it in controller, model, or view? which one is the best?