This replaces the old journal*AccountQuery with the new Type query. This enables uniform treatment of account type, and fixes a subtle bug (#1921). Note that cbcsubreportquery no longer takes Journal as an argument.
63 lines
1.8 KiB
Haskell
63 lines
1.8 KiB
Haskell
{-# 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 {
|
|
cbcdoc = $(embedFileRelative "Hledger/Cli/Commands/Incomestatement.txt"),
|
|
cbctitle = "Income Statement",
|
|
cbcqueries = [
|
|
CBCSubreportSpec{
|
|
cbcsubreporttitle="Revenues"
|
|
,cbcsubreportquery=Type [Revenue]
|
|
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyNegative})
|
|
,cbcsubreporttransform=fmap maNegate
|
|
,cbcsubreportincreasestotal=True
|
|
}
|
|
,CBCSubreportSpec{
|
|
cbcsubreporttitle="Expenses"
|
|
,cbcsubreportquery=Type [Expense]
|
|
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyPositive})
|
|
,cbcsubreporttransform=id
|
|
,cbcsubreportincreasestotal=False
|
|
}
|
|
],
|
|
cbcaccum = PerPeriod
|
|
}
|
|
|
|
incomestatementmode :: Mode RawOpts
|
|
incomestatementmode = compoundBalanceCommandMode incomestatementSpec
|
|
|
|
incomestatement :: CliOpts -> Journal -> IO ()
|
|
incomestatement = compoundBalanceCommand incomestatementSpec
|
|
{-
|
|
Summary of code flow, 2021-11:
|
|
|
|
incomestatement
|
|
compoundBalanceCommand
|
|
compoundBalanceReport
|
|
compoundBalanceReportWith
|
|
colps = getPostingsByColumn
|
|
startps = startingPostings
|
|
generateSubreport
|
|
startbals = startingBalances (startps restricted to this subreport)
|
|
generateMultiBalanceReport startbals (colps restricted to this subreport)
|
|
matrix = calculateReportMatrix startbals colps
|
|
displaynames = displayedAccounts
|
|
buildReportRows displaynames matrix
|
|
-}
|
|
|