aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model/Payment.elm
diff options
context:
space:
mode:
authorJoris2016-04-06 14:28:16 +0200
committerJoris2016-04-06 14:28:16 +0200
commitac8a7c6210e2f430a3015e8004ff0726ef24d63b (patch)
tree0df4ccbef7fca622a0ee4e89d35b9ce7d2d6eb09 /src/client/elm/Model/Payment.elm
parentd889c728c6ef1462fdeb56891de8d4d1a3df70c6 (diff)
downloadbudget-ac8a7c6210e2f430a3015e8004ff0726ef24d63b.tar.gz
budget-ac8a7c6210e2f430a3015e8004ff0726ef24d63b.tar.bz2
budget-ac8a7c6210e2f430a3015e8004ff0726ef24d63b.zip
Add payments by month in stat
Diffstat (limited to 'src/client/elm/Model/Payment.elm')
-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