From ede7b4fade5c396b47d386bd616e05805622b647 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 13 Nov 2016 11:58:22 +0100 Subject: Show a different message on weekly report if there were no activity during the previous week --- src/server/View/Mail/WeeklyReport.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/server/View/Mail') diff --git a/src/server/View/Mail/WeeklyReport.hs b/src/server/View/Mail/WeeklyReport.hs index b333891..f76fb0e 100644 --- a/src/server/View/Mail/WeeklyReport.hs +++ b/src/server/View/Mail/WeeklyReport.hs @@ -14,7 +14,7 @@ import Data.Time.Clock (UTCTime) import Data.Time.Calendar (Day, toGregorian) import Data.List (sortOn) -import Resource (Status(..), groupByStatus) +import Resource (Status(..), groupByStatus, statuses) import Database.Persist (Entity, entityVal) @@ -44,14 +44,14 @@ mail conf users payments incomes start end = body :: Conf -> [Entity User] -> Map Status [Payment] -> Map Status [Income] -> Text body conf users paymentsByStatus incomesByStatus = - T.intercalate "\n\n" . catMaybes $ - [ paymentSection Created conf users <$> M.lookup Created paymentsByStatus - , paymentSection Edited conf users <$> M.lookup Edited paymentsByStatus - , paymentSection Deleted conf users <$> M.lookup Deleted paymentsByStatus - , incomeSection Created conf users <$> M.lookup Created incomesByStatus - , incomeSection Edited conf users <$> M.lookup Edited incomesByStatus - , incomeSection Deleted conf users <$> M.lookup Deleted incomesByStatus - ] + if M.null paymentsByStatus && M.null incomesByStatus + then + getMessage K.WeeklyReportEmpty + else + T.intercalate "\n\n" . catMaybes . concat $ + [ map (\s -> paymentSection s conf users <$> M.lookup s paymentsByStatus) statuses + , map (\s -> incomeSection s conf users <$> M.lookup s incomesByStatus) statuses + ] paymentSection :: Status -> Conf -> [Entity User] -> [Payment] -> Text paymentSection status conf users payments = -- cgit v1.2.3