hledger/bin/hledger-report1.hs

62 lines
2.4 KiB
Haskell
Raw Normal View History

#!/usr/bin/env stack
-- stack runghc --verbosity error --package hledger --package hledger-lib --package text --package safe
2023-10-23 21:29:32 +03:00
-- (use the local hledger source)
-- -- stack script --compile --resolver nightly-2023-10-13 --verbosity info --package hledger --package text
2023-10-23 21:29:32 +03:00
-- -- (use a released hledger from stackage)
2023-10-23 21:29:32 +03:00
-- A custom compound report - like incomestatement but with different,
2023-10-23 21:33:41 +03:00
-- customisable subheadings/subreports. More verbose and haskelly than
-- hledger-report1.sh but also more robust and powerful.
{-# LANGUAGE OverloadedStrings, PackageImports #-}
import Hledger.Cli.Script
import qualified "text" Data.Text as T
import qualified "text" Data.Text.IO as T
cmdmode = hledgerCommandMode (unlines
["report1"
,"A custom compound report - like the incomestatement command but easier to customise."
,"Usage: hledger-report1 [OPTS] [ARGS]"
,"or: hledger report1 -- [OPTS] [ARGS]"
]) [] [generalflagsgroup1] [] ([], Just $ argsFlag "[ARGS]")
main = do
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts cmdmode
withJournalDo opts $ flip compoundBalanceCommand opts $
2023-10-23 21:33:41 +03:00
-- see https://hackage.haskell.org/package/hledger/docs/Hledger-Cli-CompoundBalanceCommand.html
-- and https://hackage.haskell.org/package/hledger-lib-1.31/docs/Hledger-Query.html
CompoundBalanceCommandSpec {
2023-10-23 21:29:32 +03:00
cbcdoc = "report1 help text",
cbctitle = "Report1 Statement",
cbcaccum = PerPeriod,
cbcqueries = [
2023-10-23 21:33:41 +03:00
CBCSubreportSpec{
2023-10-23 21:29:32 +03:00
cbcsubreporttitle="Revenues"
,cbcsubreportquery=Type [Revenue]
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyNegative})
,cbcsubreporttransform=fmap maNegate
,cbcsubreportincreasestotal=True
}
2023-10-23 21:33:41 +03:00
,CBCSubreportSpec{
2023-10-23 21:29:32 +03:00
cbcsubreporttitle="Operating Expenses"
,cbcsubreportquery=And [Type [Expense], Acct $ toRegex' "Operating"]
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyPositive})
,cbcsubreporttransform=id
,cbcsubreportincreasestotal=False
}
2023-10-23 21:33:41 +03:00
,CBCSubreportSpec{
2023-10-23 21:29:32 +03:00
cbcsubreporttitle="Other Expenses"
,cbcsubreportquery=And [Type [Expense], Not $ Acct $ toRegex' "Operating"]
,cbcsubreportoptions=(\ropts -> ropts{normalbalance_=Just NormallyPositive})
,cbcsubreporttransform=id
,cbcsubreportincreasestotal=False
}
]
2023-10-23 21:33:41 +03:00
}