From 86a96decdb8892b10c5314eb916ef15a64204450 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 13 Nov 2016 00:49:32 +0100 Subject: Send weekly activity at start of week about previous week --- src/server/Job/WeeklyReport.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/server/Job/WeeklyReport.hs (limited to 'src/server/Job/WeeklyReport.hs') diff --git a/src/server/Job/WeeklyReport.hs b/src/server/Job/WeeklyReport.hs new file mode 100644 index 0000000..0d1eb35 --- /dev/null +++ b/src/server/Job/WeeklyReport.hs @@ -0,0 +1,31 @@ +module Job.WeeklyReport + ( weeklyReport + ) where + +import Data.Time.Clock (UTCTime, getCurrentTime) + +import Model.Database (runDb) +import qualified Model.Payment as Payment +import qualified Model.Income as Income +import Model.User (getUsers) + +import SendMail + +import Conf (Conf) + +import View.Mail.WeeklyReport (mail) + +weeklyReport :: Conf -> Maybe UTCTime -> IO UTCTime +weeklyReport conf mbLastExecution = do + now <- getCurrentTime + case mbLastExecution of + Nothing -> return () + Just lastExecution -> do + (payments, incomes, users) <- runDb $ + (,,) <$> + Payment.modifiedDuring lastExecution now <*> + Income.modifiedDuring lastExecution now <*> + getUsers + _ <- sendMail (mail conf users payments incomes lastExecution now) + return () + return now -- cgit v1.2.3