Skip to content

Commit

Permalink
small change to balance filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed May 23, 2017
1 parent 05e1908 commit a386209
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@ import (
// Accounts are sorted by name.
func GetBalances(generalLedger []*Transaction, filterArr []string) []*Account {
balances := make(map[string]*big.Rat)
filters := len(filterArr) > 0
for _, trans := range generalLedger {
for _, accChange := range trans.AccountChanges {
inFilter := len(filterArr) == 0
for _, filter := range filterArr {
if strings.Contains(accChange.Name, filter) {
inFilter = true
inFilter := false
if filters {
for i := 0; i < len(filterArr) && !inFilter; i++ {
if strings.Contains(accChange.Name, filterArr[i]) {
inFilter = true
}
}
} else {
inFilter = true
}
if inFilter {
accHier := strings.Split(accChange.Name, ":")
accDepth := len(accHier)
for currDepth := accDepth; currDepth > 0; currDepth-- {
currAccName := strings.Join(accHier[:currDepth], ":")
if ratNum, ok := balances[currAccName]; !ok {
ratNum = new(big.Rat)
ratNum.SetString(accChange.Balance.RatString())
balances[currAccName] = ratNum
balances[currAccName] = new(big.Rat).Set(accChange.Balance)
} else {
ratNum.Add(ratNum, accChange.Balance)
}
Expand Down

0 comments on commit a386209

Please sign in to comment.