From 79812f974a4943e2e0c9de03ad4da3fc7d011292 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 15 Jan 2018 13:05:20 -0800 Subject: [PATCH] rename NormalBalance -> NormalSign --- hledger-lib/Hledger/Data/Account.hs | 4 ++-- hledger-lib/Hledger/Data/Types.hs | 15 ++++++++------- hledger-lib/Hledger/Reports/BalanceReport.hs | 4 ++-- .../Hledger/Reports/MultiBalanceReports.hs | 4 ++-- hledger-lib/Hledger/Reports/ReportOptions.hs | 9 +++++---- hledger/Hledger/Cli/Commands/Balancesheet.hs | 4 ++-- .../Hledger/Cli/Commands/Balancesheetequity.hs | 6 +++--- hledger/Hledger/Cli/Commands/Cashflow.hs | 2 +- hledger/Hledger/Cli/Commands/Incomestatement.hs | 4 ++-- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 8 ++++---- 10 files changed, 31 insertions(+), 29 deletions(-) diff --git a/hledger-lib/Hledger/Data/Account.hs b/hledger-lib/Hledger/Data/Account.hs index e1dc82415..d07301b6d 100644 --- a/hledger-lib/Hledger/Data/Account.hs +++ b/hledger-lib/Hledger/Data/Account.hs @@ -189,14 +189,14 @@ filterAccounts p a -- so that the accounts with largest normal balances are listed first. -- The provided normal balance sign determines whether normal balances -- are negative or positive. -sortAccountTreeByAmount :: NormalBalance -> Account -> Account +sortAccountTreeByAmount :: NormalSign -> Account -> Account sortAccountTreeByAmount normalsign a | null $ asubs a = a | otherwise = a{asubs= sortBy (maybeflip $ comparing aibalance) $ map (sortAccountTreeByAmount normalsign) $ asubs a} where - maybeflip | normalsign==NormalNegative = id + maybeflip | normalsign==NormallyNegative = id | otherwise = flip -- | Search an account list by name. diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index e0ed5e702..dbb2c722d 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -362,13 +362,14 @@ data Account = Account { aboring :: Bool -- ^ used in the accounts report to label elidable parents } deriving (Typeable, Data, Generic) --- | Whether an account's balance is normally a positive number (in accounting terms, --- normally a debit balance), as for asset and expense accounts, or a negative number --- (in accounting terms, normally a credit balance), as for liability, equity and --- income accounts. Cf https://en.wikipedia.org/wiki/Normal_balance . -data NormalBalance = - NormalPositive -- ^ normally debit - assets, expenses... - | NormalNegative -- ^ normally credit - liabilities, equity, income... +-- | Whether an account's balance is normally a positive number (in +-- accounting terms, a debit balance) or a negative number (credit balance). +-- Assets and expenses are normally positive (debit), while liabilities, equity +-- and income are normally negative (credit). +-- https://en.wikipedia.org/wiki/Normal_balance +data NormalSign = + NormallyPositive -- ^ normally debit - assets, expenses... + | NormallyNegative -- ^ normally credit - liabilities, equity, income... deriving (Show, Data, Eq) -- | A Ledger has the journal it derives from, and the accounts diff --git a/hledger-lib/Hledger/Reports/BalanceReport.hs b/hledger-lib/Hledger/Reports/BalanceReport.hs index 6bbec3ee5..bb7b2fb2a 100644 --- a/hledger-lib/Hledger/Reports/BalanceReport.hs +++ b/hledger-lib/Hledger/Reports/BalanceReport.hs @@ -108,8 +108,8 @@ balanceReport opts q j = (items, total) maybesortflat | sort_amount_ opts = sortBy (maybeflip $ comparing balance) | otherwise = id where - maybeflip = if normalbalance_ opts == Just NormalNegative then id else flip - maybesorttree | sort_amount_ opts = sortAccountTreeByAmount (fromMaybe NormalPositive $ normalbalance_ opts) + maybeflip = if normalbalance_ opts == Just NormallyNegative then id else flip + maybesorttree | sort_amount_ opts = sortAccountTreeByAmount (fromMaybe NormallyPositive $ normalbalance_ opts) | otherwise = id items = dbg1 "items" $ map (balanceReportItem opts q) accts' total | not (flat_ opts) = dbg1 "total" $ sum [amt | (_,_,indent,amt) <- items, indent == 0] diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReports.hs b/hledger-lib/Hledger/Reports/MultiBalanceReports.hs index e3ba1e692..81dcd7383 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReports.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReports.hs @@ -192,7 +192,7 @@ multiBalanceReport opts q j = MultiBalanceReport (displayspans, sorteditems, tot -- Sort the report rows, representing a flat account list, by row total. sortFlatMultiBalanceReportRowsByAmount = sortBy (maybeflip $ comparing fifth6) where - maybeflip = if normalbalance_ opts == Just NormalNegative then id else flip + maybeflip = if normalbalance_ opts == Just NormallyNegative then id else flip -- Sort the report rows, representing a tree of accounts, by row total at each level. -- To do this we recreate an Account tree with the row totals as balances, @@ -209,7 +209,7 @@ multiBalanceReport opts q j = MultiBalanceReport (displayspans, sorteditems, tot where -- this error should not happen, but it's ugly TODO setibalance a = a{aibalance=fromMaybe (error "sortTreeMultiBalanceReportRowsByAmount 1") $ lookup (aname a) atotals} - sortedaccounttree = sortAccountTreeByAmount (fromMaybe NormalPositive $ normalbalance_ opts) accounttreewithbals + sortedaccounttree = sortAccountTreeByAmount (fromMaybe NormallyPositive $ normalbalance_ opts) accounttreewithbals sortedaccounts = drop 1 $ flattenAccounts sortedaccounttree sortedrows = [ -- this error should not happen, but it's ugly TODO diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index dcbd569b1..660b8c796 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -102,10 +102,11 @@ data ReportOpts = ReportOpts { ,value_ :: Bool ,pretty_tables_ :: Bool ,sort_amount_ :: Bool - ,normalbalance_ :: Maybe NormalBalance - -- ^ when running a balance report on accounts of the same normal balance type, - -- eg in the income section of an income statement, this helps --sort-amount know - -- how to sort negative numbers. + ,normalbalance_ :: Maybe NormalSign + -- ^ This can be set when running balance reports on a set of accounts + -- with the same normal balance type (eg all assets, or all incomes). + -- It helps --sort-amount know how to sort negative numbers + -- (eg in the income section of an income statement) ,color_ :: Bool ,forecast_ :: Bool ,auto_ :: Bool diff --git a/hledger/Hledger/Cli/Commands/Balancesheet.hs b/hledger/Hledger/Cli/Commands/Balancesheet.hs index 7c9a8509f..00d7b0ade 100644 --- a/hledger/Hledger/Cli/Commands/Balancesheet.hs +++ b/hledger/Hledger/Cli/Commands/Balancesheet.hs @@ -29,8 +29,8 @@ It assumes that these accounts are under a top-level `asset` or `liability` account (case insensitive, plural forms also allowed). |], cbctitle = "Balance Sheet", - cbcqueries = [ ("Assets" , journalAssetAccountQuery, Just NormalPositive), - ("Liabilities", journalLiabilityAccountQuery, Just NormalNegative) + cbcqueries = [ ("Assets" , journalAssetAccountQuery, Just NormallyPositive), + ("Liabilities", journalLiabilityAccountQuery, Just NormallyNegative) ], cbctype = HistoricalBalance } diff --git a/hledger/Hledger/Cli/Commands/Balancesheetequity.hs b/hledger/Hledger/Cli/Commands/Balancesheetequity.hs index 515725f9b..4c6ba4e7c 100644 --- a/hledger/Hledger/Cli/Commands/Balancesheetequity.hs +++ b/hledger/Hledger/Cli/Commands/Balancesheetequity.hs @@ -26,9 +26,9 @@ It assumes that these accounts are under a top-level `asset`, `liability` and `e account (plural forms also allowed). |], cbctitle = "Balance Sheet With Equity", - cbcqueries = [("Assets", journalAssetAccountQuery, Just NormalPositive), - ("Liabilities", journalLiabilityAccountQuery, Just NormalNegative), - ("Equity", journalEquityAccountQuery, Just NormalNegative) + cbcqueries = [("Assets", journalAssetAccountQuery, Just NormallyPositive), + ("Liabilities", journalLiabilityAccountQuery, Just NormallyNegative), + ("Equity", journalEquityAccountQuery, Just NormallyNegative) ], cbctype = HistoricalBalance } diff --git a/hledger/Hledger/Cli/Commands/Cashflow.hs b/hledger/Hledger/Cli/Commands/Cashflow.hs index 432d5a9f1..9a9c129da 100644 --- a/hledger/Hledger/Cli/Commands/Cashflow.hs +++ b/hledger/Hledger/Cli/Commands/Cashflow.hs @@ -32,7 +32,7 @@ in "cash" accounts. It assumes that these accounts are under a top-level contain `receivable` or `A/R` in their name. |], cbctitle = "Cashflow Statement", - cbcqueries = [("Cash flows", journalCashAccountQuery, Just NormalPositive)], + cbcqueries = [("Cash flows", journalCashAccountQuery, Just NormallyPositive)], cbctype = PeriodChange } diff --git a/hledger/Hledger/Cli/Commands/Incomestatement.hs b/hledger/Hledger/Cli/Commands/Incomestatement.hs index 926cd77e8..9bc2b4d6c 100644 --- a/hledger/Hledger/Cli/Commands/Incomestatement.hs +++ b/hledger/Hledger/Cli/Commands/Incomestatement.hs @@ -29,8 +29,8 @@ top-level `revenue` or `income` or `expense` account (case insensitive, plural forms also allowed). |], cbctitle = "Income Statement", - cbcqueries = [ ("Revenues", journalIncomeAccountQuery, Just NormalNegative), - ("Expenses", journalExpenseAccountQuery, Just NormalPositive) + cbcqueries = [ ("Revenues", journalIncomeAccountQuery, Just NormallyNegative), + ("Expenses", journalExpenseAccountQuery, Just NormallyPositive) ], cbctype = PeriodChange } diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index 068889337..920c538dc 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -39,8 +39,8 @@ data CompoundBalanceCommandSpec = CompoundBalanceCommandSpec { cbcaliases :: [String], -- ^ command aliases cbchelp :: String, -- ^ command line help cbctitle :: String, -- ^ overall report title - cbcqueries :: [(String, Journal -> Query, Maybe NormalBalance)], - -- ^ title, journal-parameterised query, and expected normal balance for each subreport. + cbcqueries :: [(String, Journal -> Query, Maybe NormalSign)], + -- ^ title, journal-parameterised query, and normal balance sign for each subreport. -- The normal balance helps --sort-amount know how to sort negative amounts. cbctype :: BalanceType -- ^ the type of "balance" this report shows (overrides command line flags) } @@ -197,7 +197,7 @@ compoundBalanceCommandSingleColumnReport -> Journal -> String -> (Journal -> Query) - -> Maybe NormalBalance + -> Maybe NormalSign -> ([String], Sum MixedAmount) compoundBalanceCommandSingleColumnReport ropts userq j subreporttitle subreportqfn subreportnormalsign = ([subreportstr], Sum total) @@ -233,7 +233,7 @@ type CompoundBalanceReport = -- | Run one subreport for a compound balance command in multi-column mode. -- This returns a MultiBalanceReport. -compoundBalanceSubreport :: ReportOpts -> Query -> Journal -> (Journal -> Query) -> Maybe NormalBalance -> MultiBalanceReport +compoundBalanceSubreport :: ReportOpts -> Query -> Journal -> (Journal -> Query) -> Maybe NormalSign -> MultiBalanceReport compoundBalanceSubreport ropts userq j subreportqfn subreportnormalsign = r' where -- force --empty to ensure same columns in all sections