mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-09 21:22:26 +03:00
print, register: show virtual accounts bracketed/parenthesised
This commit is contained in:
parent
2373429b64
commit
92d67926f5
@ -74,12 +74,23 @@ showLedgerTransaction' elide t =
|
||||
where
|
||||
showposting p = showacct p ++ " " ++ (showamount $ pamount p) ++ (showcomment $ pcomment p)
|
||||
showpostingnoamt p = rstrip $ showacct p ++ " " ++ (showcomment $ pcomment p)
|
||||
showacct p = " " ++ showstatus p ++ (showaccountname $ paccount p)
|
||||
showacct p = " " ++ showstatus p ++ (printf "%-34s" $ showAccountName (Just 34) (ptype p) (paccount p))
|
||||
showamount = printf "%12s" . showMixedAmount
|
||||
showaccountname s = printf "%-34s" s
|
||||
showcomment s = if (length s) > 0 then " ; "++s else ""
|
||||
showstatus p = if pstatus p then "* " else ""
|
||||
|
||||
-- | Show an account name, clipped to the given width if any, and
|
||||
-- appropriately bracketed/parenthesised for the given posting type.
|
||||
showAccountName :: Maybe Int -> PostingType -> AccountName -> String
|
||||
showAccountName w = fmt
|
||||
where
|
||||
fmt RegularPosting = take w'
|
||||
fmt VirtualPosting = parenthesise . reverse . take (w'-2) . reverse
|
||||
fmt BalancedVirtualPosting = bracket . reverse . take (w'-2) . reverse
|
||||
w' = fromMaybe 999999 w
|
||||
parenthesise s = "("++s++")"
|
||||
bracket s = "["++s++"]"
|
||||
|
||||
isLedgerTransactionBalanced :: LedgerTransaction -> Bool
|
||||
isLedgerTransactionBalanced (LedgerTransaction {ltpostings=ps}) =
|
||||
all (isReallyZeroMixedAmount . costOfMixedAmount . sum . map pamount)
|
||||
|
@ -14,7 +14,7 @@ import Ledger.Dates
|
||||
import Ledger.Utils
|
||||
import Ledger.Types
|
||||
import Ledger.Dates
|
||||
import Ledger.LedgerTransaction
|
||||
import Ledger.LedgerTransaction (showAccountName)
|
||||
import Ledger.Posting
|
||||
import Ledger.Amount
|
||||
|
||||
@ -23,8 +23,9 @@ instance Show Transaction where show=showTransaction
|
||||
|
||||
showTransaction :: Transaction -> String
|
||||
showTransaction (Transaction eno stat d desc a amt ttype) =
|
||||
s ++ unwords [showDate d,desc,a,show amt,show ttype]
|
||||
s ++ unwords [showDate d,desc,a',show amt,show ttype]
|
||||
where s = if stat then " *" else ""
|
||||
a' = showAccountName Nothing ttype a
|
||||
|
||||
-- | Convert a 'LedgerTransaction' to two or more 'Transaction's. An id number
|
||||
-- is attached to the transactions to preserve their grouping - it should
|
||||
|
9
Tests.hs
9
Tests.hs
@ -92,6 +92,15 @@ hledger.hs: could not balance this transaction, amounts do not add up to zero:
|
||||
|
||||
@
|
||||
|
||||
@
|
||||
$ printf "2009/1/1 x\n (virtual) 100\n a 1\n b\n" | runhaskell hledger.hs -f- print 2>&1 ; true
|
||||
2009/01/01 x
|
||||
(virtual) 100
|
||||
a 1
|
||||
b
|
||||
|
||||
@
|
||||
|
||||
Unicode input/output tests
|
||||
|
||||
-- layout of the balance command with unicode names
|
||||
|
Loading…
Reference in New Issue
Block a user