Fix credit, debit and balance computation on SQLite

issue3877
review8271002
Add test for credit, debit and balance calculation

issue3877
review8271002
Use a list of field names to calculate credit and debit

issue3886
review13261002