balance: support --date2 in multicolumn reports (cf #174)
This commit is contained in:
parent
d4993092fb
commit
a761ae5b86
@ -28,6 +28,7 @@ module Hledger.Data.Posting (
|
||||
isPostingInDateSpan,
|
||||
isPostingInDateSpan',
|
||||
postingsDateSpan,
|
||||
postingsDateSpan',
|
||||
-- * account name operations
|
||||
accountNamesFromPostings,
|
||||
accountNamePostingType,
|
||||
@ -176,6 +177,14 @@ postingsDateSpan [] = DateSpan Nothing Nothing
|
||||
postingsDateSpan ps = DateSpan (Just $ postingDate $ head ps') (Just $ addDays 1 $ postingDate $ last ps')
|
||||
where ps' = sortBy (comparing postingDate) ps
|
||||
|
||||
-- --date2-sensitive version, as above.
|
||||
postingsDateSpan' :: WhichDate -> [Posting] -> DateSpan
|
||||
postingsDateSpan' wd [] = DateSpan Nothing Nothing
|
||||
postingsDateSpan' wd ps = DateSpan (Just $ postingdate $ head ps') (Just $ addDays 1 $ postingdate $ last ps')
|
||||
where
|
||||
ps' = sortBy (comparing postingdate) ps
|
||||
postingdate = if wd == PrimaryDate then postingDate else postingDate2
|
||||
|
||||
-- AccountName stuff that depends on PostingType
|
||||
|
||||
accountNamePostingType :: AccountName -> PostingType
|
||||
|
||||
@ -89,7 +89,7 @@ multiBalanceReport opts q j = MultiBalanceReport (spans, items, totals)
|
||||
where
|
||||
requestedspan = queryDateSpan (date2_ opts) q -- based on -b/-e/-p opts and query args IIRC
|
||||
journalspan = journalDateSpan j
|
||||
matchedspan = postingsDateSpan ps
|
||||
matchedspan = postingsDateSpan' (whichDateFromOpts opts) ps
|
||||
spans :: [DateSpan] =
|
||||
dbg "spans" $
|
||||
splitSpan (intervalFromOpts opts) reportspan
|
||||
@ -97,7 +97,7 @@ multiBalanceReport opts q j = MultiBalanceReport (spans, items, totals)
|
||||
|
||||
psPerSpan :: [[Posting]] =
|
||||
dbg "psPerSpan" $
|
||||
[filter (isPostingInDateSpan s) ps | s <- spans]
|
||||
[filter (isPostingInDateSpan' (whichDateFromOpts opts) s) ps | s <- spans]
|
||||
|
||||
postedAcctBalChangesPerSpan :: [[(ClippedAccountName, MixedAmount)]] =
|
||||
dbg "postedAcctBalChangesPerSpan" $
|
||||
|
||||
@ -237,3 +237,23 @@ Ending balance (historical):
|
||||
|
||||
>>>=0
|
||||
|
||||
# 17. --date2 should work
|
||||
hledgerdev -f- balance --monthly --date2
|
||||
<<<
|
||||
2014/1/1
|
||||
(a) 1
|
||||
|
||||
2014/2/1=2014/1/31
|
||||
(b) 1
|
||||
|
||||
>>>
|
||||
Change of balance (flow):
|
||||
|
||||
|| 2014/01/01-2014/01/31
|
||||
===++========================
|
||||
a || 1
|
||||
b || 1
|
||||
---++------------------------
|
||||
|| 2
|
||||
|
||||
>>>=0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user