budget: more regular layout, simple fixed-width columns

old:
Balance changes in 2018/03/19w12:

                   ||   2018/03/19w12
===================++=================
 <unbudgeted>:aaa  ||               0
 bbb               ||        1.33 [0]
 bbb:bbbbbbbbbbbbb || 1.25 [42% of 3]
 ccc               ||     0 [0% of 0]
 ddd               ||     0 [0% of 0]
 eee               || 0.75 [75% of 1]
 fff               || 3.50 [50% of 7]
 ggg               ||        1.25 [0]
 hhh               ||     0 [0% of 6]
 iii               ||     0 [0% of 0]
-------------------++-----------------
                   ||            8.08

new:
                   ||          2018/03/19w12
===================++========================
 <unbudgeted>:aaa  ||       0
 bbb               ||    1.33 [           0]
 bbb:bbbbbbbbbbbbb ||    1.25 [ 42% of    3]
 ccc               ||       0 [  0% of    0]
 ddd               ||       0 [  0% of    0]
 eee               ||    0.75 [ 75% of    1]
 fff               ||    3.50 [ 50% of    7]
 ggg               ||    1.25 [           0]
 hhh               ||       0 [  0% of    6]
 iii               ||       0 [  0% of    0]
-------------------++------------------------
                   ||    8.08
This commit is contained in:
Simon Michael 2018-03-21 17:01:03 +00:00
parent 550425810f
commit 6970a4c6e8

View File

@ -667,11 +667,22 @@ multiBalanceReportWithBudgetAsText opts budgetr actualr =
actualandbudgetamts = combine (balanceReportAsTable opts actualr) (balanceReportAsTable opts budgetr)
showcell :: (ActualAmount, Maybe BudgetAmount) -> String
showcell (actual, Nothing) = showamt actual
showcell (actual, Just budget) =
case percentage actual budget of
Just pct -> printf "%s [%s%% of %s]" (showamt actual) (show $ roundTo 0 pct) (showamt budget)
Nothing -> printf "%s [%s]" (showamt actual) (showamt budget)
showcell (actual, mbudget) =
case (actual, mbudget) of
(actual, Nothing) ->
printf ("%"++show actualwidth++"s " ++ replicate (percentwidth + 7 + budgetwidth) ' ') (showamt actual)
(actual, Just budget) ->
case percentage actual budget of
Just pct ->
printf ("%"++show actualwidth++"s [%"++show percentwidth++"s%% of %"++show budgetwidth++"s]")
(showamt actual) (show $ roundTo 0 pct) (showamt budget)
Nothing ->
printf ("%"++show actualwidth++"s ["++replicate (percentwidth+5) ' '++"%"++show budgetwidth++"s]")
(showamt actual) (showamt budget)
where
actualwidth = 7
percentwidth = 3
budgetwidth = 4
percentage :: ActualAmount -> BudgetAmount -> Maybe Percentage
percentage actual budget =