aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Income
diff options
context:
space:
mode:
authorJoris2016-04-07 23:58:23 +0200
committerJoris2016-04-07 23:58:23 +0200
commit6541fa5316816d6f97a87a370775cfe278e7eeb8 (patch)
tree733c7136776d652db2711fad2d8427d70136bccf /src/client/elm/LoggedIn/Income
parentf101c20c9da59c8c644d3cb6fa0b1d08f63e40e4 (diff)
Add cumulative incomes by user
Diffstat (limited to 'src/client/elm/LoggedIn/Income')
-rw-r--r--src/client/elm/LoggedIn/Income/View.elm43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm
index f62902a..9e77fde 100644
--- a/src/client/elm/LoggedIn/Income/View.elm
+++ b/src/client/elm/LoggedIn/Income/View.elm
@@ -4,6 +4,7 @@ module LoggedIn.Income.View
import Dict
import Date
+import Time exposing (Time)
import Html exposing (..)
import Html.Events exposing (..)
@@ -13,8 +14,10 @@ import Form.Input as Input
import LoggedData exposing (LoggedData)
-import Model.Income exposing (IncomeId, Income)
-import Model.Translations exposing (getMessage)
+import Model.Income exposing (IncomeId, Income, userCumulativeIncomeSince)
+import Model.Translations exposing (getMessage, getParamMessage)
+import Model.Payer exposing (useIncomesFrom)
+import Model.User exposing (UserId, User)
import LoggedIn.Income.Model as IncomeModel
import Mailbox
@@ -28,16 +31,46 @@ import LoggedIn.View.Format as Format
import Utils.Maybe exposing (isJust)
+import LoggedIn.View.Date exposing (renderLongDate)
+import View.Events exposing (onSubmitPrevDefault)
+
view : LoggedData -> IncomeModel.Model -> Html
view loggedData incomeModel =
div
[ class "income" ]
- [ h1 [] [ text <| getMessage "AddIncome" loggedData.translations ]
+ [ case useIncomesFrom loggedData.users loggedData.incomes loggedData.payments of
+ Just since -> cumulativeIncomesView loggedData since
+ Nothing -> text ""
+ , h1 [] [ text <| getMessage "AddIncome" loggedData.translations ]
, addIncomeView loggedData incomeModel.addIncome
, h1 [] [ text <| getMessage "MonthlyNetIncomes" loggedData.translations ]
, incomesView loggedData
]
+cumulativeIncomesView : LoggedData -> Time -> Html
+cumulativeIncomesView loggedData since =
+ let longDate = renderLongDate (Date.fromTime since) loggedData.translations
+ in div
+ []
+ [ h1 [] [ text <| getParamMessage [longDate] "CumulativeIncomesSince" loggedData.translations ]
+ , ul
+ []
+ ( Dict.toList loggedData.users
+ |> List.map (\(userId, user) ->
+ (user.name, userCumulativeIncomeSince loggedData.currentTime since loggedData.incomes userId)
+ )
+ |> List.sortBy snd
+ |> List.map (\(userName, cumulativeIncome) ->
+ li
+ []
+ [ text userName
+ , text ": "
+ , text <| Format.price loggedData.conf cumulativeIncome
+ ]
+ )
+ )
+ ]
+
addIncomeView : LoggedData -> Form () IncomeModel.AddIncome -> Html
addIncomeView loggedData addIncome =
let
@@ -49,8 +82,8 @@ addIncomeView loggedData addIncome =
creation = Form.getFieldAsString "creation" addIncome
amount = Form.getFieldAsString "amount" addIncome
in
- div
- []
+ Html.form
+ [ onSubmitPrevDefault Mailbox.address Action.NoOp ]
[ label [] [ text "Creation" ]
, Input.textInput creation formAddress []
, errorFor "DateValidationError" creation