diff --git a/cmd/lweb/handler_report.go b/cmd/lweb/handler_report.go index d7e68eee..68bd3e8f 100644 --- a/cmd/lweb/handler_report.go +++ b/cmd/lweb/handler_report.go @@ -231,6 +231,13 @@ func ReportHandler(w http.ResponseWriter, r *http.Request, params martini.Params colorIdx++ } + for _, calcAccount := range rConf.CalculatedAccounts { + lData.DataSets = append(lData.DataSets, + lineData{AccountName: calcAccount.Name, + RGBColor: colorlist[colorIdx]}) + colorIdx++ + } + var rType ledger.RangeType switch rConf.Chart { case "line": @@ -287,6 +294,24 @@ func ReportHandler(w http.ResponseWriter, r *http.Request, params martini.Params } } } + for _, calcAccount := range rConf.CalculatedAccounts { + for _, bal := range rb.Balances { + for _, acctOp := range calcAccount.AccountOperations { + if acctOp.Name == bal.Name { + fval, _ := bal.Balance.Float64() + fval = math.Abs(fval) + aval := accVals[calcAccount.Name] + switch acctOp.Operation { + case "+": + aval += fval + case "-": + aval -= fval + } + accVals[calcAccount.Name] = aval + } + } + } + } for dIdx := range lData.DataSets { lData.DataSets[dIdx].Values = append(lData.DataSets[dIdx].Values, accVals[lData.DataSets[dIdx].AccountName]) } diff --git a/cmd/lweb/main.go b/cmd/lweb/main.go index c899cc0e..24da73f7 100644 --- a/cmd/lweb/main.go +++ b/cmd/lweb/main.go @@ -46,7 +46,7 @@ type accountOp struct { type calculatedAccount struct { Name string `toml:"name"` - AccountOperations []accountOp `toml:"account_operations"` + AccountOperations []accountOp `toml:"account_operation"` } type reportConfig struct { @@ -56,7 +56,7 @@ type reportConfig struct { DateFreq string `toml:"date_freq"` Accounts []string Exclude []string `toml:"exclude"` - CalculatedAccounts []calculatedAccount `toml:"calculated_accounts"` + CalculatedAccounts []calculatedAccount `toml:"calculated_account"` } type reportConfigStruct struct { diff --git a/cmd/lweb/reports-sample.toml b/cmd/lweb/reports-sample.toml index a6efbd6b..6d4fffd1 100644 --- a/cmd/lweb/reports-sample.toml +++ b/cmd/lweb/reports-sample.toml @@ -24,6 +24,24 @@ chart = "pie" date_range = "YTD" accounts = [ "Expenses" ] +[[report]] +name = "YTD Monthly Savings" +chart = "bar" +date_range = "YTD" +date_freq = "Monthly" +accounts = [ "Income", "Expenses" ] + + [[report.calculated_account]] + name = "Savings" + + [[report.calculated_account.account_operation]] + name = "Income" + operation = "+" + + [[report.calculated_account.account_operation]] + name = "Expenses" + operation = "-" + [[report]] name = "AT Net Worth" chart = "line" @@ -38,6 +56,13 @@ date_range = "All Time" date_freq = "Quarterly" accounts = [ "Assets:Fixed Assets", "Expenses:Depreciation" ,"Liabilities:Loans:Auto" ] +[[report]] +name = "AT Vehicle Expenses" +chart = "stackedbar" +date_range = "All Time" +date_freq = "Yearly" +accounts = [ "Expenses:Depreciation", "Expenses:Auto:Gas", "Expenses:Auto:Insurance", "Expenses:Auto:Maintenance" ] + [[report]] name = "AT Yearly Income" chart = "bar"