| 1 |
{-# LANGUAGE QuasiQuotes #-} |
| 2 |
{-# LANGUAGE TemplateHaskell #-} |
| 3 |
{-# LANGUAGE OverloadedStrings #-} |
| 4 |
{-| |
| 5 |
|
| 6 |
The @incomestatement@ command prints a simple income statement (profit & loss report). |
| 7 |
|
| 8 |
-} |
| 9 |
|
| 10 |
module Hledger.Cli.Commands.Incomestatement ( |
| 11 |
incomestatementmode |
| 12 |
,incomestatement |
| 13 |
) where |
| 14 |
|
| 15 |
import System.Console.CmdArgs.Explicit |
| 16 |
|
| 17 |
import Hledger |
| 18 |
import Hledger.Cli.CliOptions |
| 19 |
import Hledger.Cli.CompoundBalanceCommand |
| 20 |
|
| 21 |
incomestatementSpec = CompoundBalanceCommandSpec { |
| 22 |
cbcdoc = $(embedFileRelative "Hledger/Cli/Commands/Incomestatement.txt"), |
| 23 |
cbctitle = "Income Statement", |
| 24 |
cbcqueries = [ |
| 25 |
CBCSubreportSpec{ |
| 26 |
cbcsubreporttitle="Revenues" |
| 27 |
,cbcsubreportquery=Type [Revenue] |
| 28 |
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyNegative}) |
| 29 |
,cbcsubreporttransform=fmap maNegate |
| 30 |
,cbcsubreportincreasestotal=True |
| 31 |
} |
| 32 |
,CBCSubreportSpec{ |
| 33 |
cbcsubreporttitle="Expenses" |
| 34 |
,cbcsubreportquery=Type [Expense] |
| 35 |
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyPositive}) |
| 36 |
,cbcsubreporttransform=id |
| 37 |
,cbcsubreportincreasestotal=False |
| 38 |
} |
| 39 |
], |
| 40 |
cbcaccum = PerPeriod |
| 41 |
} |
| 42 |
|
| 43 |
incomestatementmode :: Mode RawOpts |
| 44 |
incomestatementmode = compoundBalanceCommandMode incomestatementSpec |
| 45 |
|
| 46 |
incomestatement :: CliOpts -> Journal -> IO () |
| 47 |
incomestatement = compoundBalanceCommand incomestatementSpec |
| 48 |
{- |
| 49 |
Summary of code flow, 2021-11: |
| 50 |
|
| 51 |
incomestatement |
| 52 |
compoundBalanceCommand |
| 53 |
compoundBalanceReport |
| 54 |
compoundBalanceReportWith |
| 55 |
colps = getPostingsByColumn |
| 56 |
startps = startingPostings |
| 57 |
generateSubreport |
| 58 |
startbals = startingBalances (startps restricted to this subreport) |
| 59 |
generateMultiBalanceReport startbals (colps restricted to this subreport) |
| 60 |
matrix = calculateReportMatrix startbals colps |
| 61 |
displaynames = displayedAccounts |
| 62 |
buildReportRows displaynames matrix |
| 63 |
-} |
| 64 |
|