bal: show percentage of budget spent

This commit is contained in:
Dmitry Astapov 2017-11-19 13:07:07 +00:00
parent 6ea5da2d9d
commit 8cd58b71ab
4 changed files with 32 additions and 18 deletions

View File

@ -252,6 +252,7 @@ import qualified Data.Map as Map
-- import Data.Monoid
import qualified Data.Text as T
import System.Console.CmdArgs.Explicit as C
import Data.Decimal (roundTo)
import Text.CSV
import Test.HUnit
import Text.Printf (printf)
@ -559,7 +560,14 @@ multiBalanceReportWithBudgetAsText opts budget r =
HistoricalBalance -> "Ending balances (historical)"
showcell (real, Nothing) = showamt real
showcell (real, Just budget) =
printf "%s [%s]" (showamt real) (showamt budget)
case percentage real budget of
Just pct -> printf "%s [%s%% of %s]" (showamt real) (show $ roundTo 0 pct) (showamt budget)
Nothing -> printf "%s [%s]" (showamt real) (showamt budget)
percentage real budget =
case (real, budget) of
(Mixed [a1], Mixed [a2]) | acommodity a1 == acommodity a2 && aquantity a2 /= 0 ->
Just $ 100 * aquantity a1 / aquantity a2
_ -> Nothing
showamt | color_ opts = cshowMixedAmountOneLineWithoutPrice
| otherwise = showMixedAmountOneLineWithoutPrice
-- combine reportTable budgetTable will combine them into a single table where cells

View File

@ -113,6 +113,7 @@ library
, text >=0.11
, utf8-string >=0.3.5 && <1.1
, wizards ==1.0.*
, Decimal
if (!(os(windows))) && (flag(terminfo))
build-depends:
terminfo
@ -192,6 +193,7 @@ executable hledger
, text >=0.11
, utf8-string >=0.3.5 && <1.1
, wizards ==1.0.*
, Decimal
if (!(os(windows))) && (flag(terminfo))
build-depends:
terminfo
@ -241,6 +243,7 @@ test-suite test
, text >=0.11
, utf8-string >=0.3.5 && <1.1
, wizards ==1.0.*
, Decimal
, test-framework
, test-framework-hunit
if (!(os(windows))) && (flag(terminfo))

View File

@ -149,6 +149,7 @@ library:
- text >=0.11
- utf8-string >=0.3.5 && <1.1
- wizards ==1.0.*
- Decimal
executables:
hledger:
@ -178,6 +179,7 @@ executables:
- text >=0.11
- utf8-string >=0.3.5 && <1.1
- wizards ==1.0.*
- Decimal
tests:
test:
@ -204,6 +206,7 @@ tests:
- text >=0.11
- utf8-string >=0.3.5 && <1.1
- wizards ==1.0.*
- Decimal
- test-framework
- test-framework-hunit

View File

@ -33,12 +33,12 @@ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget
Balance changes in 2016/12/01-2016/12/03:
|| 2016/12/01 2016/12/02 2016/12/03
=======================++=======================================
=======================++=============================================================
<unbudgeted>:expenses || 0 0 $40
assets:cash || $-10 [$-25] $-14 [$-25] $-51 [$-25]
expenses:food || $10 [$10] $9 [$10] $11 [$10]
expenses:leisure || 0 [$15] $5 [$15] 0 [$15]
-----------------------++---------------------------------------
assets:cash || $-10 [40% of $-25] $-14 [56% of $-25] $-51 [204% of $-25]
expenses:food || $10 [100% of $10] $9 [90% of $10] $11 [110% of $10]
expenses:leisure || 0 [$15] $5 [33% of $15] 0 [$15]
-----------------------++-------------------------------------------------------------
|| 0 0 0
>>>2
@ -79,13 +79,13 @@ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget --show-unbudgeted
Balance changes in 2016/12/01-2016/12/03:
|| 2016/12/01 2016/12/02 2016/12/03
==================++=======================================
assets:cash || $-10 [$-25] $-14 [$-25] $-51 [$-25]
==================++=============================================================
assets:cash || $-10 [40% of $-25] $-14 [56% of $-25] $-51 [204% of $-25]
expenses:cab || 0 0 $15
expenses:food || $10 [$10] $9 [$10] $11 [$10]
expenses:leisure || 0 [$15] $5 [$15] 0 [$15]
expenses:food || $10 [100% of $10] $9 [90% of $10] $11 [110% of $10]
expenses:leisure || 0 [$15] $5 [33% of $15] 0 [$15]
expenses:movies || 0 0 $25
------------------++---------------------------------------
------------------++-------------------------------------------------------------
|| 0 0 0
>>>2