bal, reg: use posting date if specified, clarify posting effective date not yet supported

This commit is contained in:
Simon Michael 2012-12-06 01:10:15 +00:00
parent dfeafa6064
commit 27621515ea
5 changed files with 25 additions and 22 deletions

View File

@ -410,13 +410,14 @@ NAME=EXACTVALUE` on the command line.
### Posting dates
You can give individual postings a different date (or dates) from their parent transaction,
by adding posting tags `date:ACTUALDATE` and/or `date2:EFFECTIVEDATE`.
You can give individual postings a different date from their parent
transaction, by adding posting tag `date:ACTUALDATE`. If present, this
date will be used by the register and balance reports.
For compatibility, ledger's posting date syntax is also supported
(`[ACTUALDATE]`, `[=EFFECTIVEDATE]` or `[ACTUALDATE=EFFECTIVEDATE]` in a
posting comment), and treated as an alterate spelling of the date and
date2 tags.
(`[ACTUALDATE]`, `[ACTUALDATE=EFFECTIVEDATE]` or `[=EFFECTIVEDATE]` in a
posting comment) and treated as an alterate spelling of the date: tag.
Note effective dates are not csurrently here are ignored, currently.
### Including other files

View File

@ -23,6 +23,7 @@ module Hledger.Data.Posting (
transactionAllTags,
-- * date operations
postingDate,
postingEffectiveDate,
isPostingInDateSpan,
postingsDateSpan,
-- * account name operations
@ -141,6 +142,14 @@ postingDate p = fromMaybe txndate $ pdate p
where
txndate = maybe nulldate tdate $ ptransaction p
-- | Get a posting's secondary (effective) date - it's own primary date if
-- specified (can't access posting secondary dates yet), otherwise the
-- parent transaction's effective date, otherwise the null date.
postingEffectiveDate :: Posting -> Day
postingEffectiveDate p = maybe nulldate transactionEffectiveDate $ ptransaction p
where
transactionEffectiveDate t = fromMaybe (tdate t) $ teffectivedate t
-- |Is this posting cleared? If this posting was individually marked
-- as cleared, returns True. Otherwise, return the parent
-- transaction's cleared status or, if there is no parent

View File

@ -76,7 +76,7 @@ data PostingType = RegularPosting | VirtualPosting | BalancedVirtualPosting
type Tag = (String, String)
data Posting = Posting {
pdate :: Maybe Day, -- ^ this posting's clearing date, if different from the transaction's
pdate :: Maybe Day, -- ^ this posting's date, if different from the transaction's
pstatus :: Bool,
paccount :: AccountName,
pamount :: MixedAmount,

View File

@ -470,13 +470,8 @@ matchesPosting (Or qs) p = any (`matchesPosting` p) qs
matchesPosting (And qs) p = all (`matchesPosting` p) qs
matchesPosting (Desc r) p = regexMatchesCI r $ maybe "" tdescription $ ptransaction p
matchesPosting (Acct r) p = regexMatchesCI r $ paccount p
matchesPosting (Date span) p =
case d of Just d' -> spanContainsDate span d'
Nothing -> False
where d = maybe Nothing (Just . tdate) $ ptransaction p
matchesPosting (EDate span) p =
case postingEffectiveDate p of Just d -> spanContainsDate span d
Nothing -> False
matchesPosting (Date span) p = span `spanContainsDate` postingDate p
matchesPosting (EDate span) p = span `spanContainsDate` postingEffectiveDate p
matchesPosting (Status v) p = v == postingCleared p
matchesPosting (Real v) p = v == isReal p
matchesPosting (Depth d) Posting{paccount=a} = Depth d `matchesAccount` a
@ -560,9 +555,6 @@ matchTagName pat name = pat == name
matchTagValue :: String -> String -> Bool
matchTagValue pat value = regexMatchesCI pat value
postingEffectiveDate :: Posting -> Maybe Day
postingEffectiveDate p = maybe Nothing (Just . transactionEffectiveDate) $ ptransaction p
-- tests
tests_Hledger_Query :: Test

View File

@ -248,7 +248,7 @@ tests_entriesReport = [
type PostingsReport = (String -- label for the running balance column XXX remove
,[PostingsReportItem] -- line items, one per posting
)
type PostingsReportItem = (Maybe (Day, String) -- transaction date and description if this is the first posting
type PostingsReportItem = (Maybe (Day, String) -- posting date and description if this is the first posting
,Posting -- the posting, possibly with account name depth-clipped
,MixedAmount -- the running total after this posting
)
@ -296,9 +296,9 @@ postingsReportItems :: [Posting] -> Posting -> Int -> MixedAmount -> (MixedAmoun
postingsReportItems [] _ _ _ _ = []
postingsReportItems (p:ps) pprev d b sumfn = i:(postingsReportItems ps p d b' sumfn)
where
i = mkpostingsReportItem isfirst p' b'
i = mkpostingsReportItem isfirstintxn p' b'
p' = p{paccount=clipAccountName d $ paccount p}
isfirst = ptransaction p /= ptransaction pprev
isfirstintxn = ptransaction p /= ptransaction pprev
b' = b `sumfn` pamount p
-- | Generate one postings report line item, given a flag indicating
@ -306,9 +306,10 @@ postingsReportItems (p:ps) pprev d b sumfn = i:(postingsReportItems ps p d b' su
-- running balance.
mkpostingsReportItem :: Bool -> Posting -> MixedAmount -> PostingsReportItem
mkpostingsReportItem False p b = (Nothing, p, b)
mkpostingsReportItem True p b = (ds, p, b)
where ds = case ptransaction p of Just (Transaction{tdate=da,tdescription=de}) -> Just (da,de)
Nothing -> Just (nulldate,"")
mkpostingsReportItem True p b = (Just (date,desc), p, b)
where
date = postingDate p
desc = maybe "" tdescription $ ptransaction p
-- | Date-sort and split a list of postings into three spans - postings matched
-- by the given display expression, and the preceding and following postings.