diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index b79ac015f..69121c976 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -75,6 +75,7 @@ module Hledger.Data.Amount ( mixed, amounts, filterMixedAmount, + filterMixedAmountByCommodity, normaliseMixedAmountPreservingFirstPrice, normaliseMixedAmountPreservingPrices, -- ** arithmetic @@ -429,6 +430,17 @@ amounts (Mixed as) = as filterMixedAmount :: (Amount -> Bool) -> MixedAmount -> MixedAmount filterMixedAmount p (Mixed as) = Mixed $ filter p as +-- | Return an unnormalised MixedAmount containing exactly one Amount +-- with the specified commodity and the quantity of that commodity +-- found in the original. NB if Amount's quantity is zero it will be +-- discarded next time the MixedAmount gets normalised. +filterMixedAmountByCommodity :: Commodity -> MixedAmount -> MixedAmount +filterMixedAmountByCommodity c (Mixed as) = Mixed as' + where + as' = case filter ((==c) . acommodity) as of + [] -> [nullamt{acommodity=c}] + as'' -> [sum as''] + -- | Convert a mixed amount's component amounts to the commodity of their -- assigned price, if any. costOfMixedAmount :: MixedAmount -> MixedAmount diff --git a/hledger-lib/Hledger/Reports/TransactionsReports.hs b/hledger-lib/Hledger/Reports/TransactionsReports.hs index f8528a4ef..48730c166 100644 --- a/hledger-lib/Hledger/Reports/TransactionsReports.hs +++ b/hledger-lib/Hledger/Reports/TransactionsReports.hs @@ -11,9 +11,12 @@ a some base account. They are used by hledger-web. module Hledger.Reports.TransactionsReports ( TransactionsReport, TransactionsReportItem, + triOrigTransaction, triDate, + triAmount, triBalance, - triSimpleBalance, + triCommodityAmount, + triCommodityBalance, journalTransactionsReport, accountTransactionsReport, transactionsReportByCommodity @@ -51,11 +54,12 @@ type TransactionsReportItem = (Transaction -- the original journal transaction, ,MixedAmount -- the running balance for the current account(s) after this transaction ) -triDate (t,_,_,_,_,_) = tdate t +triOrigTransaction (torig,_,_,_,_,_) = torig +triDate (_,tacct,_,_,_,_) = tdate tacct triAmount (_,_,_,_,a,_) = a triBalance (_,_,_,_,_,a) = a -triSimpleBalance (_,_,_,_,_,Mixed a) = case a of [] -> "0" - (Amount{aquantity=q}):_ -> show q +triCommodityAmount c = filterMixedAmountByCommodity c . triAmount +triCommodityBalance c = filterMixedAmountByCommodity c . triBalance ------------------------------------------------------------------------------- @@ -237,9 +241,5 @@ filterTransactionsReportByCommodity c (label,items) = go bal ((t,t2,s,o,amt,_):is) = (t,t2,s,o,amt,bal'):go bal' is where bal' = bal + amt --- | Filter out all but the specified commodity from this amount. -filterMixedAmountByCommodity :: Commodity -> MixedAmount -> MixedAmount -filterMixedAmountByCommodity c (Mixed as) = Mixed $ filter ((==c). acommodity) as - ------------------------------------------------------------------------------- diff --git a/hledger-web/Foundation.hs b/hledger-web/Foundation.hs index 42570b1d5..06c6cc185 100644 --- a/hledger-web/Foundation.hs +++ b/hledger-web/Foundation.hs @@ -134,6 +134,7 @@ instance Yesod App where addScript $ StaticR js_jquery_hotkeys_js addScript $ StaticR js_jquery_flot_min_js addScript $ StaticR js_jquery_flot_time_min_js + addScript $ StaticR js_jquery_flot_tooltip_min_js toWidget [hamlet| \ |] addStylesheet $ StaticR hledger_css addScript $ StaticR hledger_js diff --git a/hledger-web/Handler/RegisterR.hs b/hledger-web/Handler/RegisterR.hs index 08c8c848b..36105d0b9 100644 --- a/hledger-web/Handler/RegisterR.hs +++ b/hledger-web/Handler/RegisterR.hs @@ -4,6 +4,7 @@ module Handler.RegisterR where import Import +import Data.List import Data.Maybe import Safe @@ -105,31 +106,69 @@ registerChartHtml percommoditytxnreports =