print: show end of line comments; all tests now passing
This commit is contained in:
parent
c6eac33d32
commit
c06580ff2a
@ -63,12 +63,13 @@ showLedgerTransaction' :: Bool -> Bool -> LedgerTransaction -> String
|
||||
showLedgerTransaction' elide effective t =
|
||||
unlines $ [description] ++ showpostings (ltpostings t) ++ [""]
|
||||
where
|
||||
description = concat [date, status, code, desc] -- , comment]
|
||||
description = concat [date, status, code, desc, comment]
|
||||
date | effective = showdate $ fromMaybe (ltdate t) $ lteffectivedate t
|
||||
| otherwise = showdate (ltdate t) ++ maybe "" showedate (lteffectivedate t)
|
||||
status = if ltstatus t then " *" else ""
|
||||
code = if length (ltcode t) > 0 then printf " (%s)" $ ltcode t else ""
|
||||
desc = ' ' : ltdescription t
|
||||
comment = if null com then "" else " ; " ++ com where com = ltcomment t
|
||||
showdate = printf "%-10s" . showDate
|
||||
showedate = printf "=%s" . showdate
|
||||
showpostings ps
|
||||
@ -81,7 +82,7 @@ showLedgerTransaction' elide effective t =
|
||||
showacct p = " " ++ showstatus p ++ printf (printf "%%-%ds" w) (showAccountName Nothing (ptype p) (paccount p))
|
||||
w = maximum $ map (length . paccount) ps
|
||||
showamount = printf "%12s" . showMixedAmount
|
||||
showcomment s = if length s > 0 then " ; "++s else ""
|
||||
showcomment s = if null s then "" else " ; "++s
|
||||
showstatus p = if pstatus p then "* " else ""
|
||||
|
||||
-- | Show an account name, clipped to the given width if any, and
|
||||
@ -108,11 +109,12 @@ isLedgerTransactionBalanced (LedgerTransaction {ltpostings=ps}) =
|
||||
-- return an error message instead.
|
||||
balanceLedgerTransaction :: LedgerTransaction -> Either String LedgerTransaction
|
||||
balanceLedgerTransaction t@LedgerTransaction{ltpostings=ps}
|
||||
| length missingamounts > 1 = Left $ printerr "could not balance this transaction, too many missing amounts"
|
||||
| length missingamounts' > 1 = Left $ printerr "could not balance this transaction, too many missing amounts"
|
||||
| not $ isLedgerTransactionBalanced t' = Left $ printerr nonzerobalanceerror
|
||||
| otherwise = Right t'
|
||||
where
|
||||
(withamounts, missingamounts) = partition hasAmount $ filter isReal ps
|
||||
(_, missingamounts') = partition hasAmount ps
|
||||
t' = t{ltpostings=ps'}
|
||||
ps' | length missingamounts == 1 = map balance ps
|
||||
| otherwise = ps
|
||||
|
||||
@ -22,8 +22,8 @@ instance Show Posting where show = showPosting
|
||||
nullrawposting = Posting False "" nullmixedamt "" RegularPosting
|
||||
|
||||
showPosting :: Posting -> String
|
||||
showPosting (Posting _ a amt _ ttype) =
|
||||
concatTopPadded [showaccountname a ++ " ", showamount amt]
|
||||
showPosting (Posting _ a amt com ttype) =
|
||||
concatTopPadded [showaccountname a ++ " ", showamount amt, comment]
|
||||
where
|
||||
showaccountname = printf "%-22s" . bracket . elideAccountName width
|
||||
(bracket,width) = case ttype of
|
||||
@ -31,9 +31,10 @@ showPosting (Posting _ a amt _ ttype) =
|
||||
VirtualPosting -> (\s -> "("++s++")", 20)
|
||||
_ -> (id,22)
|
||||
showamount = padleft 12 . showMixedAmountOrZero
|
||||
comment = if null com then "" else " ; " ++ com
|
||||
-- XXX refactor
|
||||
showPostingWithoutPrice (Posting _ a amt _ ttype) =
|
||||
concatTopPadded [showaccountname a ++ " ", showamount amt]
|
||||
showPostingWithoutPrice (Posting _ a amt com ttype) =
|
||||
concatTopPadded [showaccountname a ++ " ", showamount amt, comment]
|
||||
where
|
||||
ledger3ishlayout = False
|
||||
acctnamewidth = if ledger3ishlayout then 25 else 22
|
||||
@ -43,6 +44,7 @@ showPostingWithoutPrice (Posting _ a amt _ ttype) =
|
||||
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
|
||||
_ -> (id,acctnamewidth)
|
||||
showamount = padleft 12 . showMixedAmountOrZeroWithoutPrice
|
||||
comment = if null com then "" else " ; " ++ com
|
||||
|
||||
isReal :: Posting -> Bool
|
||||
isReal p = ptype p == RegularPosting
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
# again, complain like ledger, but we could handle this
|
||||
-f - print
|
||||
<<<
|
||||
2009/1/1 x
|
||||
@ -5,10 +6,4 @@
|
||||
b
|
||||
(c)
|
||||
(d)
|
||||
>>>
|
||||
2009/01/01 x
|
||||
a 1
|
||||
b -1
|
||||
(c)
|
||||
(d)
|
||||
|
||||
>>>2 /too many missing/
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
# could balance this, but complain instead like ledger
|
||||
-f - register
|
||||
<<<
|
||||
2009/6/24 carwash
|
||||
@ -5,14 +6,4 @@
|
||||
assets:cash
|
||||
[expenses:car] $3.50
|
||||
[simon]
|
||||
>>>2
|
||||
"-" (line 6, column 1):
|
||||
unexpected end of input
|
||||
could not balance this transaction, amounts do not add up to zero:
|
||||
2009/06/24 carwash
|
||||
equity:draw:personal:transportatio $3.50
|
||||
assets:cash
|
||||
[expenses:car] $3.50
|
||||
[simon]
|
||||
|
||||
|
||||
>>>2 /too many missing/
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
# let's have print preserve comments as far as possible
|
||||
# we preserve line-end comments but not full line comments
|
||||
-f - print
|
||||
<<<
|
||||
2009/1/1 x ; description comment
|
||||
@ -10,9 +11,5 @@
|
||||
>>>
|
||||
2009/01/01 x ; description comment
|
||||
a 1 ; amount comment
|
||||
; middle posting comment
|
||||
b -1
|
||||
; trailing posting comment
|
||||
; post-entry comment (?)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user