{-# LANGUAGE ScopedTypeVariables, OverloadedStrings, QuasiQuotes, NamedFieldPuns #-} -- | /register handlers. module Handler.RegisterR where import Import import Data.Time import Data.List (intersperse) import qualified Data.Text as T import Safe (headMay) import Handler.Common (hledgerLayout, numberTransactionsReportItems, mixedAmountAsHtml) import Hledger import Hledger.Cli.CliOptions import Hledger.Web.WebOptions -- | The main journal/account register view, with accounts sidebar. getRegisterR :: Handler Html getRegisterR = do vd@VD{j, m, opts, qopts} <- getViewData let title = a <> s1 <> s2 where (a,inclsubs) = fromMaybe ("all accounts",True) $ inAccount qopts s1 = if inclsubs then "" else " (excluding subaccounts)" s2 = if m /= Any then ", filtered" else "" hledgerLayout vd "register" $ do _ <- [hamlet|

#{title}|] registerReportHtml qopts $ accountTransactionsReport (reportopts_ $ cliopts_ opts) j m $ fromMaybe Any $ inAccountQuery qopts -- | Generate html for an account register, including a balance chart and transaction list. registerReportHtml :: [QueryOpt] -> TransactionsReport -> HtmlUrl AppRoute registerReportHtml qopts r = [hamlet|
^{registerChartHtml $ transactionsReportByCommodity r} ^{registerItemsHtml qopts r} |] -- | Generate html for a transaction list from an "TransactionsReport". registerItemsHtml :: [QueryOpt] -> TransactionsReport -> HtmlUrl AppRoute registerItemsHtml qopts (balancelabel,items) = [hamlet|
Date Description To/From Account(s) Amount Out/In #{balancelabel'} $forall i <- numberTransactionsReportItems items ^{itemAsHtml i} |] where insomeacct = isJust $ inAccount qopts balancelabel' = if insomeacct then balancelabel else "Total" itemAsHtml :: (Int, Bool, Bool, Bool, TransactionsReportItem) -> HtmlUrl AppRoute itemAsHtml (n, newd, newm, _, (torig, tacct, split, acct, amt, bal)) = [hamlet| #{date} #{textElideRight 30 desc} #{elideRight 40 acct} $if showamt \#{mixedAmountAsHtml amt} #{mixedAmountAsHtml bal} |] where evenodd = if even n then "even" else "odd" :: Text datetransition | newm = "newmonth" | newd = "newday" | otherwise = "" :: Text (firstposting, date, desc) = (False, show $ tdate tacct, tdescription tacct) showamt = not split || not (isZeroMixedAmount amt) -- | Generate javascript/html for a register balance line chart based on -- the provided "TransactionsReportItem"s. registerChartHtml :: [(CommoditySymbol, (String, [TransactionsReportItem]))] -> HtmlUrl AppRoute registerChartHtml percommoditytxnreports = -- have to make sure plot is not called when our container (maincontent) -- is hidden, eg with add form toggled [hamlet|