From 9ab9d460c1778a0f50443cad29af6d9b81e4da1b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 11 Jul 2007 08:15:58 +0000 Subject: [PATCH] report unbalanced entries --- LedgerEntry.hs | 10 ++++++---- LedgerTransaction.hs | 2 +- Parse.hs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/LedgerEntry.hs b/LedgerEntry.hs index 4187c630f..eca29f5d3 100644 --- a/LedgerEntry.hs +++ b/LedgerEntry.hs @@ -26,12 +26,14 @@ showDate d = printf "%-10s" d showDescription s = printf "%-20s" (elideRight 20 s) isEntryBalanced :: LedgerEntry -> Bool -isEntryBalanced e = (sumLedgerTransactions . etransactions) e == 0 +isEntryBalanced = (0==) . quantity . sumLedgerTransactions . etransactions autofillEntry :: LedgerEntry -> LedgerEntry -autofillEntry e = - LedgerEntry (edate e) (estatus e) (ecode e) (edescription e) (ecomment e) - (autofillTransactions (etransactions e)) +autofillEntry e@(LedgerEntry _ _ _ _ _ ts) = + let e' = e{etransactions=autofillTransactions ts} in + case (isEntryBalanced e') of + True -> e' + False -> (error $ "transactions don't balance in " ++ show e) -- the print command shows cleaned up ledger file entries, something like: -- diff --git a/LedgerTransaction.hs b/LedgerTransaction.hs index 7858e1b22..0c8d92c4c 100644 --- a/LedgerTransaction.hs +++ b/LedgerTransaction.hs @@ -27,8 +27,8 @@ autofillTransactions ts = otherwise -> error "too many blank transactions in this entry" where (normals, blanks) = partition isnormal ts - balance t = if isnormal t then t else t{tamount = -(sumLedgerTransactions normals)} isnormal t = (symbol $ currency $ tamount t) /= "AUTO" + balance t = if isnormal t then t else t{tamount = -(sumLedgerTransactions normals)} sumLedgerTransactions :: [LedgerTransaction] -> Amount sumLedgerTransactions = sum . map tamount diff --git a/Parse.hs b/Parse.hs index 2c766f638..01248fbea 100644 --- a/Parse.hs +++ b/Parse.hs @@ -195,7 +195,7 @@ ledgerentry = do date <- ledgerdate status <- ledgerstatus code <- ledgercode --- ledger treats entry comments as part of the description, we too for now +-- ledger treats entry comments as part of the description, we will too -- desc <- many (noneOf ";\n") "description" -- let description = reverse $ dropWhile (==' ') $ reverse desc description <- many (noneOf "\n") "description"