mirror of
https://github.com/simonmichael/hledger.git
synced 2025-01-08 11:49:44 +03:00
lib: Write.Ods.printFods: change type of number of fixed rows/columns from (Maybe Int) to Int
0 is a perfect value for no fixed row or column.
This commit is contained in:
parent
b2aad52168
commit
3714ac0593
@ -13,6 +13,7 @@ module Hledger.Write.Ods (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude hiding (Applicative(..))
|
import Prelude hiding (Applicative(..))
|
||||||
|
import Control.Monad (guard)
|
||||||
import Control.Applicative (Applicative(..))
|
import Control.Applicative (Applicative(..))
|
||||||
|
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
@ -38,7 +39,7 @@ import Hledger.Data.Types (acommodity, aquantity, astyle, asprecision)
|
|||||||
|
|
||||||
printFods ::
|
printFods ::
|
||||||
IO.TextEncoding ->
|
IO.TextEncoding ->
|
||||||
Map Text ((Maybe Int, Maybe Int), [[Cell Spr.NumLines Text]]) -> TL.Text
|
Map Text ((Int, Int), [[Cell Spr.NumLines Text]]) -> TL.Text
|
||||||
printFods encoding tables =
|
printFods encoding tables =
|
||||||
let fileOpen customStyles =
|
let fileOpen customStyles =
|
||||||
map (map (\c -> case c of '\'' -> '"'; _ -> c)) $
|
map (map (\c -> case c of '\'' -> '"'; _ -> c)) $
|
||||||
@ -87,14 +88,14 @@ printFods encoding tables =
|
|||||||
" <config:config-item-map-entry>" :
|
" <config:config-item-map-entry>" :
|
||||||
" <config:config-item-map-named config:name='Tables'>" :
|
" <config:config-item-map-named config:name='Tables'>" :
|
||||||
(fold $
|
(fold $
|
||||||
flip Map.mapWithKey tableNames $ \tableName (mTopRow,mLeftColumn) ->
|
flip Map.mapWithKey tableNames $ \tableName (topRow,leftColumn) ->
|
||||||
printf " <config:config-item-map-entry config:name='%s'>" tableName :
|
printf " <config:config-item-map-entry config:name='%s'>" tableName :
|
||||||
(flip foldMap mLeftColumn $ \leftColumn ->
|
((guard (leftColumn>0) >>) $
|
||||||
" <config:config-item config:name='HorizontalSplitMode' config:type='short'>2</config:config-item>" :
|
" <config:config-item config:name='HorizontalSplitMode' config:type='short'>2</config:config-item>" :
|
||||||
printf " <config:config-item config:name='HorizontalSplitPosition' config:type='int'>%d</config:config-item>" leftColumn :
|
printf " <config:config-item config:name='HorizontalSplitPosition' config:type='int'>%d</config:config-item>" leftColumn :
|
||||||
printf " <config:config-item config:name='PositionRight' config:type='int'>%d</config:config-item>" leftColumn :
|
printf " <config:config-item config:name='PositionRight' config:type='int'>%d</config:config-item>" leftColumn :
|
||||||
[]) ++
|
[]) ++
|
||||||
(flip foldMap mTopRow $ \topRow ->
|
((guard (topRow>0) >>) $
|
||||||
" <config:config-item config:name='VerticalSplitMode' config:type='short'>2</config:config-item>" :
|
" <config:config-item config:name='VerticalSplitMode' config:type='short'>2</config:config-item>" :
|
||||||
printf " <config:config-item config:name='VerticalSplitPosition' config:type='int'>%d</config:config-item>" topRow :
|
printf " <config:config-item config:name='VerticalSplitPosition' config:type='int'>%d</config:config-item>" topRow :
|
||||||
printf " <config:config-item config:name='PositionBottom' config:type='int'>%d</config:config-item>" topRow :
|
printf " <config:config-item config:name='PositionBottom' config:type='int'>%d</config:config-item>" topRow :
|
||||||
|
@ -121,7 +121,7 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
|
|||||||
| fmt=="tsv" = printTSV . accountTransactionsReportAsCsv wd (_rsQuery rspec') thisacctq
|
| fmt=="tsv" = printTSV . accountTransactionsReportAsCsv wd (_rsQuery rspec') thisacctq
|
||||||
| fmt=="fods" =
|
| fmt=="fods" =
|
||||||
printFods IO.localeEncoding . Map.singleton "Aregister" .
|
printFods IO.localeEncoding . Map.singleton "Aregister" .
|
||||||
(,) (Just 1, Nothing) .
|
(,) (1,0) .
|
||||||
accountTransactionsReportAsSpreadsheet oneLineNoCostFmt wd (_rsQuery rspec') thisacctq
|
accountTransactionsReportAsSpreadsheet oneLineNoCostFmt wd (_rsQuery rspec') thisacctq
|
||||||
| fmt=="json" = toJsonText
|
| fmt=="json" = toJsonText
|
||||||
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
||||||
|
@ -394,7 +394,7 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ ropts of
|
|||||||
"html" -> (<>"\n") . L.renderText .
|
"html" -> (<>"\n") . L.renderText .
|
||||||
printHtml . map (map (fmap L.toHtml)) . budgetReportAsSpreadsheet ropts
|
printHtml . map (map (fmap L.toHtml)) . budgetReportAsSpreadsheet ropts
|
||||||
"fods" -> printFods IO.localeEncoding .
|
"fods" -> printFods IO.localeEncoding .
|
||||||
Map.singleton "Budget Report" . (,) (Just 1, Nothing) . budgetReportAsSpreadsheet ropts
|
Map.singleton "Budget Report" . (,) (1,0) . budgetReportAsSpreadsheet ropts
|
||||||
_ -> error' $ unsupportedOutputFormatError fmt
|
_ -> error' $ unsupportedOutputFormatError fmt
|
||||||
writeOutputLazyText opts $ render budgetreport
|
writeOutputLazyText opts $ render budgetreport
|
||||||
|
|
||||||
@ -420,7 +420,7 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ ropts of
|
|||||||
"html" -> (<>"\n") . L.renderText .
|
"html" -> (<>"\n") . L.renderText .
|
||||||
printHtml . map (map (fmap L.toHtml)) . balanceReportAsSpreadsheet ropts
|
printHtml . map (map (fmap L.toHtml)) . balanceReportAsSpreadsheet ropts
|
||||||
"json" -> (<>"\n") . toJsonText
|
"json" -> (<>"\n") . toJsonText
|
||||||
"fods" -> printFods IO.localeEncoding . Map.singleton "Balance Report" . (,) (Just 1, Nothing) . balanceReportAsSpreadsheet ropts
|
"fods" -> printFods IO.localeEncoding . Map.singleton "Balance Report" . (,) (1,0) . balanceReportAsSpreadsheet ropts
|
||||||
_ -> error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
_ -> error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
||||||
writeOutputLazyText opts $ render report
|
writeOutputLazyText opts $ render report
|
||||||
where
|
where
|
||||||
@ -718,12 +718,12 @@ multiBalanceReportAsHtml ropts mbr =
|
|||||||
-- Returns the heading row, 0 or more body rows, and the totals row if enabled.
|
-- Returns the heading row, 0 or more body rows, and the totals row if enabled.
|
||||||
multiBalanceReportAsSpreadsheet ::
|
multiBalanceReportAsSpreadsheet ::
|
||||||
ReportOpts -> MultiBalanceReport ->
|
ReportOpts -> MultiBalanceReport ->
|
||||||
((Maybe Int, Maybe Int), [[Ods.Cell Ods.NumLines Text]])
|
((Int, Int), [[Ods.Cell Ods.NumLines Text]])
|
||||||
multiBalanceReportAsSpreadsheet ropts mbr =
|
multiBalanceReportAsSpreadsheet ropts mbr =
|
||||||
let (header,body,total) =
|
let (header,body,total) =
|
||||||
multiBalanceReportAsSpreadsheetParts oneLineNoCostFmt ropts mbr
|
multiBalanceReportAsSpreadsheetParts oneLineNoCostFmt ropts mbr
|
||||||
in (if transpose_ ropts then swap *** Ods.transpose else id) $
|
in (if transpose_ ropts then swap *** Ods.transpose else id) $
|
||||||
((Just 1, case layout_ ropts of LayoutWide _ -> Just 1; _ -> Nothing),
|
((1, case layout_ ropts of LayoutWide _ -> 1; _ -> 0),
|
||||||
header : body ++ total)
|
header : body ++ total)
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ printEntries opts@CliOpts{rawopts_=rawopts, reportspec_=rspec} j =
|
|||||||
styleAmounts styles
|
styleAmounts styles
|
||||||
| fmt=="fods" =
|
| fmt=="fods" =
|
||||||
printFods IO.localeEncoding . Map.singleton "Print" .
|
printFods IO.localeEncoding . Map.singleton "Print" .
|
||||||
(,) (Just 1, Nothing) .
|
(,) (1,0) .
|
||||||
entriesReportAsSpreadsheet oneLineNoCostFmt baseUrl query .
|
entriesReportAsSpreadsheet oneLineNoCostFmt baseUrl query .
|
||||||
styleAmounts styles
|
styleAmounts styles
|
||||||
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
||||||
|
@ -108,7 +108,7 @@ register opts@CliOpts{rawopts_=rawopts, reportspec_=rspec} j
|
|||||||
postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query
|
postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query
|
||||||
| fmt=="fods" =
|
| fmt=="fods" =
|
||||||
printFods IO.localeEncoding . Map.singleton "Register" .
|
printFods IO.localeEncoding . Map.singleton "Register" .
|
||||||
(,) (Just 1, Nothing) .
|
(,) (1,0) .
|
||||||
postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query
|
postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query
|
||||||
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
|
||||||
where fmt = outputFormatFromOpts opts
|
where fmt = outputFormatFromOpts opts
|
||||||
@ -119,6 +119,8 @@ postingsReportAsCsv :: PostingsReport -> CSV
|
|||||||
postingsReportAsCsv =
|
postingsReportAsCsv =
|
||||||
Spr.rawTableContent . postingsReportAsSpreadsheet machineFmt Nothing []
|
Spr.rawTableContent . postingsReportAsSpreadsheet machineFmt Nothing []
|
||||||
|
|
||||||
|
-- ToDo: --layout=bare etc.
|
||||||
|
-- ToDo: Text output does not show headers, but Spreadsheet does
|
||||||
postingsReportAsSpreadsheet ::
|
postingsReportAsSpreadsheet ::
|
||||||
AmountFormat -> Maybe Text -> [Text] ->
|
AmountFormat -> Maybe Text -> [Text] ->
|
||||||
PostingsReport -> [[Spr.Cell Spr.NumLines Text]]
|
PostingsReport -> [[Spr.Cell Spr.NumLines Text]]
|
||||||
|
@ -343,7 +343,7 @@ compoundBalanceReportAsHtml ropts cbr =
|
|||||||
compoundBalanceReportAsSpreadsheet ::
|
compoundBalanceReportAsSpreadsheet ::
|
||||||
AmountFormat -> T.Text -> Maybe T.Text ->
|
AmountFormat -> T.Text -> Maybe T.Text ->
|
||||||
ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount ->
|
ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount ->
|
||||||
(T.Text, ((Maybe Int, Maybe Int), NonEmpty [Spr.Cell Spr.NumLines T.Text]))
|
(T.Text, ((Int, Int), NonEmpty [Spr.Cell Spr.NumLines T.Text]))
|
||||||
compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr =
|
compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr =
|
||||||
let
|
let
|
||||||
CompoundPeriodicReport title colspans subreports totalrow = cbr
|
CompoundPeriodicReport title colspans subreports totalrow = cbr
|
||||||
@ -397,5 +397,5 @@ compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr =
|
|||||||
& addTotalBorders -- marking the first row for special styling
|
& addTotalBorders -- marking the first row for special styling
|
||||||
|
|
||||||
in (title,
|
in (title,
|
||||||
((Just 1, Just 1),
|
((1,1),
|
||||||
headerrow :| concatMap subreportrows subreports ++ totalrows))
|
headerrow :| concatMap subreportrows subreports ++ totalrows))
|
||||||
|
Loading…
Reference in New Issue
Block a user