mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-14 02:14:14 +03:00
bin: Update bin scripts for current hledger-lib.
(cherry picked from commit bc4aef17b7fa13ec0754b93325e1c5e5ee04f1e7)
This commit is contained in:
parent
06b466d847
commit
a64d1aa6d0
@ -31,13 +31,13 @@ main = do
|
|||||||
args <- getArgs
|
args <- getArgs
|
||||||
let report1args = takeWhile (/= "--") args
|
let report1args = takeWhile (/= "--") args
|
||||||
let report2args = drop 1 $ dropWhile (/= "--") args
|
let report2args = drop 1 $ dropWhile (/= "--") args
|
||||||
(_,report1) <- mbReport report1args
|
(_,_,report1) <- mbReport report1args
|
||||||
(ropts2,report2) <- mbReport report2args
|
(ropts2,j,report2) <- mbReport report2args
|
||||||
let pastAsBudget = combineBudgetAndActual report1{prDates=prDates report2} report2
|
let pastAsBudget = combineBudgetAndActual ropts2 j report1{prDates=prDates report2} report2
|
||||||
putStrLn $ budgetReportAsText ropts2 pastAsBudget
|
putStrLn $ budgetReportAsText ropts2 pastAsBudget
|
||||||
where
|
where
|
||||||
mbReport args = do
|
mbReport args = do
|
||||||
opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts' cmdmode args
|
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
report <- withJournalDo opts (return . multiBalanceReport d ropts)
|
(report,j) <- withJournalDo opts $ \j -> return (multiBalanceReport rspec j, j)
|
||||||
return (ropts,report)
|
return (rsOpts rspec,j,report)
|
||||||
|
@ -335,7 +335,7 @@ data Opts = Opts
|
|||||||
, assertionsAlways :: [(String, Predicate)]
|
, assertionsAlways :: [(String, Predicate)]
|
||||||
-- ^ Account assertions that must hold after each txn.
|
-- ^ Account assertions that must hold after each txn.
|
||||||
}
|
}
|
||||||
deriving (Eq, Ord, Show)
|
deriving (Show)
|
||||||
|
|
||||||
-- | Command-line arguments.
|
-- | Command-line arguments.
|
||||||
args :: ParserInfo Opts
|
args :: ParserInfo Opts
|
||||||
|
@ -28,9 +28,8 @@ appendReports r1 r2 =
|
|||||||
both _ = mergeRows
|
both _ = mergeRows
|
||||||
|
|
||||||
-- name/depth in the second row would be the same by contruction
|
-- 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
|
PeriodicReportRow { prrName = name
|
||||||
, prrDepth = depth
|
|
||||||
, prrAmounts = amt1++amt2
|
, prrAmounts = amt1++amt2
|
||||||
, prrTotal = tot1+tot2
|
, prrTotal = tot1+tot2
|
||||||
, prrAverage = averageMixedAmounts [avg1,avg2]
|
, prrAverage = averageMixedAmounts [avg1,avg2]
|
||||||
@ -61,12 +60,11 @@ main = do
|
|||||||
let report1args = takeWhile (/= "--") args
|
let report1args = takeWhile (/= "--") args
|
||||||
let report2args = drop 1 $ dropWhile (/= "--") args
|
let report2args = drop 1 $ dropWhile (/= "--") args
|
||||||
(_,report1) <- mbReport report1args
|
(_,report1) <- mbReport report1args
|
||||||
(ropts2,report2) <- mbReport report2args
|
(rspec2,report2) <- mbReport report2args
|
||||||
let merged = appendReports report1 report2
|
let merged = appendReports report1 report2
|
||||||
putStrLn $ multiBalanceReportAsText ropts2 merged
|
putStrLn $ multiBalanceReportAsText (rsOpts rspec2) merged
|
||||||
where
|
where
|
||||||
mbReport args = do
|
mbReport args = do
|
||||||
opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts' cmdmode args
|
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
|
||||||
d <- getCurrentDay
|
report <- withJournalDo opts (return . multiBalanceReport rspec)
|
||||||
report <- withJournalDo opts (return . multiBalanceReport d ropts)
|
return (rspec,report)
|
||||||
return (ropts,report)
|
|
||||||
|
@ -51,22 +51,22 @@ _FLAGS
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
copts@CliOpts{reportopts_=ropts, rawopts_} <- getHledgerCliOpts cmdmode
|
copts@CliOpts{reportspec_=rspec, rawopts_} <- getHledgerCliOpts cmdmode
|
||||||
let copts' = copts{
|
let ropts = rsOpts rspec
|
||||||
|
copts' = copts{
|
||||||
-- One of our postings will probably have a missing amount; this ensures it's
|
-- One of our postings will probably have a missing amount; this ensures it's
|
||||||
-- explicit on all the others.
|
-- 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
|
-- 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
|
withJournalDo copts' $ \j -> do
|
||||||
today <- getCurrentDay
|
today <- getCurrentDay
|
||||||
let
|
let
|
||||||
menddate = reportPeriodLastDay ropts
|
menddate = reportPeriodLastDay rspec
|
||||||
args = words' $ query_ ropts
|
q = rsQuery rspec
|
||||||
q = queryFromOpts today ropts
|
acct = headDef (error' "Please provide an account name argument") $ querystring_ ropts
|
||||||
acct = T.pack $ headDef (error' "Please provide an account name argument") args
|
pr = postingsReport rspec{rsQuery = And [Acct $ accountNameToAccountRegexCI acct, q]} j
|
||||||
pr = postingsReport ropts (And [Acct $ accountNameToAccountRegexCI acct, q]) j
|
|
||||||
|
|
||||||
-- dates of postings to acct (in report)
|
-- dates of postings to acct (in report)
|
||||||
pdates = map (postingDate . fourth5) (snd pr)
|
pdates = map (postingDate . fourth5) (snd pr)
|
||||||
|
@ -25,13 +25,13 @@ _FLAGS
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts cmdmode
|
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts cmdmode
|
||||||
withJournalDo opts $
|
withJournalDo opts $
|
||||||
\j -> do
|
\j -> do
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
let
|
let
|
||||||
q = queryFromOpts d ropts
|
q = rsQuery rspec
|
||||||
ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j
|
ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts (rsOpts rspec) j
|
||||||
ts' = map transactionSwapDates ts
|
ts' = map transactionSwapDates ts
|
||||||
mapM_ (putStrLn . showTransaction) ts'
|
mapM_ (putStrLn . showTransaction) ts'
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ module Hledger.Reports.BudgetReport (
|
|||||||
budgetReportAsCsv,
|
budgetReportAsCsv,
|
||||||
-- * Helpers
|
-- * Helpers
|
||||||
reportPeriodName,
|
reportPeriodName,
|
||||||
|
combineBudgetAndActual,
|
||||||
-- * Tests
|
-- * Tests
|
||||||
tests_BudgetReport
|
tests_BudgetReport
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user