bal: show percentage of budget spent
This commit is contained in:
parent
6ea5da2d9d
commit
8cd58b71ab
@ -252,6 +252,7 @@ import qualified Data.Map as Map
|
|||||||
-- import Data.Monoid
|
-- import Data.Monoid
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import System.Console.CmdArgs.Explicit as C
|
import System.Console.CmdArgs.Explicit as C
|
||||||
|
import Data.Decimal (roundTo)
|
||||||
import Text.CSV
|
import Text.CSV
|
||||||
import Test.HUnit
|
import Test.HUnit
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
@ -559,7 +560,14 @@ multiBalanceReportWithBudgetAsText opts budget r =
|
|||||||
HistoricalBalance -> "Ending balances (historical)"
|
HistoricalBalance -> "Ending balances (historical)"
|
||||||
showcell (real, Nothing) = showamt real
|
showcell (real, Nothing) = showamt real
|
||||||
showcell (real, Just budget) =
|
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
|
showamt | color_ opts = cshowMixedAmountOneLineWithoutPrice
|
||||||
| otherwise = showMixedAmountOneLineWithoutPrice
|
| otherwise = showMixedAmountOneLineWithoutPrice
|
||||||
-- combine reportTable budgetTable will combine them into a single table where cells
|
-- combine reportTable budgetTable will combine them into a single table where cells
|
||||||
|
|||||||
@ -113,6 +113,7 @@ library
|
|||||||
, text >=0.11
|
, text >=0.11
|
||||||
, utf8-string >=0.3.5 && <1.1
|
, utf8-string >=0.3.5 && <1.1
|
||||||
, wizards ==1.0.*
|
, wizards ==1.0.*
|
||||||
|
, Decimal
|
||||||
if (!(os(windows))) && (flag(terminfo))
|
if (!(os(windows))) && (flag(terminfo))
|
||||||
build-depends:
|
build-depends:
|
||||||
terminfo
|
terminfo
|
||||||
@ -192,6 +193,7 @@ executable hledger
|
|||||||
, text >=0.11
|
, text >=0.11
|
||||||
, utf8-string >=0.3.5 && <1.1
|
, utf8-string >=0.3.5 && <1.1
|
||||||
, wizards ==1.0.*
|
, wizards ==1.0.*
|
||||||
|
, Decimal
|
||||||
if (!(os(windows))) && (flag(terminfo))
|
if (!(os(windows))) && (flag(terminfo))
|
||||||
build-depends:
|
build-depends:
|
||||||
terminfo
|
terminfo
|
||||||
@ -241,6 +243,7 @@ test-suite test
|
|||||||
, text >=0.11
|
, text >=0.11
|
||||||
, utf8-string >=0.3.5 && <1.1
|
, utf8-string >=0.3.5 && <1.1
|
||||||
, wizards ==1.0.*
|
, wizards ==1.0.*
|
||||||
|
, Decimal
|
||||||
, test-framework
|
, test-framework
|
||||||
, test-framework-hunit
|
, test-framework-hunit
|
||||||
if (!(os(windows))) && (flag(terminfo))
|
if (!(os(windows))) && (flag(terminfo))
|
||||||
|
|||||||
@ -149,6 +149,7 @@ library:
|
|||||||
- text >=0.11
|
- text >=0.11
|
||||||
- utf8-string >=0.3.5 && <1.1
|
- utf8-string >=0.3.5 && <1.1
|
||||||
- wizards ==1.0.*
|
- wizards ==1.0.*
|
||||||
|
- Decimal
|
||||||
|
|
||||||
executables:
|
executables:
|
||||||
hledger:
|
hledger:
|
||||||
@ -178,6 +179,7 @@ executables:
|
|||||||
- text >=0.11
|
- text >=0.11
|
||||||
- utf8-string >=0.3.5 && <1.1
|
- utf8-string >=0.3.5 && <1.1
|
||||||
- wizards ==1.0.*
|
- wizards ==1.0.*
|
||||||
|
- Decimal
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
test:
|
test:
|
||||||
@ -204,6 +206,7 @@ tests:
|
|||||||
- text >=0.11
|
- text >=0.11
|
||||||
- utf8-string >=0.3.5 && <1.1
|
- utf8-string >=0.3.5 && <1.1
|
||||||
- wizards ==1.0.*
|
- wizards ==1.0.*
|
||||||
|
- Decimal
|
||||||
- test-framework
|
- test-framework
|
||||||
- test-framework-hunit
|
- test-framework-hunit
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
Balance changes in 2016/12/01-2016/12/03:
|
||||||
|
|
||||||
|| 2016/12/01 2016/12/02 2016/12/03
|
|| 2016/12/01 2016/12/02 2016/12/03
|
||||||
=======================++=======================================
|
=======================++=============================================================
|
||||||
<unbudgeted>:expenses || 0 0 $40
|
<unbudgeted>:expenses || 0 0 $40
|
||||||
assets:cash || $-10 [$-25] $-14 [$-25] $-51 [$-25]
|
assets:cash || $-10 [40% of $-25] $-14 [56% of $-25] $-51 [204% of $-25]
|
||||||
expenses:food || $10 [$10] $9 [$10] $11 [$10]
|
expenses:food || $10 [100% of $10] $9 [90% of $10] $11 [110% of $10]
|
||||||
expenses:leisure || 0 [$15] $5 [$15] 0 [$15]
|
expenses:leisure || 0 [$15] $5 [33% of $15] 0 [$15]
|
||||||
-----------------------++---------------------------------------
|
-----------------------++-------------------------------------------------------------
|
||||||
|| 0 0 0
|
|| 0 0 0
|
||||||
|
|
||||||
>>>2
|
>>>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:
|
Balance changes in 2016/12/01-2016/12/03:
|
||||||
|
|
||||||
|| 2016/12/01 2016/12/02 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:cab || 0 0 $15
|
||||||
expenses:food || $10 [$10] $9 [$10] $11 [$10]
|
expenses:food || $10 [100% of $10] $9 [90% of $10] $11 [110% of $10]
|
||||||
expenses:leisure || 0 [$15] $5 [$15] 0 [$15]
|
expenses:leisure || 0 [$15] $5 [33% of $15] 0 [$15]
|
||||||
expenses:movies || 0 0 $25
|
expenses:movies || 0 0 $25
|
||||||
------------------++---------------------------------------
|
------------------++-------------------------------------------------------------
|
||||||
|| 0 0 0
|
|| 0 0 0
|
||||||
|
|
||||||
>>>2
|
>>>2
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user