balance: --flat provides a simple non-hierarchical format
This commit is contained in:
parent
927948a644
commit
5d7f141239
@ -123,21 +123,25 @@ showBalanceReport opts filterspec j = acctsstr ++ totalstr
|
||||
l = journalToLedger filterspec j
|
||||
acctsstr = unlines $ map showacct interestingaccts
|
||||
where
|
||||
showacct = showInterestingAccount l interestingaccts
|
||||
showacct = showInterestingAccount opts l interestingaccts
|
||||
interestingaccts = filter (isInteresting opts l) acctnames
|
||||
acctnames = sort $ tail $ flatten $ treemap aname accttree
|
||||
accttree = ledgerAccountTree (fromMaybe 99999 $ depthFromOpts opts) l
|
||||
totalstr | NoTotal `elem` opts = ""
|
||||
| notElem Empty opts && isZeroMixedAmount total = ""
|
||||
| otherwise = printf "--------------------\n%s\n" $ padleft 20 $ showMixedAmountWithoutPrice total
|
||||
where
|
||||
total = sum $ map abalance $ ledgerTopAccounts l
|
||||
|
||||
-- | Display one line of the balance report with appropriate indenting and eliding.
|
||||
showInterestingAccount :: Ledger -> [AccountName] -> AccountName -> String
|
||||
showInterestingAccount l interestingaccts a = concatTopPadded [amt, " ", depthspacer ++ partialname]
|
||||
showInterestingAccount :: [Opt] -> Ledger -> [AccountName] -> AccountName -> String
|
||||
showInterestingAccount opts l interestingaccts a = concatTopPadded [amt, " ", name]
|
||||
where
|
||||
amt = padleft 20 $ showMixedAmountWithoutPrice $ abalance $ ledgerAccount l a
|
||||
amt = padleft 20 $ showMixedAmountWithoutPrice bal
|
||||
bal | Flat `elem` opts = exclusiveBalance acct
|
||||
| otherwise = abalance acct
|
||||
acct = ledgerAccount l a
|
||||
name | Flat `elem` opts = a
|
||||
| otherwise = depthspacer ++ partialname
|
||||
parents = parentAccountNames a
|
||||
interestingparents = filter (`elem` interestingaccts) parents
|
||||
depthspacer = replicate (indentperlevel * length interestingparents) ' '
|
||||
@ -147,9 +151,23 @@ showInterestingAccount l interestingaccts a = concatTopPadded [amt, " ", depths
|
||||
partialname = accountNameFromComponents $ reverse (map accountLeafName ps) ++ [accountLeafName a]
|
||||
where ps = takeWhile boring parents where boring = not . (`elem` interestingparents)
|
||||
|
||||
exclusiveBalance :: Account -> MixedAmount
|
||||
exclusiveBalance = sumPostings . apostings
|
||||
|
||||
-- | Is the named account considered interesting for this ledger's balance report ?
|
||||
isInteresting :: [Opt] -> Ledger -> AccountName -> Bool
|
||||
isInteresting opts l a
|
||||
isInteresting opts l a | Flat `elem` opts = isInterestingFlat opts l a
|
||||
| otherwise = isInterestingIndented opts l a
|
||||
|
||||
isInterestingFlat :: [Opt] -> Ledger -> AccountName -> Bool
|
||||
isInterestingFlat opts l a = notempty || emptyflag
|
||||
where
|
||||
acct = ledgerAccount l a
|
||||
notempty = not $ isZeroMixedAmount $ exclusiveBalance acct
|
||||
emptyflag = Empty `elem` opts
|
||||
|
||||
isInterestingIndented :: [Opt] -> Ledger -> AccountName -> Bool
|
||||
isInterestingIndented opts l a
|
||||
| numinterestingsubs==1 && not atmaxdepth = notlikesub
|
||||
| otherwise = notzero || emptyflag
|
||||
where
|
||||
|
||||
@ -75,6 +75,7 @@ options = [
|
||||
,Option "" ["effective"] (NoArg Effective) "use transactions' effective dates, if any"
|
||||
,Option "E" ["empty"] (NoArg Empty) "show empty/zero things which are normally elided"
|
||||
,Option "R" ["real"] (NoArg Real) "report only on real (non-virtual) transactions"
|
||||
,Option "" ["flat"] (NoArg Flat) "balance report: show full account names, unindented"
|
||||
,Option "" ["no-total"] (NoArg NoTotal) "balance report: hide the final total"
|
||||
-- ,Option "s" ["subtotal"] (NoArg SubTotal) "balance report: show subaccounts"
|
||||
,Option "W" ["weekly"] (NoArg WeeklyOpt) "register report: show weekly summary"
|
||||
@ -113,6 +114,7 @@ data Opt =
|
||||
Effective |
|
||||
Empty |
|
||||
Real |
|
||||
Flat |
|
||||
NoTotal |
|
||||
SubTotal |
|
||||
WeeklyOpt |
|
||||
|
||||
@ -224,6 +224,7 @@ Here is the command-line help:
|
||||
--effective use transactions' effective dates, if any
|
||||
-E --empty show empty/zero things which are normally elided
|
||||
-R --real report only on real (non-virtual) transactions
|
||||
--flat balance report: show full account names, unindented
|
||||
--no-total balance report: hide the final total
|
||||
-W --weekly register report: show weekly summary
|
||||
-M --monthly register report: show monthly summary
|
||||
@ -274,14 +275,21 @@ Examples:
|
||||
|
||||
##### balance
|
||||
|
||||
The balance command displays accounts and their balances.
|
||||
|
||||
The balance command displays accounts and their balances, indented to show the account hierarchy.
|
||||
Examples:
|
||||
|
||||
$ hledger balance
|
||||
$ hledger balance food -p 'last month'
|
||||
|
||||
A final total is displayed, use `--no-total` to suppress this. Also, the
|
||||
`--depth` option shows accounts only to the specified depth, useful for an overview:
|
||||
|
||||
$ for y in 2006 2007 2008 2009 2010; do echo; echo $y; hledger -f $y.ledger balance ^expenses --depth 2; done
|
||||
|
||||
With `--flat`, a non-hierarchical list of full account names is displayed
|
||||
instead. This mode shows just the accounts actually contributing to the
|
||||
balance, making the arithmetic a little more obvious to non-hledger users.
|
||||
|
||||
##### chart
|
||||
|
||||
The chart command saves a pie chart of your top account balances to an
|
||||
|
||||
Loading…
Reference in New Issue
Block a user