aboutsummaryrefslogtreecommitdiff
path: root/server/src/Job/MonthlyPayment.hs
blob: dfbe8b47d83201f4753de649d192b5aad5f82530 (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 Common.Util.Time    as Time

import qualified Model.Query         as Query
import qualified Persistence.Payment as PaymentPersistence

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