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
showtxn t = showacct t ++ " " ++ (showamount $ tamount 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
showaccountname s = printf "%-34s" s
showcomment s = if (length s) > 0 then " ; "++s else ""
showdate d = printf "%-10s" (showDate d)
showstatus t = case tstatus t of
True -> "* "
False -> ""
isEntryBalanced :: Entry -> Bool
isEntryBalanced (Entry {etransactions=ts}) =

View File

@ -366,16 +366,18 @@ ledgertransaction = many1 spacenonewline >> choice [ normaltransaction, virtualt
normaltransaction :: GenParser Char LedgerFileCtx RawTransaction
normaltransaction = do
status <- ledgerstatus
account <- transactionaccountname
amount <- transactionamount
many spacenonewline
comment <- ledgercomment
restofline
parent <- getParentAccount
return (RawTransaction account amount comment RegularTransaction)
return (RawTransaction status account amount comment RegularTransaction)
virtualtransaction :: GenParser Char LedgerFileCtx RawTransaction
virtualtransaction = do
status <- ledgerstatus
char '('
account <- transactionaccountname
char ')'
@ -384,10 +386,11 @@ virtualtransaction = do
comment <- ledgercomment
restofline
parent <- getParentAccount
return (RawTransaction account amount comment VirtualTransaction)
return (RawTransaction status account amount comment VirtualTransaction)
balancedvirtualtransaction :: GenParser Char LedgerFileCtx RawTransaction
balancedvirtualtransaction = do
status <- ledgerstatus
char '['
account <- transactionaccountname
char ']'
@ -395,7 +398,7 @@ balancedvirtualtransaction = do
many spacenonewline
comment <- ledgercomment
restofline
return (RawTransaction account amount comment BalancedVirtualTransaction)
return (RawTransaction status account amount comment BalancedVirtualTransaction)
-- Qualify with the parent account from parsing context
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
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
fixrawtransaction (RawTransaction s ac a c t) = RawTransaction s ac (fixmixedamount a) c t
fixmixedamount (Mixed as) = Mixed $ map fixamount as
fixamount = fixcommodity . (if costbasis then costOfAmount else id)
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
nullrawtxn = RawTransaction "" nullmixedamt "" RegularTransaction
nullrawtxn = RawTransaction False "" nullmixedamt "" RegularTransaction
showRawTransaction :: RawTransaction -> String
showRawTransaction (RawTransaction a amt _ ttype) =
showRawTransaction (RawTransaction s a amt _ ttype) =
concatTopPadded [showaccountname a ++ " ", showamount amt]
where
showaccountname = printf "%-22s" . bracket . elideAccountName width

View File

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

View File

@ -18,14 +18,16 @@ import Ledger.Amount
instance Show Transaction where show=showTransaction
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
-- is attached to the transactions to preserve their grouping - it should
-- be unique per entry.
flattenEntry :: (Entry, Int) -> [Transaction]
flattenEntry (Entry d _ _ desc _ ts _, e) =
[Transaction e d desc (taccount t) (tamount t) (rttype t) | t <- ts]
flattenEntry (Entry d s _ desc _ ts _, e) =
[Transaction e s d desc (taccount t) (tamount t) (rttype t) | t <- ts]
accountNamesFromTransactions :: [Transaction] -> [AccountName]
accountNamesFromTransactions ts = nub $ map account ts
@ -33,4 +35,4 @@ accountNamesFromTransactions ts = nub $ map account ts
sumTransactions :: [Transaction] -> MixedAmount
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)
data RawTransaction = RawTransaction {
tstatus :: Bool,
taccount :: AccountName,
tamount :: MixedAmount,
tcomment :: String,
@ -101,6 +102,7 @@ data TimeLog = TimeLog {
data Transaction = Transaction {
entryno :: Int,
status :: Bool,
date :: Day,
description :: String,
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
date = showDate $ da
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)
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 = RawTransaction "expenses:food:dining" (Mixed [dollars 10]) "" RegularTransaction
rawtransaction1 = RawTransaction False "expenses:food:dining" (Mixed [dollars 10]) "" RegularTransaction
entry1_str = unlines
["2007/01/28 coopportunity"
@ -793,8 +793,8 @@ entry1_str = unlines
entry1 =
(Entry (parsedate "2007/01/28") False "" "coopportunity" ""
[RawTransaction "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularTransaction,
RawTransaction "assets:checking" (Mixed [dollars (-47.18)]) "" RegularTransaction] "")
[RawTransaction False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularTransaction,
RawTransaction False "assets:checking" (Mixed [dollars (-47.18)]) "" RegularTransaction] "")
entry2_str = unlines
@ -948,12 +948,14 @@ rawledger7 = RawLedger
ecomment="",
etransactions=[
RawTransaction {
tstatus=False,
taccount="assets:cash",
tamount=(Mixed [dollars 4.82]),
tcomment="",
rttype=RegularTransaction
},
RawTransaction {
tstatus=False,
taccount="equity:opening balances",
tamount=(Mixed [dollars (-4.82)]),
tcomment="",
@ -971,12 +973,14 @@ rawledger7 = RawLedger
ecomment="",
etransactions=[
RawTransaction {
tstatus=False,
taccount="expenses:vacation",
tamount=(Mixed [dollars 179.92]),
tcomment="",
rttype=RegularTransaction
},
RawTransaction {
tstatus=False,
taccount="assets:checking",
tamount=(Mixed [dollars (-179.92)]),
tcomment="",
@ -994,12 +998,14 @@ rawledger7 = RawLedger
ecomment="",
etransactions=[
RawTransaction {
tstatus=False,
taccount="assets:saving",
tamount=(Mixed [dollars 200]),
tcomment="",
rttype=RegularTransaction
},
RawTransaction {
tstatus=False,
taccount="assets:checking",
tamount=(Mixed [dollars (-200)]),
tcomment="",
@ -1017,12 +1023,14 @@ rawledger7 = RawLedger
ecomment="",
etransactions=[
RawTransaction {
tstatus=False,
taccount="expenses:food:dining",
tamount=(Mixed [dollars 4.82]),
tcomment="",
rttype=RegularTransaction
},
RawTransaction {
tstatus=False,
taccount="assets:cash",
tamount=(Mixed [dollars (-4.82)]),
tcomment="",
@ -1040,12 +1048,14 @@ rawledger7 = RawLedger
ecomment="",
etransactions=[
RawTransaction {
tstatus=False,
taccount="expenses:phone",
tamount=(Mixed [dollars 95.11]),
tcomment="",
rttype=RegularTransaction
},
RawTransaction {
tstatus=False,
taccount="assets:checking",
tamount=(Mixed [dollars (-95.11)]),
tcomment="",
@ -1063,12 +1073,14 @@ rawledger7 = RawLedger
ecomment="",
etransactions=[
RawTransaction {
tstatus=False,
taccount="liabilities:credit cards:discover",
tamount=(Mixed [dollars 80]),
tcomment="",
rttype=RegularTransaction
},
RawTransaction {
tstatus=False,
taccount="assets:checking",
tamount=(Mixed [dollars (-80)]),
tcomment="",