aboutsummaryrefslogtreecommitdiff
path: root/server/src/View/Mail
diff options
context:
space:
mode:
authorJoris2019-11-24 16:19:53 +0100
committerJoris2019-11-24 16:19:53 +0100
commit54628c70cb33de5e4309c35b9f6b57bbe9f7a07b (patch)
tree57e331cadfdf81b5598d21f76302f5269fd58344 /server/src/View/Mail
parent3c67fcf1d524811a18f0c4db3ef6eed1270b9a12 (diff)
Compute cumulative income with a DB query
Diffstat (limited to 'server/src/View/Mail')
-rw-r--r--server/src/View/Mail/WeeklyReport.hs21
1 files changed, 10 insertions, 11 deletions
diff --git a/server/src/View/Mail/WeeklyReport.hs b/server/src/View/Mail/WeeklyReport.hs
index 1f637bc..3fe224f 100644
--- a/server/src/View/Mail/WeeklyReport.hs
+++ b/server/src/View/Mail/WeeklyReport.hs
@@ -9,7 +9,6 @@ import Data.Maybe (catMaybes, fromMaybe)
import Data.Monoid ((<>))
import Data.Text (Text)
import qualified Data.Text as T
-import Data.Time.Calendar (Day)
import Data.Time.Clock (UTCTime)
import Common.Model (ExceedingPayer (..), Income (..),
@@ -27,8 +26,8 @@ import Model.PaymentResource (PaymentResource (..))
import qualified Payer as Payer
import Resource (Status (..), groupByStatus, statuses)
-mail :: Conf -> [User] -> [Payment] -> Map UserId Int -> Map UserId Int -> Maybe Day -> [Income] -> UTCTime -> UTCTime -> Mail
-mail conf users weekPayments preIncomeRepartition postIncomeRepartition firstPayment incomes start end =
+mail :: Conf -> [User] -> [Income] -> [Payment] -> Map UserId Int -> Map UserId Int -> Map UserId Int -> UTCTime -> UTCTime -> Mail
+mail conf users weekIncomes weekPayments cumulativeIncome preIncomeRepartition postIncomeRepartition start end =
Mail
{ M.from = Conf.noReplyMail conf
, M.to = map _user_email users
@@ -37,24 +36,24 @@ mail conf users weekPayments preIncomeRepartition postIncomeRepartition firstPay
, " − "
, Msg.get Msg.WeeklyReport_Title
]
- , M.body = body conf users weekPayments preIncomeRepartition postIncomeRepartition firstPayment incomes start end
+ , M.body = body conf users weekIncomes weekPayments cumulativeIncome preIncomeRepartition postIncomeRepartition start end
}
-body :: Conf -> [User] -> [Payment] -> Map UserId Int -> Map UserId Int -> Maybe Day -> [Income] -> UTCTime -> UTCTime -> Text
-body conf users weekPayments preIncomeRepartition postIncomeRepartition firstPayment incomes start end =
+body :: Conf -> [User] -> [Income] -> [Payment] -> Map UserId Int -> Map UserId Int -> Map UserId Int -> UTCTime -> UTCTime -> Text
+body conf users weekIncomes weekPayments cumulativeIncome preIncomeRepartition postIncomeRepartition start end =
T.intercalate "\n" $
- [ exceedingPayers conf end users incomes preIncomeRepartition postIncomeRepartition firstPayment
+ [ exceedingPayers conf users cumulativeIncome preIncomeRepartition postIncomeRepartition
, operations conf users paymentsGroupedByStatus incomesGroupedByStatus
]
where
paymentsGroupedByStatus = groupByStatus start end . map PaymentResource $ weekPayments
- incomesGroupedByStatus = groupByStatus start end . map IncomeResource $ incomes
+ incomesGroupedByStatus = groupByStatus start end . map IncomeResource $ weekIncomes
-exceedingPayers :: Conf -> UTCTime -> [User] -> [Income] -> Map UserId Int -> Map UserId Int -> Maybe Day -> Text
-exceedingPayers conf time users incomes preIncomeRepartition postIncomeRepartition firstPayment =
+exceedingPayers :: Conf -> [User] -> Map UserId Int -> Map UserId Int -> Map UserId Int -> Text
+exceedingPayers conf users cumulativeIncome preIncomeRepartition postIncomeRepartition =
T.intercalate "\n" . map formatPayer $ payers
where
- payers = Payer.getExceedingPayers time users incomes preIncomeRepartition postIncomeRepartition firstPayment
+ payers = Payer.getExceedingPayers users cumulativeIncome preIncomeRepartition postIncomeRepartition
formatPayer p = T.concat
[ " * "
, fromMaybe "" $ _user_name <$> CM.findUser (_exceedingPayer_userId p) users