module Job.MonthlyPayment ( monthlyPayment ) where import Data.Time.Clock (UTCTime, getCurrentTime) import Model.Frequency import qualified Model.Payment as Payment import Utils.Time (timeToDay) import qualified Model.Query as Query 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