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

View File

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