aboutsummaryrefslogtreecommitdiff
path: root/src/server/Job/MonthlyPayment.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Job/MonthlyPayment.hs')
-rw-r--r--src/server/Job/MonthlyPayment.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/server/Job/MonthlyPayment.hs b/src/server/Job/MonthlyPayment.hs
new file mode 100644
index 0000000..bac7062
--- /dev/null
+++ b/src/server/Job/MonthlyPayment.hs
@@ -0,0 +1,24 @@
+module Job.MonthlyPayment
+ ( monthlyPayment
+ ) where
+
+import Control.Monad.IO.Class (liftIO)
+
+import Data.Time.Clock (UTCTime, getCurrentTime)
+
+import Database.Persist (entityVal, insert)
+
+import Model.Database
+import qualified Model.Payment as Payment
+import Model.Frequency
+
+import Utils.Time (timeToDay)
+
+monthlyPayment :: Maybe UTCTime -> IO UTCTime
+monthlyPayment _ = runDb $ do
+ monthlyPayments <- map entityVal <$> Payment.listMonthly
+ now <- liftIO $ getCurrentTime
+ actualDay <- liftIO $ timeToDay now
+ let punctualPayments = map (\p -> p { paymentFrequency = Punctual, paymentDate = actualDay, paymentCreatedAt = now }) monthlyPayments
+ _ <- sequence $ map insert punctualPayments
+ return now