blob: 907be2be44aba740ed80f9fef7701af9192efad6 (
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 Util.Time (timeToDay)
monthlyPayment :: Maybe UTCTime -> IO UTCTime
monthlyPayment _ = do
monthlyPayments <- Query.run Payment.listActiveMonthlyOrderedByName
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
|