individual transactions now have a cleared status

This commit is contained in:
Simon Michael 2009-01-23 00:14:12 +00:00
parent 55c0a688c0
commit 1fc9db3af5
9 changed files with 39 additions and 17 deletions

View File

@ -70,11 +70,14 @@ showEntry' elide e =
| otherwise = map showtxn ts | otherwise = map showtxn ts
showtxn t = showacct t ++ " " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t) showtxn t = showacct t ++ " " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t)
showtxnnoamt t = showacct t ++ " " ++ (showcomment $ tcomment t) showtxnnoamt t = showacct t ++ " " ++ (showcomment $ tcomment t)
showacct t = " " ++ (showaccountname $ taccount t) showacct t = " " ++ showstatus t ++ (showaccountname $ taccount t)
showamount = printf "%12s" . showMixedAmount showamount = printf "%12s" . showMixedAmount
showaccountname s = printf "%-34s" s showaccountname s = printf "%-34s" s
showcomment s = if (length s) > 0 then " ; "++s else "" showcomment s = if (length s) > 0 then " ; "++s else ""
showdate d = printf "%-10s" (showDate d) showdate d = printf "%-10s" (showDate d)
showstatus t = case tstatus t of
True -> "* "
False -> ""
isEntryBalanced :: Entry -> Bool isEntryBalanced :: Entry -> Bool
isEntryBalanced (Entry {etransactions=ts}) = isEntryBalanced (Entry {etransactions=ts}) =

View File

@ -366,16 +366,18 @@ ledgertransaction = many1 spacenonewline >> choice [ normaltransaction, virtualt
normaltransaction :: GenParser Char LedgerFileCtx RawTransaction normaltransaction :: GenParser Char LedgerFileCtx RawTransaction
normaltransaction = do normaltransaction = do
status <- ledgerstatus
account <- transactionaccountname account <- transactionaccountname
amount <- transactionamount amount <- transactionamount
many spacenonewline many spacenonewline
comment <- ledgercomment comment <- ledgercomment
restofline restofline
parent <- getParentAccount parent <- getParentAccount
return (RawTransaction account amount comment RegularTransaction) return (RawTransaction status account amount comment RegularTransaction)
virtualtransaction :: GenParser Char LedgerFileCtx RawTransaction virtualtransaction :: GenParser Char LedgerFileCtx RawTransaction
virtualtransaction = do virtualtransaction = do
status <- ledgerstatus
char '(' char '('
account <- transactionaccountname account <- transactionaccountname
char ')' char ')'
@ -384,10 +386,11 @@ virtualtransaction = do
comment <- ledgercomment comment <- ledgercomment
restofline restofline
parent <- getParentAccount parent <- getParentAccount
return (RawTransaction account amount comment VirtualTransaction) return (RawTransaction status account amount comment VirtualTransaction)
balancedvirtualtransaction :: GenParser Char LedgerFileCtx RawTransaction balancedvirtualtransaction :: GenParser Char LedgerFileCtx RawTransaction
balancedvirtualtransaction = do balancedvirtualtransaction = do
status <- ledgerstatus
char '[' char '['
account <- transactionaccountname account <- transactionaccountname
char ']' char ']'
@ -395,7 +398,7 @@ balancedvirtualtransaction = do
many spacenonewline many spacenonewline
comment <- ledgercomment comment <- ledgercomment
restofline restofline
return (RawTransaction account amount comment BalancedVirtualTransaction) return (RawTransaction status account amount comment BalancedVirtualTransaction)
-- Qualify with the parent account from parsing context -- Qualify with the parent account from parsing context
transactionaccountname :: GenParser Char LedgerFileCtx AccountName transactionaccountname :: GenParser Char LedgerFileCtx AccountName

View File

@ -128,7 +128,7 @@ canonicaliseAmounts :: Bool -> RawLedger -> RawLedger
canonicaliseAmounts costbasis l@(RawLedger ms ps es tls hs f) = RawLedger ms ps (map fixentry es) tls hs f canonicaliseAmounts costbasis l@(RawLedger ms ps es tls hs f) = RawLedger ms ps (map fixentry es) tls hs 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 s ac a c t) = RawTransaction s ac (fixmixedamount a) c t
fixmixedamount (Mixed as) = Mixed $ map fixamount as fixmixedamount (Mixed as) = Mixed $ map fixamount as
fixamount = fixcommodity . (if costbasis then costOfAmount else id) fixamount = fixcommodity . (if costbasis then costOfAmount else id)
fixcommodity a = a{commodity=c} where c = canonicalcommoditymap ! (symbol $ commodity a) fixcommodity a = a{commodity=c} where c = canonicalcommoditymap ! (symbol $ commodity a)

View File

@ -15,10 +15,10 @@ import Ledger.AccountName
instance Show RawTransaction where show = showRawTransaction instance Show RawTransaction where show = showRawTransaction
nullrawtxn = RawTransaction "" nullmixedamt "" RegularTransaction nullrawtxn = RawTransaction False "" nullmixedamt "" RegularTransaction
showRawTransaction :: RawTransaction -> String showRawTransaction :: RawTransaction -> String
showRawTransaction (RawTransaction a amt _ ttype) = showRawTransaction (RawTransaction s a amt _ ttype) =
concatTopPadded [showaccountname a ++ " ", showamount amt] concatTopPadded [showaccountname a ++ " ", showamount amt]
where where
showaccountname = printf "%-22s" . bracket . elideAccountName width showaccountname = printf "%-22s" . bracket . elideAccountName width

