module Hledger.Cli.Cashflow (
cashflow
,tests_Hledger_Cli_Cashflow
) where
import qualified Data.Text.Lazy.IO as LT
import Test.HUnit
import Text.Shakespeare.Text
import Hledger
import Hledger.Cli.Options
import Hledger.Cli.Balance
cashflow :: CliOpts -> Journal -> IO ()
cashflow CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay
let q = queryFromOpts d (withoutBeginDate ropts)
cashreport@(_,total) = accountsReport ropts (And [q, journalCashAccountQuery j]) j
LT.putStr $ [lt|Cashflow Statement
Cash flows:
#{unlines $ accountsReportAsText ropts cashreport}
Total:
#{padleft 20 $ showMixedAmountWithoutPrice total}
|]
withoutBeginDate :: ReportOpts -> ReportOpts
withoutBeginDate ropts@ReportOpts{..} = ropts{begin_=Nothing, period_=p}
where p = case period_ of Nothing -> Nothing
Just (i, DateSpan _ e) -> Just (i, DateSpan Nothing e)
tests_Hledger_Cli_Cashflow = TestList
[
]