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

The @incomestatement@ command prints a simple income statement (profit & loss report).

-}

module Hledger.Cli.Commands.Incomestatement (
  incomestatementmode
 ,incomestatement
) where

import System.Console.CmdArgs.Explicit

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

incomestatementSpec :: CompoundBalanceCommandSpec
incomestatementSpec = CompoundBalanceCommandSpec :: CommandDoc
-> CommandDoc
-> [CBCSubreportSpec DisplayName]
-> BalanceType
-> CompoundBalanceCommandSpec
CompoundBalanceCommandSpec {
  cbcdoc :: CommandDoc
cbcdoc      = $(embedFileRelative "Hledger/Cli/Commands/Incomestatement.txt"),
  cbctitle :: CommandDoc
cbctitle    = CommandDoc
"Income 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
"Revenues"
     ,cbcsubreportquery :: Journal -> Query
cbcsubreportquery=Journal -> Query
journalRevenueAccountQuery
     ,cbcsubreportoptions :: ReportOpts -> ReportOpts
cbcsubreportoptions=(\ReportOpts
ropts -> ReportOpts
ropts{normalbalance_ :: Maybe NormalSign
normalbalance_=NormalSign -> Maybe NormalSign
forall a. a -> Maybe a
Just NormalSign
NormallyNegative})
     ,cbcsubreporttransform :: PeriodicReport DisplayName MixedAmount
-> PeriodicReport DisplayName MixedAmount
cbcsubreporttransform=(MixedAmount -> MixedAmount)
-> PeriodicReport DisplayName MixedAmount
-> PeriodicReport DisplayName MixedAmount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MixedAmount -> MixedAmount
forall a. Num a => a -> a
negate
     ,cbcsubreportincreasestotal :: Bool
cbcsubreportincreasestotal=Bool
True
     }
    ,CBCSubreportSpec :: forall a.
CommandDoc
-> (Journal -> Query)
-> (ReportOpts -> ReportOpts)
-> (PeriodicReport DisplayName MixedAmount
    -> PeriodicReport a MixedAmount)
-> Bool
-> CBCSubreportSpec a
CBCSubreportSpec{
      cbcsubreporttitle :: CommandDoc
cbcsubreporttitle=CommandDoc
"Expenses"
     ,cbcsubreportquery :: Journal -> Query
cbcsubreportquery=Journal -> Query
journalExpenseAccountQuery
     ,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
False
     }
    ],
  cbctype :: BalanceType
cbctype     = BalanceType
PeriodChange
}

incomestatementmode :: Mode RawOpts
incomestatementmode :: Mode RawOpts
incomestatementmode = CompoundBalanceCommandSpec -> Mode RawOpts
compoundBalanceCommandMode CompoundBalanceCommandSpec
incomestatementSpec

incomestatement :: CliOpts -> Journal -> IO ()
incomestatement :: CliOpts -> Journal -> IO ()
incomestatement = CompoundBalanceCommandSpec -> CliOpts -> Journal -> IO ()
compoundBalanceCommand CompoundBalanceCommandSpec
incomestatementSpec