Add the total number of transactions in an account to AccountTransactionsList

This commit is contained in:
Aaron Lindsay 2015-08-08 09:08:37 -04:00
parent b670e67ebb
commit 684e8defb7
1 changed files with 13 additions and 5 deletions

View File

@ -40,9 +40,9 @@ func (s *Split) Valid() bool {
const (
Entered int64 = 1
Cleared = 2
Reconciled = 3
Voided = 4
Cleared = 2
Reconciled = 3
Voided = 4
)
type Transaction struct {
@ -59,8 +59,9 @@ type TransactionList struct {
}
type AccountTransactionsList struct {
Account *Account `json:"account"`
Transactions *[]Transaction `json:"transactions"`
Account *Account `json:"account"`
Transactions *[]Transaction `json:"transactions"`
TotalTransactions int64 `json:"totaltransactions"`
}
func (t *Transaction) Write(w http.ResponseWriter) error {
@ -574,6 +575,13 @@ func GetAccountTransactions(user *User, accountid int64, sort string, page uint6
}
}
count, err := transaction.SelectInt("SELECT count(DISTINCT transactions.TransactionId) FROM transactions INNER JOIN splits ON transactions.TransactionId = splits.TransactionId WHERE transactions.UserId=? AND splits.AccountId=?", user.UserId, accountid)
if err != nil {
transaction.Rollback()
return nil, err
}
atl.TotalTransactions = count
err = transaction.Commit()
if err != nil {
transaction.Rollback()