mirror of
https://github.com/simonmichael/hledger.git
synced 2025-01-06 02:23:46 +03:00
Added timelog entries to ledger and added useful utilities
This commit is contained in:
parent
b51740e9bb
commit
5e0313e447
@ -29,6 +29,26 @@ instance Show RawLedger where
|
||||
-- ++ (show $ rawLedgerTransactions l)
|
||||
where accounts = flatten $ rawLedgerAccountNameTree l
|
||||
|
||||
rawLedgerEmpty :: RawLedger
|
||||
rawLedgerEmpty = RawLedger { modifier_entries = []
|
||||
, periodic_entries = []
|
||||
, entries = []
|
||||
, open_timelog_entries = []
|
||||
, final_comment_lines = []
|
||||
}
|
||||
|
||||
addEntry :: Entry -> RawLedger -> RawLedger
|
||||
addEntry e l0 = l0 { entries = e : (entries l0) }
|
||||
|
||||
addModifierEntry :: ModifierEntry -> RawLedger -> RawLedger
|
||||
addModifierEntry me l0 = l0 { modifier_entries = me : (modifier_entries l0) }
|
||||
|
||||
addPeriodicEntry :: PeriodicEntry -> RawLedger -> RawLedger
|
||||
addPeriodicEntry pe l0 = l0 { periodic_entries = pe : (periodic_entries l0) }
|
||||
|
||||
addTimeLogEntry :: TimeLogEntry -> RawLedger -> RawLedger
|
||||
addTimeLogEntry tle l0 = l0 { open_timelog_entries = tle : (open_timelog_entries l0) }
|
||||
|
||||
rawLedgerTransactions :: RawLedger -> [Transaction]
|
||||
rawLedgerTransactions = txnsof . entries
|
||||
where txnsof es = concat $ map flattenEntry $ zip es [1..]
|
||||
@ -54,16 +74,16 @@ filterRawLedger span pats clearedonly realonly =
|
||||
|
||||
-- | Keep only entries whose description matches the description patterns.
|
||||
filterRawLedgerEntriesByDescription :: [String] -> RawLedger -> RawLedger
|
||||
filterRawLedgerEntriesByDescription pats (RawLedger ms ps es f) =
|
||||
RawLedger ms ps (filter matchdesc es) f
|
||||
filterRawLedgerEntriesByDescription pats (RawLedger ms ps es tls f) =
|
||||
RawLedger ms ps (filter matchdesc es) tls f
|
||||
where matchdesc = matchpats pats . edescription
|
||||
|
||||
-- | Keep only entries which fall between begin and end dates.
|
||||
-- We include entries on the begin date and exclude entries on the end
|
||||
-- date, like ledger. An empty date string means no restriction.
|
||||
filterRawLedgerEntriesByDate :: DateSpan -> RawLedger -> RawLedger
|
||||
filterRawLedgerEntriesByDate (DateSpan begin end) (RawLedger ms ps es f) =
|
||||
RawLedger ms ps (filter matchdate es) f
|
||||
filterRawLedgerEntriesByDate (DateSpan begin end) (RawLedger ms ps es tls f) =
|
||||
RawLedger ms ps (filter matchdate es) tls f
|
||||
where
|
||||
matchdate e = (maybe True (edate e>=) begin) && (maybe True (edate e<) end)
|
||||
|
||||
@ -71,21 +91,21 @@ filterRawLedgerEntriesByDate (DateSpan begin end) (RawLedger ms ps es f) =
|
||||
-- do no filtering.
|
||||
filterRawLedgerEntriesByClearedStatus :: Bool -> RawLedger -> RawLedger
|
||||
filterRawLedgerEntriesByClearedStatus False l = l
|
||||
filterRawLedgerEntriesByClearedStatus True (RawLedger ms ps es f) =
|
||||
RawLedger ms ps (filter estatus es) f
|
||||
filterRawLedgerEntriesByClearedStatus True (RawLedger ms ps es tls f) =
|
||||
RawLedger ms ps (filter estatus es) tls f
|
||||
|
||||
-- | Strip out any virtual transactions, if the flag is true, otherwise do
|
||||
-- no filtering.
|
||||
filterRawLedgerTransactionsByRealness :: Bool -> RawLedger -> RawLedger
|
||||
filterRawLedgerTransactionsByRealness False l = l
|
||||
filterRawLedgerTransactionsByRealness True (RawLedger ms ps es f) =
|
||||
RawLedger ms ps (map filtertxns es) f
|
||||
filterRawLedgerTransactionsByRealness True (RawLedger ms ps es tls f) =
|
||||
RawLedger ms ps (map filtertxns es) tls f
|
||||
where filtertxns e@Entry{etransactions=ts} = e{etransactions=filter isReal ts}
|
||||
|
||||
-- | Keep only entries which affect accounts matched by the account patterns.
|
||||
filterRawLedgerEntriesByAccount :: [String] -> RawLedger -> RawLedger
|
||||
filterRawLedgerEntriesByAccount apats (RawLedger ms ps es f) =
|
||||
RawLedger ms ps (filter (any (matchpats apats . taccount) . etransactions) es) f
|
||||
filterRawLedgerEntriesByAccount apats (RawLedger ms ps es tls f) =
|
||||
RawLedger ms ps (filter (any (matchpats apats . taccount) . etransactions) es) tls f
|
||||
|
||||
-- | Give all a ledger's amounts their canonical display settings. That
|
||||
-- is, in each commodity, amounts will use the display settings of the
|
||||
@ -93,7 +113,7 @@ filterRawLedgerEntriesByAccount apats (RawLedger ms ps es f) =
|
||||
-- detected. Also, amounts are converted to cost basis if that flag is
|
||||
-- active.
|
||||
canonicaliseAmounts :: Bool -> RawLedger -> RawLedger
|
||||
canonicaliseAmounts costbasis l@(RawLedger ms ps es f) = RawLedger ms ps (map fixentry es) f
|
||||
canonicaliseAmounts costbasis l@(RawLedger ms ps es tls f) = RawLedger ms ps (map fixentry es) tls f
|
||||
where
|
||||
fixentry (Entry d s c de co ts pr) = Entry d s c de co (map fixrawtransaction ts) pr
|
||||
fixrawtransaction (RawTransaction ac a c t) = RawTransaction ac (fixmixedamount a) c t
|
||||
|
@ -77,6 +77,7 @@ data RawLedger = RawLedger {
|
||||
modifier_entries :: [ModifierEntry],
|
||||
periodic_entries :: [PeriodicEntry],
|
||||
entries :: [Entry],
|
||||
open_timelog_entries :: [TimeLogEntry],
|
||||
final_comment_lines :: String
|
||||
} deriving (Eq)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user