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)
|
-- ++ (show $ rawLedgerTransactions l)
|
||||||
where accounts = flatten $ rawLedgerAccountNameTree 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 :: RawLedger -> [Transaction]
|
||||||
rawLedgerTransactions = txnsof . entries
|
rawLedgerTransactions = txnsof . entries
|
||||||
where txnsof es = concat $ map flattenEntry $ zip es [1..]
|
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.
|
-- | Keep only entries whose description matches the description patterns.
|
||||||
filterRawLedgerEntriesByDescription :: [String] -> RawLedger -> RawLedger
|
filterRawLedgerEntriesByDescription :: [String] -> RawLedger -> RawLedger
|
||||||
filterRawLedgerEntriesByDescription pats (RawLedger ms ps es f) =
|
filterRawLedgerEntriesByDescription pats (RawLedger ms ps es tls f) =
|
||||||
RawLedger ms ps (filter matchdesc es) f
|
RawLedger ms ps (filter matchdesc es) tls f
|
||||||
where matchdesc = matchpats pats . edescription
|
where matchdesc = matchpats pats . edescription
|
||||||
|
|
||||||
-- | Keep only entries which fall between begin and end dates.
|
-- | Keep only entries which fall between begin and end dates.
|
||||||
-- We include entries on the begin date and exclude entries on the end
|
-- We include entries on the begin date and exclude entries on the end
|
||||||
-- date, like ledger. An empty date string means no restriction.
|
-- date, like ledger. An empty date string means no restriction.
|
||||||
filterRawLedgerEntriesByDate :: DateSpan -> RawLedger -> RawLedger
|
filterRawLedgerEntriesByDate :: DateSpan -> RawLedger -> RawLedger
|
||||||
filterRawLedgerEntriesByDate (DateSpan begin end) (RawLedger ms ps es f) =
|
filterRawLedgerEntriesByDate (DateSpan begin end) (RawLedger ms ps es tls f) =
|
||||||
RawLedger ms ps (filter matchdate es) f
|
RawLedger ms ps (filter matchdate es) tls f
|
||||||
where
|
where
|
||||||
matchdate e = (maybe True (edate e>=) begin) && (maybe True (edate e<) end)
|
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.
|
-- do no filtering.
|
||||||
filterRawLedgerEntriesByClearedStatus :: Bool -> RawLedger -> RawLedger
|
filterRawLedgerEntriesByClearedStatus :: Bool -> RawLedger -> RawLedger
|
||||||
filterRawLedgerEntriesByClearedStatus False l = l
|
filterRawLedgerEntriesByClearedStatus False l = l
|
||||||
filterRawLedgerEntriesByClearedStatus True (RawLedger ms ps es f) =
|
filterRawLedgerEntriesByClearedStatus True (RawLedger ms ps es tls f) =
|
||||||
RawLedger ms ps (filter estatus es) f
|
RawLedger ms ps (filter estatus es) tls f
|
||||||
|
|
||||||
-- | Strip out any virtual transactions, if the flag is true, otherwise do
|
-- | Strip out any virtual transactions, if the flag is true, otherwise do
|
||||||
-- no filtering.
|
-- no filtering.
|
||||||
filterRawLedgerTransactionsByRealness :: Bool -> RawLedger -> RawLedger
|
filterRawLedgerTransactionsByRealness :: Bool -> RawLedger -> RawLedger
|
||||||
filterRawLedgerTransactionsByRealness False l = l
|
filterRawLedgerTransactionsByRealness False l = l
|
||||||
filterRawLedgerTransactionsByRealness True (RawLedger ms ps es f) =
|
filterRawLedgerTransactionsByRealness True (RawLedger ms ps es tls f) =
|
||||||
RawLedger ms ps (map filtertxns es) f
|
RawLedger ms ps (map filtertxns es) tls f
|
||||||
where filtertxns e@Entry{etransactions=ts} = e{etransactions=filter isReal ts}
|
where filtertxns e@Entry{etransactions=ts} = e{etransactions=filter isReal ts}
|
||||||
|
|
||||||
-- | Keep only entries which affect accounts matched by the account patterns.
|
-- | Keep only entries which affect accounts matched by the account patterns.
|
||||||
filterRawLedgerEntriesByAccount :: [String] -> RawLedger -> RawLedger
|
filterRawLedgerEntriesByAccount :: [String] -> RawLedger -> RawLedger
|
||||||
filterRawLedgerEntriesByAccount apats (RawLedger ms ps es f) =
|
filterRawLedgerEntriesByAccount apats (RawLedger ms ps es tls f) =
|
||||||
RawLedger ms ps (filter (any (matchpats apats . taccount) . etransactions) es) f
|
RawLedger ms ps (filter (any (matchpats apats . taccount) . etransactions) es) tls f
|
||||||
|
|
||||||
-- | Give all a ledger's amounts their canonical display settings. That
|
-- | Give all a ledger's amounts their canonical display settings. That
|
||||||
-- is, in each commodity, amounts will use the display settings of the
|
-- 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
|
-- detected. Also, amounts are converted to cost basis if that flag is
|
||||||
-- active.
|
-- active.
|
||||||
canonicaliseAmounts :: Bool -> RawLedger -> RawLedger
|
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
|
where
|
||||||
fixentry (Entry d s c de co ts pr) = Entry d s c de co (map fixrawtransaction ts) pr
|
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
|
fixrawtransaction (RawTransaction ac a c t) = RawTransaction ac (fixmixedamount a) c t
|
||||||
|
|||||||
@ -77,6 +77,7 @@ data RawLedger = RawLedger {
|
|||||||
modifier_entries :: [ModifierEntry],
|
modifier_entries :: [ModifierEntry],
|
||||||
periodic_entries :: [PeriodicEntry],
|
periodic_entries :: [PeriodicEntry],
|
||||||
entries :: [Entry],
|
entries :: [Entry],
|
||||||
|
open_timelog_entries :: [TimeLogEntry],
|
||||||
final_comment_lines :: String
|
final_comment_lines :: String
|
||||||
} deriving (Eq)
|
} deriving (Eq)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user