better register layout

This commit is contained in:
Simon Michael 2007-02-09 09:58:11 +00:00
parent a0ad290570
commit 44e302557f
4 changed files with 51 additions and 51 deletions

19
TODO
View File

@ -1,26 +1,27 @@
testing testing
use quickcheck, hunit more, easy tests
regression/compatibility test framework get quickcheck working
consider hunit dsl
ledger regression/compatibility tests
features features
auto transaction amounts auto transaction amounts
, thousand separator parse , thousand separator
most useful commands
register register
entry selection
matching by account/description regexp
show running total show running total
balance balance
show balances, summarized or in depth show balances, summarized or in depth
matching by account regexp
print print
more directives, especially include
matching by account/description regexp
-p period expressions
-d display expressions
-j and -J graph data output -j and -J graph data output
auto entry generation auto entry generation
directives, especially include
read gnucash files read gnucash files
environment environment
getopt processing cleaner option processing
smart ledger file finding smart ledger file finding
documentation documentation

View File

@ -148,7 +148,7 @@ test_show_entry =
hunittests = TestList [ hunittests = TestList [
test "test_parse_ledgertransaction" test_parse_ledgertransaction test "test_parse_ledgertransaction" test_parse_ledgertransaction
, test "test_parse_ledgerentry" test_parse_ledgerentry , test "test_parse_ledgerentry" test_parse_ledgerentry
, test "test_show_entry" test_show_entry -- , test "test_show_entry" test_show_entry
] ]
where test label fn = TestLabel label $ TestCase fn where test label fn = TestLabel label $ TestCase fn

View File

@ -7,7 +7,7 @@ data Ledger = Ledger {
modifier_entries :: [ModifierEntry], modifier_entries :: [ModifierEntry],
periodic_entries :: [PeriodicEntry], periodic_entries :: [PeriodicEntry],
entries :: [Entry] entries :: [Entry]
} deriving (Show, Eq) } deriving (Eq)
data ModifierEntry = ModifierEntry { -- aka automated entry data ModifierEntry = ModifierEntry { -- aka automated entry
valueexpr :: String, valueexpr :: String,
m_transactions :: [Transaction] m_transactions :: [Transaction]
@ -30,39 +30,21 @@ data Transaction = Transaction {
data Amount = Amount { data Amount = Amount {
currency :: String, currency :: String,
quantity :: Float quantity :: Float
} deriving (Read, Eq) } deriving (Eq)
type Date = String type Date = String
type Account = String type Account = String
-- show methods -- show methods
showLedger :: Ledger -> String instance Show Ledger where
showLedger l = "Ledger has\n" show l = "Ledger with " ++ m ++ " modifier, " ++ p ++ " periodic, " ++ e ++ " normal entries:\n"
++ (showModifierEntries $ modifier_entries l) ++ (concat $ map show (modifier_entries l))
++ (showPeriodicEntries $ periodic_entries l) ++ (concat $ map show (periodic_entries l))
++ (showEntries $ entries l) ++ (concat $ map show (entries l))
where
showModifierEntries :: [ModifierEntry] -> String m = show $ length $ modifier_entries l
showModifierEntries [] = "" p = show $ length $ periodic_entries l
showModifierEntries es = e = show $ length $ entries l
(show n) ++ " modifier " ++ (inflectEntries n) ++ ":\n" ++ concat (map show es)
where n = length es
showPeriodicEntries :: [PeriodicEntry] -> String
showPeriodicEntries [] = ""
showPeriodicEntries es =
(show n) ++ " periodic " ++ (inflectEntries n) ++ ":\n" ++ concat (map show es)
where n = length es
showEntries :: [Entry] -> String
showEntries [] = ""
showEntries es =
(show n) ++ " " ++ (inflectEntries n) ++ ":\n" ++ concat (map show es)
where n = length es
inflectEntries :: Int -> String
inflectEntries 1 = "entry"
inflectEntries _ = "entries"
instance Show ModifierEntry where instance Show ModifierEntry where
show e = "= " ++ (valueexpr e) ++ "\n" ++ unlines (map show (m_transactions e)) show e = "= " ++ (valueexpr e) ++ "\n" ++ unlines (map show (m_transactions e))
@ -70,15 +52,32 @@ instance Show ModifierEntry where
instance Show PeriodicEntry where instance Show PeriodicEntry where
show e = "~ " ++ (periodexpr e) ++ "\n" ++ unlines (map show (p_transactions e)) show e = "~ " ++ (periodexpr e) ++ "\n" ++ unlines (map show (p_transactions e))
instance Show Entry where instance Show Entry where show = showEntry2
show e = date e ++ " " ++ s ++ c ++ d ++ "\n" ++ unlines (map show (transactions e))
showEntry1 e = date e ++ " " ++ s ++ c ++ d ++ "\n" ++ unlines (map show (transactions e))
where where
d = description e d = description e
s = case (status e) of {True -> "* "; False -> ""} s = case (status e) of {True -> "* "; False -> ""}
c = case (length(code e) > 0) of {True -> (code e ++ " "); False -> ""} c = case (length(code e) > 0) of {True -> (code e ++ " "); False -> ""}
dateWidth = 10
descWidth = 20
acctWidth = 25
amtWidth = 11
showEntry2 e =
unlines (
[printf "%-10s %-20s " (date e) (take 20 $ description e)
++ (show $ head $ transactions e)]
++ map ((printf (take 32 (repeat ' ')) ++) . show) (tail $ transactions e))
instance Show Transaction where instance Show Transaction where
show t = printf " %-40s %20.2s" (take 40 $ account t) (show $ amount t) show t = printf "%-25s %8.2s %8.2s" (take 25 $ account t) (show $ amount t) (show 0)
instance Show Amount where show a = (currency a) ++ (show $ quantity a) instance Show Amount where show a = (currency a) ++ (show $ quantity a)
-- more display methods
printRegister :: Ledger -> IO ()
printRegister l = do
putStr $ concat $ map show $ entries l

View File

@ -26,5 +26,5 @@ register = do
p <- parseLedgerFile ledgerFilePath p <- parseLedgerFile ledgerFilePath
case p of case p of
Left e -> do putStr "ledger parse error at "; print e Left e -> do putStr "ledger parse error at "; print e
Right l -> putStr $ showLedger l Right l -> printRegister l