aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Model')
-rw-r--r--src/client/elm/Model/Payment.elm11
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