; lib: drop the Maybe from SummaryPosting
This commit is contained in:
parent
e97a9c4bfa
commit
ad83919c6a
@ -58,6 +58,12 @@ type PostingsReportItem = (Maybe Day -- The posting date, if this is the firs
|
|||||||
-- the running total/average.
|
-- the running total/average.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
-- | A summary posting summarises the activity in one account within a report
|
||||||
|
-- interval. It is kludgily represented by a regular Posting with no description,
|
||||||
|
-- the interval's start date stored as the posting date, and the interval's end
|
||||||
|
-- date attached with a tuple.
|
||||||
|
type SummaryPosting = (Posting, Day)
|
||||||
|
|
||||||
-- | Select postings from the journal and add running balance and other
|
-- | Select postings from the journal and add running balance and other
|
||||||
-- information to make a postings report. Used by eg hledger's register command.
|
-- information to make a postings report. Used by eg hledger's register command.
|
||||||
postingsReport :: ReportOpts -> Query -> Journal -> PostingsReport
|
postingsReport :: ReportOpts -> Query -> Journal -> PostingsReport
|
||||||
@ -90,22 +96,21 @@ postingsReport ropts@ReportOpts{..} q j@Journal{..} =
|
|||||||
|
|
||||||
multiperiod = interval_ /= NoInterval
|
multiperiod = interval_ /= NoInterval
|
||||||
|
|
||||||
-- Postings or summary pseudo postings to be displayed.
|
-- Postings, or summary postings along with their subperiod's end date, to be displayed.
|
||||||
displayps =
|
displayps :: [(Posting, Maybe Day)] =
|
||||||
if multiperiod then
|
if multiperiod then
|
||||||
let
|
let
|
||||||
showempty = empty_ || average_
|
showempty = empty_ || average_
|
||||||
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan reportps
|
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan reportps
|
||||||
summarypsendvalue = [(postingValue prices periodlastday p, periodend) | (p,periodend) <- summaryps
|
summaryps' = [(p, Just e) | (p,e) <- summaryps]
|
||||||
,let periodlastday = maybe
|
summarypsendvalue = [ (postingValue prices periodlastday p, Just periodend)
|
||||||
(error' "postingsReport: expected a subperiod end date") -- XXX shouldn't happen
|
| (p,periodend) <- summaryps
|
||||||
(addDays (-1))
|
, let periodlastday = addDays (-1) periodend
|
||||||
periodend
|
|
||||||
]
|
]
|
||||||
summarypsdatevalue d = [(postingValue prices d p, periodend) | (p,periodend) <- summaryps]
|
summarypsdatevalue d = [(postingValue prices d p, Just periodend) | (p,periodend) <- summaryps]
|
||||||
in case value_ of
|
in case value_ of
|
||||||
Nothing -> summaryps
|
Nothing -> summaryps'
|
||||||
Just (AtCost _mc) -> summaryps -- conversion to cost was done earlier
|
Just (AtCost _mc) -> summaryps' -- conversion to cost was done earlier
|
||||||
Just (AtEnd _mc) -> summarypsendvalue
|
Just (AtEnd _mc) -> summarypsendvalue
|
||||||
Just (AtNow _mc) -> summarypsdatevalue today
|
Just (AtNow _mc) -> summarypsdatevalue today
|
||||||
Just (AtDefault _mc) | multiperiod -> summarypsendvalue
|
Just (AtDefault _mc) | multiperiod -> summarypsendvalue
|
||||||
@ -257,12 +262,6 @@ summarisePostingsByInterval interval wd depth showempty reportspan ps = concatMa
|
|||||||
summarisespan s = summarisePostingsInDateSpan s wd depth showempty (postingsinspan s)
|
summarisespan s = summarisePostingsInDateSpan s wd depth showempty (postingsinspan s)
|
||||||
postingsinspan s = filter (isPostingInDateSpan' wd s) ps
|
postingsinspan s = filter (isPostingInDateSpan' wd s) ps
|
||||||
|
|
||||||
-- | A summary posting summarises the activity in one account within a report
|
|
||||||
-- interval. It is currently kludgily represented by a regular Posting with no
|
|
||||||
-- description, the interval's start date stored as the posting date, and the
|
|
||||||
-- interval's end date attached with a tuple.
|
|
||||||
type SummaryPosting = (Posting, Maybe Day)
|
|
||||||
|
|
||||||
-- | Given a date span (representing a report interval) and a list of
|
-- | Given a date span (representing a report interval) and a list of
|
||||||
-- postings within it, aggregate the postings into one summary posting per
|
-- postings within it, aggregate the postings into one summary posting per
|
||||||
-- account. Each summary posting will have a non-Nothing interval end date.
|
-- account. Each summary posting will have a non-Nothing interval end date.
|
||||||
@ -278,7 +277,7 @@ type SummaryPosting = (Posting, Maybe Day)
|
|||||||
summarisePostingsInDateSpan :: DateSpan -> WhichDate -> Int -> Bool -> [Posting] -> [SummaryPosting]
|
summarisePostingsInDateSpan :: DateSpan -> WhichDate -> Int -> Bool -> [Posting] -> [SummaryPosting]
|
||||||
summarisePostingsInDateSpan (DateSpan b e) wd depth showempty ps
|
summarisePostingsInDateSpan (DateSpan b e) wd depth showempty ps
|
||||||
| null ps && (isNothing b || isNothing e) = []
|
| null ps && (isNothing b || isNothing e) = []
|
||||||
| null ps && showempty = [(summaryp, Just e')]
|
| null ps && showempty = [(summaryp, e')]
|
||||||
| otherwise = summarypes
|
| otherwise = summarypes
|
||||||
where
|
where
|
||||||
postingdate = if wd == PrimaryDate then postingDate else postingDate2
|
postingdate = if wd == PrimaryDate then postingDate else postingDate2
|
||||||
@ -289,7 +288,7 @@ summarisePostingsInDateSpan (DateSpan b e) wd depth showempty ps
|
|||||||
| otherwise = ["..."]
|
| otherwise = ["..."]
|
||||||
summaryps | depth > 0 = [summaryp{paccount=a,pamount=balance a} | a <- clippedanames]
|
summaryps | depth > 0 = [summaryp{paccount=a,pamount=balance a} | a <- clippedanames]
|
||||||
| otherwise = [summaryp{paccount="...",pamount=sum $ map pamount ps}]
|
| otherwise = [summaryp{paccount="...",pamount=sum $ map pamount ps}]
|
||||||
summarypes = map (, Just e') $ (if showempty then id else filter (not . isZeroMixedAmount . pamount)) summaryps
|
summarypes = map (, e') $ (if showempty then id else filter (not . isZeroMixedAmount . pamount)) summaryps
|
||||||
anames = sort $ nub $ map paccount ps
|
anames = sort $ nub $ map paccount ps
|
||||||
-- aggregate balances by account, like ledgerFromJournal, then do depth-clipping
|
-- aggregate balances by account, like ledgerFromJournal, then do depth-clipping
|
||||||
accts = accountsFromPostings ps
|
accts = accountsFromPostings ps
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user