View File

@ -73,6 +73,6 @@ entryFromTimeLogInOut i o
odate = localDay otime odate = localDay otime
hrs = elapsedSeconds (toutc otime) (toutc itime) / 3600 where toutc = localTimeToUTC utc hrs = elapsedSeconds (toutc otime) (toutc itime) / 3600 where toutc = localTimeToUTC utc
amount = Mixed [hours hrs] amount = Mixed [hours hrs]
txns = [RawTransaction acctname amount "" RegularTransaction txns = [RawTransaction False acctname amount "" RegularTransaction
--,RawTransaction "assets:time" (-amount) "" RegularTransaction --,RawTransaction "assets:time" (-amount) "" RegularTransaction
] ]

View File

@ -18,14 +18,16 @@ import Ledger.Amount
instance Show Transaction where show=showTransaction instance Show Transaction where show=showTransaction
showTransaction :: Transaction -> String showTransaction :: Transaction -> String
showTransaction (Transaction eno d desc a amt ttype) = unwords [showDate d,desc,a,show amt,show ttype] showTransaction (Transaction eno stat d desc a amt ttype) =
s ++ unwords [showDate d,desc,a,show amt,show ttype]
where s = if stat then " *" else ""
-- | Convert a 'Entry' to two or more 'Transaction's. An id number -- | Convert a 'Entry' to two or more 'Transaction's. An id number
-- is attached to the transactions to preserve their grouping - it should -- is attached to the transactions to preserve their grouping - it should
-- be unique per entry. -- be unique per entry.
flattenEntry :: (Entry, Int) -> [Transaction] flattenEntry :: (Entry, Int) -> [Transaction]
flattenEntry (Entry d _ _ desc _ ts _, e) = flattenEntry (Entry d s _ desc _ ts _, e) =
[Transaction e d desc (taccount t) (tamount t) (rttype t) | t <- ts] [Transaction e s d desc (taccount t) (tamount t) (rttype t) | t <- ts]
accountNamesFromTransactions :: [Transaction] -> [AccountName] accountNamesFromTransactions :: [Transaction] -> [AccountName]
accountNamesFromTransactions ts = nub $ map account ts accountNamesFromTransactions ts = nub $ map account ts
@ -33,4 +35,4 @@ accountNamesFromTransactions ts = nub $ map account ts
sumTransactions :: [Transaction] -> MixedAmount sumTransactions :: [Transaction] -> MixedAmount
sumTransactions = sum . map amount sumTransactions = sum . map amount
nulltxn = Transaction 0 (parsedate "1900/1/1") "" "" nullmixedamt RegularTransaction nulltxn = Transaction 0 False (parsedate "1900/1/1") "" "" nullmixedamt RegularTransaction

View File

