report unbalanced entries

This commit is contained in:
Simon Michael 2007-07-11 08:15:58 +00:00
parent d52b365fa0
commit 9ab9d460c1
3 changed files with 8 additions and 6 deletions

View File

@ -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:
--

View File

@ -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

View File

@ -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"