diff options
author | Joris | 2016-04-06 14:28:16 +0200 |
---|---|---|
committer | Joris | 2016-04-06 14:28:16 +0200 |
commit | ac8a7c6210e2f430a3015e8004ff0726ef24d63b (patch) | |
tree | 0df4ccbef7fca622a0ee4e89d35b9ce7d2d6eb09 /src/client/elm/Model | |
parent | d889c728c6ef1462fdeb56891de8d4d1a3df70c6 (diff) |
Add payments by month in stat
Diffstat (limited to 'src/client/elm/Model')
-rw-r--r-- | src/client/elm/Model/Payment.elm | 11 |
1 files changed, 11 insertions, 0 deletions
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 |