diff options
author | Joris | 2017-04-02 17:51:12 +0200 |
---|---|---|
committer | Joris | 2017-04-02 21:07:08 +0200 |
commit | 5c110716cfda6e616a795edd12f2012b132dca9f (patch) | |
tree | 71c3d04780302edf0648bec1cd914757cdbb2883 /src/client/LoggedIn/Stat/Model.elm | |
parent | 64ff4707fdcd81c27c6be9903c3c82bc543ef016 (diff) |
Add a chart on payments by month by categories
Diffstat (limited to 'src/client/LoggedIn/Stat/Model.elm')
-rw-r--r-- | src/client/LoggedIn/Stat/Model.elm | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/client/LoggedIn/Stat/Model.elm b/src/client/LoggedIn/Stat/Model.elm new file mode 100644 index 0000000..bfc66f2 --- /dev/null +++ b/src/client/LoggedIn/Stat/Model.elm @@ -0,0 +1,34 @@ +module LoggedIn.Stat.Model exposing + ( Model + , init + , getPaymentsByMonthByCategory + ) + +import Date exposing (Month) +import List.Extra as List +import Time exposing (Time) + +import Model.Category exposing (CategoryId) +import Model.Conf exposing (Conf) +import Model.Payment as Payment exposing (Payments) +import Model.PaymentCategory as PaymentCategory exposing (PaymentCategories) + +type alias Model = + { paymentsByMonthByCategory : List ((Month, Int), List (CategoryId, Int)) + } + +init : Time -> PaymentCategories -> Payments -> Model +init currentTime paymentCategories payments = + { paymentsByMonthByCategory = getPaymentsByMonthByCategory currentTime paymentCategories payments + } + +getPaymentsByMonthByCategory : Time -> PaymentCategories -> Payments -> List ((Month, Int), List (CategoryId, Int)) +getPaymentsByMonthByCategory currentTime paymentCategories payments = + Payment.punctual payments + |> Payment.groupAndSortByMonth + |> List.map (\(m, payments) -> + ( m + , PaymentCategory.groupPaymentsByCategory paymentCategories payments + |> List.map (Tuple.mapSecond (List.sum << List.map .cost)) + ) + ) |