ref!: postingDateOrDate2, transactionDateOrDate2, whichDateFromOpts -> whichDate (#1731)
This commit is contained in:
parent
9ff5ac1288
commit
b4c1188c26
@ -42,6 +42,7 @@ module Hledger.Data.Posting (
|
|||||||
-- * date operations
|
-- * date operations
|
||||||
postingDate,
|
postingDate,
|
||||||
postingDate2,
|
postingDate2,
|
||||||
|
postingDateOrDate2,
|
||||||
isPostingInDateSpan,
|
isPostingInDateSpan,
|
||||||
isPostingInDateSpan',
|
isPostingInDateSpan',
|
||||||
-- * account name operations
|
-- * account name operations
|
||||||
@ -220,6 +221,11 @@ postingDate2 p = fromMaybe nulldate $ asum dates
|
|||||||
, tdate <$> ptransaction p
|
, tdate <$> ptransaction p
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- | Get a posting's primary or secondary date, as specified.
|
||||||
|
postingDateOrDate2 :: WhichDate -> Posting -> Day
|
||||||
|
postingDateOrDate2 PrimaryDate = postingDate
|
||||||
|
postingDateOrDate2 SecondaryDate = postingDate2
|
||||||
|
|
||||||
-- | Get a posting's status. This is cleared or pending if those are
|
-- | Get a posting's status. This is cleared or pending if those are
|
||||||
-- explicitly set on the posting, otherwise the status of its parent
|
-- explicitly set on the posting, otherwise the status of its parent
|
||||||
-- transaction, or unmarked if there is no parent transaction. (Note
|
-- transaction, or unmarked if there is no parent transaction. (Note
|
||||||
|
|||||||
@ -34,6 +34,7 @@ module Hledger.Data.Transaction
|
|||||||
-- nonzerobalanceerror
|
-- nonzerobalanceerror
|
||||||
-- * date operations
|
-- * date operations
|
||||||
, transactionDate2
|
, transactionDate2
|
||||||
|
, transactionDateOrDate2
|
||||||
-- * transaction description parts
|
-- * transaction description parts
|
||||||
, transactionPayee
|
, transactionPayee
|
||||||
, transactionNote
|
, transactionNote
|
||||||
@ -320,10 +321,15 @@ balancedVirtualPostings = filter isBalancedVirtual . tpostings
|
|||||||
transactionsPostings :: [Transaction] -> [Posting]
|
transactionsPostings :: [Transaction] -> [Posting]
|
||||||
transactionsPostings = concatMap tpostings
|
transactionsPostings = concatMap tpostings
|
||||||
|
|
||||||
-- Get a transaction's secondary date, defaulting to the primary date.
|
-- Get a transaction's secondary date, or the primary date if there is none.
|
||||||
transactionDate2 :: Transaction -> Day
|
transactionDate2 :: Transaction -> Day
|
||||||
transactionDate2 t = fromMaybe (tdate t) $ tdate2 t
|
transactionDate2 t = fromMaybe (tdate t) $ tdate2 t
|
||||||
|
|
||||||
|
-- Get a transaction's primary or secondary date, as specified.
|
||||||
|
transactionDateOrDate2 :: WhichDate -> Transaction -> Day
|
||||||
|
transactionDateOrDate2 PrimaryDate = tdate
|
||||||
|
transactionDateOrDate2 SecondaryDate = transactionDate2
|
||||||
|
|
||||||
-- | Ensure a transaction's postings refer back to it, so that eg
|
-- | Ensure a transaction's postings refer back to it, so that eg
|
||||||
-- relatedPostings works right.
|
-- relatedPostings works right.
|
||||||
txnTieKnot :: Transaction -> Transaction
|
txnTieKnot :: Transaction -> Transaction
|
||||||
|
|||||||
@ -244,9 +244,7 @@ getPostingsByColumn rspec j priceoracle reportspan =
|
|||||||
ps = dbg5 "getPostingsByColumn" $ getPostings rspec j priceoracle
|
ps = dbg5 "getPostingsByColumn" $ getPostings rspec j priceoracle
|
||||||
-- The date spans to be included as report columns.
|
-- The date spans to be included as report columns.
|
||||||
colspans = dbg3 "colspans" $ splitSpan (interval_ $ _rsReportOpts rspec) reportspan
|
colspans = dbg3 "colspans" $ splitSpan (interval_ $ _rsReportOpts rspec) reportspan
|
||||||
getDate = case whichDateFromOpts (_rsReportOpts rspec) of
|
getDate = postingDateOrDate2 (whichDate (_rsReportOpts rspec))
|
||||||
PrimaryDate -> postingDate
|
|
||||||
SecondaryDate -> postingDate2
|
|
||||||
|
|
||||||
-- | Gather postings matching the query within the report period.
|
-- | Gather postings matching the query within the report period.
|
||||||
getPostings :: ReportSpec -> Journal -> PriceOracle -> [Posting]
|
getPostings :: ReportSpec -> Journal -> PriceOracle -> [Posting]
|
||||||
|
|||||||
@ -64,7 +64,7 @@ postingsReport :: ReportSpec -> Journal -> PostingsReport
|
|||||||
postingsReport rspec@ReportSpec{_rsReportOpts=ropts@ReportOpts{..}} j = items
|
postingsReport rspec@ReportSpec{_rsReportOpts=ropts@ReportOpts{..}} j = items
|
||||||
where
|
where
|
||||||
reportspan = reportSpanBothDates j rspec
|
reportspan = reportSpanBothDates j rspec
|
||||||
whichdate = whichDateFromOpts ropts
|
whichdate = whichDate ropts
|
||||||
mdepth = queryDepth $ _rsQuery rspec
|
mdepth = queryDepth $ _rsQuery rspec
|
||||||
multiperiod = interval_ /= NoInterval
|
multiperiod = interval_ /= NoInterval
|
||||||
|
|
||||||
@ -116,9 +116,11 @@ matchedPostingsBeforeAndDuring rspec@ReportSpec{_rsReportOpts=ropts,_rsQuery=q}
|
|||||||
dbg5 "beforeps, duringps" $ span (beforestartq `matchesPosting`) beforeandduringps
|
dbg5 "beforeps, duringps" $ span (beforestartq `matchesPosting`) beforeandduringps
|
||||||
where
|
where
|
||||||
beforestartq = dbg3 "beforestartq" $ dateqtype $ DateSpan Nothing $ spanStart reportspan
|
beforestartq = dbg3 "beforestartq" $ dateqtype $ DateSpan Nothing $ spanStart reportspan
|
||||||
beforeandduringps = sortOn (if date2_ ropts then postingDate2 else postingDate) -- sort postings by date or date2
|
beforeandduringps =
|
||||||
. (if invert_ ropts then map negatePostingAmount else id) -- with --invert, invert amounts
|
sortOn (postingDateOrDate2 (whichDate ropts)) -- sort postings by date or date2
|
||||||
. journalPostings $ journalValueAndFilterPostings rspec{_rsQuery=beforeandduringq} j
|
. (if invert_ ropts then map negatePostingAmount else id) -- with --invert, invert amounts
|
||||||
|
. journalPostings
|
||||||
|
$ journalValueAndFilterPostings rspec{_rsQuery=beforeandduringq} j
|
||||||
|
|
||||||
-- filter postings by the query, with no start date or depth limit
|
-- filter postings by the query, with no start date or depth limit
|
||||||
beforeandduringq = dbg4 "beforeandduringq" $ And [depthless $ dateless q, beforeendq]
|
beforeandduringq = dbg4 "beforeandduringq" $ And [depthless $ dateless q, beforeendq]
|
||||||
@ -152,15 +154,12 @@ postingsReportItems ((p,mperiod):ps) (pprev,mperiodprev) wd d b runningcalcfn it
|
|||||||
-- the transaction description.
|
-- the transaction description.
|
||||||
mkpostingsReportItem :: Bool -> Bool -> WhichDate -> Maybe Period -> Posting -> MixedAmount -> PostingsReportItem
|
mkpostingsReportItem :: Bool -> Bool -> WhichDate -> Maybe Period -> Posting -> MixedAmount -> PostingsReportItem
|
||||||
mkpostingsReportItem showdate showdesc wd mperiod p b =
|
mkpostingsReportItem showdate showdesc wd mperiod p b =
|
||||||
(if showdate then Just date else Nothing
|
(if showdate then Just $ postingDateOrDate2 wd p else Nothing
|
||||||
,mperiod
|
,mperiod
|
||||||
,if showdesc then tdescription <$> ptransaction p else Nothing
|
,if showdesc then tdescription <$> ptransaction p else Nothing
|
||||||
,p
|
,p
|
||||||
,b
|
,b
|
||||||
)
|
)
|
||||||
where
|
|
||||||
date = case wd of PrimaryDate -> postingDate p
|
|
||||||
SecondaryDate -> postingDate2 p
|
|
||||||
|
|
||||||
-- | Convert a list of postings into summary postings, one per interval,
|
-- | Convert a list of postings into summary postings, one per interval,
|
||||||
-- aggregated to the specified depth if any.
|
-- aggregated to the specified depth if any.
|
||||||
@ -170,13 +169,10 @@ summarisePostingsByInterval interval wd mdepth showempty reportspan =
|
|||||||
concatMap (\(s,ps) -> summarisePostingsInDateSpan s wd mdepth showempty ps)
|
concatMap (\(s,ps) -> summarisePostingsInDateSpan s wd mdepth showempty ps)
|
||||||
-- Group postings into their columns. We try to be efficient, since
|
-- Group postings into their columns. We try to be efficient, since
|
||||||
-- there can possibly be a very large number of intervals (cf #1683)
|
-- there can possibly be a very large number of intervals (cf #1683)
|
||||||
. groupByDateSpan showempty getDate colspans
|
. groupByDateSpan showempty (postingDateOrDate2 wd) colspans
|
||||||
where
|
where
|
||||||
-- The date spans to be included as report columns.
|
-- The date spans to be included as report columns.
|
||||||
colspans = splitSpan interval reportspan
|
colspans = splitSpan interval reportspan
|
||||||
getDate = case wd of
|
|
||||||
PrimaryDate -> postingDate
|
|
||||||
SecondaryDate -> postingDate2
|
|
||||||
|
|
||||||
-- | 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
|
||||||
|
|||||||
@ -38,7 +38,7 @@ module Hledger.Reports.ReportOptions (
|
|||||||
tree_,
|
tree_,
|
||||||
reportOptsToggleStatus,
|
reportOptsToggleStatus,
|
||||||
simplifyStatuses,
|
simplifyStatuses,
|
||||||
whichDateFromOpts,
|
whichDate,
|
||||||
journalValueAndFilterPostings,
|
journalValueAndFilterPostings,
|
||||||
journalValueAndFilterPostingsWith,
|
journalValueAndFilterPostingsWith,
|
||||||
journalApplyValuationFromOpts,
|
journalApplyValuationFromOpts,
|
||||||
@ -486,8 +486,8 @@ postingDateFn :: ReportOpts -> (Posting -> Day)
|
|||||||
postingDateFn ReportOpts{..} = if date2_ then postingDate2 else postingDate
|
postingDateFn ReportOpts{..} = if date2_ then postingDate2 else postingDate
|
||||||
|
|
||||||
-- | Report which date we will report on based on --date2.
|
-- | Report which date we will report on based on --date2.
|
||||||
whichDateFromOpts :: ReportOpts -> WhichDate
|
whichDate :: ReportOpts -> WhichDate
|
||||||
whichDateFromOpts ReportOpts{..} = if date2_ then SecondaryDate else PrimaryDate
|
whichDate ReportOpts{..} = if date2_ then SecondaryDate else PrimaryDate
|
||||||
|
|
||||||
-- | Legacy-compatible convenience aliases for accountlistmode_.
|
-- | Legacy-compatible convenience aliases for accountlistmode_.
|
||||||
tree_ :: ReportOpts -> Bool
|
tree_ :: ReportOpts -> Bool
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user