cli: Commands.Aregister.htmlRow: replace by call to generic accountTransactionsReportItemAsRecord
This commit is contained in:
parent
4c189dde32
commit
067c5e4db6
@ -23,17 +23,21 @@ import Data.Default (def)
|
|||||||
import Data.List (find)
|
import Data.List (find)
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
import Data.Foldable (for_)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
import qualified Data.Text.Lazy.Builder as TB
|
import qualified Data.Text.Lazy.Builder as TB
|
||||||
import Lucid as L hiding (value_)
|
import Control.Monad (guard)
|
||||||
|
import Lucid (toHtml)
|
||||||
|
import qualified Lucid as L
|
||||||
import System.Console.CmdArgs.Explicit (flagNone, flagReq)
|
import System.Console.CmdArgs.Explicit (flagNone, flagReq)
|
||||||
|
|
||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Write.Csv (CSV, printCSV, printTSV)
|
import Hledger.Write.Csv (CSV, printCSV, printTSV)
|
||||||
import Hledger.Write.Ods (printFods)
|
import Hledger.Write.Ods (printFods)
|
||||||
import qualified Hledger.Write.Spreadsheet as Spr
|
import qualified Hledger.Write.Spreadsheet as Spr
|
||||||
|
import qualified Hledger.Write.Html.Lucid as Html
|
||||||
import Hledger.Cli.CliOptions
|
import Hledger.Cli.CliOptions
|
||||||
import Hledger.Cli.Utils
|
import Hledger.Cli.Utils
|
||||||
import Text.Tabular.AsciiWide hiding (render)
|
import Text.Tabular.AsciiWide hiding (render)
|
||||||
@ -137,20 +141,19 @@ accountTransactionsReportAsSpreadsheet fmt wd reportq thisacctq is =
|
|||||||
Spr.addHeaderBorders
|
Spr.addHeaderBorders
|
||||||
(map Spr.headerCell
|
(map Spr.headerCell
|
||||||
["txnidx","date","code","description","otheraccounts","change","balance"])
|
["txnidx","date","code","description","otheraccounts","change","balance"])
|
||||||
: map (accountTransactionsReportItemAsRecord fmt wd reportq thisacctq) is
|
: map (accountTransactionsReportItemAsRecord fmt True wd reportq thisacctq) is
|
||||||
|
|
||||||
accountTransactionsReportItemAsRecord ::
|
accountTransactionsReportItemAsRecord ::
|
||||||
(Spr.Lines border) =>
|
AmountFormat -> Bool ->
|
||||||
AmountFormat ->
|
|
||||||
WhichDate -> Query -> Query -> AccountTransactionsReportItem ->
|
WhichDate -> Query -> Query -> AccountTransactionsReportItem ->
|
||||||
[Spr.Cell border Text]
|
[Spr.Cell Spr.NumLines Text]
|
||||||
accountTransactionsReportItemAsRecord
|
accountTransactionsReportItemAsRecord
|
||||||
fmt wd reportq thisacctq
|
fmt internals wd reportq thisacctq
|
||||||
(t@Transaction{tindex,tcode,tdescription}, _, _issplit, otheracctsstr, change, balance)
|
(t@Transaction{tindex,tcode,tdescription}, _, _issplit, otheracctsstr, change, balance)
|
||||||
= [Spr.integerCell tindex,
|
= (guard internals >> [Spr.integerCell tindex]) ++
|
||||||
date,
|
date :
|
||||||
cell tcode,
|
(guard internals >> [cell tcode]) ++
|
||||||
cell tdescription,
|
[cell tdescription,
|
||||||
cell otheracctsstr,
|
cell otheracctsstr,
|
||||||
amountCell change,
|
amountCell change,
|
||||||
amountCell balance]
|
amountCell balance]
|
||||||
@ -167,7 +170,7 @@ accountTransactionsReportItemAsRecord
|
|||||||
accountTransactionsReportAsHTML :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
accountTransactionsReportAsHTML :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
||||||
accountTransactionsReportAsHTML copts reportq thisacctq items =
|
accountTransactionsReportAsHTML copts reportq thisacctq items =
|
||||||
L.renderText $ do
|
L.renderText $ do
|
||||||
L.link_ [L.rel_ "stylesheet", href_ "hledger.css"]
|
L.link_ [L.rel_ "stylesheet", L.href_ "hledger.css"]
|
||||||
L.table_ $ do
|
L.table_ $ do
|
||||||
L.thead_ $ L.tr_ $ do
|
L.thead_ $ L.tr_ $ do
|
||||||
L.th_ "date"
|
L.th_ "date"
|
||||||
@ -175,18 +178,12 @@ accountTransactionsReportAsHTML copts reportq thisacctq items =
|
|||||||
L.th_ "otheraccounts"
|
L.th_ "otheraccounts"
|
||||||
L.th_ "change"
|
L.th_ "change"
|
||||||
L.th_ "balance"
|
L.th_ "balance"
|
||||||
L.tbody_ $ mconcat $ map (htmlRow copts reportq thisacctq) items
|
L.tbody_ $ for_ items $
|
||||||
|
Html.formatRow . map (fmap toHtml) .
|
||||||
-- | Render one account register report line item as a HTML table row snippet.
|
accountTransactionsReportItemAsRecord
|
||||||
htmlRow :: CliOpts -> Query -> Query -> AccountTransactionsReportItem -> L.Html ()
|
oneLineNoCostFmt False
|
||||||
htmlRow CliOpts{reportspec_=ReportSpec{_rsReportOpts=ropts}} reportq thisacctq
|
(whichDate $ _rsReportOpts $ reportspec_ copts)
|
||||||
(t@Transaction{tdescription}, _, _issplit, otheracctsstr, amt, bal) =
|
reportq thisacctq
|
||||||
L.tr_ (do (L.td_ . toHtml . show . transactionRegisterDate (whichDate ropts) reportq thisacctq) t
|
|
||||||
(L.td_ . toHtml) tdescription
|
|
||||||
(L.td_ . toHtml) otheracctsstr
|
|
||||||
-- piggy back on the oneLineNoCostFmt display style for now.
|
|
||||||
(L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineNoCostFmt) amt
|
|
||||||
(L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineNoCostFmt) bal)
|
|
||||||
|
|
||||||
-- | Render a register report as plain text suitable for console output.
|
-- | Render a register report as plain text suitable for console output.
|
||||||
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user