budget: only periodic txns with the selected interval are used
This commit is contained in:
parent
6f8714cdbd
commit
083d9190fd
@ -16,6 +16,7 @@ module Hledger.Data.AutoTransaction
|
|||||||
-- * Accessors
|
-- * Accessors
|
||||||
, mtvaluequery
|
, mtvaluequery
|
||||||
, jdatespan
|
, jdatespan
|
||||||
|
, periodTransactionInterval
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@ -260,3 +261,14 @@ runPeriodicTransaction pt = generate where
|
|||||||
in
|
in
|
||||||
if d == firstDate then (i,s)
|
if d == firstDate then (i,s)
|
||||||
else error' $ "Unable to generate transactions according to "++(show periodExpr)++" as "++(show d)++" is not a first day of the "++x
|
else error' $ "Unable to generate transactions according to "++(show periodExpr)++" as "++(show d)++" is not a first day of the "++x
|
||||||
|
|
||||||
|
-- | What is the interval of this 'PeriodicTransaction's period expression, if it can be parsed ?
|
||||||
|
periodTransactionInterval :: PeriodicTransaction -> Maybe Interval
|
||||||
|
periodTransactionInterval pt =
|
||||||
|
let
|
||||||
|
expr = ptperiodicexpr pt
|
||||||
|
err = error' $ "Current date cannot be referenced in " ++ show (T.unpack expr)
|
||||||
|
in
|
||||||
|
case parsePeriodExpr err expr of
|
||||||
|
Left _ -> Nothing
|
||||||
|
Right (i,_) -> Just i
|
||||||
|
|||||||
@ -19,6 +19,7 @@ module Hledger.Reports.ReportOptions (
|
|||||||
simplifyStatuses,
|
simplifyStatuses,
|
||||||
whichDateFromOpts,
|
whichDateFromOpts,
|
||||||
journalSelectingAmountFromOpts,
|
journalSelectingAmountFromOpts,
|
||||||
|
intervalFromRawOpts,
|
||||||
queryFromOpts,
|
queryFromOpts,
|
||||||
queryFromOptsOnly,
|
queryFromOptsOnly,
|
||||||
queryOptsFromOpts,
|
queryOptsFromOpts,
|
||||||
|
|||||||
@ -368,14 +368,21 @@ budgetRollUp CliOpts{rawopts_=rawopts} budget j = j { jtxns = remapTxn <$> jtxns
|
|||||||
remapTxn = mapPostings (map remapPosting)
|
remapTxn = mapPostings (map remapPosting)
|
||||||
mapPostings f t = txnTieKnot $ t { tpostings = f $ tpostings t }
|
mapPostings f t = txnTieKnot $ t { tpostings = f $ tpostings t }
|
||||||
|
|
||||||
-- | Generate journal of all periodic transactions in the given journal for the
|
-- | Select all periodic transactions from the given journal which
|
||||||
-- entirety of its history or reporting period, whatever is smaller.
|
-- match the opts-specified report interval, and use them to generate
|
||||||
|
-- budget transactions (like forecast transactions) in the specified
|
||||||
|
-- report period.
|
||||||
budgetJournal :: CliOpts -> Journal -> Journal
|
budgetJournal :: CliOpts -> Journal -> Journal
|
||||||
budgetJournal opts j = journalBalanceTransactions' opts j { jtxns = budget }
|
budgetJournal opts j = journalBalanceTransactions' opts j { jtxns = budgetts }
|
||||||
where
|
where
|
||||||
dates = spanIntersect (jdatespan j) (periodAsDateSpan $ period_ $ reportopts_ opts)
|
interval = intervalFromRawOpts $ rawopts_ opts
|
||||||
budget = [makeBudget t | pt <- jperiodictxns j, t <- runPeriodicTransaction pt dates]
|
dates = spanIntersect (jdatespan j) (periodAsDateSpan $ period_ $ reportopts_ opts)
|
||||||
makeBudget t = txnTieKnot $ t { tdescription = T.pack "Budget transaction" }
|
budgetts = [makeBudgetTxn t
|
||||||
|
| pt <- jperiodictxns j
|
||||||
|
, periodTransactionInterval pt == Just interval
|
||||||
|
, t <- runPeriodicTransaction pt dates
|
||||||
|
]
|
||||||
|
makeBudgetTxn t = txnTieKnot $ t { tdescription = T.pack "Budget transaction" }
|
||||||
journalBalanceTransactions' opts j =
|
journalBalanceTransactions' opts j =
|
||||||
let assrt = not . ignore_assertions_ $ inputopts_ opts
|
let assrt = not . ignore_assertions_ $ inputopts_ opts
|
||||||
in
|
in
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user