bal, reg: use posting date if specified, clarify posting effective date not yet supported
This commit is contained in:
parent
dfeafa6064
commit
27621515ea
11
MANUAL.md
11
MANUAL.md
@ -410,13 +410,14 @@ NAME=EXACTVALUE` on the command line.
|
|||||||
|
|
||||||
### Posting dates
|
### Posting dates
|
||||||
|
|
||||||
You can give individual postings a different date (or dates) from their parent transaction,
|
You can give individual postings a different date from their parent
|
||||||
by adding posting tags `date:ACTUALDATE` and/or `date2:EFFECTIVEDATE`.
|
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
|
For compatibility, ledger's posting date syntax is also supported
|
||||||
(`[ACTUALDATE]`, `[=EFFECTIVEDATE]` or `[ACTUALDATE=EFFECTIVEDATE]` in a
|
(`[ACTUALDATE]`, `[ACTUALDATE=EFFECTIVEDATE]` or `[=EFFECTIVEDATE]` in a
|
||||||
posting comment), and treated as an alterate spelling of the date and
|
posting comment) and treated as an alterate spelling of the date: tag.
|
||||||
date2 tags.
|
Note effective dates are not csurrently here are ignored, currently.
|
||||||
|
|
||||||
### Including other files
|
### Including other files
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ module Hledger.Data.Posting (
|
|||||||
transactionAllTags,
|
transactionAllTags,
|
||||||
-- * date operations
|
-- * date operations
|
||||||
postingDate,
|
postingDate,
|
||||||
|
postingEffectiveDate,
|
||||||
isPostingInDateSpan,
|
isPostingInDateSpan,
|
||||||
postingsDateSpan,
|
postingsDateSpan,
|
||||||
-- * account name operations
|
-- * account name operations
|
||||||
@ -141,6 +142,14 @@ postingDate p = fromMaybe txndate $ pdate p
|
|||||||
where
|
where
|
||||||
txndate = maybe nulldate tdate $ ptransaction p
|
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
|
-- |Is this posting cleared? If this posting was individually marked
|
||||||
-- as cleared, returns True. Otherwise, return the parent
|
-- as cleared, returns True. Otherwise, return the parent
|
||||||
-- transaction's cleared status or, if there is no parent
|
-- transaction's cleared status or, if there is no parent
|
||||||
|
|||||||
@ -76,7 +76,7 @@ data PostingType = RegularPosting | VirtualPosting | BalancedVirtualPosting
|
|||||||
type Tag = (String, String)
|
type Tag = (String, String)
|
||||||
|
|
||||||
data Posting = Posting {
|
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,
|
pstatus :: Bool,
|
||||||
paccount :: AccountName,
|
paccount :: AccountName,
|
||||||
pamount :: MixedAmount,
|
pamount :: MixedAmount,
|
||||||
|
|||||||
@ -470,13 +470,8 @@ matchesPosting (Or qs) p = any (`matchesPosting` p) qs
|
|||||||
matchesPosting (And qs) p = all (`matchesPosting` p) qs
|
matchesPosting (And qs) p = all (`matchesPosting` p) qs
|
||||||
matchesPosting (Desc r) p = regexMatchesCI r $ maybe "" tdescription $ ptransaction p
|
matchesPosting (Desc r) p = regexMatchesCI r $ maybe "" tdescription $ ptransaction p
|
||||||
matchesPosting (Acct r) p = regexMatchesCI r $ paccount p
|
matchesPosting (Acct r) p = regexMatchesCI r $ paccount p
|
||||||
matchesPosting (Date span) p =
|
matchesPosting (Date span) p = span `spanContainsDate` postingDate p
|
||||||
case d of Just d' -> spanContainsDate span d'
|
matchesPosting (EDate span) p = span `spanContainsDate` postingEffectiveDate p
|
||||||
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 (Status v) p = v == postingCleared p
|
matchesPosting (Status v) p = v == postingCleared p
|
||||||
matchesPosting (Real v) p = v == isReal p
|
matchesPosting (Real v) p = v == isReal p
|
||||||
matchesPosting (Depth d) Posting{paccount=a} = Depth d `matchesAccount` a
|
matchesPosting (Depth d) Posting{paccount=a} = Depth d `matchesAccount` a
|
||||||
@ -560,9 +555,6 @@ matchTagName pat name = pat == name
|
|||||||
matchTagValue :: String -> String -> Bool
|
matchTagValue :: String -> String -> Bool
|
||||||
matchTagValue pat value = regexMatchesCI pat value
|
matchTagValue pat value = regexMatchesCI pat value
|
||||||
|
|
||||||
postingEffectiveDate :: Posting -> Maybe Day
|
|
||||||
postingEffectiveDate p = maybe Nothing (Just . transactionEffectiveDate) $ ptransaction p
|
|
||||||
|
|
||||||
-- tests
|
-- tests
|
||||||
|
|
||||||
tests_Hledger_Query :: Test
|
tests_Hledger_Query :: Test
|
||||||
|
|||||||
@ -248,7 +248,7 @@ tests_entriesReport = [
|
|||||||
type PostingsReport = (String -- label for the running balance column XXX remove
|
type PostingsReport = (String -- label for the running balance column XXX remove
|
||||||
,[PostingsReportItem] -- line items, one per posting
|
,[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
|
,Posting -- the posting, possibly with account name depth-clipped
|
||||||
,MixedAmount -- the running total after this posting
|
,MixedAmount -- the running total after this posting
|
||||||
)
|
)
|
||||||
@ -296,9 +296,9 @@ postingsReportItems :: [Posting] -> Posting -> Int -> MixedAmount -> (MixedAmoun
|
|||||||
postingsReportItems [] _ _ _ _ = []
|
postingsReportItems [] _ _ _ _ = []
|
||||||
postingsReportItems (p:ps) pprev d b sumfn = i:(postingsReportItems ps p d b' sumfn)
|
postingsReportItems (p:ps) pprev d b sumfn = i:(postingsReportItems ps p d b' sumfn)
|
||||||
where
|
where
|
||||||
i = mkpostingsReportItem isfirst p' b'
|
i = mkpostingsReportItem isfirstintxn p' b'
|
||||||
p' = p{paccount=clipAccountName d $ paccount p}
|
p' = p{paccount=clipAccountName d $ paccount p}
|
||||||
isfirst = ptransaction p /= ptransaction pprev
|
isfirstintxn = ptransaction p /= ptransaction pprev
|
||||||
b' = b `sumfn` pamount p
|
b' = b `sumfn` pamount p
|
||||||
|
|
||||||
-- | Generate one postings report line item, given a flag indicating
|
-- | 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.
|
-- running balance.
|
||||||
mkpostingsReportItem :: Bool -> Posting -> MixedAmount -> PostingsReportItem
|
mkpostingsReportItem :: Bool -> Posting -> MixedAmount -> PostingsReportItem
|
||||||
mkpostingsReportItem False p b = (Nothing, p, b)
|
mkpostingsReportItem False p b = (Nothing, p, b)
|
||||||
mkpostingsReportItem True p b = (ds, p, b)
|
mkpostingsReportItem True p b = (Just (date,desc), p, b)
|
||||||
where ds = case ptransaction p of Just (Transaction{tdate=da,tdescription=de}) -> Just (da,de)
|
where
|
||||||
Nothing -> Just (nulldate,"")
|
date = postingDate p
|
||||||
|
desc = maybe "" tdescription $ ptransaction p
|
||||||
|
|
||||||
-- | Date-sort and split a list of postings into three spans - postings matched
|
-- | Date-sort and split a list of postings into three spans - postings matched
|
||||||
-- by the given display expression, and the preceding and following postings.
|
-- by the given display expression, and the preceding and following postings.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user