rename NormalBalance -> NormalSign
This commit is contained in:
parent
02516ef987
commit
79812f974a
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user