From ac8a7c6210e2f430a3015e8004ff0726ef24d63b Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 6 Apr 2016 14:28:16 +0200 Subject: Add payments by month in stat --- src/client/elm/Model/Payment.elm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/client/elm/Model/Payment.elm') diff --git a/src/client/elm/Model/Payment.elm b/src/client/elm/Model/Payment.elm index 27d5bed..69315a9 100644 --- a/src/client/elm/Model/Payment.elm +++ b/src/client/elm/Model/Payment.elm @@ -10,6 +10,7 @@ module Model.Payment , totalPayments , punctual , monthly + , groupAndSortByMonth ) where import Date exposing (..) @@ -18,6 +19,9 @@ import Json.Decode as Json exposing ((:=)) import Model.User exposing (UserId, userIdDecoder) import Model.Date exposing (dateDecoder) +import Utils.List as List +import Utils.Date as Date + perPage : Int perPage = 8 @@ -81,3 +85,10 @@ punctual = List.filter ((==) Punctual << .frequency) monthly : UserId -> Payments -> Payments monthly userId = List.filter (\p -> p.frequency == Monthly && p.userId == userId) + +groupAndSortByMonth : Payments -> List ((Int, Int), Payments) +groupAndSortByMonth payments = + payments + |> List.groupBy (\payment -> (Date.year payment.creation, Date.monthToNum << Date.month <| payment.creation)) + |> List.sortBy fst + |> List.reverse -- cgit v1.2.3