@ -45,6 +45,7 @@ data TransactionType = RegularTransaction | VirtualTransaction | BalancedVirtual
deriving (Eq,Show) deriving (Eq,Show)
data RawTransaction = RawTransaction { data RawTransaction = RawTransaction {
tstatus :: Bool,
taccount :: AccountName, taccount :: AccountName,
tamount :: MixedAmount, tamount :: MixedAmount,
tcomment :: String, tcomment :: String,
@ -101,6 +102,7 @@ data TimeLog = TimeLog {
data Transaction = Transaction { data Transaction = Transaction {
entryno :: Int, entryno :: Int,
status :: Bool,
date :: Day, date :: Day,
description :: String, description :: String,
account :: AccountName, account :: AccountName,

View File

@ -118,7 +118,7 @@ showtxn omitdesc t b = concatBottomPadded [entrydesc ++ txn ++ " ", bal] ++ "\n"
entrydesc = if omitdesc then replicate 32 ' ' else printf "%s %s " date desc entrydesc = if omitdesc then replicate 32 ' ' else printf "%s %s " date desc
date = showDate $ da date = showDate $ da
desc = printf "%-20s" $ elideRight 20 de :: String desc = printf "%-20s" $ elideRight 20 de :: String
txn = showRawTransaction $ RawTransaction a amt "" tt txn = showRawTransaction $ RawTransaction s a amt "" tt
bal = padleft 12 (showMixedAmountOrZero b) bal = padleft 12 (showMixedAmountOrZero b)
Transaction{date=da,description=de,account=a,amount=amt,ttype=tt} = t Transaction{status=s,date=da,description=de,account=a,amount=amt,ttype=tt} = t

View File

@ -782,7 +782,7 @@ write_sample_ledger = writeFile "sample.ledger" sample_ledger_str
rawtransaction1_str = " expenses:food:dining $10.00\n" rawtransaction1_str = " expenses:food:dining $10.00\n"
rawtransaction1 = RawTransaction "expenses:food:dining" (Mixed [dollars 10]) "" RegularTransaction rawtransaction1 = RawTransaction False "expenses:food:dining" (Mixed [dollars 10]) "" RegularTransaction
entry1_str = unlines entry1_str = unlines
["2007/01/28 coopportunity" ["2007/01/28 coopportunity"
@ -793,8 +793,8 @@ entry1_str = unlines
entry1 = entry1 =
(Entry (parsedate "2007/01/28") False "" "coopportunity" "" (Entry (parsedate "2007/01/28") False "" "coopportunity" ""
[RawTransaction "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularTransaction, [RawTransaction False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularTransaction,
RawTransaction "assets:checking" (Mixed [dollars (-47.18)]) "" RegularTransaction] "") RawTransaction False "assets:checking" (Mixed [dollars (-47.18)]) "" RegularTransaction] "")
entry2_str = unlines entry2_str = unlines
@ -948,12 +948,14 @@ rawledger7 = RawLedger
ecomment="", ecomment="",
etransactions=[ etransactions=[
RawTransaction { RawTransaction {
tstatus=False,
taccount="assets:cash", taccount="assets:cash",
tamount=(Mixed [dollars 4.82]), tamount=(Mixed [dollars 4.82]),
tcomment="", tcomment="",
rttype=RegularTransaction rttype=RegularTransaction
}, },
RawTransaction { RawTransaction {
tstatus=False,
taccount="equity:opening balances", taccount="equity:opening balances",
tamount=(Mixed [dollars (-4.82)]), tamount=(Mixed [dollars (-4.82)]),
tcomment="", tcomment="",
@ -971,12 +973,14 @@ rawledger7 = RawLedger
ecomment="", ecomment="",
etransactions=[ etransactions=[
RawTransaction { RawTransaction {
tstatus=False,
taccount="expenses:vacation", taccount="expenses:vacation",
tamount=(Mixed [dollars 179.92]), tamount=(Mixed [dollars 179.92]),
tcomment="", tcomment="",
rttype=RegularTransaction rttype=RegularTransaction
}, },
RawTransaction { RawTransaction {
tstatus=False,
taccount="assets:checking", taccount="assets:checking",
tamount=(Mixed [dollars (-179.92)]), tamount=(Mixed [dollars (-179.92)]),
tcomment="", tcomment="",
@ -994,12 +998,14 @@ rawledger7 = RawLedger
ecomment="", ecomment="",
etransactions=[ etransactions=[
RawTransaction { RawTransaction {
tstatus=False,
taccount="assets:saving", taccount="assets:saving",
tamount=(Mixed [dollars 200]), tamount=(Mixed [dollars 200]),
tcomment="", tcomment="",
rttype=RegularTransaction rttype=RegularTransaction
}, },
RawTransaction { RawTransaction {
tstatus=False,
taccount="assets:checking", taccount="assets:checking",
tamount=(Mixed [dollars (-200)]), tamount=(Mixed [dollars (-200)]),
tcomment="", tcomment="",
@ -1017,12 +1023,14 @@ rawledger7 = RawLedger
ecomment="", ecomment="",
etransactions=[ etransactions=[
RawTransaction { RawTransaction {
tstatus=False,
taccount="expenses:food:dining", taccount="expenses:food:dining",
tamount=(Mixed [dollars 4.82]), tamount=(Mixed [dollars 4.82]),
tcomment="", tcomment="",
rttype=RegularTransaction rttype=RegularTransaction
}, },
RawTransaction { RawTransaction {
tstatus=False,
taccount="assets:cash", taccount="assets:cash",
tamount=(Mixed [dollars (-4.82)]), tamount=(Mixed [dollars (-4.82)]),
tcomment="", tcomment="",
@ -1040,12 +1048,14 @@ rawledger7 = RawLedger
ecomment="", ecomment="",
etransactions=[ etransactions=[
RawTransaction { RawTransaction {
tstatus=False,
taccount="expenses:phone", taccount="expenses:phone",
tamount=(Mixed [dollars 95.11]), tamount=(Mixed [dollars 95.11]),
tcomment="", tcomment="",
rttype=RegularTransaction rttype=RegularTransaction
}, },
RawTransaction { RawTransaction {
tstatus=False,
taccount="assets:checking", taccount="assets:checking",
tamount=(Mixed [dollars (-95.11)]), tamount=(Mixed [dollars (-95.11)]),
tcomment="", tcomment="",
@ -1063,12 +1073,14 @@ rawledger7 = RawLedger
ecomment="", ecomment="",
etransactions=[ etransactions=[
RawTransaction { RawTransaction {
tstatus=False,
taccount="liabilities:credit cards:discover", taccount="liabilities:credit cards:discover",
tamount=(Mixed [dollars 80]), tamount=(Mixed [dollars 80]),
tcomment="", tcomment="",
rttype=RegularTransaction rttype=RegularTransaction
}, },
RawTransaction { RawTransaction {
tstatus=False,
taccount="assets:checking", taccount="assets:checking",
tamount=(Mixed [dollars (-80)]), tamount=(Mixed [dollars (-80)]),
tcomment="", tcomment="",