diff --git a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs index f19d94fb4..026bb7d7e 100644 --- a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs +++ b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs @@ -65,10 +65,7 @@ import Hledger.Utils -- posts to the current account), most recent first. -- Reporting intervals are currently ignored. -- -type AccountTransactionsReport = - (String -- label for the balance column, eg "balance" or "total" - ,[AccountTransactionsReportItem] -- line items, one per transaction - ) +type AccountTransactionsReport = [AccountTransactionsReportItem] -- line items, one per transaction type AccountTransactionsReportItem = ( @@ -80,11 +77,8 @@ type AccountTransactionsReportItem = ,MixedAmount -- the register's running total or the current account(s)'s historical balance, after this transaction ) -totallabel = "Period Total" -balancelabel = "Historical Total" - accountTransactionsReport :: ReportSpec -> Journal -> Query -> Query -> AccountTransactionsReport -accountTransactionsReport rspec@ReportSpec{rsOpts=ropts} j reportq thisacctq = (label, items) +accountTransactionsReport rspec@ReportSpec{rsOpts=ropts} j reportq thisacctq = items where -- a depth limit should not affect the account transactions report -- seems unnecessary for some reason XXX @@ -130,9 +124,9 @@ accountTransactionsReport rspec@ReportSpec{rsOpts=ropts} j reportq thisacctq = ( ptraceAtWith 5 (("ts5:\n"++).pshowTransactions) $ sortBy (comparing (transactionRegisterDate reportq' thisacctq)) ts4 - (startbal,label) - | balancetype_ ropts == HistoricalBalance = (sumPostings priorps, balancelabel) - | otherwise = (nullmixedamt, totallabel) + startbal + | balancetype_ ropts == HistoricalBalance = sumPostings priorps + | otherwise = nullmixedamt where priorps = dbg5 "priorps" $ filter (matchesPosting diff --git a/hledger-lib/Hledger/Reports/TransactionsReport.hs b/hledger-lib/Hledger/Reports/TransactionsReport.hs index a89f65c71..b3da66179 100644 --- a/hledger-lib/Hledger/Reports/TransactionsReport.hs +++ b/hledger-lib/Hledger/Reports/TransactionsReport.hs @@ -40,9 +40,7 @@ import Hledger.Utils -- them) with or without a notion of current account(s). -- Two kinds of report use this data structure, see transactionsReport -- and accountTransactionsReport below for details. -type TransactionsReport = (String -- label for the balance column, eg "balance" or "total" - ,[TransactionsReportItem] -- line items, one per transaction - ) +type TransactionsReport = [TransactionsReportItem] -- line items, one per transaction type TransactionsReportItem = (Transaction -- the original journal transaction, unmodified ,Transaction -- the transaction as seen from a particular account, with postings maybe filtered ,Bool -- is this a split, ie more than one other account posting @@ -60,14 +58,12 @@ triBalance (_,_,_,_,_,a) = a triCommodityAmount c = filterMixedAmountByCommodity c . triAmount triCommodityBalance c = filterMixedAmountByCommodity c . triBalance -totallabel = "Period Total" - -- | Select transactions from the whole journal. This is similar to a -- "postingsReport" except with transaction-based report items which -- are ordered most recent first. XXX Or an EntriesReport - use that instead ? -- This is used by hledger-web's journal view. transactionsReport :: ReportOpts -> Journal -> Query -> TransactionsReport -transactionsReport opts j q = (totallabel, items) +transactionsReport opts j q = items where -- XXX items' first element should be the full transaction with all postings items = reverse $ accountTransactionsReportItems q None nullmixedamt id ts @@ -80,15 +76,14 @@ transactionsReportByCommodity :: TransactionsReport -> [(CommoditySymbol, Transa transactionsReportByCommodity tr = [(c, filterTransactionsReportByCommodity c tr) | c <- transactionsReportCommodities tr] where - transactionsReportCommodities (_,items) = - nubSort . map acommodity $ concatMap (amounts . triAmount) items + transactionsReportCommodities = nubSort . map acommodity . concatMap (amounts . triAmount) -- Remove transaction report items and item amount (and running -- balance amount) components that don't involve the specified -- commodity. Other item fields such as the transaction are left unchanged. filterTransactionsReportByCommodity :: CommoditySymbol -> TransactionsReport -> TransactionsReport -filterTransactionsReportByCommodity c (label,items) = - (label, fixTransactionsReportItemBalances $ concat [filterTransactionsReportItemByCommodity c i | i <- items]) +filterTransactionsReportByCommodity c = + fixTransactionsReportItemBalances . concatMap (filterTransactionsReportItemByCommodity c) where filterTransactionsReportItemByCommodity c (t,t2,s,o,a,bal) | c `elem` cs = [item'] diff --git a/hledger-ui/Hledger/UI/RegisterScreen.hs b/hledger-ui/Hledger/UI/RegisterScreen.hs index aef2a9319..f41de8f79 100644 --- a/hledger-ui/Hledger/UI/RegisterScreen.hs +++ b/hledger-ui/Hledger/UI/RegisterScreen.hs @@ -79,7 +79,7 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=CliOpts{reportspec_=rspec ,Not generatedTransactionTag ] - (_label,items) = accountTransactionsReport rspec' j q thisacctq + items = accountTransactionsReport rspec' j q thisacctq items' = (if empty_ ropts then id else filter (not . mixedAmountLooksZero . fifth6)) $ -- without --empty, exclude no-change txns reverse -- most recent last items diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index 2f65c7e2c..1e07b16c1 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -208,7 +208,7 @@ regenerateTransactions rspec j s acct i ui = let q = filterQuery (not . queryIsDepth) $ rsQuery rspec thisacctq = Acct $ accountNameToAccountRegex acct -- includes subs - items = reverse $ snd $ accountTransactionsReport rspec j q thisacctq + items = reverse $ accountTransactionsReport rspec j q thisacctq ts = map first6 items numberedts = zip [1..] ts -- select the best current transaction from the new list diff --git a/hledger-web/Hledger/Web/Handler/JournalR.hs b/hledger-web/Hledger/Web/Handler/JournalR.hs index b0713889f..4e8dd2093 100644 --- a/hledger-web/Hledger/Web/Handler/JournalR.hs +++ b/hledger-web/Hledger/Web/Handler/JournalR.hs @@ -27,7 +27,7 @@ getJournalR = do Just (a, inclsubs) -> "Transactions in " <> a <> if inclsubs then "" else " (excluding subaccounts)" title' = title <> if m /= Any then ", filtered" else "" acctlink a = (RegisterR, [("q", replaceInacct q $ accountQuery a)]) - (_, items) = transactionsReport (rsOpts . reportspec_ $ cliopts_ opts) j m + items = transactionsReport (rsOpts . reportspec_ $ cliopts_ opts) j m transactionFrag = transactionFragment j defaultLayout $ do diff --git a/hledger-web/Hledger/Web/Handler/RegisterR.hs b/hledger-web/Hledger/Web/Handler/RegisterR.hs index c0a7e9d3d..b8daf19e4 100644 --- a/hledger-web/Hledger/Web/Handler/RegisterR.hs +++ b/hledger-web/Hledger/Web/Handler/RegisterR.hs @@ -44,8 +44,11 @@ getRegisterR = do zip xs $ zip (map (T.unpack . accountSummarisedName . paccount) xs) $ tail $ (", "<$xs) ++ [""] - r@(balancelabel,items) = accountTransactionsReport rspec j m acctQuery - balancelabel' = if isJust (inAccount qopts) then balancelabel else "Total" + items = accountTransactionsReport rspec j m acctQuery + balancelabel + | isJust (inAccount qopts), balancetype_ (rsOpts rspec) == HistoricalBalance = "Historical Total" + | isJust (inAccount qopts) = "Period Total" + | otherwise = "Total" transactionFrag = transactionFragment j defaultLayout $ do setTitle "register - hledger-web" @@ -96,14 +99,12 @@ decorateLinks = -- | Generate javascript/html for a register balance line chart based on -- the provided "TransactionsReportItem"s. -registerChartHtml :: [(CommoditySymbol, (String, [TransactionsReportItem]))] -> HtmlUrl AppRoute -registerChartHtml percommoditytxnreports = $(hamletFile "templates/chart.hamlet") +registerChartHtml :: String -> [(CommoditySymbol, [TransactionsReportItem])] -> HtmlUrl AppRoute +registerChartHtml title percommoditytxnreports = $(hamletFile "templates/chart.hamlet") -- have to make sure plot is not called when our container (maincontent) -- is hidden, eg with add form toggled where - charttitle = case maybe "" (fst . snd) $ listToMaybe percommoditytxnreports of - "" -> "" - s -> s <> ":" + charttitle = if null title then "" else title ++ ":" colorForCommodity = fromMaybe 0 . flip lookup commoditiesIndex commoditiesIndex = zip (map fst percommoditytxnreports) [0..] :: [(CommoditySymbol,Int)] simpleMixedAmountQuantity = maybe 0 aquantity . listToMaybe . amounts diff --git a/hledger-web/templates/chart.hamlet b/hledger-web/templates/chart.hamlet index 7c32556eb..b5999424a 100644 --- a/hledger-web/templates/chart.hamlet +++ b/hledger-web/templates/chart.hamlet @@ -6,7 +6,7 @@ if ($chartdiv.is(':visible')) { \$('#register-chart-label').text('#{charttitle}'); var seriesData = [ - $forall (c,(_,items)) <- percommoditytxnreports + $forall (c,items) <- percommoditytxnreports /* we render each commodity using two series: * one with extra data points added to show a stepped balance line */ { diff --git a/hledger-web/templates/register.hamlet b/hledger-web/templates/register.hamlet index 0c890c6b8..1656bc3e2 100644 --- a/hledger-web/templates/register.hamlet +++ b/hledger-web/templates/register.hamlet @@ -2,7 +2,7 @@ #{header}
- ^{registerChartHtml $ transactionsReportByCommodity r} + ^{registerChartHtml balancelabel $ transactionsReportByCommodity items} @@ -15,7 +15,7 @@ $forall (torig, tacct, split, _acct, amt, bal) <- items diff --git a/hledger/Hledger/Cli/Commands/Aregister.hs b/hledger/Hledger/Cli/Commands/Aregister.hs index 857f44d98..41520b3d4 100644 --- a/hledger/Hledger/Cli/Commands/Aregister.hs +++ b/hledger/Hledger/Cli/Commands/Aregister.hs @@ -108,7 +108,7 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do ] -- run the report -- TODO: need to also pass the queries so we can choose which date to render - move them into the report ? - (balancelabel,items) = accountTransactionsReport rspec' j reportq thisacctq + items = accountTransactionsReport rspec' j reportq thisacctq items' = (if empty_ ropts then id else filter (not . mixedAmountLooksZero . fifth6)) $ reverse items -- select renderer @@ -119,10 +119,10 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do where fmt = outputFormatFromOpts opts - writeOutputLazyText opts $ render (balancelabel,items') + writeOutputLazyText opts $ render items' accountTransactionsReportAsCsv :: Query -> Query -> AccountTransactionsReport -> CSV -accountTransactionsReportAsCsv reportq thisacctq (_,is) = +accountTransactionsReportAsCsv reportq thisacctq is = ["txnidx","date","code","description","otheraccounts","change","balance"] : map (accountTransactionsReportItemAsCsvRecord reportq thisacctq) is @@ -141,7 +141,7 @@ accountTransactionsReportItemAsCsvRecord -- | Render a register report as plain text suitable for console output. accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text -accountTransactionsReportAsText copts reportq thisacctq (_balancelabel, items) +accountTransactionsReportAsText copts reportq thisacctq items = TB.toLazyText . mconcat . intersperse (TB.fromText "\n") $ title : map (accountTransactionsReportItemAsText copts reportq thisacctq amtwidth balwidth) items
To/From Account(s) Amount Out/In - #{balancelabel'} + #{balancelabel}