mirror of
https://github.com/simonmichael/hledger.git
synced 2024-10-04 01:50:50 +03:00
Merge e60c05614f
into eeb070195c
This commit is contained in:
commit
0b80f1d415
@ -691,9 +691,10 @@ balanceReportAsSpreadsheet ::
|
||||
balanceReportAsSpreadsheet opts (items, total) =
|
||||
(if transpose_ opts then Ods.transpose else id) $
|
||||
headers :
|
||||
concatMap (\(a, _, _, b) -> rows Value a b) items ++
|
||||
concatMap (rows Value) items ++
|
||||
if no_total_ opts then []
|
||||
else addTotalBorders $ rows Total totalRowHeadingSpreadsheet total
|
||||
else addTotalBorders $
|
||||
rows Total (totalRowHeadingSpreadsheet, totalRowHeadingSpreadsheet, 0, total)
|
||||
where
|
||||
cell = Ods.defaultCell
|
||||
headers =
|
||||
@ -702,14 +703,14 @@ balanceReportAsSpreadsheet opts (items, total) =
|
||||
LayoutBare -> ["commodity", "balance"]
|
||||
_ -> ["balance"]
|
||||
rows ::
|
||||
RowClass -> AccountName ->
|
||||
MixedAmount -> [[Ods.Cell Ods.NumLines Text]]
|
||||
rows rc name ma =
|
||||
RowClass -> BalanceReportItem ->
|
||||
[[Ods.Cell Ods.NumLines Text]]
|
||||
rows rc (name, dispName, dep, ma) =
|
||||
let accountCell =
|
||||
setAccountAnchor
|
||||
(guard (rc==Value) >> balance_base_url_ opts)
|
||||
(querystring_ opts) name $
|
||||
cell $ accountNameDrop (drop_ opts) name in
|
||||
cell $ renderBalanceAcct opts nbsp (name, dispName, dep) in
|
||||
addRowSpanHeader accountCell $
|
||||
case layout_ opts of
|
||||
LayoutBare ->
|
||||
@ -806,7 +807,7 @@ multiBalanceReportAsSpreadsheetParts ishtml opts@ReportOpts{..} (PeriodicReport
|
||||
where acctName = prrFullName row
|
||||
anchorCell =
|
||||
setAccountAnchor balance_base_url_ querystring_ acctName $
|
||||
accountCell $ accountNameDrop drop_ acctName
|
||||
accountCell $ renderPeriodicAcct opts nbsp row
|
||||
totalrows =
|
||||
if no_total_
|
||||
then []
|
||||
@ -1046,7 +1047,7 @@ budgetReportAsText ropts@ReportOpts{..} budgetr = TB.toLazyText $
|
||||
|
||||
-- | Build a 'Table' from a multi-column balance report.
|
||||
budgetReportAsTable :: ReportOpts -> BudgetReport -> Table Text Text WideBuilder
|
||||
budgetReportAsTable ReportOpts{..} (PeriodicReport spans items totrow) =
|
||||
budgetReportAsTable ropts@ReportOpts{..} (PeriodicReport spans items totrow) =
|
||||
maybetransposetable $
|
||||
addtotalrow $
|
||||
Table
|
||||
@ -1152,17 +1153,10 @@ budgetReportAsTable ReportOpts{..} (PeriodicReport spans items totrow) =
|
||||
shownitems =
|
||||
map (\i ->
|
||||
let
|
||||
addacctcolumn = map (\(cs, cvals) -> (renderacct i, cs, cvals))
|
||||
addacctcolumn = map (\(cs, cvals) -> (renderPeriodicAcct ropts " " i, cs, cvals))
|
||||
isunbudgetedrow = displayFull (prrName i) == unbudgetedAccountName
|
||||
in addacctcolumn $ showrow isunbudgetedrow $ rowToBudgetCells i)
|
||||
items
|
||||
where
|
||||
-- FIXME. Have to check explicitly for which to render here, since
|
||||
-- budgetReport sets accountlistmode to ALTree. Find a principled way to do
|
||||
-- this.
|
||||
renderacct row = case accountlistmode_ of
|
||||
ALTree -> T.replicate ((prrDepth row - 1)*2) " " <> prrDisplayName row
|
||||
ALFlat -> accountNameDrop (drop_) $ prrFullName row
|
||||
|
||||
(totrowcs, totrowtexts) = unzip $ concat showntotrow
|
||||
where
|
||||
@ -1271,7 +1265,7 @@ budgetReportAsCsv ropts report
|
||||
budgetReportAsSpreadsheet ::
|
||||
ReportOpts -> BudgetReport -> [[Ods.Cell Ods.NumLines Text]]
|
||||
budgetReportAsSpreadsheet
|
||||
ReportOpts{..}
|
||||
ropts@ReportOpts{..}
|
||||
(PeriodicReport colspans items totrow)
|
||||
= (if transpose_ then Ods.transpose else id) $
|
||||
|
||||
@ -1285,14 +1279,18 @@ budgetReportAsSpreadsheet
|
||||
) :
|
||||
|
||||
-- account rows
|
||||
concatMap (rowAsTexts Value prrFullName) items
|
||||
concatMap (\row -> rowAsTexts Value (accountCell row) row) items
|
||||
|
||||
-- totals row
|
||||
++ addTotalBorders
|
||||
(concat [ rowAsTexts Total (const totalRowHeadingBudgetCsv) totrow | not no_total_ ])
|
||||
(concat [ rowAsTexts Total (cell totalRowHeadingBudgetCsv) totrow | not no_total_ ])
|
||||
|
||||
where
|
||||
cell = Ods.defaultCell
|
||||
accountCell row =
|
||||
let name = prrFullName row in
|
||||
setAccountAnchor (balance_base_url_) querystring_ name $
|
||||
cell $ renderPeriodicAcct ropts nbsp row
|
||||
{-
|
||||
ToDo: The chosen HTML cell class names are not put in stone.
|
||||
If you find you need more systematic names,
|
||||
@ -1304,17 +1302,18 @@ budgetReportAsSpreadsheet
|
||||
maybe Ods.emptyCell (fmap wbToText . curry (cellFromMixedAmount oneLineNoCostFmt) cls) mval
|
||||
|
||||
rowAsTexts :: RowClass
|
||||
-> (PeriodicReportRow a BudgetCell -> Text)
|
||||
-> Ods.Cell Ods.NumLines Text
|
||||
-> PeriodicReportRow a BudgetCell
|
||||
-> [[Ods.Cell Ods.NumLines Text]]
|
||||
rowAsTexts rc render row@(PeriodicReportRow _ as (rowtot,budgettot) (rowavg, budgetavg))
|
||||
| layout_ /= LayoutBare = [accountCell : map showNorm vals]
|
||||
| otherwise =
|
||||
addRowSpanHeader accountCell -- add name
|
||||
. zipWith (:) (map cell cs) -- add symbols
|
||||
rowAsTexts rc acctCell (PeriodicReportRow _ as (rowtot,budgettot) (rowavg, budgetavg)) =
|
||||
addRowSpanHeader acctCell $
|
||||
case layout_ of
|
||||
LayoutBare ->
|
||||
zipWith (:) (map cell cs) -- add symbols
|
||||
. transpose -- each row becomes a list of Text quantities
|
||||
. map (map (fmap wbToText) . cellsFromMixedAmount dopts . second (fromMaybe nullmixedamt))
|
||||
$ vals
|
||||
_ -> [map showNorm vals]
|
||||
where
|
||||
cs = S.toList . mconcat . map maCommodities $ mapMaybe snd vals
|
||||
dopts = oneLineNoCostFmt{displayCommodity=layout_ /= LayoutBare, displayCommodityOrder=Just cs, displayMinWidth=Nothing}
|
||||
@ -1326,10 +1325,25 @@ budgetReportAsSpreadsheet
|
||||
(budgetAverageClass rc, budgetavg)]
|
||||
| average_]
|
||||
|
||||
accountCell =
|
||||
let name = render row in
|
||||
setAccountAnchor (guard (rc==Value) >> balance_base_url_)
|
||||
querystring_ name (cell name)
|
||||
|
||||
nbsp :: Text
|
||||
nbsp = "\160"
|
||||
|
||||
renderBalanceAcct ::
|
||||
ReportOpts -> Text -> (AccountName, AccountName, Int) -> Text
|
||||
renderBalanceAcct opts space (fullName, displayName, dep) =
|
||||
case accountlistmode_ opts of
|
||||
ALTree -> T.replicate ((dep - 1)*2) space <> displayName
|
||||
ALFlat -> accountNameDrop (drop_ opts) fullName
|
||||
|
||||
-- FIXME. Have to check explicitly for which to render here, since
|
||||
-- budgetReport sets accountlistmode to ALTree. Find a principled way to do
|
||||
-- this.
|
||||
renderPeriodicAcct ::
|
||||
ReportOpts -> Text -> PeriodicReportRow DisplayName a -> Text
|
||||
renderPeriodicAcct opts space row =
|
||||
renderBalanceAcct opts space
|
||||
(prrFullName row, prrDisplayName row, prrDepth row)
|
||||
|
||||
|
||||
-- tests
|
||||
|
Loading…
Reference in New Issue
Block a user