diff --git a/hledger-lib/Hledger/Reports/BalanceReport.hs b/hledger-lib/Hledger/Reports/BalanceReport.hs index 94cb3e55c..f932d7a88 100644 --- a/hledger-lib/Hledger/Reports/BalanceReport.hs +++ b/hledger-lib/Hledger/Reports/BalanceReport.hs @@ -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. diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReports.hs b/hledger-lib/Hledger/Reports/MultiBalanceReports.hs index 0cc23533f..befa06eb1 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReports.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReports.hs @@ -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. diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index ec5b6c272..7eb942c37 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -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. diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index 95598f767..a2f219447 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -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