mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-10 05:39:31 +03:00
ref: bal: rename some report types to clarify/sync with docs
ReportType -> BalanceCalculation ChangeReport -> CalcChange BudgetReport -> CalcBudget ValueChangeReport -> CalcValueChange BalanceType -> BalanceAccumulation PeriodChange -> PerPeriod CumulativeChange -> Cumulative HistoricalBalance -> Historical ReportOpts: reporttype_ -> balancecalc_ balancetype_ -> balanceaccum_ CompoundBalanceCommandSpec: cbctype -> cbcaccum Hledger.Reports.ReportOptions: balanceTypeOverride -> balanceAccumulationOverride
This commit is contained in:
parent
f54e645dbf
commit
87f575e643
@ -107,8 +107,8 @@ accountTransactionsReport rspec@ReportSpec{rsOpts=ropts} j reportq thisacctq = i
|
||||
$ journalApplyValuationFromOpts rspec j
|
||||
|
||||
startbal
|
||||
| balancetype_ ropts == HistoricalBalance = sumPostings priorps
|
||||
| otherwise = nullmixedamt
|
||||
| balanceaccum_ ropts == Historical = sumPostings priorps
|
||||
| otherwise = nullmixedamt
|
||||
where
|
||||
priorps = dbg5 "priorps" $
|
||||
filter (matchesPosting
|
||||
|
@ -280,7 +280,7 @@ budgetReportAsText ropts@ReportOpts{..} budgetr = TB.toLazyText $
|
||||
-- | Build a 'Table' from a multi-column balance report.
|
||||
budgetReportAsTable :: ReportOpts -> BudgetReport -> Table Text Text (Maybe MixedAmount, Maybe MixedAmount)
|
||||
budgetReportAsTable
|
||||
ropts@ReportOpts{balancetype_}
|
||||
ropts@ReportOpts{balanceaccum_}
|
||||
(PeriodicReport spans rows (PeriodicReportRow _ coltots grandtot grandavg)) =
|
||||
addtotalrow $
|
||||
Table
|
||||
@ -288,7 +288,7 @@ budgetReportAsTable
|
||||
(Tab.Group NoLine $ map Header colheadings)
|
||||
(map rowvals rows)
|
||||
where
|
||||
colheadings = map (reportPeriodName balancetype_ spans) spans
|
||||
colheadings = map (reportPeriodName balanceaccum_ spans) spans
|
||||
++ [" Total" | row_total_ ropts]
|
||||
++ ["Average" | average_ ropts]
|
||||
|
||||
|
@ -292,17 +292,17 @@ calculateReportMatrix rspec@ReportSpec{rsOpts=ropts} j priceoracle startbals col
|
||||
-- The valued row amounts to be displayed: per-period changes,
|
||||
-- zero-based cumulative totals, or
|
||||
-- starting-balance-based historical balances.
|
||||
rowbals name changes = dbg5 "rowbals" $ case balancetype_ ropts of
|
||||
PeriodChange -> changeamts
|
||||
CumulativeChange -> cumulative
|
||||
HistoricalBalance -> historical
|
||||
rowbals name changes = dbg5 "rowbals" $ case balanceaccum_ ropts of
|
||||
PerPeriod -> changeamts
|
||||
Cumulative -> cumulative
|
||||
Historical -> historical
|
||||
where
|
||||
-- changes to report on: usually just the changes itself, but use the
|
||||
-- differences in the historical amount for ValueChangeReports.
|
||||
changeamts = case reporttype_ ropts of
|
||||
ChangeReport -> M.mapWithKey avalue changes
|
||||
BudgetReport -> M.mapWithKey avalue changes
|
||||
ValueChangeReport -> periodChanges valuedStart historical
|
||||
changeamts = case balancecalc_ ropts of
|
||||
CalcChange -> M.mapWithKey avalue changes
|
||||
CalcBudget -> M.mapWithKey avalue changes
|
||||
CalcValueChange -> periodChanges valuedStart historical
|
||||
cumulative = cumulativeSum avalue nullacct changeamts
|
||||
historical = cumulativeSum avalue startingBalance changes
|
||||
startingBalance = HM.lookupDefault nullacct name startbals
|
||||
@ -368,9 +368,9 @@ buildReportRows ropts displaynames =
|
||||
-- The total and average for the row.
|
||||
-- These are always simply the sum/average of the displayed row amounts.
|
||||
-- Total for a cumulative/historical report is always the last column.
|
||||
rowtot = case balancetype_ ropts of
|
||||
PeriodChange -> maSum rowbals
|
||||
_ -> lastDef nullmixedamt rowbals
|
||||
rowtot = case balanceaccum_ ropts of
|
||||
PerPeriod -> maSum rowbals
|
||||
_ -> lastDef nullmixedamt rowbals
|
||||
rowavg = averageMixedAmounts rowbals
|
||||
balance = case accountlistmode_ ropts of ALTree -> aibalance; ALFlat -> aebalance
|
||||
|
||||
@ -476,9 +476,9 @@ calculateTotalsRow ropts rows =
|
||||
-- Calculate the grand total and average. These are always the sum/average
|
||||
-- of the column totals.
|
||||
-- Total for a cumulative/historical report is always the last column.
|
||||
grandtotal = case balancetype_ ropts of
|
||||
PeriodChange -> maSum coltotals
|
||||
_ -> lastDef nullmixedamt coltotals
|
||||
grandtotal = case balanceaccum_ ropts of
|
||||
PerPeriod -> maSum coltotals
|
||||
_ -> lastDef nullmixedamt coltotals
|
||||
grandaverage = averageMixedAmounts coltotals
|
||||
|
||||
-- | Map the report rows to percentages if needed
|
||||
@ -574,7 +574,7 @@ tests_MultiBalanceReport = tests "MultiBalanceReport" [
|
||||
(defreportspec, nulljournal) `gives` ([], nullmixedamt)
|
||||
|
||||
,test "with -H on a populated period" $
|
||||
(defreportspec{rsOpts=defreportopts{period_= PeriodBetween (fromGregorian 2008 1 1) (fromGregorian 2008 1 2), balancetype_=HistoricalBalance}}, samplejournal) `gives`
|
||||
(defreportspec{rsOpts=defreportopts{period_= PeriodBetween (fromGregorian 2008 1 1) (fromGregorian 2008 1 2), balanceaccum_=Historical}}, samplejournal) `gives`
|
||||
(
|
||||
[ PeriodicReportRow (flatDisplayName "assets:bank:checking") [mamountp' "$1.00"] (mamountp' "$1.00") (mixedAmount amt0{aquantity=1})
|
||||
, PeriodicReportRow (flatDisplayName "income:salary") [mamountp' "$-1.00"] (mamountp' "$-1.00") (mixedAmount amt0{aquantity=(-1)})
|
||||
@ -582,7 +582,7 @@ tests_MultiBalanceReport = tests "MultiBalanceReport" [
|
||||
mamountp' "$0.00")
|
||||
|
||||
-- ,test "a valid history on an empty period" $
|
||||
-- (defreportopts{period_= PeriodBetween (fromGregorian 2008 1 2) (fromGregorian 2008 1 3), balancetype_=HistoricalBalance}, samplejournal) `gives`
|
||||
-- (defreportopts{period_= PeriodBetween (fromGregorian 2008 1 2) (fromGregorian 2008 1 3), balanceaccum_=Historical}, samplejournal) `gives`
|
||||
-- (
|
||||
-- [
|
||||
-- ("assets:bank:checking","checking",3, [mamountp' "$1.00"], mamountp' "$1.00",mixedAmount amt0 {aquantity=1})
|
||||
@ -591,7 +591,7 @@ tests_MultiBalanceReport = tests "MultiBalanceReport" [
|
||||
-- mixedAmount usd0)
|
||||
|
||||
-- ,test "a valid history on an empty period (more complex)" $
|
||||
-- (defreportopts{period_= PeriodBetween (fromGregorian 2009 1 1) (fromGregorian 2009 1 2), balancetype_=HistoricalBalance}, samplejournal) `gives`
|
||||
-- (defreportopts{period_= PeriodBetween (fromGregorian 2009 1 1) (fromGregorian 2009 1 2), balanceaccum_=Historical}, samplejournal) `gives`
|
||||
-- (
|
||||
-- [
|
||||
-- ("assets:bank:checking","checking",3, [mamountp' "$1.00"], mamountp' "$1.00",mixedAmount amt0 {aquantity=1})
|
||||
|
@ -90,7 +90,7 @@ postingsReport rspec@ReportSpec{rsOpts=ropts@ReportOpts{..}} j = items
|
||||
-- may be converting to value per hledger_options.m4.md "Effect
|
||||
-- of --value on reports".
|
||||
-- XXX balance report doesn't value starting balance.. should this ?
|
||||
historical = balancetype_ == HistoricalBalance
|
||||
historical = balanceaccum_ == Historical
|
||||
startbal | average_ = if historical then precedingavg else nullmixedamt
|
||||
| otherwise = if historical then precedingsum else nullmixedamt
|
||||
where
|
||||
|
@ -11,8 +11,8 @@ Options common to most hledger reports.
|
||||
module Hledger.Reports.ReportOptions (
|
||||
ReportOpts(..),
|
||||
ReportSpec(..),
|
||||
ReportType(..),
|
||||
BalanceType(..),
|
||||
BalanceCalculation(..),
|
||||
BalanceAccumulation(..),
|
||||
AccountListMode(..),
|
||||
ValuationType(..),
|
||||
defreportopts,
|
||||
@ -22,7 +22,7 @@ module Hledger.Reports.ReportOptions (
|
||||
updateReportSpec,
|
||||
updateReportSpecWith,
|
||||
rawOptsToReportSpec,
|
||||
balanceTypeOverride,
|
||||
balanceAccumulationOverride,
|
||||
flat_,
|
||||
tree_,
|
||||
reportOptsToggleStatus,
|
||||
@ -65,23 +65,26 @@ import Hledger.Query
|
||||
import Hledger.Utils
|
||||
|
||||
|
||||
-- | What is calculated and shown in each cell in a balance report.
|
||||
data ReportType = ChangeReport -- ^ The sum of posting amounts.
|
||||
| BudgetReport -- ^ The sum of posting amounts and the goal.
|
||||
| ValueChangeReport -- ^ The change of value of period-end historical values.
|
||||
-- | What to calculate for each cell in a balance report.
|
||||
-- "Balance report types -> Calculation type" in the hledger manual.
|
||||
data BalanceCalculation =
|
||||
CalcChange -- ^ Sum of posting amounts in the period.
|
||||
| CalcBudget -- ^ Sum of posting amounts and the goal for the period.
|
||||
| CalcValueChange -- ^ Change from previous period's historical end value to this period's historical end value.
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Default ReportType where def = ChangeReport
|
||||
instance Default BalanceCalculation where def = CalcChange
|
||||
|
||||
-- | Which "accumulation method" is being shown in a balance report.
|
||||
data BalanceType = PeriodChange -- ^ The accumulate change over a single period.
|
||||
| CumulativeChange -- ^ The accumulated change across multiple periods.
|
||||
| HistoricalBalance -- ^ The historical ending balance, including the effect of
|
||||
-- all postings before the report period. Unless altered by,
|
||||
-- a query, this is what you would see on a bank statement.
|
||||
-- | How to accumulate calculated values across periods (columns) in a balance report.
|
||||
-- "Balance report types -> Accumulation type" in the hledger manual.
|
||||
data BalanceAccumulation =
|
||||
PerPeriod -- ^ No accumulation. Eg, shows the change of balance in each period.
|
||||
| Cumulative -- ^ Accumulate changes across periods, starting from zero at report start.
|
||||
| Historical -- ^ Accumulate changes across periods, including any from before report start.
|
||||
-- Eg, shows the historical end balance of each period.
|
||||
deriving (Eq,Show)
|
||||
|
||||
instance Default BalanceType where def = PeriodChange
|
||||
instance Default BalanceAccumulation where def = PerPeriod
|
||||
|
||||
-- | Should accounts be displayed: in the command's default style, hierarchically, or as a flat list ?
|
||||
data AccountListMode = ALFlat | ALTree deriving (Eq, Show)
|
||||
@ -114,8 +117,8 @@ data ReportOpts = ReportOpts {
|
||||
-- for account transactions reports (aregister)
|
||||
,txn_dates_ :: Bool
|
||||
-- for balance reports (bal, bs, cf, is)
|
||||
,reporttype_ :: ReportType
|
||||
,balancetype_ :: BalanceType
|
||||
,balancecalc_ :: BalanceCalculation
|
||||
,balanceaccum_ :: BalanceAccumulation
|
||||
,accountlistmode_ :: AccountListMode
|
||||
,drop_ :: Int
|
||||
,row_total_ :: Bool
|
||||
@ -162,8 +165,8 @@ defreportopts = ReportOpts
|
||||
, average_ = False
|
||||
, related_ = False
|
||||
, txn_dates_ = False
|
||||
, reporttype_ = def
|
||||
, balancetype_ = def
|
||||
, balancecalc_ = def
|
||||
, balanceaccum_ = def
|
||||
, accountlistmode_ = ALFlat
|
||||
, drop_ = 0
|
||||
, row_total_ = False
|
||||
@ -209,8 +212,8 @@ rawOptsToReportOpts rawopts = do
|
||||
,average_ = boolopt "average" rawopts
|
||||
,related_ = boolopt "related" rawopts
|
||||
,txn_dates_ = boolopt "txn-dates" rawopts
|
||||
,reporttype_ = reporttypeopt rawopts
|
||||
,balancetype_ = balancetypeopt rawopts
|
||||
,balancecalc_ = balancecalcopt rawopts
|
||||
,balanceaccum_ = balanceaccumopt rawopts
|
||||
,accountlistmode_ = accountlistmodeopt rawopts
|
||||
,drop_ = posintopt "drop" rawopts
|
||||
,row_total_ = boolopt "row-total" rawopts
|
||||
@ -286,29 +289,29 @@ accountlistmodeopt =
|
||||
"flat" -> Just ALFlat
|
||||
_ -> Nothing
|
||||
|
||||
reporttypeopt :: RawOpts -> ReportType
|
||||
reporttypeopt =
|
||||
fromMaybe ChangeReport . choiceopt parse where
|
||||
balancecalcopt :: RawOpts -> BalanceCalculation
|
||||
balancecalcopt =
|
||||
fromMaybe CalcChange . choiceopt parse where
|
||||
parse = \case
|
||||
"sum" -> Just ChangeReport
|
||||
"valuechange" -> Just ValueChangeReport
|
||||
"budget" -> Just BudgetReport
|
||||
"sum" -> Just CalcChange
|
||||
"valuechange" -> Just CalcValueChange
|
||||
"budget" -> Just CalcBudget
|
||||
_ -> Nothing
|
||||
|
||||
balancetypeopt :: RawOpts -> BalanceType
|
||||
balancetypeopt = fromMaybe PeriodChange . balanceTypeOverride
|
||||
balanceaccumopt :: RawOpts -> BalanceAccumulation
|
||||
balanceaccumopt = fromMaybe PerPeriod . balanceAccumulationOverride
|
||||
|
||||
balanceTypeOverride :: RawOpts -> Maybe BalanceType
|
||||
balanceTypeOverride rawopts = choiceopt parse rawopts <|> reportbal
|
||||
balanceAccumulationOverride :: RawOpts -> Maybe BalanceAccumulation
|
||||
balanceAccumulationOverride rawopts = choiceopt parse rawopts <|> reportbal
|
||||
where
|
||||
parse = \case
|
||||
"historical" -> Just HistoricalBalance
|
||||
"cumulative" -> Just CumulativeChange
|
||||
"change" -> Just PeriodChange
|
||||
"historical" -> Just Historical
|
||||
"cumulative" -> Just Cumulative
|
||||
"change" -> Just PerPeriod
|
||||
_ -> Nothing
|
||||
reportbal = case reporttypeopt rawopts of
|
||||
ValueChangeReport -> Just PeriodChange
|
||||
_ -> Nothing
|
||||
reportbal = case balancecalcopt rawopts of
|
||||
CalcValueChange -> Just PerPeriod
|
||||
_ -> Nothing
|
||||
|
||||
-- Get the period specified by any -b/--begin, -e/--end and/or -p/--period
|
||||
-- options appearing in the command line.
|
||||
@ -321,8 +324,7 @@ periodFromRawOpts d rawopts =
|
||||
(Nothing, Nothing) -> PeriodAll
|
||||
(Just b, Nothing) -> PeriodFrom b
|
||||
(Nothing, Just e) -> PeriodTo e
|
||||
(Just b, Just e) -> simplifyPeriod $
|
||||
PeriodBetween b e
|
||||
(Just b, Just e) -> simplifyPeriod $ PeriodBetween b e
|
||||
where
|
||||
mlastb = case beginDatesFromRawOpts d rawopts of
|
||||
[] -> Nothing
|
||||
@ -439,8 +441,8 @@ valuationTypeFromRawOpts :: RawOpts -> (Costing, Maybe ValuationType)
|
||||
valuationTypeFromRawOpts rawopts = (costing, valuation)
|
||||
where
|
||||
costing = if (any ((Cost==) . fst) valuationopts) then Cost else NoCost
|
||||
valuation = case reporttypeopt rawopts of
|
||||
ValueChangeReport -> case directval of
|
||||
valuation = case balancecalcopt rawopts of
|
||||
CalcValueChange -> case directval of
|
||||
Nothing -> Just $ AtEnd Nothing -- If no valuation requested for valuechange, use AtEnd
|
||||
Just (AtEnd _) -> directval -- If AtEnd valuation requested, use it
|
||||
Just _ -> usageError "--valuechange only produces sensible results with --value=end"
|
||||
@ -544,8 +546,8 @@ valuationAfterSum :: ReportOpts -> Maybe (Maybe CommoditySymbol)
|
||||
valuationAfterSum ropts = case value_ ropts of
|
||||
Just (AtEnd mc) | valueAfterSum -> Just mc
|
||||
_ -> Nothing
|
||||
where valueAfterSum = reporttype_ ropts == ValueChangeReport
|
||||
|| balancetype_ ropts /= PeriodChange
|
||||
where valueAfterSum = balancecalc_ ropts == CalcValueChange
|
||||
|| balanceaccum_ ropts /= PerPeriod
|
||||
|
||||
|
||||
-- | Convert report options to a query, ignoring any non-flag command line arguments.
|
||||
@ -652,10 +654,10 @@ reportPeriodOrJournalLastDay rspec j = reportPeriodLastDay rspec <|> journalOrPr
|
||||
--
|
||||
-- - all other balance change reports: a description of the datespan,
|
||||
-- abbreviated to compact form if possible (see showDateSpan).
|
||||
reportPeriodName :: BalanceType -> [DateSpan] -> DateSpan -> T.Text
|
||||
reportPeriodName balancetype spans =
|
||||
case balancetype of
|
||||
PeriodChange -> if multiyear then showDateSpan else showDateSpanMonthAbbrev
|
||||
reportPeriodName :: BalanceAccumulation -> [DateSpan] -> DateSpan -> T.Text
|
||||
reportPeriodName balanceaccumulation spans =
|
||||
case balanceaccumulation of
|
||||
PerPeriod -> if multiyear then showDateSpan else showDateSpanMonthAbbrev
|
||||
where
|
||||
multiyear = (>1) $ length $ nubSort $ map spanStartYear spans
|
||||
_ -> maybe "" (showDate . prevday) . spanEnd
|
||||
|
@ -64,7 +64,7 @@ type Average = MixedAmount -- ^ The average of 'Change's or 'Balance's in a rep
|
||||
--
|
||||
-- * A list of amounts, one for each column. Depending on the value type,
|
||||
-- these can represent balance changes, ending balances, budget
|
||||
-- performance, etc. (for example, see 'BalanceType' and
|
||||
-- performance, etc. (for example, see 'BalanceAccumulation' and
|
||||
-- "Hledger.Cli.Commands.Balance").
|
||||
--
|
||||
-- * the total of the row's amounts for a periodic report,
|
||||
|
@ -153,7 +153,7 @@ asDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}}
|
||||
|
||||
where
|
||||
ropts = rsOpts rspec
|
||||
ishistorical = balancetype_ ropts == HistoricalBalance
|
||||
ishistorical = balanceaccum_ ropts == Historical
|
||||
|
||||
toplabel =
|
||||
withAttr ("border" <> "filename") files
|
||||
|
@ -109,7 +109,7 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportspec_=rsp
|
||||
period_=periodfromoptsandargs, -- query's date part
|
||||
no_elide_=True, -- avoid squashing boring account names, for a more regular tree (unlike hledger)
|
||||
empty_=not $ empty_ ropts, -- show zero items by default, hide them with -E (unlike hledger)
|
||||
balancetype_=HistoricalBalance -- show historical balances by default (unlike hledger)
|
||||
balanceaccum_=Historical -- show historical balances by default (unlike hledger)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=CliOpts{reportspec_=rspec
|
||||
depth_=Nothing
|
||||
-- XXX aregister also has this, needed ?
|
||||
-- always show historical balance
|
||||
-- , balancetype_= HistoricalBalance
|
||||
-- , balanceaccum_= Historical
|
||||
}
|
||||
rspec' =
|
||||
either (error "rsInit: adjusting the query for register, should not have failed") id $ -- PARTIAL:
|
||||
@ -201,7 +201,7 @@ rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}}
|
||||
|
||||
where
|
||||
ropts = rsOpts rspec
|
||||
ishistorical = balancetype_ ropts == HistoricalBalance
|
||||
ishistorical = balanceaccum_ ropts == Historical
|
||||
-- inclusive = tree_ ropts || rsForceInclusive
|
||||
|
||||
toplabel =
|
||||
|
@ -146,10 +146,10 @@ toggleTree ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspe
|
||||
-- | Toggle between historical balances and period balances.
|
||||
toggleHistorical :: UIState -> UIState
|
||||
toggleHistorical ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{rsOpts=ropts}}}} =
|
||||
ui{aopts=uopts{cliopts_=copts{reportspec_=rspec{rsOpts=ropts{balancetype_=b}}}}}
|
||||
ui{aopts=uopts{cliopts_=copts{reportspec_=rspec{rsOpts=ropts{balanceaccum_=b}}}}}
|
||||
where
|
||||
b | balancetype_ ropts == HistoricalBalance = PeriodChange
|
||||
| otherwise = HistoricalBalance
|
||||
b | balanceaccum_ ropts == Historical = PerPeriod
|
||||
| otherwise = Historical
|
||||
|
||||
-- | Toggle hledger-ui's "forecast/future mode". When this mode is enabled,
|
||||
-- hledger-shows regular transactions which have future dates, and
|
||||
|
@ -46,7 +46,7 @@ getRegisterR = do
|
||||
tail $ (", "<$xs) ++ [""]
|
||||
items = accountTransactionsReport rspec j m acctQuery
|
||||
balancelabel
|
||||
| isJust (inAccount qopts), balancetype_ (rsOpts rspec) == HistoricalBalance = "Historical Total"
|
||||
| isJust (inAccount qopts), balanceaccum_ (rsOpts rspec) == Historical = "Historical Total"
|
||||
| isJust (inAccount qopts) = "Period Total"
|
||||
| otherwise = "Total"
|
||||
transactionFrag = transactionFragment j
|
||||
|
@ -86,7 +86,7 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
|
||||
-- ignore any depth limit, as in postingsReport; allows register's total to match balance reports (cf #1468)
|
||||
depth_=Nothing
|
||||
-- always show historical balance
|
||||
, balancetype_= HistoricalBalance
|
||||
, balanceaccum_= Historical
|
||||
}
|
||||
-- and regenerate the ReportSpec, making sure to use the above
|
||||
rspec' = rspec{ rsQuery=simplifyQuery $ And [queryFromFlags ropts', argsquery]
|
||||
|
@ -310,8 +310,8 @@ balancemode = hledgerCommandMode
|
||||
|
||||
-- | The balance command, prints a balance report.
|
||||
balance :: CliOpts -> Journal -> IO ()
|
||||
balance opts@CliOpts{reportspec_=rspec} j = case reporttype_ of
|
||||
BudgetReport -> do -- single or multi period budget report
|
||||
balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ of
|
||||
CalcBudget -> do -- single or multi period budget report
|
||||
let reportspan = reportSpan j rspec
|
||||
budgetreport = budgetReport rspec (balancingopts_ $ inputopts_ opts) reportspan j
|
||||
render = case fmt of
|
||||
@ -586,12 +586,12 @@ multiBalanceReportAsText ropts@ReportOpts{..} r = TB.toLazyText $
|
||||
where
|
||||
title = mtitle <> " in " <> showDateSpan (periodicReportSpan r) <> valuationdesc <> ":"
|
||||
|
||||
mtitle = case (reporttype_, balancetype_) of
|
||||
(ValueChangeReport, PeriodChange ) -> "Period-end value changes"
|
||||
(ValueChangeReport, CumulativeChange ) -> "Cumulative period-end value changes"
|
||||
(_, PeriodChange ) -> "Balance changes"
|
||||
(_, CumulativeChange ) -> "Ending balances (cumulative)"
|
||||
(_, HistoricalBalance) -> "Ending balances (historical)"
|
||||
mtitle = case (balancecalc_, balanceaccum_) of
|
||||
(CalcValueChange, PerPeriod ) -> "Period-end value changes"
|
||||
(CalcValueChange, Cumulative ) -> "Cumulative period-end value changes"
|
||||
(_, PerPeriod ) -> "Balance changes"
|
||||
(_, Cumulative ) -> "Ending balances (cumulative)"
|
||||
(_, Historical) -> "Ending balances (historical)"
|
||||
valuationdesc =
|
||||
(case cost_ of
|
||||
Cost -> ", converted to cost"
|
||||
@ -604,14 +604,14 @@ multiBalanceReportAsText ropts@ReportOpts{..} r = TB.toLazyText $
|
||||
Just (AtDate d _mc) -> ", valued at " <> showDate d
|
||||
Nothing -> "")
|
||||
|
||||
changingValuation = case (reporttype_, balancetype_) of
|
||||
(ValueChangeReport, PeriodChange) -> True
|
||||
(ValueChangeReport, CumulativeChange) -> True
|
||||
changingValuation = case (balancecalc_, balanceaccum_) of
|
||||
(CalcValueChange, PerPeriod) -> True
|
||||
(CalcValueChange, Cumulative) -> True
|
||||
_ -> False
|
||||
|
||||
-- | Build a 'Table' from a multi-column balance report.
|
||||
balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table T.Text T.Text MixedAmount
|
||||
balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_}
|
||||
balanceReportAsTable opts@ReportOpts{average_, row_total_, balanceaccum_}
|
||||
(PeriodicReport spans items (PeriodicReportRow _ coltotals tot avg)) =
|
||||
maybetranspose $
|
||||
addtotalrow $
|
||||
@ -620,8 +620,8 @@ balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_}
|
||||
(Tab.Group NoLine $ map Header colheadings)
|
||||
(map rowvals items)
|
||||
where
|
||||
totalscolumn = row_total_ && balancetype_ `notElem` [CumulativeChange, HistoricalBalance]
|
||||
colheadings = map (reportPeriodName balancetype_ spans) spans
|
||||
totalscolumn = row_total_ && balanceaccum_ `notElem` [Cumulative, Historical]
|
||||
colheadings = map (reportPeriodName balanceaccum_ spans) spans
|
||||
++ [" Total" | totalscolumn]
|
||||
++ ["Average" | average_]
|
||||
accts = map renderacct items
|
||||
|
@ -37,7 +37,7 @@ balancesheetSpec = CompoundBalanceCommandSpec {
|
||||
,cbcsubreportincreasestotal=False
|
||||
}
|
||||
],
|
||||
cbctype = HistoricalBalance
|
||||
cbcaccum = Historical
|
||||
}
|
||||
|
||||
balancesheetmode :: Mode RawOpts
|
||||
|
@ -45,7 +45,7 @@ balancesheetequitySpec = CompoundBalanceCommandSpec {
|
||||
,cbcsubreportincreasestotal=False
|
||||
}
|
||||
],
|
||||
cbctype = HistoricalBalance
|
||||
cbcaccum = Historical
|
||||
}
|
||||
|
||||
balancesheetequitymode :: Mode RawOpts
|
||||
|
@ -34,7 +34,7 @@ cashflowSpec = CompoundBalanceCommandSpec {
|
||||
,cbcsubreportincreasestotal=True
|
||||
}
|
||||
],
|
||||
cbctype = PeriodChange
|
||||
cbcaccum = PerPeriod
|
||||
}
|
||||
|
||||
cashflowmode :: Mode RawOpts
|
||||
|
@ -102,7 +102,7 @@ close CliOpts{rawopts_=rawopts, reportspec_=rspec} j = do
|
||||
explicit = boolopt "explicit" rawopts
|
||||
|
||||
-- the balances to close
|
||||
ropts = (rsOpts rspec){balancetype_=HistoricalBalance, accountlistmode_=ALFlat}
|
||||
ropts = (rsOpts rspec){balanceaccum_=Historical, accountlistmode_=ALFlat}
|
||||
rspec_ = rspec{rsOpts=ropts}
|
||||
(acctbals',_) = balanceReport rspec_ j
|
||||
acctbals = map (\(a,_,_,b) -> (a, if show_costs_ ropts then b else mixedAmountStripPrices b)) acctbals'
|
||||
|
@ -35,7 +35,7 @@ incomestatementSpec = CompoundBalanceCommandSpec {
|
||||
,cbcsubreportincreasestotal=False
|
||||
}
|
||||
],
|
||||
cbctype = PeriodChange
|
||||
cbcaccum = PerPeriod
|
||||
}
|
||||
|
||||
incomestatementmode :: Mode RawOpts
|
||||
|
@ -47,8 +47,8 @@ data CompoundBalanceCommandSpec = CompoundBalanceCommandSpec {
|
||||
cbcdoc :: CommandDoc, -- ^ the command's name(s) and documentation
|
||||
cbctitle :: String, -- ^ overall report title
|
||||
cbcqueries :: [CBCSubreportSpec DisplayName], -- ^ subreport details
|
||||
cbctype :: BalanceType -- ^ the "balance" type (change, cumulative, historical)
|
||||
-- this report shows (overrides command line flags)
|
||||
cbcaccum :: BalanceAccumulation -- ^ how to accumulate balances (per-period, cumulative, historical)
|
||||
-- (overrides command line flags)
|
||||
}
|
||||
|
||||
-- | Generate a cmdargs option-parsing mode from a compound balance command
|
||||
@ -66,13 +66,13 @@ compoundBalanceCommandMode CompoundBalanceCommandSpec{..} =
|
||||
|
||||
,flagNone ["change"] (setboolopt "change")
|
||||
("accumulate amounts from column start to column end (in multicolumn reports)"
|
||||
++ defType PeriodChange)
|
||||
++ defaultMarker PerPeriod)
|
||||
,flagNone ["cumulative"] (setboolopt "cumulative")
|
||||
("accumulate amounts from report start (specified by e.g. -b/--begin) to column end"
|
||||
++ defType CumulativeChange)
|
||||
++ defaultMarker Cumulative)
|
||||
,flagNone ["historical","H"] (setboolopt "historical")
|
||||
("accumulate amounts from journal start to column end (includes postings before report start date)"
|
||||
++ defType HistoricalBalance ++ "\n ")
|
||||
++ defaultMarker Historical ++ "\n ")
|
||||
]
|
||||
++ flattreeflags True ++
|
||||
[flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
|
||||
@ -91,9 +91,9 @@ compoundBalanceCommandMode CompoundBalanceCommandSpec{..} =
|
||||
hiddenflags
|
||||
([], Just $ argsFlag "[QUERY]")
|
||||
where
|
||||
defType :: BalanceType -> String
|
||||
defType bt | bt == cbctype = " (default)"
|
||||
| otherwise = ""
|
||||
defaultMarker :: BalanceAccumulation -> String
|
||||
defaultMarker bacc | bacc == cbcaccum = " (default)"
|
||||
| otherwise = ""
|
||||
|
||||
-- | Generate a runnable command from a compound balance command specification.
|
||||
compoundBalanceCommand :: CompoundBalanceCommandSpec -> (CliOpts -> Journal -> IO ())
|
||||
@ -102,10 +102,10 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r
|
||||
where
|
||||
ropts@ReportOpts{..} = rsOpts rspec
|
||||
-- use the default balance type for this report, unless the user overrides
|
||||
mBalanceTypeOverride = balanceTypeOverride rawopts
|
||||
balancetype = fromMaybe cbctype mBalanceTypeOverride
|
||||
mbalanceAccumulationOverride = balanceAccumulationOverride rawopts
|
||||
balanceaccumulation = fromMaybe cbcaccum mbalanceAccumulationOverride
|
||||
-- Set balance type in the report options.
|
||||
ropts' = ropts{balancetype_=balancetype}
|
||||
ropts' = ropts{balanceaccum_=balanceaccumulation}
|
||||
|
||||
title =
|
||||
T.pack cbctitle
|
||||
@ -116,24 +116,24 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r
|
||||
where
|
||||
|
||||
-- XXX #1078 the title of ending balance reports
|
||||
-- (HistoricalBalance) should mention the end date(s) shown as
|
||||
-- (Historical) should mention the end date(s) shown as
|
||||
-- column heading(s) (not the date span of the transactions).
|
||||
-- Also the dates should not be simplified (it should show
|
||||
-- "2008/01/01-2008/12/31", not "2008").
|
||||
titledatestr = case balancetype of
|
||||
HistoricalBalance -> showEndDates enddates
|
||||
titledatestr = case balanceaccumulation of
|
||||
Historical -> showEndDates enddates
|
||||
_ -> showDateSpan requestedspan
|
||||
where
|
||||
enddates = map (addDays (-1)) . mapMaybe spanEnd $ cbrDates cbr -- these spans will always have a definite end date
|
||||
requestedspan = reportSpan j rspec
|
||||
|
||||
-- when user overrides, add an indication to the report title
|
||||
-- Do we need to deal with overridden ReportType?
|
||||
mtitleclarification = flip fmap mBalanceTypeOverride $ \case
|
||||
PeriodChange | changingValuation -> "(Period-End Value Changes)"
|
||||
PeriodChange -> "(Balance Changes)"
|
||||
CumulativeChange -> "(Cumulative Ending Balances)"
|
||||
HistoricalBalance -> "(Historical Ending Balances)"
|
||||
-- Do we need to deal with overridden BalanceCalculation?
|
||||
mtitleclarification = flip fmap mbalanceAccumulationOverride $ \case
|
||||
PerPeriod | changingValuation -> "(Period-End Value Changes)"
|
||||
PerPeriod -> "(Balance Changes)"
|
||||
Cumulative -> "(Cumulative Ending Balances)"
|
||||
Historical -> "(Historical Ending Balances)"
|
||||
|
||||
valuationdesc =
|
||||
(case cost_ of
|
||||
@ -147,9 +147,9 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r
|
||||
Just (AtDate today _mc) -> ", valued at " <> showDate today
|
||||
Nothing -> "")
|
||||
|
||||
changingValuation = case (reporttype_, balancetype_) of
|
||||
(ValueChangeReport, PeriodChange) -> True
|
||||
(ValueChangeReport, CumulativeChange) -> True
|
||||
changingValuation = case (balancecalc_, balanceaccum_) of
|
||||
(CalcValueChange, PerPeriod) -> True
|
||||
(CalcValueChange, Cumulative) -> True
|
||||
_ -> False
|
||||
|
||||
-- make a CompoundBalanceReport.
|
||||
@ -239,7 +239,7 @@ compoundBalanceReportAsCsv ropts (CompoundPeriodicReport title colspans subrepor
|
||||
addtotals $
|
||||
padRow title
|
||||
: ( "Account"
|
||||
: map (reportPeriodName (balancetype_ ropts) colspans) colspans
|
||||
: map (reportPeriodName (balanceaccum_ ropts) colspans) colspans
|
||||
++ (if row_total_ ropts then ["Total"] else [])
|
||||
++ (if average_ ropts then ["Average"] else [])
|
||||
)
|
||||
@ -284,7 +284,7 @@ compoundBalanceReportAsHtml ropts cbr =
|
||||
[tr_ $ th_ [colspanattr, leftattr] $ h2_ $ toHtml title]
|
||||
++ [thRow $
|
||||
"" :
|
||||
map (reportPeriodName (balancetype_ ropts) colspans) colspans
|
||||
map (reportPeriodName (balanceaccum_ ropts) colspans) colspans
|
||||
++ (if row_total_ ropts then ["Total"] else [])
|
||||
++ (if average_ ropts then ["Average"] else [])
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user