From 80c21f9620b9bdc35a9a107343818fb764621e1d Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Mon, 5 Jun 2017 12:49:35 -0500 Subject: [PATCH] add multiply and division as operations for reports --- cmd/lweb/handler_report.go | 16 ++++++++++++++++ cmd/lweb/main.go | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/lweb/handler_report.go b/cmd/lweb/handler_report.go index 0d3b8c4c..94dca74e 100644 --- a/cmd/lweb/handler_report.go +++ b/cmd/lweb/handler_report.go @@ -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 } diff --git a/cmd/lweb/main.go b/cmd/lweb/main.go index 20243e24..4bdea842 100644 --- a/cmd/lweb/main.go +++ b/cmd/lweb/main.go @@ -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 {