mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-10-30 07:40:05 -04:00
Report account balances correctly for both date sorts
This commit is contained in:
parent
693f1e8253
commit
770cd384a7
@ -355,20 +355,20 @@ const AccountRegister = React.createClass({
|
||||
}
|
||||
|
||||
var transactions = [];
|
||||
var balance = new Big(data.BeginningBalance);
|
||||
var balance = new Big(data.EndingBalance);
|
||||
|
||||
for (var i = 0; i < data.Transactions.length; i++) {
|
||||
var t = new Transaction();
|
||||
t.fromJSON(data.Transactions[i]);
|
||||
|
||||
t.Balance = balance.plus(0); // Make a copy of the current balance
|
||||
// Keep a talley of the running balance of these transactions
|
||||
for (var j = 0; j < data.Transactions[i].Splits.length; j++) {
|
||||
var split = data.Transactions[i].Splits[j];
|
||||
if (this.props.selectedAccount.AccountId == split.AccountId) {
|
||||
balance = balance.plus(split.Amount);
|
||||
balance = balance.minus(split.Amount);
|
||||
}
|
||||
}
|
||||
t.Balance = balance.plus(0); // Make a copy
|
||||
transactions.push(t);
|
||||
}
|
||||
var a = new Account();
|
||||
|
@ -541,11 +541,26 @@ func GetAccountTransactions(user *User, accountid int64, sort string, page uint6
|
||||
var transactions []Transaction
|
||||
var atl AccountTransactionsList
|
||||
|
||||
var sqlsort string
|
||||
transaction, err := DB.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var sqlsort, balanceLimitOffset string
|
||||
var balanceLimitOffsetArg uint64
|
||||
if sort == "date-asc" {
|
||||
sqlsort = " ORDER BY transactions.Date ASC"
|
||||
balanceLimitOffset = " LIMIT ?"
|
||||
balanceLimitOffsetArg = page*limit
|
||||
} else if sort == "date-desc" {
|
||||
numSplits, err := transaction.SelectInt("SELECT count(*) FROM splits")
|
||||
if err != nil {
|
||||
transaction.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
sqlsort = " ORDER BY transactions.Date DESC"
|
||||
balanceLimitOffset = fmt.Sprintf(" LIMIT %d OFFSET ?", numSplits)
|
||||
balanceLimitOffsetArg = (page + 1)*limit
|
||||
}
|
||||
|
||||
var sqloffset string
|
||||
@ -553,11 +568,6 @@ func GetAccountTransactions(user *User, accountid int64, sort string, page uint6
|
||||
sqloffset = fmt.Sprintf(" OFFSET %d", page*limit)
|
||||
}
|
||||
|
||||
transaction, err := DB.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
account, err := GetAccountTx(transaction, accountid, user.UserId)
|
||||
if err != nil {
|
||||
transaction.Rollback()
|
||||
@ -611,8 +621,8 @@ func GetAccountTransactions(user *User, accountid int64, sort string, page uint6
|
||||
// Sum all the splits for all transaction splits for this account that
|
||||
// occurred before the page we're returning
|
||||
var amounts []string
|
||||
sql = "SELECT splits.Amount FROM splits WHERE splits.AccountId=? AND splits.TransactionId IN (SELECT DISTINCT transactions.TransactionId FROM transactions INNER JOIN splits ON transactions.TransactionId = splits.TransactionId WHERE transactions.UserId=? AND splits.AccountId=?" + sqlsort + " LIMIT ?)"
|
||||
_, err = transaction.Select(&amounts, sql, accountid, user.UserId, accountid, page*limit)
|
||||
sql = "SELECT splits.Amount FROM splits WHERE splits.AccountId=? AND splits.TransactionId IN (SELECT DISTINCT transactions.TransactionId FROM transactions INNER JOIN splits ON transactions.TransactionId = splits.TransactionId WHERE transactions.UserId=? AND splits.AccountId=?" + sqlsort + balanceLimitOffset + ")"
|
||||
_, err = transaction.Select(&amounts, sql, accountid, user.UserId, accountid, balanceLimitOffsetArg)
|
||||
if err != nil {
|
||||
transaction.Rollback()
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user