mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
report unbalanced entries
This commit is contained in:
parent
d52b365fa0
commit
9ab9d460c1
@ -26,12 +26,14 @@ showDate d = printf "%-10s" d
|
|||||||
showDescription s = printf "%-20s" (elideRight 20 s)
|
showDescription s = printf "%-20s" (elideRight 20 s)
|
||||||
|
|
||||||
isEntryBalanced :: LedgerEntry -> Bool
|
isEntryBalanced :: LedgerEntry -> Bool
|
||||||
isEntryBalanced e = (sumLedgerTransactions . etransactions) e == 0
|
isEntryBalanced = (0==) . quantity . sumLedgerTransactions . etransactions
|
||||||
|
|
||||||
autofillEntry :: LedgerEntry -> LedgerEntry
|
autofillEntry :: LedgerEntry -> LedgerEntry
|
||||||
autofillEntry e =
|
autofillEntry e@(LedgerEntry _ _ _ _ _ ts) =
|
||||||
LedgerEntry (edate e) (estatus e) (ecode e) (edescription e) (ecomment e)
|
let e' = e{etransactions=autofillTransactions ts} in
|
||||||
(autofillTransactions (etransactions e))
|
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:
|
-- the print command shows cleaned up ledger file entries, something like:
|
||||||
--
|
--
|
||||||
|
@ -27,8 +27,8 @@ autofillTransactions ts =
|
|||||||
otherwise -> error "too many blank transactions in this entry"
|
otherwise -> error "too many blank transactions in this entry"
|
||||||
where
|
where
|
||||||
(normals, blanks) = partition isnormal ts
|
(normals, blanks) = partition isnormal ts
|
||||||
balance t = if isnormal t then t else t{tamount = -(sumLedgerTransactions normals)}
|
|
||||||
isnormal t = (symbol $ currency $ tamount t) /= "AUTO"
|
isnormal t = (symbol $ currency $ tamount t) /= "AUTO"
|
||||||
|
balance t = if isnormal t then t else t{tamount = -(sumLedgerTransactions normals)}
|
||||||
|
|
||||||
sumLedgerTransactions :: [LedgerTransaction] -> Amount
|
sumLedgerTransactions :: [LedgerTransaction] -> Amount
|
||||||
sumLedgerTransactions = sum . map tamount
|
sumLedgerTransactions = sum . map tamount
|
||||||
|
2
Parse.hs
2
Parse.hs
@ -195,7 +195,7 @@ ledgerentry = do
|
|||||||
date <- ledgerdate
|
date <- ledgerdate
|
||||||
status <- ledgerstatus
|
status <- ledgerstatus
|
||||||
code <- ledgercode
|
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"
|
-- desc <- many (noneOf ";\n") <?> "description"
|
||||||
-- let description = reverse $ dropWhile (==' ') $ reverse desc
|
-- let description = reverse $ dropWhile (==' ') $ reverse desc
|
||||||
description <- many (noneOf "\n") <?> "description"
|
description <- many (noneOf "\n") <?> "description"
|
||||||
|
Loading…
Reference in New Issue
Block a user