{-# LANGUAGE QuasiQuotes, RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-|

The @cashflow@ command prints a simplified cashflow statement.  It just
shows the change in all "cash" accounts for the period (without the
traditional segmentation into operating, investing, and financing
cash flows.)

-}

module Hledger.Cli.Commands.Cashflow (
  cashflowmode
 ,cashflow
) where

import System.Console.CmdArgs.Explicit

import Hledger
import Hledger.Cli.CliOptions
import Hledger.Cli.CompoundBalanceCommand

cashflowSpec :: CompoundBalanceCommandSpec
cashflowSpec = CompoundBalanceCommandSpec :: CommandDoc
-> CommandDoc
-> [CBCSubreportSpec DisplayName]
-> BalanceType
-> CompoundBalanceCommandSpec
CompoundBalanceCommandSpec {
  cbcdoc :: CommandDoc
cbcdoc      = $(embedFileRelative "Hledger/Cli/Commands/Cashflow.txt"),
  cbctitle :: CommandDoc
cbctitle    = CommandDoc
"Cashflow Statement",
  cbcqueries :: [CBCSubreportSpec DisplayName]
cbcqueries  = [
     CBCSubreportSpec :: forall a.
CommandDoc
-> (Journal -> Query)
-> (ReportOpts -> ReportOpts)
-> (PeriodicReport DisplayName MixedAmount
    -> PeriodicReport a MixedAmount)
-> Bool
-> CBCSubreportSpec a
CBCSubreportSpec{
      cbcsubreporttitle :: CommandDoc
cbcsubreporttitle=CommandDoc
"Cash flows"
     ,cbcsubreportquery :: Journal -> Query
cbcsubreportquery=Journal -> Query
journalCashAccountQuery
     ,cbcsubreportoptions :: ReportOpts -> ReportOpts
cbcsubreportoptions=(\ReportOpts
ropts -> ReportOpts
ropts{normalbalance_ :: Maybe NormalSign
normalbalance_= NormalSign -> Maybe NormalSign
forall a. a -> Maybe a
Just NormalSign
NormallyPositive})
     ,cbcsubreporttransform :: PeriodicReport DisplayName MixedAmount
-> PeriodicReport DisplayName MixedAmount
cbcsubreporttransform=PeriodicReport DisplayName MixedAmount
-> PeriodicReport DisplayName MixedAmount
forall a. a -> a
id
     ,cbcsubreportincreasestotal :: Bool
cbcsubreportincreasestotal=Bool
True
     }
    ],
  cbctype :: BalanceType
cbctype     = BalanceType
PeriodChange
}

cashflowmode :: Mode RawOpts
cashflowmode :: Mode RawOpts
cashflowmode = CompoundBalanceCommandSpec -> Mode RawOpts
compoundBalanceCommandMode CompoundBalanceCommandSpec
cashflowSpec

cashflow :: CliOpts -> Journal -> IO ()
cashflow :: CliOpts -> Journal -> IO ()
cashflow = CompoundBalanceCommandSpec -> CliOpts -> Journal -> IO ()
compoundBalanceCommand CompoundBalanceCommandSpec
cashflowSpec