aboutsummaryrefslogtreecommitdiff
path: root/server/src/Job/MonthlyPayment.hs
blob: 8cb1c2711364386b289799ba0d709322982b1d54 (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
module Job.MonthlyPayment
  ( monthlyPayment
  ) where

import           Data.Time.Clock (UTCTime, getCurrentTime)

import           Common.Model    (Frequency (..), Payment (..))

import qualified Model.Payment   as Payment
import qualified Model.Query     as Query
import           Utils.Time      (timeToDay)

monthlyPayment :: Maybe UTCTime -> IO UTCTime
monthlyPayment _ = do
  monthlyPayments <- Query.run Payment.listMonthly
  now <- getCurrentTime
  actualDay <- timeToDay now
  let punctualPayments = map
        (\p -> p
          { _payment_frequency = Punctual
          , _payment_date = actualDay
          , _payment_createdAt = now
          })
        monthlyPayments
  _ <- Query.run (Payment.createMany punctualPayments)
  return now