support all single-column balance features for balancesheet/incomestatement/cashflow
This commit is contained in:
parent
321ace107e
commit
573eda15e6
@ -6,6 +6,7 @@ module Hledger.Cli.BalanceView (
|
|||||||
,balanceviewReport
|
,balanceviewReport
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Monad (unless)
|
||||||
import Data.Time.Calendar (Day)
|
import Data.Time.Calendar (Day)
|
||||||
import Data.List (intercalate)
|
import Data.List (intercalate)
|
||||||
import Data.Monoid (Sum(..), (<>))
|
import Data.Monoid (Sum(..), (<>))
|
||||||
@ -29,6 +30,10 @@ balanceviewmode bv@BV{..} = (defCommandMode $ bvmode : bvaliases) {
|
|||||||
groupUnnamed = [
|
groupUnnamed = [
|
||||||
flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show accounts as a list"
|
flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show accounts as a list"
|
||||||
,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
|
,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
|
||||||
|
,flagNone ["value","V"] (setboolopt "value") "convert amounts to their market value on the report end date (using the most recent applicable market price, if any)"
|
||||||
|
,flagNone ["no-total","N"] (\opts -> setboolopt "no-total" opts) "omit the final total row"
|
||||||
|
,flagNone ["no-elide"] (\opts -> setboolopt "no-elide" opts) "don't squash boring parent accounts (in tree mode)"
|
||||||
|
,flagReq ["format"] (\s opts -> Right $ setopt "format" s opts) "FORMATSTR" "use this custom line format (in simple reports)"
|
||||||
]
|
]
|
||||||
,groupHidden = []
|
,groupHidden = []
|
||||||
,groupNamed = [generalflagsgroup1]
|
,groupNamed = [generalflagsgroup1]
|
||||||
@ -38,22 +43,29 @@ balanceviewmode bv@BV{..} = (defCommandMode $ bvmode : bvaliases) {
|
|||||||
balanceviewQueryReport
|
balanceviewQueryReport
|
||||||
:: ReportOpts
|
:: ReportOpts
|
||||||
-> Day
|
-> Day
|
||||||
|
-> Maybe Day
|
||||||
-> Journal
|
-> Journal
|
||||||
-> String
|
-> String
|
||||||
-> (Journal -> Query)
|
-> (Journal -> Query)
|
||||||
-> ([String], Sum MixedAmount)
|
-> ([String], Sum MixedAmount)
|
||||||
balanceviewQueryReport ropts d j t q = ([view], Sum amt)
|
balanceviewQueryReport ropts currDay reportEnd j t q = ([view], Sum amt)
|
||||||
where
|
where
|
||||||
q' = And [queryFromOpts d (withoutBeginDate ropts), q j]
|
q' = And [queryFromOpts currDay (withoutBeginDate ropts), q j]
|
||||||
rep@(_ , amt) = balanceReport ropts q' j
|
convert | value_ ropts = maybe id (balanceReportValue j) reportEnd
|
||||||
|
| otherwise = id
|
||||||
|
rep@(_ , amt) = convert $ balanceReport ropts q' j
|
||||||
view = intercalate "\n" [t <> ":", balanceReportAsText ropts rep]
|
view = intercalate "\n" [t <> ":", balanceReportAsText ropts rep]
|
||||||
|
|
||||||
balanceviewReport :: BalanceView -> CliOpts -> Journal -> IO ()
|
balanceviewReport :: BalanceView -> CliOpts -> Journal -> IO ()
|
||||||
balanceviewReport BV{..} CliOpts{reportopts_=ropts} j = do
|
balanceviewReport BV{..} CliOpts{reportopts_=ropts} j = do
|
||||||
d <- getCurrentDay
|
currDay <- getCurrentDay
|
||||||
let (views, amt) = foldMap (uncurry (balanceviewQueryReport ropts d j)) bvqueries
|
reportEnd <- reportEndDate j ropts
|
||||||
|
let (views, amt) =
|
||||||
|
foldMap (uncurry (balanceviewQueryReport ropts currDay reportEnd j))
|
||||||
|
bvqueries
|
||||||
mapM_ putStrLn (bvname : "" : views)
|
mapM_ putStrLn (bvname : "" : views)
|
||||||
putStrLn . unlines $
|
|
||||||
|
unless (no_total_ ropts) . putStrLn . unlines $
|
||||||
[ "Total:"
|
[ "Total:"
|
||||||
, "--------------------"
|
, "--------------------"
|
||||||
, padleft 20 $ showMixedAmountWithoutPrice (getSum amt)
|
, padleft 20 $ showMixedAmountWithoutPrice (getSum amt)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user