bin: Update bin scripts for current hledger-lib.

(cherry picked from commit bc4aef17b7fa13ec0754b93325e1c5e5ee04f1e7)
This commit is contained in:
Stephen Morgan 2020-12-30 17:59:12 +11:00 committed by Simon Michael
parent 06b466d847
commit a64d1aa6d0
6 changed files with 28 additions and 29 deletions

View File

@ -31,13 +31,13 @@ main = do
args <- getArgs
let report1args = takeWhile (/= "--") args
let report2args = drop 1 $ dropWhile (/= "--") args
(_,report1) <- mbReport report1args
(ropts2,report2) <- mbReport report2args
let pastAsBudget = combineBudgetAndActual report1{prDates=prDates report2} report2
(_,_,report1) <- mbReport report1args
(ropts2,j,report2) <- mbReport report2args
let pastAsBudget = combineBudgetAndActual ropts2 j report1{prDates=prDates report2} report2
putStrLn $ budgetReportAsText ropts2 pastAsBudget
where
mbReport args = do
opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts' cmdmode args
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
d <- getCurrentDay
report <- withJournalDo opts (return . multiBalanceReport d ropts)
return (ropts,report)
(report,j) <- withJournalDo opts $ \j -> return (multiBalanceReport rspec j, j)
return (rsOpts rspec,j,report)

View File

@ -335,7 +335,7 @@ data Opts = Opts
, assertionsAlways :: [(String, Predicate)]
-- ^ Account assertions that must hold after each txn.
}
deriving (Eq, Ord, Show)
deriving (Show)
-- | Command-line arguments.
args :: ParserInfo Opts

View File

@ -14,23 +14,22 @@ appendReports :: MultiBalanceReport -> MultiBalanceReport -> MultiBalanceReport
appendReports r1 r2 =
PeriodicReport
{ prDates = prDates r1 ++ prDates r2
, prRows = map snd $ M.toAscList mergedRows
, prRows = map snd $ M.toAscList mergedRows
, prTotals = mergeRows (prTotals r1) (prTotals r2)
}
where
rowsByAcct report = M.fromList $ map (\r -> (prrName r, r)) (prRows report)
r1map = rowsByAcct r1
r2map = rowsByAcct r2
mergedRows = merge (mapMissing left) (mapMissing right) (zipWithMatched both) r1map r2map
left _ row = row{prrAmounts = prrAmounts row ++ [nullmixedamt]}
right _ row = row{prrAmounts = nullmixedamt:(prrAmounts row) }
both _ = mergeRows
-- name/depth in the second row would be the same by contruction
mergeRows (PeriodicReportRow name depth amt1 tot1 avg1) (PeriodicReportRow _ _ amt2 tot2 avg2) =
mergeRows (PeriodicReportRow name amt1 tot1 avg1) (PeriodicReportRow _ amt2 tot2 avg2) =
PeriodicReportRow { prrName = name
, prrDepth = depth
, prrAmounts = amt1++amt2
, prrTotal = tot1+tot2
, prrAverage = averageMixedAmounts [avg1,avg2]
@ -61,12 +60,11 @@ main = do
let report1args = takeWhile (/= "--") args
let report2args = drop 1 $ dropWhile (/= "--") args
(_,report1) <- mbReport report1args
(ropts2,report2) <- mbReport report2args
(rspec2,report2) <- mbReport report2args
let merged = appendReports report1 report2
putStrLn $ multiBalanceReportAsText ropts2 merged
putStrLn $ multiBalanceReportAsText (rsOpts rspec2) merged
where
mbReport args = do
opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts' cmdmode args
d <- getCurrentDay
report <- withJournalDo opts (return . multiBalanceReport d ropts)
return (ropts,report)
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
report <- withJournalDo opts (return . multiBalanceReport rspec)
return (rspec,report)

View File

@ -51,22 +51,22 @@ _FLAGS
main :: IO ()
main = do
copts@CliOpts{reportopts_=ropts, rawopts_} <- getHledgerCliOpts cmdmode
let copts' = copts{
copts@CliOpts{reportspec_=rspec, rawopts_} <- getHledgerCliOpts cmdmode
let ropts = rsOpts rspec
copts' = copts{
-- One of our postings will probably have a missing amount; this ensures it's
-- explicit on all the others.
rawopts_=setboolopt "explicit" rawopts_
rawopts_ = setboolopt "explicit" rawopts_
-- Don't let our ACCT argument be interpreted as a query by print
,reportopts_=ropts{query_=""}
,reportspec_ = rspec{rsOpts=ropts{querystring_=[]}}
}
withJournalDo copts' $ \j -> do
today <- getCurrentDay
let
menddate = reportPeriodLastDay ropts
args = words' $ query_ ropts
q = queryFromOpts today ropts
acct = T.pack $ headDef (error' "Please provide an account name argument") args
pr = postingsReport ropts (And [Acct $ accountNameToAccountRegexCI acct, q]) j
menddate = reportPeriodLastDay rspec
q = rsQuery rspec
acct = headDef (error' "Please provide an account name argument") $ querystring_ ropts
pr = postingsReport rspec{rsQuery = And [Acct $ accountNameToAccountRegexCI acct, q]} j
-- dates of postings to acct (in report)
pdates = map (postingDate . fourth5) (snd pr)

View File

@ -25,13 +25,13 @@ _FLAGS
main :: IO ()
main = do
opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts cmdmode
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts cmdmode
withJournalDo opts $
\j -> do
d <- getCurrentDay
let
q = queryFromOpts d ropts
ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j
q = rsQuery rspec
ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts (rsOpts rspec) j
ts' = map transactionSwapDates ts
mapM_ (putStrLn . showTransaction) ts'

View File

@ -21,6 +21,7 @@ module Hledger.Reports.BudgetReport (
budgetReportAsCsv,
-- * Helpers
reportPeriodName,
combineBudgetAndActual,
-- * Tests
tests_BudgetReport
)