{-# LANGUAGE LambdaCase        #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes       #-}
{-# LANGUAGE 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
 ,cashflowSpec
) where

import System.Console.CmdArgs.Explicit

import Hledger.Utils.I18n (i18n)
import Hledger
import Hledger.Cli.CliOptions
import Hledger.Cli.CompoundBalanceCommand

cashflowSpec :: CompoundBalanceCommandSpec
cashflowSpec :: CompoundBalanceCommandSpec
cashflowSpec = CompoundBalanceCommandSpec {
  cbcdoc :: CommandHelpStr
cbcdoc      = $(embedFileRelative "Hledger/Cli/Commands/Cashflow.txt"),
  -- TRANSLATORS: the report title, with its reporting interval if any. Each is a
  -- whole phrase, so put the words in the order and form your language needs.
  cbctitle :: Interval -> Text
cbctitle    = \case
    Interval
NoInterval -> Text -> Text
i18n Text
"Cashflow Statement"
    Days Int
1     -> Text -> Text
i18n Text
"Daily Cashflow Statement"
    Weeks Int
1    -> Text -> Text
i18n Text
"Weekly Cashflow Statement"
    Weeks Int
2    -> Text -> Text
i18n Text
"Biweekly Cashflow Statement"
    Months Int
1   -> Text -> Text
i18n Text
"Monthly Cashflow Statement"
    Months Int
2   -> Text -> Text
i18n Text
"Bimonthly Cashflow Statement"
    Months Int
3   -> Text -> Text
i18n Text
"Quarterly Cashflow Statement"
    Months Int
6   -> Text -> Text
i18n Text
"Half-yearly Cashflow Statement"
    Years Int
1    -> Text -> Text
i18n Text
"Yearly Cashflow Statement"
    Years Int
2    -> Text -> Text
i18n Text
"Biennial Cashflow Statement"
    Interval
_          -> Text -> Text
i18n Text
"Periodic Cashflow Statement",
  cbcqueries :: [CBCSubreportSpec DisplayName]
cbcqueries  = [
     CBCSubreportSpec{
      cbcsubreporttitle :: Text
cbcsubreporttitle=Text -> Text
i18n Text
"Cash flows"
     ,cbcsubreportquery :: Query
cbcsubreportquery=[AccountType] -> Query
Type [AccountType
Cash]
     ,cbcsubreportoptions :: ReportOpts -> ReportOpts
cbcsubreportoptions=(\ReportOpts
ropts -> ReportOpts
ropts{normalbalance_= Just 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
     }
    ],
  cbcaccum :: BalanceAccumulation
cbcaccum     = BalanceAccumulation
PerPeriod
}

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