2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
module Entry
|
|
|
|
where
|
|
|
|
import Utils
|
2007-07-02 18:54:36 +04:00
|
|
|
import Types
|
2007-02-16 12:00:17 +03:00
|
|
|
import Transaction
|
|
|
|
|
|
|
|
|
2007-07-03 03:41:07 +04:00
|
|
|
instance Show Entry where show = showEntry
|
|
|
|
|
2007-02-16 12:00:17 +03:00
|
|
|
-- a register entry is displayed as two or more lines like this:
|
|
|
|
-- date description account amount balance
|
|
|
|
-- DDDDDDDDDD dddddddddddddddddddd aaaaaaaaaaaaaaaaaaaaaa AAAAAAAAAAA AAAAAAAAAAAA
|
|
|
|
-- aaaaaaaaaaaaaaaaaaaaaa AAAAAAAAAAA AAAAAAAAAAAA
|
|
|
|
-- ... ... ...
|
|
|
|
-- dateWidth = 10
|
|
|
|
-- descWidth = 20
|
|
|
|
-- acctWidth = 22
|
|
|
|
-- amtWidth = 11
|
|
|
|
-- balWidth = 12
|
|
|
|
|
|
|
|
showEntry e = (showDate $ edate e) ++ " " ++ (showDescription $ edescription e) ++ " "
|
|
|
|
showDate d = printf "%-10s" d
|
|
|
|
showDescription s = printf "%-20s" (elideRight 20 s)
|
|
|
|
|
|
|
|
isEntryBalanced :: Entry -> Bool
|
|
|
|
isEntryBalanced e = (sumTransactions . etransactions) e == 0
|
|
|
|
|
|
|
|
autofillEntry :: Entry -> Entry
|
|
|
|
autofillEntry e =
|
|
|
|
Entry (edate e) (estatus e) (ecode e) (edescription e)
|
|
|
|
(autofillTransactions (etransactions e))
|
|
|
|
|
|
|
|
-- modifier & periodic entries
|
|
|
|
|
|
|
|
instance Show ModifierEntry where
|
|
|
|
show e = "= " ++ (valueexpr e) ++ "\n" ++ unlines (map show (m_transactions e))
|
|
|
|
|
|
|
|
instance Show PeriodicEntry where
|
|
|
|
show e = "~ " ++ (periodexpr e) ++ "\n" ++ unlines (map show (p_transactions e))
|
|
|
|
|