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