;lib: brValue cleanup
This commit is contained in:
parent
ec1b98434c
commit
12c0bfb39b
@ -18,7 +18,6 @@ module Hledger.Reports.BalanceReport (
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Control.Applicative ((<|>))
|
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Ord
|
import Data.Ord
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
@ -185,32 +184,21 @@ brValue ropts@ReportOpts{..} j (items, total) =
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
val amt =
|
val amt =
|
||||||
let val' d = mixedAmountValue prices d amt in
|
|
||||||
case value_at_ of
|
case value_at_ of
|
||||||
AtTransaction -> amt -- this case is converted earlier, see Balance.hs
|
AtTransaction -> amt -- this case is converted earlier, see Balance.hs
|
||||||
AtPeriod ->
|
AtPeriod -> val' reportperiodlastday
|
||||||
let mperiodorjournallastday = mperiodlastday <|> journalEndDate False j
|
AtNow -> val' today
|
||||||
-- Get the last day of the report period.
|
|
||||||
-- Will be Nothing if no report period is specified, or also
|
|
||||||
-- if ReportOpts does not have today_ set, since we need that
|
|
||||||
-- to get the report period robustly.
|
|
||||||
mperiodlastday :: Maybe Day = do
|
|
||||||
t <- today_
|
|
||||||
let q = queryFromOpts t ropts
|
|
||||||
qend <- queryEndDate False q
|
|
||||||
return $ addDays (-1) qend
|
|
||||||
d = fromMaybe (error' "brValue: expected a non-empty journal") -- XXX shouldn't happen
|
|
||||||
mperiodorjournallastday
|
|
||||||
in val' d
|
|
||||||
AtNow -> case today_ of
|
|
||||||
Just d -> val' d
|
|
||||||
Nothing -> error' "brValue: ReportOpts today_ is unset so could not satisfy --value-at=now"
|
|
||||||
AtDate d -> val' d
|
AtDate d -> val' d
|
||||||
|
where
|
||||||
|
val' d = mixedAmountValue prices d amt
|
||||||
-- 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
|
||||||
|
reportperiodlastday =
|
||||||
|
fromMaybe (error' "brValue: expected a non-empty journal") -- XXX shouldn't happen
|
||||||
|
$ reportPeriodOrJournalLastDay ropts j
|
||||||
|
today =
|
||||||
|
fromMaybe (error' "brValue: ReportOpts today_ is unset so could not satisfy --value-at=now") today_
|
||||||
|
|
||||||
-- -- | 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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user