diff --git a/Ledger/Entry.hs b/Ledger/Entry.hs index 33ca47bf3..1ecbee4d1 100644 --- a/Ledger/Entry.hs +++ b/Ledger/Entry.hs @@ -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}) = diff --git a/Ledger/Parse.hs b/Ledger/Parse.hs index edd5f2bd6..9b91a59a6 100644 --- a/Ledger/Parse.hs +++ b/Ledger/Parse.hs @@ -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 diff --git a/Ledger/RawLedger.hs b/Ledger/RawLedger.hs index 663c19422..33c7f9377 100644 --- a/Ledger/RawLedger.hs +++ b/Ledger/RawLedger.hs @@ -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) diff --git a/Ledger/RawTransaction.hs b/Ledger/RawTransaction.hs index 7e87741fe..3c4bca713 100644 --- a/Ledger/RawTransaction.hs +++ b/Ledger/RawTransaction.hs @@ -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 diff --git a/Ledger/TimeLog.hs b/Ledger/TimeLog.hs index d10285441..748d22758 100644 --- a/Ledger/TimeLog.hs +++ b/Ledger/TimeLog.hs @@ -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 ] diff --git a/Ledger/Transaction.hs b/Ledger/Transaction.hs index 7403667f3..4430fb3d6 100644 --- a/Ledger/Transaction.hs +++ b/Ledger/Transaction.hs @@ -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 diff --git a/Ledger/Types.hs b/Ledger/Types.hs index e82d56e2e..62201a574 100644 --- a/Ledger/Types.hs +++ b/Ledger/Types.hs @@ -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, diff --git a/RegisterCommand.hs b/RegisterCommand.hs index a61a242da..e76726c16 100644 --- a/RegisterCommand.hs +++ b/RegisterCommand.hs @@ -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 diff --git a/Tests.hs b/Tests.hs index fddb5a36f..eae68abe3 100644 --- a/Tests.hs +++ b/Tests.hs @@ -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="",