lib: drop postingValueAtDate
This commit is contained in:
parent
4a75971c6d
commit
37c0edb1f9
@ -12,13 +12,10 @@ value of things at a given date.
|
|||||||
|
|
||||||
module Hledger.Data.MarketPrice (
|
module Hledger.Data.MarketPrice (
|
||||||
showMarketPrice
|
showMarketPrice
|
||||||
,postingValueAtDate
|
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Data.List
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Time.Calendar
|
|
||||||
|
|
||||||
import Hledger.Data.Amount
|
import Hledger.Data.Amount
|
||||||
import Hledger.Data.Dates
|
import Hledger.Data.Dates
|
||||||
@ -34,14 +31,14 @@ showMarketPrice mp = unwords
|
|||||||
, (showAmount . setAmountPrecision maxprecision) (mpamount mp)
|
, (showAmount . setAmountPrecision maxprecision) (mpamount mp)
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | Convert this posting's amount to its value on the given date in
|
-- -- | Convert this posting's amount to its value on the given date in
|
||||||
-- its default valuation commodity, using market prices from the given journal.
|
-- -- its default valuation commodity, using market prices from the given journal.
|
||||||
postingValueAtDate :: Journal -> Day -> Posting -> Posting
|
-- postingValueAtDate :: Journal -> Day -> Posting -> Posting
|
||||||
postingValueAtDate j d p@Posting{..} = p{pamount=mixedAmountValue prices d pamount}
|
-- postingValueAtDate j d p@Posting{..} = p{pamount=mixedAmountValue prices d pamount}
|
||||||
where
|
-- where
|
||||||
-- prices are in parse order - sort into date then parse order,
|
-- -- prices are in parse order - sort into date then parse order,
|
||||||
-- & reversed for quick lookup of the latest price.
|
-- -- & reversed for quick lookup of the latest price.
|
||||||
prices = reverse $ sortOn mpdate $ jmarketprices j
|
-- prices = reverse $ sortOn mpdate $ jmarketprices j
|
||||||
|
|
||||||
-- -- | Find the best commodity to convert to when asked to show the
|
-- -- | Find the best commodity to convert to when asked to show the
|
||||||
-- -- market value of this commodity on the given date. That is, the one
|
-- -- market value of this commodity on the given date. That is, the one
|
||||||
|
|||||||
@ -88,7 +88,7 @@ type ClippedAccountName = AccountName
|
|||||||
-- hledger's most powerful and useful report, used by the balance
|
-- hledger's most powerful and useful report, used by the balance
|
||||||
-- command (in multiperiod mode) and by the bs/cf/is commands.
|
-- command (in multiperiod mode) and by the bs/cf/is commands.
|
||||||
multiBalanceReport :: ReportOpts -> Query -> Journal -> MultiBalanceReport
|
multiBalanceReport :: ReportOpts -> Query -> Journal -> MultiBalanceReport
|
||||||
multiBalanceReport ropts@ReportOpts{..} q j =
|
multiBalanceReport ropts@ReportOpts{..} q j@Journal{..} =
|
||||||
(if invert_ then mbrNegate else id) $
|
(if invert_ then mbrNegate else id) $
|
||||||
MultiBalanceReport (colspans, sortedrowsvalued, totalsrow)
|
MultiBalanceReport (colspans, sortedrowsvalued, totalsrow)
|
||||||
where
|
where
|
||||||
@ -161,7 +161,7 @@ multiBalanceReport ropts@ReportOpts{..} q j =
|
|||||||
today = fromMaybe (error' "postingsReport: ReportOpts today_ is unset so could not satisfy --value-at=now") today_
|
today = fromMaybe (error' "postingsReport: ReportOpts today_ is unset so could not satisfy --value-at=now") today_
|
||||||
-- Market prices. Sort into date then parse order,
|
-- Market prices. Sort into date then parse order,
|
||||||
-- & reverse for quick lookup of the latest price.
|
-- & reverse for quick lookup of the latest price.
|
||||||
prices = reverse $ sortOn mpdate $ jmarketprices j
|
prices = reverse $ sortOn mpdate jmarketprices
|
||||||
-- A helper for valuing amounts according to --value-at.
|
-- A helper for valuing amounts according to --value-at.
|
||||||
maybevalue :: Day -> MixedAmount -> MixedAmount
|
maybevalue :: Day -> MixedAmount -> MixedAmount
|
||||||
maybevalue periodlastday amt = case value_ of
|
maybevalue periodlastday amt = case value_ of
|
||||||
@ -244,7 +244,7 @@ multiBalanceReport ropts@ReportOpts{..} q j =
|
|||||||
-- If --value-at=transaction is in effect, convert the postings to value before summing.
|
-- If --value-at=transaction is in effect, convert the postings to value before summing.
|
||||||
colpsmaybevalued :: [([Posting], Maybe Day)] =
|
colpsmaybevalued :: [([Posting], Maybe Day)] =
|
||||||
case value_ of
|
case value_ of
|
||||||
Just (AtCost _mc) -> [([postingValueAtDate j (postingDate p) p | p <- ps], periodend) | (ps,periodend) <- colps]
|
Just (AtCost _mc) -> [([postingValue jmarketprices (postingDate p) p | p <- ps], periodend) | (ps,periodend) <- colps]
|
||||||
_ -> colps
|
_ -> colps
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|||||||
@ -61,7 +61,7 @@ type PostingsReportItem = (Maybe Day -- The posting date, if this is the firs
|
|||||||
-- | 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
|
||||||
postingsReport ropts@ReportOpts{..} q j =
|
postingsReport ropts@ReportOpts{..} q j@Journal{..} =
|
||||||
(totallabel, items)
|
(totallabel, items)
|
||||||
where
|
where
|
||||||
reportspan = adjustReportDates ropts q j
|
reportspan = adjustReportDates ropts q j
|
||||||
@ -99,29 +99,30 @@ postingsReport ropts@ReportOpts{..} q j =
|
|||||||
showempty = empty_ || average_
|
showempty = empty_ || average_
|
||||||
-- for --value-at=transaction, need to value the postings before summarising them
|
-- for --value-at=transaction, need to value the postings before summarising them
|
||||||
maybevaluedreportps
|
maybevaluedreportps
|
||||||
-- | value_==Just AtTransaction = [postingValueAtDate j (postingDate p) p | p <- reportps]
|
-- | value_==Just AtTransaction = [postingValue jmarketprices (postingDate p) p | p <- reportps]
|
||||||
| otherwise = reportps
|
| otherwise = reportps
|
||||||
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan maybevaluedreportps
|
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan maybevaluedreportps
|
||||||
in case value_ of
|
in case value_ of
|
||||||
Just (AtEnd _mc) -> [(postingValueAtDate j periodlastday p , periodend) | (p,periodend) <- summaryps
|
Just (AtEnd _mc) -> [(postingValue jmarketprices periodlastday p , periodend) | (p,periodend) <- summaryps
|
||||||
,let periodlastday = maybe
|
,let periodlastday = maybe
|
||||||
(error' "postingsReport: expected a subperiod end date") -- XXX shouldn't happen
|
(error' "postingsReport: expected a subperiod end date") -- XXX shouldn't happen
|
||||||
(addDays (-1))
|
(addDays (-1))
|
||||||
periodend
|
periodend
|
||||||
]
|
]
|
||||||
Just (AtNow _mc) -> [(postingValueAtDate j today p , periodend) | (p,periodend) <- summaryps]
|
Just (AtNow _mc) -> [(postingValue jmarketprices today p , periodend) | (p,periodend) <- summaryps]
|
||||||
Just (AtDate d _mc) -> [(postingValueAtDate j d p , periodend) | (p,periodend) <- summaryps]
|
Just (AtDate d _mc) -> [(postingValue jmarketprices d p , periodend) | (p,periodend) <- summaryps]
|
||||||
_ -> summaryps
|
Just (AtCost _mc) -> summaryps -- XXX already handled
|
||||||
|
_ -> summaryps
|
||||||
else
|
else
|
||||||
let reportperiodlastday =
|
let reportperiodlastday =
|
||||||
fromMaybe (error' "postingsReport: expected a non-empty journal") -- XXX shouldn't happen
|
fromMaybe (error' "postingsReport: expected a non-empty journal") -- XXX shouldn't happen
|
||||||
$ reportPeriodOrJournalLastDay ropts j
|
$ reportPeriodOrJournalLastDay ropts j
|
||||||
in case value_ of
|
in case value_ of
|
||||||
Nothing -> [(p , Nothing) | p <- reportps]
|
Nothing -> [(p , Nothing) | p <- reportps]
|
||||||
Just (AtCost _mc) -> [(postingValueAtDate j (postingDate p) p , Nothing) | p <- reportps]
|
Just (AtCost _mc) -> [(postingValue jmarketprices (postingDate p) p , Nothing) | p <- reportps]
|
||||||
Just (AtEnd _mc) -> [(postingValueAtDate j reportperiodlastday p, Nothing) | p <- reportps]
|
Just (AtEnd _mc) -> [(postingValue jmarketprices reportperiodlastday p, Nothing) | p <- reportps]
|
||||||
Just (AtNow _mc) -> [(postingValueAtDate j today p , Nothing) | p <- reportps]
|
Just (AtNow _mc) -> [(postingValue jmarketprices today p , Nothing) | p <- reportps]
|
||||||
Just (AtDate d _mc) -> [(postingValueAtDate j d p , Nothing) | p <- reportps]
|
Just (AtDate d _mc) -> [(postingValue jmarketprices d p , Nothing) | p <- reportps]
|
||||||
|
|
||||||
-- posting report items ready for display
|
-- posting report items ready for display
|
||||||
items = dbg1 "postingsReport items" $ postingsReportItems displayps (nullposting,Nothing) whichdate depth valuedstartbal runningcalc startnum
|
items = dbg1 "postingsReport items" $ postingsReportItems displayps (nullposting,Nothing) whichdate depth valuedstartbal runningcalc startnum
|
||||||
@ -149,7 +150,7 @@ postingsReport ropts@ReportOpts{..} q j =
|
|||||||
$ reportPeriodOrJournalStart ropts j
|
$ reportPeriodOrJournalStart ropts j
|
||||||
-- prices are in parse order - sort into date then parse order,
|
-- prices are in parse order - sort into date then parse order,
|
||||||
-- & reversed for quick lookup of the latest price.
|
-- & reversed for quick lookup of the latest price.
|
||||||
prices = reverse $ sortOn mpdate $ jmarketprices j
|
prices = reverse $ sortOn mpdate jmarketprices
|
||||||
|
|
||||||
startnum = if historical then length precedingps + 1 else 1
|
startnum = if historical then length precedingps + 1 else 1
|
||||||
runningcalc = registerRunningCalculationFn ropts
|
runningcalc = registerRunningCalculationFn ropts
|
||||||
@ -200,7 +201,7 @@ matchedPostingsBeforeAndDuring opts q j (DateSpan mstart mend) =
|
|||||||
dbg1 "ps3" $ map (filterPostingAmount symq) $ -- remove amount parts which the query's cur: terms would exclude
|
dbg1 "ps3" $ map (filterPostingAmount symq) $ -- remove amount parts which the query's cur: terms would exclude
|
||||||
dbg1 "ps2" $ (if related_ opts then concatMap relatedPostings else id) $ -- with -r, replace each with its sibling postings
|
dbg1 "ps2" $ (if related_ opts then concatMap relatedPostings else id) $ -- with -r, replace each with its sibling postings
|
||||||
dbg1 "ps1" $ filter (beforeandduringq `matchesPosting`) $ -- filter postings by the query, with no start date or depth limit
|
dbg1 "ps1" $ filter (beforeandduringq `matchesPosting`) $ -- filter postings by the query, with no start date or depth limit
|
||||||
journalPostings $ journalSelectingAmountFromOpts opts j
|
journalPostings $ journalSelectingAmountFromOpts opts j -- XXX stop ?
|
||||||
where
|
where
|
||||||
beforeandduringq = dbg1 "beforeandduringq" $ And [depthless $ dateless q, beforeendq]
|
beforeandduringq = dbg1 "beforeandduringq" $ And [depthless $ dateless q, beforeendq]
|
||||||
where
|
where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user