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