Skip to content

Commit

Permalink
add multiply and division as operations for reports
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Jun 5, 2017
1 parent f8b84d2 commit 80c21f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions cmd/lweb/handler_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,27 @@ func calcBalances(calcAccts []calculatedAccount, balances []*ledger.Account) (re
if !found {
aval = big.NewRat(0, 1)
}
if acctOp.MultiplicationFactor != 0 {
factor := big.NewRat(1, 1).SetFloat64(acctOp.MultiplicationFactor)
fval = fval.Mul(factor, fval)
}
oval := big.NewRat(1, 1)
if acctOp.SubAccount != "" {
for _, obal := range balances {
if acctOp.SubAccount == obal.Name {
oval = oval.Abs(obal.Balance)
}
}
}
switch acctOp.Operation {
case "+":
aval.Add(aval, fval)
case "-":
aval.Sub(aval, fval)
case "*":
aval.Mul(fval, oval)
case "/":
aval.Quo(fval, oval)
}
accVals[calcAccount.Name] = aval
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/lweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ func getTransactions() ([]*ledger.Transaction, error) {
}

type accountOp struct {
Name string `toml:"name"`
Operation string `toml:"operation"` // +, -
Name string `toml:"name"`
Operation string `toml:"operation"` // +, -
MultiplicationFactor float64 `toml:"factor"`
SubAccount string `toml:"other_account"` // *, /
}

type calculatedAccount struct {
Expand Down

0 comments on commit 80c21f9

Please sign in to comment.