From cc58377a48d13ef85cedb5ec0e19eb8b879dd497 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 28 Mar 2016 18:04:25 +0200 Subject: Compute payment count client side --- src/server/Model/Payer/Payment.hs | 40 --------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/server/Model/Payer/Payment.hs (limited to 'src/server/Model/Payer/Payment.hs') diff --git a/src/server/Model/Payer/Payment.hs b/src/server/Model/Payer/Payment.hs deleted file mode 100644 index 6efc38d..0000000 --- a/src/server/Model/Payer/Payment.hs +++ /dev/null @@ -1,40 +0,0 @@ -module Model.Payer.Payment - ( getTotalPaymentsBefore - , getTotalPaymentsAfter - ) where - -import Data.Time.Clock (UTCTime) -import Data.Maybe (catMaybes) - -import Database.Persist -import Database.Esqueleto -import qualified Database.Esqueleto as E - -import Model.Database -import Model.Frequency - -getTotalPaymentsBefore :: UTCTime -> Persist [(UserId, Int)] -getTotalPaymentsBefore time = - getTotalPayments (\p -> p ^. PaymentCreation E.<. val time) - -getTotalPaymentsAfter :: UTCTime -> Persist [(UserId, Int)] -getTotalPaymentsAfter time = - getTotalPayments (\p -> p ^. PaymentCreation E.>=. val time) - -getTotalPayments :: (SqlExpr (Entity Payment) -> SqlExpr (Value Bool)) -> Persist [(UserId, Int)] -getTotalPayments paymentWhere = do - values <- select $ - from $ \payment -> do - where_ (isNothing (payment ^. PaymentDeletedAt)) - where_ (payment ^. PaymentFrequency E.==. val Punctual) - where_ (paymentWhere payment) - groupBy (payment ^. PaymentUserId) - return (payment ^. PaymentUserId, sum_ (payment ^. PaymentCost)) - return $ catMaybes . map (unMaybe . unValueTuple) $ values - -unValueTuple :: (Value a, Value b) -> (a, b) -unValueTuple (Value a, Value b) = (a, b) - -unMaybe :: (a, Maybe b) -> Maybe (a, b) -unMaybe (a, Just b) = Just (a, b) -unMaybe _ = Nothing -- cgit v1.2.3