{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
module Hledger.Cli.Commands.Balance.Internal where
import Control.Monad (guard)
import Data.List (transpose)
import Data.Set qualified as S
import Data.Text (Text)
import Data.Text qualified as T
import Data.Time (addDays)
import Text.Tabular.AsciiWide (Header(..), Properties(..), Table(..), concatTables)
import Hledger.Utils.I18n qualified as I18n
import Hledger
import Hledger.Cli.Anchor (LinkOpts(..), valueParam, dateTerm, removeDates, withLink, setAccountAnchorWith,
dateSpanCellWith, totalDateSpanCell, headerDateSpanCell, renderPeriodHeading, amountPhrase)
import Hledger.Write.Spreadsheet (rawTableContent, headerCell,
addHeaderBorders, addRowSpanHeader,
cellFromMixedAmount, cellsFromMixedAmount)
import Hledger.Write.Spreadsheet qualified as Ods
accountClass :: Ods.Class
accountClass :: Class
accountClass = Text -> Class
Ods.Class Text
"account"
treeAccountClass :: ReportOpts -> Int -> AccountName -> Ods.Class
treeAccountClass :: ReportOpts -> Int -> Text -> Class
treeAccountClass ReportOpts
opts Int
indent Text
acct
| ReportOpts -> AccountListMode
accountlistmode_ ReportOpts
opts AccountListMode -> AccountListMode -> Bool
forall a. Eq a => a -> a -> Bool
== AccountListMode
ALTree = Text -> Class
Ods.Class (Text -> Class) -> Text -> Class
forall a b. (a -> b) -> a -> b
$
Text
"account indent-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
indent) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" depth-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show (Text -> Int
accountNameLevel Text
acct))
| Bool
otherwise = Class
accountClass
data RowClass = Value | Total
deriving (RowClass -> RowClass -> Bool
(RowClass -> RowClass -> Bool)
-> (RowClass -> RowClass -> Bool) -> Eq RowClass
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RowClass -> RowClass -> Bool
== :: RowClass -> RowClass -> Bool
$c/= :: RowClass -> RowClass -> Bool
/= :: RowClass -> RowClass -> Bool
Eq, Eq RowClass
Eq RowClass =>
(RowClass -> RowClass -> Ordering)
-> (RowClass -> RowClass -> Bool)
-> (RowClass -> RowClass -> Bool)
-> (RowClass -> RowClass -> Bool)
-> (RowClass -> RowClass -> Bool)
-> (RowClass -> RowClass -> RowClass)
-> (RowClass -> RowClass -> RowClass)
-> Ord RowClass
RowClass -> RowClass -> Bool
RowClass -> RowClass -> Ordering
RowClass -> RowClass -> RowClass
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RowClass -> RowClass -> Ordering
compare :: RowClass -> RowClass -> Ordering
$c< :: RowClass -> RowClass -> Bool
< :: RowClass -> RowClass -> Bool
$c<= :: RowClass -> RowClass -> Bool
<= :: RowClass -> RowClass -> Bool
$c> :: RowClass -> RowClass -> Bool
> :: RowClass -> RowClass -> Bool
$c>= :: RowClass -> RowClass -> Bool
>= :: RowClass -> RowClass -> Bool
$cmax :: RowClass -> RowClass -> RowClass
max :: RowClass -> RowClass -> RowClass
$cmin :: RowClass -> RowClass -> RowClass
min :: RowClass -> RowClass -> RowClass
Ord, Int -> RowClass
RowClass -> Int
RowClass -> [RowClass]
RowClass -> RowClass
RowClass -> RowClass -> [RowClass]
RowClass -> RowClass -> RowClass -> [RowClass]
(RowClass -> RowClass)
-> (RowClass -> RowClass)
-> (Int -> RowClass)
-> (RowClass -> Int)
-> (RowClass -> [RowClass])
-> (RowClass -> RowClass -> [RowClass])
-> (RowClass -> RowClass -> [RowClass])
-> (RowClass -> RowClass -> RowClass -> [RowClass])
-> Enum RowClass
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: RowClass -> RowClass
succ :: RowClass -> RowClass
$cpred :: RowClass -> RowClass
pred :: RowClass -> RowClass
$ctoEnum :: Int -> RowClass
toEnum :: Int -> RowClass
$cfromEnum :: RowClass -> Int
fromEnum :: RowClass -> Int
$cenumFrom :: RowClass -> [RowClass]
enumFrom :: RowClass -> [RowClass]
$cenumFromThen :: RowClass -> RowClass -> [RowClass]
enumFromThen :: RowClass -> RowClass -> [RowClass]
$cenumFromTo :: RowClass -> RowClass -> [RowClass]
enumFromTo :: RowClass -> RowClass -> [RowClass]
$cenumFromThenTo :: RowClass -> RowClass -> RowClass -> [RowClass]
enumFromThenTo :: RowClass -> RowClass -> RowClass -> [RowClass]
Enum, RowClass
RowClass -> RowClass -> Bounded RowClass
forall a. a -> a -> Bounded a
$cminBound :: RowClass
minBound :: RowClass
$cmaxBound :: RowClass
maxBound :: RowClass
Bounded, Int -> RowClass -> ShowS
[RowClass] -> ShowS
RowClass -> String
(Int -> RowClass -> ShowS)
-> (RowClass -> String) -> ([RowClass] -> ShowS) -> Show RowClass
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RowClass -> ShowS
showsPrec :: Int -> RowClass -> ShowS
$cshow :: RowClass -> String
show :: RowClass -> String
$cshowList :: [RowClass] -> ShowS
showList :: [RowClass] -> ShowS
Show)
amountClass :: RowClass -> Ods.Class
amountClass :: RowClass -> Class
amountClass RowClass
rc =
Text -> Class
Ods.Class (Text -> Class) -> Text -> Class
forall a b. (a -> b) -> a -> b
$
case RowClass
rc of RowClass
Value -> Text
"amount"; RowClass
Total -> Text
"amount coltotal"
rowTotalClass :: RowClass -> Ods.Class
rowTotalClass :: RowClass -> Class
rowTotalClass RowClass
rc =
Text -> Class
Ods.Class (Text -> Class) -> Text -> Class
forall a b. (a -> b) -> a -> b
$
case RowClass
rc of RowClass
Value -> Text
"amount rowtotal"; RowClass
Total -> Text
"amount coltotal"
rowAverageClass :: RowClass -> Ods.Class
rowAverageClass :: RowClass -> Class
rowAverageClass RowClass
rc =
Text -> Class
Ods.Class (Text -> Class) -> Text -> Class
forall a b. (a -> b) -> a -> b
$
case RowClass
rc of RowClass
Value -> Text
"amount rowaverage"; RowClass
Total -> Text
"amount colaverage"
totalRowHeadingText :: Text
totalRowHeadingSpreadsheet :: Text
totalRowHeadingBudgetText :: Text
totalRowHeadingBudgetCsv :: Text
totalRowHeadingText :: Text
totalRowHeadingText = Text
""
totalRowHeadingSpreadsheet :: Text
totalRowHeadingSpreadsheet = Text
"Total:"
totalRowHeadingBudgetText :: Text
totalRowHeadingBudgetText = Text
""
totalRowHeadingBudgetCsv :: Text
totalRowHeadingBudgetCsv = Text
"Total:"
headerWithoutBorders :: [Ods.Cell () text] -> [Ods.Cell Ods.NumLines text]
= (Cell () text -> Cell NumLines text)
-> [Cell () text] -> [Cell NumLines text]
forall a b. (a -> b) -> [a] -> [b]
map (\Cell () text
c -> Cell () text
c {Ods.cellBorder = Ods.noBorder})
simpleDateSpanCell :: PeriodTitles -> DateSpan -> Ods.Cell Ods.NumLines Text
simpleDateSpanCell :: PeriodTitles -> DateSpan -> Cell NumLines Text
simpleDateSpanCell PeriodTitles
ph = Text -> Cell NumLines Text
forall border text. Lines border => text -> Cell border text
Ods.defaultCell (Text -> Cell NumLines Text)
-> (DateSpan -> Text) -> DateSpan -> Cell NumLines Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeriodTitles -> DateSpan -> Text
renderPeriodHeading PeriodTitles
ph
figuresLink :: ReportOpts -> Bool
figuresLink :: ReportOpts -> Bool
figuresLink ReportOpts
ropts = ReportOpts -> BalanceCalculation
balancecalc_ ReportOpts
ropts BalanceCalculation -> BalanceCalculation -> Bool
forall a. Eq a => a -> a -> Bool
== BalanceCalculation
CalcChange Bool -> Bool -> Bool
&& Bool -> Bool
not (ReportOpts -> Bool
percent_ ReportOpts
ropts)
reportLinkOpts :: ReportOpts -> [DateSpan] -> LinkOpts
reportLinkOpts :: ReportOpts -> [DateSpan] -> LinkOpts
reportLinkOpts ReportOpts
ropts [DateSpan]
colspans = LinkOpts {
loAccum :: BalanceAccumulation
loAccum = ReportOpts -> BalanceAccumulation
balanceaccum_ ReportOpts
ropts,
loSpan :: DateSpan
loSpan = [DateSpan] -> DateSpan
spansSpan [DateSpan]
colspans,
loDate2 :: Bool
loDate2 = ReportOpts -> Bool
date2_ ReportOpts
ropts,
loIncludesSubs :: Bool
loIncludesSubs = Bool
True,
loNegated :: Bool
loNegated = ReportOpts -> Maybe NormalSign
normalbalance_ ReportOpts
ropts Maybe NormalSign -> Maybe NormalSign -> Bool
forall a. Eq a => a -> a -> Bool
== NormalSign -> Maybe NormalSign
forall a. a -> Maybe a
Just NormalSign
NormallyNegative,
loValue :: Maybe Text
loValue = Maybe ConversionOp -> Maybe ValuationType -> Maybe Text
valueParam (ReportOpts -> Maybe ConversionOp
conversionop_ ReportOpts
ropts) (ReportOpts -> Maybe ValuationType
value_ ReportOpts
ropts)
}
rowLinkOpts :: ReportOpts -> [DateSpan] -> S.Set AccountName -> AccountName -> LinkOpts
rowLinkOpts :: ReportOpts -> [DateSpan] -> Set Text -> Text -> LinkOpts
rowLinkOpts ReportOpts
ropts [DateSpan]
colspans Set Text
shownParents Text
acct =
(ReportOpts -> [DateSpan] -> LinkOpts
reportLinkOpts ReportOpts
ropts [DateSpan]
colspans) {
loIncludesSubs = tree_ ropts || acct `S.notMember` shownParents
}
shownParentsOf :: [AccountName] -> S.Set AccountName
shownParentsOf :: [Text] -> Set Text
shownParentsOf = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
S.fromList ([Text] -> Set Text) -> ([Text] -> [Text]) -> [Text] -> Set Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> [Text]) -> [Text] -> [Text]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Text -> [Text]
parentAccountNames
addTotalBorders ::
(Functor f) =>
[f (Ods.Cell border text)] -> [f (Ods.Cell Ods.NumLines text)]
addTotalBorders :: forall (f :: * -> *) border text.
Functor f =>
[f (Cell border text)] -> [f (Cell NumLines text)]
addTotalBorders =
(NumLines -> f (Cell border text) -> f (Cell NumLines text))
-> [NumLines] -> [f (Cell border text)] -> [f (Cell NumLines text)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith
(\NumLines
border ->
(Cell border text -> Cell NumLines text)
-> f (Cell border text) -> f (Cell NumLines text)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Cell border text
c -> Cell border text
c {
Ods.cellStyle = Ods.Body Ods.Total,
Ods.cellBorder = Ods.noBorder {Ods.borderTop = border}}))
(NumLines
Ods.DoubleLine NumLines -> [NumLines] -> [NumLines]
forall a. a -> [a] -> [a]
: NumLines -> [NumLines]
forall a. a -> [a]
repeat NumLines
Ods.NoLine)
nbsp :: Text
nbsp :: Text
nbsp = Text
"\160"
renderBalanceAcct ::
ReportOpts -> Text -> (AccountName, AccountName, Int) -> Text
renderBalanceAcct :: ReportOpts -> Text -> (Text, Text, Int) -> Text
renderBalanceAcct ReportOpts
opts Text
space (Text
fullName, Text
displayName, Int
dep) =
if ReportOpts -> AccountListMode
accountlistmode_ ReportOpts
opts AccountListMode -> AccountListMode -> Bool
forall a. Eq a => a -> a -> Bool
== AccountListMode
ALTree Bool -> Bool -> Bool
&& Bool -> Bool
not (ReportOpts -> Bool
full_names_ ReportOpts
opts)
then Int -> Text -> Text
T.replicate (Int
depInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
2) Text
space Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
displayName
else Int -> Text -> Text
accountNameDrop (ReportOpts -> Int
drop_ ReportOpts
opts) Text
fullName
renderPeriodicAcct ::
ReportOpts -> Text -> PeriodicReportRow DisplayName a -> Text
renderPeriodicAcct :: forall a.
ReportOpts -> Text -> PeriodicReportRow DisplayName a -> Text
renderPeriodicAcct ReportOpts
opts Text
space PeriodicReportRow DisplayName a
row =
ReportOpts -> Text -> (Text, Text, Int) -> Text
renderBalanceAcct ReportOpts
opts Text
space
(PeriodicReportRow DisplayName a -> Text
forall a. PeriodicReportRow DisplayName a -> Text
prrFullName PeriodicReportRow DisplayName a
row, PeriodicReportRow DisplayName a -> Text
forall a. PeriodicReportRow DisplayName a -> Text
prrDisplayName PeriodicReportRow DisplayName a
row, PeriodicReportRow DisplayName a -> Int
forall a. PeriodicReportRow DisplayName a -> Int
prrIndent PeriodicReportRow DisplayName a
row)
multiBalanceHasTotalsColumn :: ReportOpts -> Bool
multiBalanceHasTotalsColumn :: ReportOpts -> Bool
multiBalanceHasTotalsColumn ReportOpts
ropts =
ReportOpts -> Bool
row_total_ ReportOpts
ropts Bool -> Bool -> Bool
&& ReportOpts -> BalanceAccumulation
balanceaccum_ ReportOpts
ropts BalanceAccumulation -> [BalanceAccumulation] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [BalanceAccumulation
Cumulative, BalanceAccumulation
Historical]
multiBalanceReportAsPartTable ::
ReportOpts -> [CommoditySymbol] -> MultiBalanceReport ->
Table T.Text T.Text WideBuilder
multiBalanceReportAsPartTable :: ReportOpts
-> [Text] -> MultiBalanceReport -> Table Text Text WideBuilder
multiBalanceReportAsPartTable
opts :: ReportOpts
opts@ReportOpts{Bool
summary_only_ :: Bool
summary_only_ :: ReportOpts -> Bool
summary_only_, Bool
average_ :: Bool
average_ :: ReportOpts -> Bool
average_}
[Text]
allCommodities
(PeriodicReport [DateSpan]
spans [PeriodicReportRow DisplayName MixedAmount]
items PeriodicReportRow () MixedAmount
tr) =
Table Text Text WideBuilder -> Table Text Text WideBuilder
forall {rh} {a}. Table rh rh a -> Table rh rh a
maybetranspose (Table Text Text WideBuilder -> Table Text Text WideBuilder)
-> Table Text Text WideBuilder -> Table Text Text WideBuilder
forall a b. (a -> b) -> a -> b
$
Table Text Text WideBuilder -> Table Text Text WideBuilder
forall {ch}. Table Text ch WideBuilder -> Table Text ch WideBuilder
addtotalrow (Table Text Text WideBuilder -> Table Text Text WideBuilder)
-> Table Text Text WideBuilder -> Table Text Text WideBuilder
forall a b. (a -> b) -> a -> b
$
Header Text
-> Header Text -> [[WideBuilder]] -> Table Text Text WideBuilder
forall rh ch a. Header rh -> Header ch -> [[a]] -> Table rh ch a
Table
(Properties -> [Header Text] -> Header Text
forall h. Properties -> [Header h] -> Header h
Group Properties
multiColumnTableInterRowBorder ([Header Text] -> Header Text) -> [Header Text] -> Header Text
forall a b. (a -> b) -> a -> b
$ (Text -> Header Text) -> [Text] -> [Header Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Header Text
forall h. h -> Header h
Header ([Text] -> [Header Text]) -> [Text] -> [Header Text]
forall a b. (a -> b) -> a -> b
$ [[Text]] -> [Text]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Text]]
accts)
(Properties -> [Header Text] -> Header Text
forall h. Properties -> [Header h] -> Header h
Group Properties
multiColumnTableInterColumnBorder ([Header Text] -> Header Text) -> [Header Text] -> Header Text
forall a b. (a -> b) -> a -> b
$ (Text -> Header Text) -> [Text] -> [Header Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Header Text
forall h. h -> Header h
Header [Text]
colheadings)
([[[WideBuilder]]] -> [[WideBuilder]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[[WideBuilder]]]
rows)
where
trc :: Text -> Text -> Text
trc = Translations -> Text -> Text -> Text
I18n.trc (ReportOpts -> Translations
translations_ ReportOpts
opts)
colheadings :: [Text]
colheadings =
[Text -> Text -> Text
trc Text
"column heading" Text
"Commodity" | ReportOpts -> Layout
layout_ ReportOpts
opts Layout -> Layout -> Bool
forall a. Eq a => a -> a -> Bool
== Layout
LayoutBare]
[Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
case ReportOpts -> Layout
layout_ ReportOpts
opts of
Layout
LayoutBareWide ->
(Text -> Text -> Text) -> [Text] -> [Text] -> [Text]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (\Text
s Text
c -> [Text] -> Text
T.concat [Text
s, Text
" (", Text
c, Text
")"])
[Text]
spanNames [Text]
allCommodities
Layout
_ -> [Text]
spanNames
spanNames :: [Text]
spanNames =
(Bool -> [()]
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
summary_only_) [()] -> [Text] -> [Text]
forall a b. [a] -> [b] -> [b]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
(DateSpan -> Text) -> [DateSpan] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (ReportOpts -> [DateSpan] -> DateSpan -> Text
reportPeriodName ReportOpts
opts [DateSpan]
spans) [DateSpan]
spans)
[Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text -> Text
trc Text
"column heading" Text
"Total" | ReportOpts -> Bool
multiBalanceHasTotalsColumn ReportOpts
opts]
[Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text -> Text -> Text
trc Text
"column heading" Text
"Average" | Bool
average_]
([[Text]]
accts, [[[WideBuilder]]]
rows) = [([Text], [[WideBuilder]])] -> ([[Text]], [[[WideBuilder]]])
forall a b. [(a, b)] -> ([a], [b])
unzip ([([Text], [[WideBuilder]])] -> ([[Text]], [[[WideBuilder]]]))
-> [([Text], [[WideBuilder]])] -> ([[Text]], [[[WideBuilder]]])
forall a b. (a -> b) -> a -> b
$ (PeriodicReportRow DisplayName MixedAmount
-> ([Text], [[WideBuilder]]))
-> [PeriodicReportRow DisplayName MixedAmount]
-> [([Text], [[WideBuilder]])]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PeriodicReportRow DisplayName MixedAmount
-> ([Text], [[WideBuilder]])
fullRowAsTexts [PeriodicReportRow DisplayName MixedAmount]
items'
where
isLeaf :: t (PeriodicReportRow DisplayName b)
-> PeriodicReportRow DisplayName b -> Bool
isLeaf t (PeriodicReportRow DisplayName b)
rs PeriodicReportRow DisplayName b
row = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (PeriodicReportRow DisplayName b -> Bool)
-> t (PeriodicReportRow DisplayName b) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\PeriodicReportRow DisplayName b
r -> Text -> Text -> Bool
T.isPrefixOf (DisplayName -> Text
displayFull (PeriodicReportRow DisplayName b -> DisplayName
forall a b. PeriodicReportRow a b -> a
prrName PeriodicReportRow DisplayName b
row) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":") (DisplayName -> Text
displayFull (PeriodicReportRow DisplayName b -> DisplayName
forall a b. PeriodicReportRow a b -> a
prrName PeriodicReportRow DisplayName b
r))) t (PeriodicReportRow DisplayName b)
rs
items' :: [PeriodicReportRow DisplayName MixedAmount]
items' = if ReportOpts -> Bool
transpose_ ReportOpts
opts Bool -> Bool -> Bool
&& ReportOpts -> Bool
tree_ ReportOpts
opts
then (PeriodicReportRow DisplayName MixedAmount -> Bool)
-> [PeriodicReportRow DisplayName MixedAmount]
-> [PeriodicReportRow DisplayName MixedAmount]
forall a. (a -> Bool) -> [a] -> [a]
filter ([PeriodicReportRow DisplayName MixedAmount]
-> PeriodicReportRow DisplayName MixedAmount -> Bool
forall {t :: * -> *} {b} {b}.
Foldable t =>
t (PeriodicReportRow DisplayName b)
-> PeriodicReportRow DisplayName b -> Bool
isLeaf [PeriodicReportRow DisplayName MixedAmount]
items) [PeriodicReportRow DisplayName MixedAmount]
items
else [PeriodicReportRow DisplayName MixedAmount]
items
fullRowAsTexts :: PeriodicReportRow DisplayName MixedAmount
-> ([Text], [[WideBuilder]])
fullRowAsTexts PeriodicReportRow DisplayName MixedAmount
row = (Int -> Text -> [Text]
forall a. Int -> a -> [a]
replicate ([[WideBuilder]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[WideBuilder]]
rs) (PeriodicReportRow DisplayName MixedAmount -> Text
forall a. PeriodicReportRow DisplayName a -> Text
renderacct PeriodicReportRow DisplayName MixedAmount
row), [[WideBuilder]]
rs)
where
rs :: [[WideBuilder]]
rs = ReportOpts
-> [Text]
-> PeriodicReportRow DisplayName MixedAmount
-> [[WideBuilder]]
forall a.
ReportOpts
-> [Text] -> PeriodicReportRow a MixedAmount -> [[WideBuilder]]
multiBalanceRowAsText ReportOpts
opts [Text]
allCommodities PeriodicReportRow DisplayName MixedAmount
row
renderacct :: PeriodicReportRow DisplayName a -> Text
renderacct PeriodicReportRow DisplayName a
row' = ReportOpts -> Text -> PeriodicReportRow DisplayName a -> Text
forall a.
ReportOpts -> Text -> PeriodicReportRow DisplayName a -> Text
renderPeriodicAcct ReportOpts
opts Text
" " PeriodicReportRow DisplayName a
row'
addtotalrow :: Table Text ch WideBuilder -> Table Text ch WideBuilder
addtotalrow
| ReportOpts -> Bool
no_total_ ReportOpts
opts = Table Text ch WideBuilder -> Table Text ch WideBuilder
forall a. a -> a
id
| Bool
otherwise =
let totalrows :: [[WideBuilder]]
totalrows = ReportOpts
-> [Text] -> PeriodicReportRow () MixedAmount -> [[WideBuilder]]
forall a.
ReportOpts
-> [Text] -> PeriodicReportRow a MixedAmount -> [[WideBuilder]]
multiBalanceRowAsText ReportOpts
opts [Text]
allCommodities PeriodicReportRow () MixedAmount
tr
rowhdrs :: Header Text
rowhdrs = Properties -> [Header Text] -> Header Text
forall h. Properties -> [Header h] -> Header h
Group Properties
NoLine ([Header Text] -> Header Text) -> [Header Text] -> Header Text
forall a b. (a -> b) -> a -> b
$ (Text -> Header Text) -> [Text] -> [Header Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Header Text
forall h. h -> Header h
Header ([Text] -> [Header Text]) -> [Text] -> [Header Text]
forall a b. (a -> b) -> a -> b
$ Text
totalRowHeadingText Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: Int -> Text -> [Text]
forall a. Int -> a -> [a]
replicate ([[WideBuilder]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[WideBuilder]]
totalrows Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Text
""
colhdrs :: Header [a]
colhdrs = [a] -> Header [a]
forall h. h -> Header h
Header []
in ((Table Text ch WideBuilder
-> Table Text [ZonkAny 0] WideBuilder -> Table Text ch WideBuilder)
-> Table Text [ZonkAny 0] WideBuilder
-> Table Text ch WideBuilder
-> Table Text ch WideBuilder
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Properties
-> Table Text ch WideBuilder
-> Table Text [ZonkAny 0] WideBuilder
-> Table Text ch WideBuilder
forall rh ch a ch2.
Properties -> Table rh ch a -> Table rh ch2 a -> Table rh ch a
concatTables Properties
SingleLine) (Table Text [ZonkAny 0] WideBuilder
-> Table Text ch WideBuilder -> Table Text ch WideBuilder)
-> Table Text [ZonkAny 0] WideBuilder
-> Table Text ch WideBuilder
-> Table Text ch WideBuilder
forall a b. (a -> b) -> a -> b
$ Header Text
-> Header [ZonkAny 0]
-> [[WideBuilder]]
-> Table Text [ZonkAny 0] WideBuilder
forall rh ch a. Header rh -> Header ch -> [[a]] -> Table rh ch a
Table Header Text
rowhdrs Header [ZonkAny 0]
forall {a}. Header [a]
colhdrs [[WideBuilder]]
totalrows)
maybetranspose :: Table rh rh a -> Table rh rh a
maybetranspose | ReportOpts -> Bool
transpose_ ReportOpts
opts = \(Table Header rh
rh Header rh
ch [[a]]
vals) -> Header rh -> Header rh -> [[a]] -> Table rh rh a
forall rh ch a. Header rh -> Header ch -> [[a]] -> Table rh ch a
Table Header rh
ch Header rh
rh ([[a]] -> [[a]]
forall a. [[a]] -> [[a]]
transpose [[a]]
vals)
| Bool
otherwise = Table rh rh a -> Table rh rh a
forall a. a -> a
id
multiColumnTableInterRowBorder :: Properties
multiColumnTableInterRowBorder = Properties
NoLine
multiColumnTableInterColumnBorder :: Properties
multiColumnTableInterColumnBorder = if ReportOpts -> Bool
pretty_ ReportOpts
opts then Properties
SingleLine else Properties
NoLine
multiBalanceRowAsText ::
ReportOpts -> [CommoditySymbol] -> PeriodicReportRow a MixedAmount -> [[WideBuilder]]
multiBalanceRowAsText :: forall a.
ReportOpts
-> [Text] -> PeriodicReportRow a MixedAmount -> [[WideBuilder]]
multiBalanceRowAsText ReportOpts
opts [Text]
allCommodities =
[[Cell NumLines WideBuilder]] -> [[WideBuilder]]
forall (f :: * -> *) border text.
Functor f =>
[f (Cell border text)] -> [f text]
rawTableContent ([[Cell NumLines WideBuilder]] -> [[WideBuilder]])
-> (PeriodicReportRow a MixedAmount
-> [[Cell NumLines WideBuilder]])
-> PeriodicReportRow a MixedAmount
-> [[WideBuilder]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
AmountFormat
-> ReportOpts
-> [DateSpan]
-> [Text]
-> RowClass
-> (DateSpan -> Cell NumLines Text)
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines WideBuilder]]
forall a.
AmountFormat
-> ReportOpts
-> [DateSpan]
-> [Text]
-> RowClass
-> (DateSpan -> Cell NumLines Text)
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines WideBuilder]]
multiBalanceRowAsCellBuilders AmountFormat
oneLineNoCostFmt{displayColour=color_ opts}
ReportOpts
opts [] [Text]
allCommodities
RowClass
Value (PeriodTitles -> DateSpan -> Cell NumLines Text
simpleDateSpanCell (PeriodTitles -> DateSpan -> Cell NumLines Text)
-> PeriodTitles -> DateSpan -> Cell NumLines Text
forall a b. (a -> b) -> a -> b
$ ReportOpts -> PeriodTitles
period_titles_ ReportOpts
opts)
multiBalanceRowAsCellBuilders ::
AmountFormat -> ReportOpts -> [DateSpan] -> [CommoditySymbol] ->
RowClass -> (DateSpan -> Ods.Cell Ods.NumLines Text) ->
PeriodicReportRow a MixedAmount ->
[[Ods.Cell Ods.NumLines WideBuilder]]
multiBalanceRowAsCellBuilders :: forall a.
AmountFormat
-> ReportOpts
-> [DateSpan]
-> [Text]
-> RowClass
-> (DateSpan -> Cell NumLines Text)
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines WideBuilder]]
multiBalanceRowAsCellBuilders AmountFormat
bopts ropts :: ReportOpts
ropts@ReportOpts{Bool
Int
[Text]
[Status]
SortSpec
Maybe Int
Maybe Text
Maybe NormalSign
Maybe ConversionOp
Maybe ValuationType
Interval
Period
DepthSpec
AccountListMode
BalanceAccumulation
BalanceCalculation
Layout
PeriodTitles
Translations
StringFormat
accountlistmode_ :: ReportOpts -> AccountListMode
balancecalc_ :: ReportOpts -> BalanceCalculation
percent_ :: ReportOpts -> Bool
balanceaccum_ :: ReportOpts -> BalanceAccumulation
date2_ :: ReportOpts -> Bool
normalbalance_ :: ReportOpts -> Maybe NormalSign
conversionop_ :: ReportOpts -> Maybe ConversionOp
value_ :: ReportOpts -> Maybe ValuationType
full_names_ :: ReportOpts -> Bool
drop_ :: ReportOpts -> Int
row_total_ :: ReportOpts -> Bool
summary_only_ :: ReportOpts -> Bool
average_ :: ReportOpts -> Bool
translations_ :: ReportOpts -> Translations
layout_ :: ReportOpts -> Layout
transpose_ :: ReportOpts -> Bool
no_total_ :: ReportOpts -> Bool
pretty_ :: ReportOpts -> Bool
color_ :: ReportOpts -> Bool
period_titles_ :: ReportOpts -> PeriodTitles
period_ :: Period
interval_ :: Interval
statuses_ :: [Status]
conversionop_ :: Maybe ConversionOp
value_ :: Maybe ValuationType
infer_prices_ :: Bool
depth_ :: DepthSpec
fold_depth_ :: Maybe Int
no_elide_ :: Bool
date2_ :: Bool
empty_ :: Bool
full_names_ :: Bool
real_ :: Bool
format_ :: StringFormat
balance_base_url_ :: Maybe Text
pretty_ :: Bool
querystring_ :: [Text]
average_ :: Bool
related_ :: Bool
sortspec_ :: SortSpec
txn_dates_ :: Bool
balancecalc_ :: BalanceCalculation
balanceaccum_ :: BalanceAccumulation
budgetpat_ :: Maybe Text
accountlistmode_ :: AccountListMode
drop_ :: Int
declared_ :: Bool
row_total_ :: Bool
no_total_ :: Bool
summary_only_ :: Bool
show_costs_ :: Bool
sort_amount_ :: Bool
percent_ :: Bool
invert_ :: Bool
normalbalance_ :: Maybe NormalSign
color_ :: Bool
transpose_ :: Bool
layout_ :: Layout
period_titles_ :: PeriodTitles
title_ :: Maybe Text
subreport_titles_ :: Maybe Text
translations_ :: Translations
balance_base_url_ :: ReportOpts -> Maybe Text
budgetpat_ :: ReportOpts -> Maybe Text
declared_ :: ReportOpts -> Bool
depth_ :: ReportOpts -> DepthSpec
empty_ :: ReportOpts -> Bool
fold_depth_ :: ReportOpts -> Maybe Int
format_ :: ReportOpts -> StringFormat
infer_prices_ :: ReportOpts -> Bool
interval_ :: ReportOpts -> Interval
invert_ :: ReportOpts -> Bool
no_elide_ :: ReportOpts -> Bool
period_ :: ReportOpts -> Period
querystring_ :: ReportOpts -> [Text]
real_ :: ReportOpts -> Bool
related_ :: ReportOpts -> Bool
show_costs_ :: ReportOpts -> Bool
sort_amount_ :: ReportOpts -> Bool
sortspec_ :: ReportOpts -> SortSpec
statuses_ :: ReportOpts -> [Status]
subreport_titles_ :: ReportOpts -> Maybe Text
title_ :: ReportOpts -> Maybe Text
txn_dates_ :: ReportOpts -> Bool
..} [DateSpan]
colspans [Text]
allCommodities
RowClass
rc DateSpan -> Cell NumLines Text
renderDateSpanCell (PeriodicReportRow a
_acct [MixedAmount]
as MixedAmount
rowtot MixedAmount
rowavg) =
case Layout
layout_ of
LayoutWide Maybe Int
width ->
[((Maybe DateSpan, (Class, MixedAmount))
-> Cell NumLines WideBuilder -> Cell NumLines WideBuilder)
-> [(Maybe DateSpan, (Class, MixedAmount))]
-> [Cell NumLines WideBuilder]
-> [Cell NumLines WideBuilder]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (Maybe DateSpan, (Class, MixedAmount))
-> Cell NumLines WideBuilder -> Cell NumLines WideBuilder
forall {a} {border} {text}.
(Maybe DateSpan, (a, MixedAmount))
-> Cell border text -> Cell border text
linkFigure [(Maybe DateSpan, (Class, MixedAmount))]
spanclsamts ([Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder])
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder]
forall a b. (a -> b) -> a -> b
$
((Class, MixedAmount) -> Cell NumLines WideBuilder)
-> [(Class, MixedAmount)] -> [Cell NumLines WideBuilder]
forall a b. (a -> b) -> [a] -> [b]
map (AmountFormat -> (Class, MixedAmount) -> Cell NumLines WideBuilder
forall border.
Lines border =>
AmountFormat -> (Class, MixedAmount) -> Cell border WideBuilder
cellFromMixedAmount AmountFormat
bopts{displayMaxWidth=width}) [(Class, MixedAmount)]
clsamts]
Layout
LayoutTall -> Cell NumLines WideBuilder
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]]
forall a. a -> [[a]] -> [[a]]
paddedTranspose Cell NumLines WideBuilder
forall border text. (Lines border, Monoid text) => Cell border text
Ods.emptyCell
([[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]])
-> ([(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]])
-> [(Class, MixedAmount)]
-> [[Cell NumLines WideBuilder]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Class, MixedAmount) -> [Cell NumLines WideBuilder])
-> [(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]]
forall a b. (a -> b) -> [a] -> [b]
map (AmountFormat -> (Class, MixedAmount) -> [Cell NumLines WideBuilder]
forall border.
Lines border =>
AmountFormat -> (Class, MixedAmount) -> [Cell border WideBuilder]
cellsFromMixedAmount AmountFormat
bopts{displayMaxWidth=Nothing})
([(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]])
-> [(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]]
forall a b. (a -> b) -> a -> b
$ [(Class, MixedAmount)]
clsamts
Layout
LayoutBare -> (Cell NumLines WideBuilder
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder])
-> [Cell NumLines WideBuilder]
-> [[Cell NumLines WideBuilder]]
-> [[Cell NumLines WideBuilder]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (:) ((Text -> Cell NumLines WideBuilder)
-> [Text] -> [Cell NumLines WideBuilder]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Cell NumLines WideBuilder
wbCell [Text]
cs)
([[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]])
-> ([(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]])
-> [(Class, MixedAmount)]
-> [[Cell NumLines WideBuilder]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]]
forall a. [[a]] -> [[a]]
transpose
([[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]])
-> ([(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]])
-> [(Class, MixedAmount)]
-> [[Cell NumLines WideBuilder]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Class, MixedAmount) -> [Cell NumLines WideBuilder])
-> [(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]]
forall a b. (a -> b) -> [a] -> [b]
map (AmountFormat -> (Class, MixedAmount) -> [Cell NumLines WideBuilder]
forall border.
Lines border =>
AmountFormat -> (Class, MixedAmount) -> [Cell border WideBuilder]
cellsFromMixedAmount ([Text] -> AmountFormat -> AmountFormat
setDisplayCommodityBare [Text]
cs AmountFormat
bopts))
([(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]])
-> [(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]]
forall a b. (a -> b) -> a -> b
$ [(Class, MixedAmount)]
clsamts
Layout
LayoutBareWide -> [((Class, MixedAmount) -> [Cell NumLines WideBuilder])
-> [(Class, MixedAmount)] -> [Cell NumLines WideBuilder]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (AmountFormat -> (Class, MixedAmount) -> [Cell NumLines WideBuilder]
forall border.
Lines border =>
AmountFormat -> (Class, MixedAmount) -> [Cell border WideBuilder]
cellsFromMixedAmount ([Text] -> AmountFormat -> AmountFormat
setDisplayCommodityBare [Text]
allCommodities AmountFormat
bopts))
([(Class, MixedAmount)] -> [Cell NumLines WideBuilder])
-> [(Class, MixedAmount)] -> [Cell NumLines WideBuilder]
forall a b. (a -> b) -> a -> b
$ [(Class, MixedAmount)]
clsamts]
Layout
LayoutTidy -> [[[Cell NumLines WideBuilder]]] -> [[Cell NumLines WideBuilder]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
([[[Cell NumLines WideBuilder]]] -> [[Cell NumLines WideBuilder]])
-> ([(Class, MixedAmount)] -> [[[Cell NumLines WideBuilder]]])
-> [(Class, MixedAmount)]
-> [[Cell NumLines WideBuilder]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DateSpan
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]])
-> [DateSpan]
-> [[[Cell NumLines WideBuilder]]]
-> [[[Cell NumLines WideBuilder]]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (([Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder])
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]]
forall a b. (a -> b) -> [a] -> [b]
map (([Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder])
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines WideBuilder]])
-> (DateSpan
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder])
-> DateSpan
-> [[Cell NumLines WideBuilder]]
-> [[Cell NumLines WideBuilder]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DateSpan
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder]
addDateColumns) [DateSpan]
colspans
([[[Cell NumLines WideBuilder]]]
-> [[[Cell NumLines WideBuilder]]])
-> ([(Class, MixedAmount)] -> [[[Cell NumLines WideBuilder]]])
-> [(Class, MixedAmount)]
-> [[[Cell NumLines WideBuilder]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Class, MixedAmount) -> [[Cell NumLines WideBuilder]])
-> [(Class, MixedAmount)] -> [[[Cell NumLines WideBuilder]]]
forall a b. (a -> b) -> [a] -> [b]
map ( (Text -> Cell NumLines WideBuilder -> [Cell NumLines WideBuilder])
-> [Text]
-> [Cell NumLines WideBuilder]
-> [[Cell NumLines WideBuilder]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Text
c Cell NumLines WideBuilder
a -> [Text -> Cell NumLines WideBuilder
wbCell Text
c, Cell NumLines WideBuilder
a]) [Text]
cs
([Cell NumLines WideBuilder] -> [[Cell NumLines WideBuilder]])
-> ((Class, MixedAmount) -> [Cell NumLines WideBuilder])
-> (Class, MixedAmount)
-> [[Cell NumLines WideBuilder]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AmountFormat -> (Class, MixedAmount) -> [Cell NumLines WideBuilder]
forall border.
Lines border =>
AmountFormat -> (Class, MixedAmount) -> [Cell border WideBuilder]
cellsFromMixedAmount ([Text] -> AmountFormat -> AmountFormat
setDisplayCommodityBare [Text]
cs AmountFormat
bopts))
([(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]])
-> [(Class, MixedAmount)] -> [[Cell NumLines WideBuilder]]
forall a b. (a -> b) -> a -> b
$ [(Class, MixedAmount)]
classified
where
wbCell :: Text -> Cell NumLines WideBuilder
wbCell = WideBuilder -> Cell NumLines WideBuilder
forall border text. Lines border => text -> Cell border text
Ods.defaultCell (WideBuilder -> Cell NumLines WideBuilder)
-> (Text -> WideBuilder) -> Text -> Cell NumLines WideBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> WideBuilder
wbFromText
wbDate :: Text -> Cell NumLines WideBuilder
wbDate Text
content = (Text -> Cell NumLines WideBuilder
wbCell Text
content) {Ods.cellType = Ods.TypeDate}
cs :: [Text]
cs = if (MixedAmount -> Bool) -> [MixedAmount] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all MixedAmount -> Bool
mixedAmountLooksZero [MixedAmount]
allamts then [Text
""] else Set Text -> [Text]
forall a. Set a -> [a]
S.toList (Set Text -> [Text]) -> Set Text -> [Text]
forall a b. (a -> b) -> a -> b
$ (MixedAmount -> Set Text) -> [MixedAmount] -> Set Text
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap MixedAmount -> Set Text
maCommodities [MixedAmount]
allamts
classified :: [(Class, MixedAmount)]
classified = (MixedAmount -> (Class, MixedAmount))
-> [MixedAmount] -> [(Class, MixedAmount)]
forall a b. (a -> b) -> [a] -> [b]
map ((,) (RowClass -> Class
amountClass RowClass
rc)) [MixedAmount]
as
allamts :: [MixedAmount]
allamts = ((Class, MixedAmount) -> MixedAmount)
-> [(Class, MixedAmount)] -> [MixedAmount]
forall a b. (a -> b) -> [a] -> [b]
map (Class, MixedAmount) -> MixedAmount
forall a b. (a, b) -> b
snd [(Class, MixedAmount)]
clsamts
clsamts :: [(Class, MixedAmount)]
clsamts = ((Maybe DateSpan, (Class, MixedAmount)) -> (Class, MixedAmount))
-> [(Maybe DateSpan, (Class, MixedAmount))]
-> [(Class, MixedAmount)]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe DateSpan, (Class, MixedAmount)) -> (Class, MixedAmount)
forall a b. (a, b) -> b
snd [(Maybe DateSpan, (Class, MixedAmount))]
spanclsamts
spanclsamts :: [(Maybe DateSpan, (Class, MixedAmount))]
spanclsamts =
(if Bool -> Bool
not Bool
summary_only_ then [Maybe DateSpan]
-> [(Class, MixedAmount)]
-> [(Maybe DateSpan, (Class, MixedAmount))]
forall a b. [a] -> [b] -> [(a, b)]
zip ((DateSpan -> Maybe DateSpan) -> [DateSpan] -> [Maybe DateSpan]
forall a b. (a -> b) -> [a] -> [b]
map DateSpan -> Maybe DateSpan
forall a. a -> Maybe a
Just [DateSpan]
colspans [Maybe DateSpan] -> [Maybe DateSpan] -> [Maybe DateSpan]
forall a. [a] -> [a] -> [a]
++ Maybe DateSpan -> [Maybe DateSpan]
forall a. a -> [a]
repeat Maybe DateSpan
forall a. Maybe a
Nothing) [(Class, MixedAmount)]
classified else []) [(Maybe DateSpan, (Class, MixedAmount))]
-> [(Maybe DateSpan, (Class, MixedAmount))]
-> [(Maybe DateSpan, (Class, MixedAmount))]
forall a. [a] -> [a] -> [a]
++
[(DateSpan -> Maybe DateSpan
forall a. a -> Maybe a
Just ([DateSpan] -> DateSpan
spansSpan [DateSpan]
colspans) Maybe DateSpan -> Maybe () -> Maybe DateSpan
forall a b. Maybe a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [DateSpan] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DateSpan]
colspans), (RowClass -> Class
rowTotalClass RowClass
rc, MixedAmount
rowtot)) |
ReportOpts -> Bool
multiBalanceHasTotalsColumn ReportOpts
ropts Bool -> Bool -> Bool
&& Bool -> Bool
not ([MixedAmount] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [MixedAmount]
as)] [(Maybe DateSpan, (Class, MixedAmount))]
-> [(Maybe DateSpan, (Class, MixedAmount))]
-> [(Maybe DateSpan, (Class, MixedAmount))]
forall a. [a] -> [a] -> [a]
++
[(Maybe DateSpan
forall a. Maybe a
Nothing, (RowClass -> Class
rowAverageClass RowClass
rc, MixedAmount
rowavg)) | Bool
average_ Bool -> Bool -> Bool
&& Bool -> Bool
not ([MixedAmount] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [MixedAmount]
as)]
linkFigure :: (Maybe DateSpan, (a, MixedAmount))
-> Cell border text -> Cell border text
linkFigure (Just DateSpan
spn, (a
_, MixedAmount
amt)) Cell border text
c
| ReportOpts -> Bool
figuresLink ReportOpts
ropts Bool -> Bool -> Bool
&& Bool -> Bool
not (MixedAmount -> Bool
mixedAmountLooksZero MixedAmount
amt) =
let dsCell :: Cell NumLines Text
dsCell = DateSpan -> Cell NumLines Text
renderDateSpanCell DateSpan
spn in
Text -> Text -> Cell border text -> Cell border text
forall border text.
Text -> Text -> Cell border text -> Cell border text
withLink (Cell NumLines Text -> Text
forall border text. Cell border text -> Text
Ods.cellAnchor Cell NumLines Text
dsCell)
(if RowClass
rc RowClass -> RowClass -> Bool
forall a. Eq a => a -> a -> Bool
== RowClass
Total then Cell NumLines Text -> Text
forall border text. Cell border text -> Text
Ods.cellTitle Cell NumLines Text
dsCell
else LinkOpts -> Bool -> Text
amountPhrase (ReportOpts -> [DateSpan] -> LinkOpts
reportLinkOpts ReportOpts
ropts [DateSpan]
colspans) Bool
False) Cell border text
c
linkFigure (Maybe DateSpan, (a, MixedAmount))
_ Cell border text
c = Cell border text
c
addDateColumns :: DateSpan
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder]
addDateColumns spn :: DateSpan
spn@(DateSpan Maybe EFDay
s Maybe EFDay
e) [Cell NumLines WideBuilder]
remCols =
(Text -> WideBuilder
wbFromText (Text -> WideBuilder)
-> Cell NumLines Text -> Cell NumLines WideBuilder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DateSpan -> Cell NumLines Text
renderDateSpanCell DateSpan
spn) Cell NumLines WideBuilder
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder]
forall a. a -> [a] -> [a]
:
Text -> Cell NumLines WideBuilder
wbDate (Text -> (EFDay -> Text) -> Maybe EFDay -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" EFDay -> Text
showEFDate Maybe EFDay
s) Cell NumLines WideBuilder
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder]
forall a. a -> [a] -> [a]
:
Text -> Cell NumLines WideBuilder
wbDate (Text -> (EFDay -> Text) -> Maybe EFDay -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (EFDay -> Text
showEFDate (EFDay -> Text) -> (EFDay -> EFDay) -> EFDay -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Day -> Day) -> EFDay -> EFDay
modifyEFDay (Integer -> Day -> Day
addDays (-Integer
1))) Maybe EFDay
e) Cell NumLines WideBuilder
-> [Cell NumLines WideBuilder] -> [Cell NumLines WideBuilder]
forall a. a -> [a] -> [a]
:
[Cell NumLines WideBuilder]
remCols
paddedTranspose :: a -> [[a]] -> [[a]]
paddedTranspose :: forall a. a -> [[a]] -> [[a]]
paddedTranspose a
_ [] = [[]]
paddedTranspose a
n [[a]]
as1 = Int -> [[a]] -> [[a]]
forall a. Int -> [a] -> [a]
take ([Int] -> Int
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([Int] -> Int) -> ([[a]] -> [Int]) -> [[a]] -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> Int) -> [[a]] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([[a]] -> Int) -> [[a]] -> Int
forall a b. (a -> b) -> a -> b
$ [[a]]
as1) ([[a]] -> [[a]]) -> ([[a]] -> [[a]]) -> [[a]] -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[a]] -> [[a]]
trans ([[a]] -> [[a]]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> a -> b
$ [[a]]
as1
where
trans :: [[a]] -> [[a]]
trans ([] : [[a]]
xss) = (a
n a -> [a] -> [a]
forall a. a -> [a] -> [a]
: ([a] -> a) -> [[a]] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> a
h [[a]]
xss) [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]] -> [[a]]
trans ([a
n] [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: ([a] -> [a]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> [a]
t [[a]]
xss)
trans ((a
x : [a]
xs) : [[a]]
xss) = (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: ([a] -> a) -> [[a]] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> a
h [[a]]
xss) [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]] -> [[a]]
trans ([a] -> [a]
m [a]
xs [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: ([a] -> [a]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> [a]
t [[a]]
xss)
trans [] = []
h :: [a] -> a
h (a
x:[a]
_) = a
x
h [] = a
n
t :: [a] -> [a]
t (a
_:[a]
xs) = [a]
xs
t [] = [a
n]
m :: [a] -> [a]
m (a
x:[a]
xs) = a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
xs
m [] = [a
n]
balanceSubReportAsSpreadsheetParts ::
AmountFormat -> ReportOpts ->
[CommoditySymbol] -> MultiBalanceReport ->
([[Ods.Cell Ods.NumLines Text]],
[[Ods.Cell Ods.NumLines Text]],
[[Ods.Cell Ods.NumLines Text]])
balanceSubReportAsSpreadsheetParts :: AmountFormat
-> ReportOpts
-> [Text]
-> MultiBalanceReport
-> ([[Cell NumLines Text]], [[Cell NumLines Text]],
[[Cell NumLines Text]])
balanceSubReportAsSpreadsheetParts AmountFormat
fmt opts :: ReportOpts
opts@ReportOpts{Bool
Int
[Text]
[Status]
SortSpec
Maybe Int
Maybe Text
Maybe NormalSign
Maybe ConversionOp
Maybe ValuationType
Interval
Period
DepthSpec
AccountListMode
BalanceAccumulation
BalanceCalculation
Layout
PeriodTitles
Translations
StringFormat
accountlistmode_ :: ReportOpts -> AccountListMode
balancecalc_ :: ReportOpts -> BalanceCalculation
percent_ :: ReportOpts -> Bool
balanceaccum_ :: ReportOpts -> BalanceAccumulation
date2_ :: ReportOpts -> Bool
normalbalance_ :: ReportOpts -> Maybe NormalSign
conversionop_ :: ReportOpts -> Maybe ConversionOp
value_ :: ReportOpts -> Maybe ValuationType
full_names_ :: ReportOpts -> Bool
drop_ :: ReportOpts -> Int
row_total_ :: ReportOpts -> Bool
summary_only_ :: ReportOpts -> Bool
average_ :: ReportOpts -> Bool
translations_ :: ReportOpts -> Translations
layout_ :: ReportOpts -> Layout
transpose_ :: ReportOpts -> Bool
no_total_ :: ReportOpts -> Bool
pretty_ :: ReportOpts -> Bool
color_ :: ReportOpts -> Bool
period_titles_ :: ReportOpts -> PeriodTitles
balance_base_url_ :: ReportOpts -> Maybe Text
budgetpat_ :: ReportOpts -> Maybe Text
declared_ :: ReportOpts -> Bool
depth_ :: ReportOpts -> DepthSpec
empty_ :: ReportOpts -> Bool
fold_depth_ :: ReportOpts -> Maybe Int
format_ :: ReportOpts -> StringFormat
infer_prices_ :: ReportOpts -> Bool
interval_ :: ReportOpts -> Interval
invert_ :: ReportOpts -> Bool
no_elide_ :: ReportOpts -> Bool
period_ :: ReportOpts -> Period
querystring_ :: ReportOpts -> [Text]
real_ :: ReportOpts -> Bool
related_ :: ReportOpts -> Bool
show_costs_ :: ReportOpts -> Bool
sort_amount_ :: ReportOpts -> Bool
sortspec_ :: ReportOpts -> SortSpec
statuses_ :: ReportOpts -> [Status]
subreport_titles_ :: ReportOpts -> Maybe Text
title_ :: ReportOpts -> Maybe Text
txn_dates_ :: ReportOpts -> Bool
period_ :: Period
interval_ :: Interval
statuses_ :: [Status]
conversionop_ :: Maybe ConversionOp
value_ :: Maybe ValuationType
infer_prices_ :: Bool
depth_ :: DepthSpec
fold_depth_ :: Maybe Int
no_elide_ :: Bool
date2_ :: Bool
empty_ :: Bool
full_names_ :: Bool
real_ :: Bool
format_ :: StringFormat
balance_base_url_ :: Maybe Text
pretty_ :: Bool
querystring_ :: [Text]
average_ :: Bool
related_ :: Bool
sortspec_ :: SortSpec
txn_dates_ :: Bool
balancecalc_ :: BalanceCalculation
balanceaccum_ :: BalanceAccumulation
budgetpat_ :: Maybe Text
accountlistmode_ :: AccountListMode
drop_ :: Int
declared_ :: Bool
row_total_ :: Bool
no_total_ :: Bool
summary_only_ :: Bool
show_costs_ :: Bool
sort_amount_ :: Bool
percent_ :: Bool
invert_ :: Bool
normalbalance_ :: Maybe NormalSign
color_ :: Bool
transpose_ :: Bool
layout_ :: Layout
period_titles_ :: PeriodTitles
title_ :: Maybe Text
subreport_titles_ :: Maybe Text
translations_ :: Translations
..}
[Text]
allCommodities (PeriodicReport [DateSpan]
colspans [PeriodicReportRow DisplayName MixedAmount]
items PeriodicReportRow () MixedAmount
tr) =
([[Cell NumLines Text]]
allHeaders, (PeriodicReportRow DisplayName MixedAmount
-> [[Cell NumLines Text]])
-> [PeriodicReportRow DisplayName MixedAmount]
-> [[Cell NumLines Text]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PeriodicReportRow DisplayName MixedAmount -> [[Cell NumLines Text]]
fullRowAsTexts [PeriodicReportRow DisplayName MixedAmount]
items, [[Cell NumLines Text]]
totalrows)
where
accountCell :: text -> Cell border text
accountCell text
label = (text -> Cell border text
forall border text. Lines border => text -> Cell border text
Ods.defaultCell text
label) {Ods.cellClass = accountClass}
hCell :: Class -> Text -> Cell border Text
hCell Class
cls Text
label = (Text -> Cell border Text
forall borders. Lines borders => Text -> Cell borders Text
headerCell Text
label) {Ods.cellClass = cls}
allHeaders :: [[Cell NumLines Text]]
allHeaders =
case Layout
layout_ of
Layout
LayoutBareWide ->
[[Cell () Text] -> [Cell NumLines Text]
forall text. [Cell () text] -> [Cell NumLines text]
headerWithoutBorders ([Cell () Text] -> [Cell NumLines Text])
-> [Cell () Text] -> [Cell NumLines Text]
forall a b. (a -> b) -> a -> b
$
Cell () Text
forall border text. (Lines border, Monoid text) => Cell border text
Ods.emptyCell Cell () Text -> [Cell () Text] -> [Cell () Text]
forall a. a -> [a] -> [a]
:
(Cell () Text -> [Cell () Text])
-> [Cell () Text] -> [Cell () Text]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ([Text] -> Cell () Text -> [Cell () Text]
forall border text a.
(Lines border, Monoid text) =>
[a] -> Cell border text -> [Cell border text]
Ods.horizontalSpan [Text]
allCommodities) [Cell () Text]
dateHeaders,
[Cell NumLines Text]
headers]
Layout
_ -> [[Cell NumLines Text]
headers]
headers :: [Cell NumLines Text]
headers =
[Cell () Text] -> [Cell NumLines Text]
forall (f :: * -> *) text.
Functor f =>
f (Cell () text) -> f (Cell NumLines text)
addHeaderBorders ([Cell () Text] -> [Cell NumLines Text])
-> [Cell () Text] -> [Cell NumLines Text]
forall a b. (a -> b) -> a -> b
$
Class -> Text -> Cell () Text
forall {border}. Lines border => Class -> Text -> Cell border Text
hCell Class
accountClass Text
"account" Cell () Text -> [Cell () Text] -> [Cell () Text]
forall a. a -> [a] -> [a]
:
case Layout
layout_ of
Layout
LayoutTidy -> (Text -> Cell () Text) -> [Text] -> [Cell () Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Cell () Text
forall borders. Lines borders => Text -> Cell borders Text
headerCell [Text]
tidyColumnLabels
Layout
LayoutBareWide -> [Cell () Text]
dateHeaders [Cell () Text] -> [Cell () Text] -> [Cell () Text]
forall a b. [a] -> [b] -> [b]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Text -> Cell () Text) -> [Text] -> [Cell () Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Cell () Text
forall borders. Lines borders => Text -> Cell borders Text
headerCell [Text]
allCommodities
Layout
LayoutBare -> Text -> Cell () Text
forall borders. Lines borders => Text -> Cell borders Text
headerCell Text
"commodity" Cell () Text -> [Cell () Text] -> [Cell () Text]
forall a. a -> [a] -> [a]
: [Cell () Text]
dateHeaders
Layout
_ -> [Cell () Text]
dateHeaders
amountHeader :: Cell border text -> Cell border text
amountHeader Cell border text
c = Cell border text
c{Ods.cellClass = amountClass Value}
dateHeaders :: [Cell () Text]
dateHeaders =
(if Bool -> Bool
not Bool
summary_only_ then (DateSpan -> Cell () Text) -> [DateSpan] -> [Cell () Text]
forall a b. (a -> b) -> [a] -> [b]
map (Cell () Text -> Cell () Text
forall {border} {text}. Cell border text -> Cell border text
amountHeader (Cell () Text -> Cell () Text)
-> (DateSpan -> Cell () Text) -> DateSpan -> Cell () Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> PeriodTitles -> Maybe Text -> [Text] -> DateSpan -> Cell () Text
headerDateSpanCell Bool
date2_ PeriodTitles
period_titles_ Maybe Text
balance_base_url_ [Text]
querystring_) [DateSpan]
colspans else [] )[Cell () Text] -> [Cell () Text] -> [Cell () Text]
forall a. [a] -> [a] -> [a]
++
[Class -> Text -> Cell () Text
forall {border}. Lines border => Class -> Text -> Cell border Text
hCell (RowClass -> Class
rowTotalClass RowClass
Value) Text
"total" | ReportOpts -> Bool
multiBalanceHasTotalsColumn ReportOpts
opts] [Cell () Text] -> [Cell () Text] -> [Cell () Text]
forall a. [a] -> [a] -> [a]
++
[Class -> Text -> Cell () Text
forall {border}. Lines border => Class -> Text -> Cell border Text
hCell (RowClass -> Class
rowAverageClass RowClass
Value) Text
"average" | Bool
average_]
shownParents :: Set Text
shownParents = [Text] -> Set Text
shownParentsOf ([Text] -> Set Text) -> [Text] -> Set Text
forall a b. (a -> b) -> a -> b
$ (PeriodicReportRow DisplayName MixedAmount -> Text)
-> [PeriodicReportRow DisplayName MixedAmount] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map PeriodicReportRow DisplayName MixedAmount -> Text
forall a. PeriodicReportRow DisplayName a -> Text
prrFullName [PeriodicReportRow DisplayName MixedAmount]
items
rowquery :: [Text]
rowquery =
[Text
t | Bool
requestedSpan, Text
t <- Bool -> DateSpan -> [Text]
dateTerm Bool
date2_ (DateSpan -> [Text]) -> DateSpan -> [Text]
forall a b. (a -> b) -> a -> b
$ [DateSpan] -> DateSpan
spansSpan [DateSpan]
colspans] [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text] -> [Text]
removeDates [Text]
querystring_
where
requestedSpan :: Bool
requestedSpan = Period
period_ Period -> Period -> Bool
forall a. Eq a => a -> a -> Bool
/= Period
PeriodAll Bool -> Bool -> Bool
|| (Text -> Bool) -> [Text] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Text -> Bool
isDateTerm [Text]
querystring_
isDateTerm :: Text -> Bool
isDateTerm Text
t = Text
"date:" Text -> Text -> Bool
`T.isPrefixOf` Text
t Bool -> Bool -> Bool
|| Text
"date2:" Text -> Text -> Bool
`T.isPrefixOf` Text
t
fullRowAsTexts :: PeriodicReportRow DisplayName MixedAmount -> [[Cell NumLines Text]]
fullRowAsTexts PeriodicReportRow DisplayName MixedAmount
row =
Cell NumLines Text
-> [[Cell NumLines Text]] -> [[Cell NumLines Text]]
forall border text.
Cell border text -> [[Cell border text]] -> [[Cell border text]]
addRowSpanHeader Cell NumLines Text
anchorCell ([[Cell NumLines Text]] -> [[Cell NumLines Text]])
-> [[Cell NumLines Text]] -> [[Cell NumLines Text]]
forall a b. (a -> b) -> a -> b
$
([Cell NumLines WideBuilder] -> [Cell NumLines Text])
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines Text]]
forall a b. (a -> b) -> [a] -> [b]
map ((Cell NumLines WideBuilder -> Cell NumLines Text)
-> [Cell NumLines WideBuilder] -> [Cell NumLines Text]
forall a b. (a -> b) -> [a] -> [b]
map ((WideBuilder -> Text)
-> Cell NumLines WideBuilder -> Cell NumLines Text
forall a b. (a -> b) -> Cell NumLines a -> Cell NumLines b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap WideBuilder -> Text
wbToText)) ([[Cell NumLines WideBuilder]] -> [[Cell NumLines Text]])
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines Text]]
forall a b. (a -> b) -> a -> b
$
AmountFormat
-> ReportOpts
-> [DateSpan]
-> [Text]
-> RowClass
-> (DateSpan -> Cell NumLines Text)
-> PeriodicReportRow DisplayName MixedAmount
-> [[Cell NumLines WideBuilder]]
forall a.
AmountFormat
-> ReportOpts
-> [DateSpan]
-> [Text]
-> RowClass
-> (DateSpan -> Cell NumLines Text)
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines WideBuilder]]
multiBalanceRowAsCellBuilders AmountFormat
fmt ReportOpts
opts [DateSpan]
colspans [Text]
allCommodities RowClass
Value
(LinkOpts
-> PeriodTitles
-> Maybe Text
-> [Text]
-> Text
-> DateSpan
-> Cell NumLines Text
forall border.
Lines border =>
LinkOpts
-> PeriodTitles
-> Maybe Text
-> [Text]
-> Text
-> DateSpan
-> Cell border Text
dateSpanCellWith LinkOpts
lo PeriodTitles
period_titles_ Maybe Text
balance_base_url_ [Text]
querystring_ Text
acctName) PeriodicReportRow DisplayName MixedAmount
row
where acctName :: Text
acctName = PeriodicReportRow DisplayName MixedAmount -> Text
forall a. PeriodicReportRow DisplayName a -> Text
prrFullName PeriodicReportRow DisplayName MixedAmount
row
lo :: LinkOpts
lo = ReportOpts -> [DateSpan] -> Set Text -> Text -> LinkOpts
rowLinkOpts ReportOpts
opts [DateSpan]
colspans Set Text
shownParents Text
acctName
anchorCell :: Cell NumLines Text
anchorCell =
LinkOpts
-> Maybe Text
-> [Text]
-> Text
-> Cell NumLines Text
-> Cell NumLines Text
forall border text.
LinkOpts
-> Maybe Text
-> [Text]
-> Text
-> Cell border text
-> Cell border text
setAccountAnchorWith LinkOpts
lo Maybe Text
balance_base_url_ [Text]
rowquery Text
acctName (Cell NumLines Text -> Cell NumLines Text)
-> Cell NumLines Text -> Cell NumLines Text
forall a b. (a -> b) -> a -> b
$
(\Cell NumLines Text
c -> Cell NumLines Text
c{Ods.cellClass = treeAccountClass opts (prrIndent row) acctName}) (Cell NumLines Text -> Cell NumLines Text)
-> Cell NumLines Text -> Cell NumLines Text
forall a b. (a -> b) -> a -> b
$
Text -> Cell NumLines Text
forall border text. Lines border => text -> Cell border text
accountCell (Text -> Cell NumLines Text) -> Text -> Cell NumLines Text
forall a b. (a -> b) -> a -> b
$ ReportOpts
-> Text -> PeriodicReportRow DisplayName MixedAmount -> Text
forall a.
ReportOpts -> Text -> PeriodicReportRow DisplayName a -> Text
renderPeriodicAcct ReportOpts
opts Text
nbsp PeriodicReportRow DisplayName MixedAmount
row
totalrows :: [[Cell NumLines Text]]
totalrows =
if Bool
no_total_
then []
else AmountFormat
-> ReportOpts
-> LinkOpts
-> [Text]
-> [Text]
-> [DateSpan]
-> Text
-> PeriodicReportRow () MixedAmount
-> [[Cell NumLines Text]]
forall a.
AmountFormat
-> ReportOpts
-> LinkOpts
-> [Text]
-> [Text]
-> [DateSpan]
-> Text
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines Text]]
multiBalanceTotalsRows AmountFormat
fmt ReportOpts
opts (ReportOpts -> [DateSpan] -> LinkOpts
reportLinkOpts ReportOpts
opts [DateSpan]
colspans) []
[Text]
allCommodities [DateSpan]
colspans Text
totalRowHeadingSpreadsheet PeriodicReportRow () MixedAmount
tr
multiBalanceTotalsRows ::
AmountFormat -> ReportOpts -> LinkOpts -> [Text] -> [CommoditySymbol] -> [DateSpan] ->
Text -> PeriodicReportRow a MixedAmount -> [[Ods.Cell Ods.NumLines Text]]
multiBalanceTotalsRows :: forall a.
AmountFormat
-> ReportOpts
-> LinkOpts
-> [Text]
-> [Text]
-> [DateSpan]
-> Text
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines Text]]
multiBalanceTotalsRows AmountFormat
fmt opts :: ReportOpts
opts@ReportOpts{Bool
Int
[Text]
[Status]
SortSpec
Maybe Int
Maybe Text
Maybe NormalSign
Maybe ConversionOp
Maybe ValuationType
Interval
Period
DepthSpec
AccountListMode
BalanceAccumulation
BalanceCalculation
Layout
PeriodTitles
Translations
StringFormat
accountlistmode_ :: ReportOpts -> AccountListMode
balancecalc_ :: ReportOpts -> BalanceCalculation
percent_ :: ReportOpts -> Bool
balanceaccum_ :: ReportOpts -> BalanceAccumulation
date2_ :: ReportOpts -> Bool
normalbalance_ :: ReportOpts -> Maybe NormalSign
conversionop_ :: ReportOpts -> Maybe ConversionOp
value_ :: ReportOpts -> Maybe ValuationType
full_names_ :: ReportOpts -> Bool
drop_ :: ReportOpts -> Int
row_total_ :: ReportOpts -> Bool
summary_only_ :: ReportOpts -> Bool
average_ :: ReportOpts -> Bool
translations_ :: ReportOpts -> Translations
layout_ :: ReportOpts -> Layout
transpose_ :: ReportOpts -> Bool
no_total_ :: ReportOpts -> Bool
pretty_ :: ReportOpts -> Bool
color_ :: ReportOpts -> Bool
period_titles_ :: ReportOpts -> PeriodTitles
balance_base_url_ :: ReportOpts -> Maybe Text
budgetpat_ :: ReportOpts -> Maybe Text
declared_ :: ReportOpts -> Bool
depth_ :: ReportOpts -> DepthSpec
empty_ :: ReportOpts -> Bool
fold_depth_ :: ReportOpts -> Maybe Int
format_ :: ReportOpts -> StringFormat
infer_prices_ :: ReportOpts -> Bool
interval_ :: ReportOpts -> Interval
invert_ :: ReportOpts -> Bool
no_elide_ :: ReportOpts -> Bool
period_ :: ReportOpts -> Period
querystring_ :: ReportOpts -> [Text]
real_ :: ReportOpts -> Bool
related_ :: ReportOpts -> Bool
show_costs_ :: ReportOpts -> Bool
sort_amount_ :: ReportOpts -> Bool
sortspec_ :: ReportOpts -> SortSpec
statuses_ :: ReportOpts -> [Status]
subreport_titles_ :: ReportOpts -> Maybe Text
title_ :: ReportOpts -> Maybe Text
txn_dates_ :: ReportOpts -> Bool
period_ :: Period
interval_ :: Interval
statuses_ :: [Status]
conversionop_ :: Maybe ConversionOp
value_ :: Maybe ValuationType
infer_prices_ :: Bool
depth_ :: DepthSpec
fold_depth_ :: Maybe Int
no_elide_ :: Bool
date2_ :: Bool
empty_ :: Bool
full_names_ :: Bool
real_ :: Bool
format_ :: StringFormat
balance_base_url_ :: Maybe Text
pretty_ :: Bool
querystring_ :: [Text]
average_ :: Bool
related_ :: Bool
sortspec_ :: SortSpec
txn_dates_ :: Bool
balancecalc_ :: BalanceCalculation
balanceaccum_ :: BalanceAccumulation
budgetpat_ :: Maybe Text
accountlistmode_ :: AccountListMode
drop_ :: Int
declared_ :: Bool
row_total_ :: Bool
no_total_ :: Bool
summary_only_ :: Bool
show_costs_ :: Bool
sort_amount_ :: Bool
percent_ :: Bool
invert_ :: Bool
normalbalance_ :: Maybe NormalSign
color_ :: Bool
transpose_ :: Bool
layout_ :: Layout
period_titles_ :: PeriodTitles
title_ :: Maybe Text
subreport_titles_ :: Maybe Text
translations_ :: Translations
..} LinkOpts
lo [Text]
extraquery [Text]
allCommodities [DateSpan]
colspans Text
label PeriodicReportRow a MixedAmount
row =
[[Cell NumLines Text]] -> [[Cell NumLines Text]]
forall (f :: * -> *) border text.
Functor f =>
[f (Cell border text)] -> [f (Cell NumLines text)]
addTotalBorders ([[Cell NumLines Text]] -> [[Cell NumLines Text]])
-> [[Cell NumLines Text]] -> [[Cell NumLines Text]]
forall a b. (a -> b) -> a -> b
$
Cell NumLines Text
-> [[Cell NumLines Text]] -> [[Cell NumLines Text]]
forall border text.
Cell border text -> [[Cell border text]] -> [[Cell border text]]
addRowSpanHeader ((Text -> Cell NumLines Text
forall border text. Lines border => text -> Cell border text
Ods.defaultCell Text
label) {Ods.cellClass = accountClass}) ([[Cell NumLines Text]] -> [[Cell NumLines Text]])
-> [[Cell NumLines Text]] -> [[Cell NumLines Text]]
forall a b. (a -> b) -> a -> b
$
([Cell NumLines WideBuilder] -> [Cell NumLines Text])
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines Text]]
forall a b. (a -> b) -> [a] -> [b]
map ((Cell NumLines WideBuilder -> Cell NumLines Text)
-> [Cell NumLines WideBuilder] -> [Cell NumLines Text]
forall a b. (a -> b) -> [a] -> [b]
map ((WideBuilder -> Text)
-> Cell NumLines WideBuilder -> Cell NumLines Text
forall a b. (a -> b) -> Cell NumLines a -> Cell NumLines b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap WideBuilder -> Text
wbToText)) ([[Cell NumLines WideBuilder]] -> [[Cell NumLines Text]])
-> [[Cell NumLines WideBuilder]] -> [[Cell NumLines Text]]
forall a b. (a -> b) -> a -> b
$
AmountFormat
-> ReportOpts
-> [DateSpan]
-> [Text]
-> RowClass
-> (DateSpan -> Cell NumLines Text)
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines WideBuilder]]
forall a.
AmountFormat
-> ReportOpts
-> [DateSpan]
-> [Text]
-> RowClass
-> (DateSpan -> Cell NumLines Text)
-> PeriodicReportRow a MixedAmount
-> [[Cell NumLines WideBuilder]]
multiBalanceRowAsCellBuilders AmountFormat
fmt ReportOpts
opts [DateSpan]
colspans [Text]
allCommodities RowClass
Total
(LinkOpts
-> PeriodTitles
-> Maybe Text
-> [Text]
-> [Text]
-> DateSpan
-> Cell NumLines Text
forall border.
Lines border =>
LinkOpts
-> PeriodTitles
-> Maybe Text
-> [Text]
-> [Text]
-> DateSpan
-> Cell border Text
totalDateSpanCell LinkOpts
lo PeriodTitles
period_titles_ Maybe Text
balance_base_url_ [Text]
extraquery [Text]
querystring_)
PeriodicReportRow a MixedAmount
row
tidyColumnLabels :: [Text]
tidyColumnLabels :: [Text]
tidyColumnLabels =
[Text
"period", Text
"start_date", Text
"end_date", Text
"commodity", Text
"value"]
allCommoditiesFromPeriodicReport ::
[PeriodicReportRow a MixedAmount] -> [CommoditySymbol]
allCommoditiesFromPeriodicReport :: forall a. [PeriodicReportRow a MixedAmount] -> [Text]
allCommoditiesFromPeriodicReport =
Set Text -> [Text]
forall a. Set a -> [a]
S.toAscList (Set Text -> [Text])
-> ([PeriodicReportRow a MixedAmount] -> Set Text)
-> [PeriodicReportRow a MixedAmount]
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PeriodicReportRow a MixedAmount -> Set Text)
-> [PeriodicReportRow a MixedAmount] -> Set Text
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((MixedAmount -> Set Text) -> [MixedAmount] -> Set Text
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap MixedAmount -> Set Text
maCommodities ([MixedAmount] -> Set Text)
-> (PeriodicReportRow a MixedAmount -> [MixedAmount])
-> PeriodicReportRow a MixedAmount
-> Set Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PeriodicReportRow a MixedAmount -> [MixedAmount]
forall a b. PeriodicReportRow a b -> [b]
prrAmounts)
setDisplayCommodityBare :: [CommoditySymbol] -> AmountFormat -> AmountFormat
setDisplayCommodityBare :: [Text] -> AmountFormat -> AmountFormat
setDisplayCommodityBare [Text]
cs AmountFormat
fmt =
AmountFormat
fmt{
displayCommodity = False,
displayCommodityOrder = Just cs,
displayMinWidth = Nothing
}