aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm
blob: 6f2439c3efc01311b72f86676773f7e8f6e697fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module LoggedIn.Home.View.ExceedingPayers exposing
  ( view
  )

import Html exposing (..)
import Html.Attributes exposing (..)

import Msg exposing (Msg)

import LoggedData exposing (LoggedData)

import LoggedIn.View.Format as Format

import Model exposing (Model)
import Model.User exposing (getUserName)
import Model.Payment as Payment
import Model.Payer exposing (..)
import Model.Translations exposing (getMessage)

view : LoggedData -> Html Msg
view loggedData =
  let payments = Payment.punctual loggedData.payments
      exceedingPayers = getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes payments
  in  div
        [ class "exceedingPayers" ]
        ( if List.isEmpty exceedingPayers
            then [ text <| getMessage loggedData.translations "PaymentsAreBalanced" ]
            else (List.map (exceedingPayer loggedData) exceedingPayers)
        )

exceedingPayer : LoggedData -> ExceedingPayer -> Html Msg
exceedingPayer loggedData payer =
  span
    [ class "exceedingPayer" ]
    [ span
        [ class "userName" ]
        [ payer.userId
            |> getUserName loggedData.users
            |> Maybe.withDefault "−"
            |> text
        ]
    , span
        [ class "amount" ]
        [ text ("+ " ++ (Format.price loggedData.conf payer.amount)) ]
    ]