lib,cli: Move reportPeriodName to Hledger.Reports.ReportOptions, use it
for HTML and CSV output for compound balance reports.
This commit is contained in:
		
							parent
							
								
									d0940bf8ce
								
							
						
					
					
						commit
						5fbb67b893
					
				| @ -20,7 +20,6 @@ module Hledger.Reports.BudgetReport ( | |||||||
|   budgetReportAsText, |   budgetReportAsText, | ||||||
|   budgetReportAsCsv, |   budgetReportAsCsv, | ||||||
|   -- * Helpers |   -- * Helpers | ||||||
|   reportPeriodName, |  | ||||||
|   combineBudgetAndActual, |   combineBudgetAndActual, | ||||||
|   -- * Tests |   -- * Tests | ||||||
|   tests_BudgetReport |   tests_BudgetReport | ||||||
| @ -318,27 +317,6 @@ budgetReportAsTable | |||||||
|                                ++ [grandavg | average_ ropts && not (null coltots)] |                                ++ [grandavg | average_ ropts && not (null coltots)] | ||||||
|                     )) |                     )) | ||||||
| 
 | 
 | ||||||
| -- | Make a name for the given period in a multiperiod report, given |  | ||||||
| -- the type of balance being reported and the full set of report |  | ||||||
| -- periods. This will be used as a column heading (or row heading, in |  | ||||||
| -- a register summary report). We try to pick a useful name as follows: |  | ||||||
| -- |  | ||||||
| -- - ending-balance reports: the period's end date |  | ||||||
| -- |  | ||||||
| -- - balance change reports where the periods are months and all in the same year: |  | ||||||
| --   the short month name in the current locale |  | ||||||
| -- |  | ||||||
| -- - 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 |  | ||||||
|       where |  | ||||||
|         multiyear = (>1) $ length $ nubSort $ map spanStartYear spans |  | ||||||
|     _ -> maybe "" (showDate . prevday) . spanEnd |  | ||||||
| 
 |  | ||||||
| -- XXX generalise this with multiBalanceReportAsCsv ? | -- XXX generalise this with multiBalanceReportAsCsv ? | ||||||
| -- | Render a budget report as CSV. Like multiBalanceReportAsCsv, | -- | Render a budget report as CSV. Like multiBalanceReportAsCsv, | ||||||
| -- but includes alternating actual and budget amount columns. | -- but includes alternating actual and budget amount columns. | ||||||
|  | |||||||
| @ -42,6 +42,7 @@ module Hledger.Reports.ReportOptions ( | |||||||
|   reportPeriodOrJournalStart, |   reportPeriodOrJournalStart, | ||||||
|   reportPeriodLastDay, |   reportPeriodLastDay, | ||||||
|   reportPeriodOrJournalLastDay, |   reportPeriodOrJournalLastDay, | ||||||
|  |   reportPeriodName | ||||||
| ) | ) | ||||||
| where | where | ||||||
| 
 | 
 | ||||||
| @ -592,3 +593,23 @@ reportPeriodOrJournalLastDay rspec j = reportPeriodLastDay rspec <|> journalOrPr | |||||||
|         Just (AtEnd _) -> max (journalEndDate False j) lastPriceDirective |         Just (AtEnd _) -> max (journalEndDate False j) lastPriceDirective | ||||||
|         _              -> journalEndDate False j |         _              -> journalEndDate False j | ||||||
|     lastPriceDirective = fmap (addDays 1) . maximumMay . map pddate $ jpricedirectives j |     lastPriceDirective = fmap (addDays 1) . maximumMay . map pddate $ jpricedirectives j | ||||||
|  | 
 | ||||||
|  | -- | Make a name for the given period in a multiperiod report, given | ||||||
|  | -- the type of balance being reported and the full set of report | ||||||
|  | -- periods. This will be used as a column heading (or row heading, in | ||||||
|  | -- a register summary report). We try to pick a useful name as follows: | ||||||
|  | -- | ||||||
|  | -- - ending-balance reports: the period's end date | ||||||
|  | -- | ||||||
|  | -- - balance change reports where the periods are months and all in the same year: | ||||||
|  | --   the short month name in the current locale | ||||||
|  | -- | ||||||
|  | -- - 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 | ||||||
|  |       where | ||||||
|  |         multiyear = (>1) $ length $ nubSort $ map spanStartYear spans | ||||||
|  |     _ -> maybe "" (showDate . prevday) . spanEnd | ||||||
|  | |||||||
| @ -243,7 +243,7 @@ compoundBalanceReportAsCsv ropts (CompoundPeriodicReport title colspans subrepor | |||||||
|     addtotals $ |     addtotals $ | ||||||
|       padRow title |       padRow title | ||||||
|       : ( "Account" |       : ( "Account" | ||||||
|         : map showDateSpanMonthAbbrev colspans |         : map (reportPeriodName (balancetype_ ropts) colspans) colspans | ||||||
|         ++ (if row_total_ ropts then ["Total"] else []) |         ++ (if row_total_ ropts then ["Total"] else []) | ||||||
|         ++ (if average_ ropts then ["Average"] else []) |         ++ (if average_ ropts then ["Average"] else []) | ||||||
|         ) |         ) | ||||||
| @ -288,7 +288,7 @@ compoundBalanceReportAsHtml ropts cbr = | |||||||
|          [tr_ $ th_ [colspanattr, leftattr] $ h2_ $ toHtml title] |          [tr_ $ th_ [colspanattr, leftattr] $ h2_ $ toHtml title] | ||||||
|       ++ [thRow $ |       ++ [thRow $ | ||||||
|           "" : |           "" : | ||||||
|           map showDateSpanMonthAbbrev colspans |           map (reportPeriodName (balancetype_ ropts) colspans) colspans | ||||||
|           ++ (if row_total_ ropts then ["Total"] else []) |           ++ (if row_total_ ropts then ["Total"] else []) | ||||||
|           ++ (if average_ ropts then ["Average"] else []) |           ++ (if average_ ropts then ["Average"] else []) | ||||||
|           ] |           ] | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user