;bin:report1: cleanups

This commit is contained in:
Simon Michael 2023-10-23 19:33:41 +01:00
parent efc87d9c0d
commit 24ce9b5be1
2 changed files with 11 additions and 2 deletions

View File

@ -5,8 +5,8 @@
-- -- (use a released hledger from stackage)
-- A custom compound report - like incomestatement but with different,
-- customisable subheadings/subreports. More verbose and haskelly but
-- also more robust and powerful than hledger-report1.sh.
-- customisable subheadings/subreports. More verbose and haskelly than
-- hledger-report1.sh but also more robust and powerful.
{-# LANGUAGE OverloadedStrings, PackageImports #-}
@ -24,6 +24,7 @@ cmdmode = hledgerCommandMode (unlines
main = do
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts cmdmode
withJournalDo opts $ flip compoundBalanceCommand opts $
-- 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 {
@ -31,6 +32,7 @@ main = do
cbctitle = "Report1 Statement",
cbcaccum = PerPeriod,
cbcqueries = [
CBCSubreportSpec{
cbcsubreporttitle="Revenues"
,cbcsubreportquery=Type [Revenue]
@ -38,6 +40,7 @@ main = do
,cbcsubreporttransform=fmap maNegate
,cbcsubreportincreasestotal=True
}
,CBCSubreportSpec{
cbcsubreporttitle="Operating Expenses"
,cbcsubreportquery=And [Type [Expense], Acct $ toRegex' "Operating"]
@ -45,6 +48,7 @@ main = do
,cbcsubreporttransform=id
,cbcsubreportincreasestotal=False
}
,CBCSubreportSpec{
cbcsubreporttitle="Other Expenses"
,cbcsubreportquery=And [Type [Expense], Not $ Acct $ toRegex' "Operating"]
@ -53,4 +57,5 @@ main = do
,cbcsubreportincreasestotal=False
}
]
}

View File

@ -4,11 +4,15 @@
# See also hledger-report1.hs.
echo "Report1 Statement $(date +%Y-%m-%d)"
printf "\nRevenues\n"
hledger bal expr:"type:r and $@" | tail +2
printf "\nOperating Expenses\n"
hledger bal expr:"type:x and operating and $@" | tail +2
printf "\nOther expenses\n"
hledger bal expr:"type:x and not:operating and $@" | tail +2
printf "\nGrand Total\n"
hledger bal expr:"type:rx and $@" | tail -1