This commit is contained in:
Simon Michael 2019-05-23 22:07:50 -07:00
parent 54c1529638
commit 7212b92079
3 changed files with 12 additions and 24 deletions

View File

@ -73,14 +73,9 @@ balanceReport ropts@ReportOpts{..} q j =
today = fromMaybe (error' "balanceReport: ReportOpts today_ is unset so could not satisfy --value=now") today_
-- For --value-at=transaction, convert all postings to value before summing them.
-- The report might not use them all but laziness probably helps here.
j' -- | mvalueat==Just AtTransaction = mapJournalPostings (\p -> postingValueAtDate j (postingDate p) p) j
| otherwise = j
-- Get all the summed accounts & balances, according to the query, as an account tree.
-- If doing cost valuation, amounts will be converted to cost first.
accttree = ledgerRootAccount $ ledgerFromJournal q $ journalSelectingAmountFromOpts ropts j'
accttree = ledgerRootAccount $ ledgerFromJournal q $ journalSelectingAmountFromOpts ropts j
-- For other kinds of valuation, convert the summed amounts to value.
valuedaccttree = mapAccounts valueaccount accttree
@ -95,10 +90,10 @@ balanceReport ropts@ReportOpts{..} q j =
where
-- prices are in parse order - sort into date then parse order,
-- & reversed for quick lookup of the latest price.
prices = reverse $ sortOn mpdate $ jmarketprices j'
prices = reverse $ sortOn mpdate $ jmarketprices j
periodlastday =
fromMaybe (error' "balanceReport: expected a non-empty journal") $ -- XXX shouldn't happen
reportPeriodOrJournalLastDay ropts j'
reportPeriodOrJournalLastDay ropts j
-- Modify this tree for display - depth limit, boring parents, zeroes - and convert to a list.
displayaccts :: [Account]
@ -143,7 +138,7 @@ balanceReport ropts@ReportOpts{..} q j =
where
anamesandrows = [(first4 r, r) | r <- rows]
anames = map fst anamesandrows
sortedanames = sortAccountNamesByDeclaration j' (tree_ ropts) anames
sortedanames = sortAccountNamesByDeclaration j (tree_ ropts) anames
sortedrows = sortAccountItemsLike sortedanames anamesandrows
-- Calculate the grand total.

View File

@ -44,9 +44,9 @@ entriesReport ropts@ReportOpts{..} q j@Journal{..} =
Just (AtCost _mc) -> postingToCost (journalCommodityStyles j) p
Just (AtEnd _mc) -> postingValue jmarketprices (fromMaybe (postingDate p) -- XXX shouldn't happen
mperiodorjournallastday) p
Just (AtNow _mc) -> postingValue jmarketprices (case today_ of
Just d -> d
Nothing -> error' "erValue: ReportOpts today_ is unset so could not satisfy --value-at=now") p
Just (AtNow _mc) -> postingValue jmarketprices (
case today_ of Just d -> d
Nothing -> error' "erValue: ReportOpts today_ is unset so could not satisfy --value=now") p
Just (AtDate d _mc) -> postingValue jmarketprices d p
where
mperiodorjournallastday = mperiodlastday <|> journalEndDate False j

View File

@ -71,7 +71,7 @@ postingsReport ropts@ReportOpts{..} q j@Journal{..} =
-- postings to be included in the report, and similarly-matched postings before the report start date
(precedingps, reportps) = matchedPostingsBeforeAndDuring ropts q j reportspan
-- We may be converting amounts to value, according to --value-at.
-- We may be converting amounts to value.
-- Currently this is done as follows (keep synced with hledger_options.m4.md):
-- register -M --value
-- cost: value each posting at cost, then summarise ; value -H starting balance at cost
@ -85,7 +85,7 @@ postingsReport ropts@ReportOpts{..} q j@Journal{..} =
-- In all cases, the running total/average is calculated from the above numbers.
-- "Day before report start" is a bit arbitrary.
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=now") today_
-- Postings or summary pseudo postings to be displayed.
displayps =
@ -95,11 +95,7 @@ postingsReport ropts@ReportOpts{..} q j@Journal{..} =
if multiperiod then
let
showempty = empty_ || average_
-- for --value-at=transaction, need to value the postings before summarising them
maybevaluedreportps
-- | value_==Just AtTransaction = [postingValue jmarketprices (postingDate p) p | p <- reportps]
| otherwise = reportps
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan maybevaluedreportps
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan reportps
in case value_ of
Just (AtEnd _mc) -> [(postingValue jmarketprices periodlastday p , periodend) | (p,periodend) <- summaryps
,let periodlastday = maybe
@ -131,10 +127,7 @@ postingsReport ropts@ReportOpts{..} q j@Journal{..} =
| otherwise = divideMixedAmount (fromIntegral $ length precedingps) precedingsum
startbal | average_ = if historical then precedingavg else 0
| otherwise = if historical then precedingsum else 0
-- For --value-at: convert the initial running total/average to value.
-- For --value-at=transaction, we don't bother valuing each
-- preceding posting at posting date - how useful would that
-- be ? Just value the initial sum/average at report start date.
-- For --value=end/now/DATE, convert the initial running total/average to value.
valuedstartbal = case value_ of
Nothing -> startbal
Just (AtCost _mc) -> startbal -- conversion to cost was done earlier