lib: valueTypeFromOpts helper
This commit is contained in:
parent
2e44d09fdb
commit
e5339218f7
@ -75,7 +75,7 @@ balanceReport ropts@ReportOpts{..} q j =
|
||||
-- transaction: value each posting at posting date before summing
|
||||
-- period: value totals at period end
|
||||
-- date: value totals at date
|
||||
mvalueat = if value_ then Just value_at_ else Nothing
|
||||
mvalueat = valueTypeFromOpts ropts
|
||||
today = fromMaybe (error' "balanceReport: ReportOpts today_ is unset so could not satisfy --value-at=now") today_
|
||||
|
||||
-- For --value-at=transaction, convert all postings to value before summing them.
|
||||
|
||||
@ -154,7 +154,7 @@ multiBalanceReport ropts@ReportOpts{..} q j =
|
||||
-- transaction: sum/average the valued amounts
|
||||
-- period: sum/average the unvalued amounts and value at report period end
|
||||
-- date: sum/average the unvalued amounts and value at date
|
||||
mvalueat = if value_ then Just value_at_ else Nothing
|
||||
mvalueat = valueTypeFromOpts ropts
|
||||
today = fromMaybe (error' "postingsReport: ReportOpts today_ is unset so could not satisfy --value-at=now") today_
|
||||
-- Market prices. Sort into date then parse order,
|
||||
-- & reverse for quick lookup of the latest price.
|
||||
|
||||
@ -87,7 +87,7 @@ postingsReport ropts@ReportOpts{..} q j =
|
||||
--
|
||||
-- "Day before report start" is a bit arbitrary.
|
||||
|
||||
mvalueat = if value_ then Just value_at_ else Nothing
|
||||
mvalueat = valueTypeFromOpts ropts
|
||||
today = fromMaybe (error' "postingsReport: ReportOpts today_ is unset so could not satisfy --value-at=now") today_
|
||||
|
||||
-- Postings or summary pseudo postings to be displayed.
|
||||
|
||||
@ -15,6 +15,7 @@ module Hledger.Reports.ReportOptions (
|
||||
defreportopts,
|
||||
rawOptsToReportOpts,
|
||||
checkReportOpts,
|
||||
valueTypeFromOpts,
|
||||
flat_,
|
||||
tree_,
|
||||
reportOptsToggleStatus,
|
||||
@ -84,8 +85,8 @@ instance Default AccountListMode where def = ALDefault
|
||||
data ValueDate =
|
||||
AtTransaction -- ^ Calculate values as of each posting's date (called "transaction" for UI reasons)
|
||||
| AtPeriod -- ^ Calculate values as of each report period's last day
|
||||
| AtNow -- ^ Calculate values as of today (report generation date) (called "now" not today for UI reasons)
|
||||
| AtDate Day -- ^ Calculate values as of some other date
|
||||
| AtNow -- ^ Calculate values as of today (report generation date) (called "now" for UI reasons)
|
||||
| AtDate Day -- ^ Calculate values as of some fixed date
|
||||
deriving (Show,Data,Eq) -- Typeable
|
||||
|
||||
instance Default ValueDate where def = AtNow
|
||||
@ -396,6 +397,18 @@ flat_ = (==ALFlat) . accountlistmode_
|
||||
-- depthFromOpts :: ReportOpts -> Int
|
||||
-- depthFromOpts opts = min (fromMaybe 99999 $ depth_ opts) (queryDepth $ queryFromOpts nulldate opts)
|
||||
|
||||
-- | A simpler way to find the type of valuation to be done, if any.
|
||||
-- Considers the --value and --value-at flagsvalueTypeFromOpts :: ReportOpts -> Maybe ValueDate
|
||||
valueTypeFromOpts ReportOpts{..} =
|
||||
case (value_, value_at_) of
|
||||
(False,_) -> Nothing
|
||||
-- (True, AtNow) -> Just $ AtDate (fromMaybe (error' "could not satisfy --value-at=now, expected ReportOpts today_ to be set") today_)
|
||||
-- , and converts --value-at=now
|
||||
-- to --value-at=DATE so you don't have to mess with today's date.
|
||||
-- Ie this will never return AtNow.
|
||||
-- (But this is not reflected in the type, or relied on by other code; XXX WIP).
|
||||
(True, vd) -> Just vd
|
||||
|
||||
-- | Convert this journal's postings' amounts to the cost basis amounts if
|
||||
-- specified by options.
|
||||
journalSelectingAmountFromOpts :: ReportOpts -> Journal -> Journal
|
||||
|
||||
Loading…
Reference in New Issue
Block a user