aboutsummaryrefslogtreecommitdiff
path: root/src/server/Job/WeeklyReport.hs
blob: 5cde3e92a540dc6877b60d09763b90fd7657dae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 qualified Model.User as User

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 <*>
          User.list
      _ <- sendMail (mail conf users payments incomes lastExecution now)
      return ()
  return now