aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Income/View.elm
blob: 5a2c18e3e5bd98c4972f97b4ad6b163292c30ee5 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module LoggedIn.Income.View exposing
  ( view
  )

import Dict
import Date
import Time exposing (Time)
import Task

import FontAwesome

import Html exposing (..)
import Html.Events exposing (..)
import Html.Attributes exposing (..)
import Html.App as Html

import Form exposing (Form)
import View.Form as Form
import View.Events exposing (onSubmitPrevDefault)

import Dialog
import Dialog.AddIncome.Model as AddIncome
import Dialog.AddIncome.View as AddIncome

import Msg exposing (Msg)

import LoggedData exposing (LoggedData)

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 Model.View as View
import LoggedIn.Income.Model as Income

import LoggedIn.Msg as LoggedInMsg
import LoggedIn.Income.Msg as IncomeMsg

import View.Date as Date
import LoggedIn.View.Format as Format
import View.Color as Color
import LoggedIn.Income.View.Table as Table

view : LoggedData -> Income.Model -> Html Msg
view loggedData incomeModel =
  div
    [ class "income" ]
    [ case useIncomesFrom loggedData.users loggedData.incomes loggedData.payments of
        Just since -> cumulativeIncomesView loggedData since
        Nothing -> text ""
    , div
        [ class "textual monthlyNetIncomes" ]
        [ h1 [] [ text <| getMessage "MonthlyNetIncomes" loggedData.translations ]
        , AddIncome.button
            "addIncome"
            loggedData
            (AddIncome.initialAdd loggedData.translations (Date.fromTime loggedData.currentTime))
            "AddIncome"
            (text (getMessage "AddIncome" loggedData.translations))
            Nothing
        ]
    , Table.view loggedData incomeModel
    ]

cumulativeIncomesView : LoggedData -> Time -> Html Msg
cumulativeIncomesView loggedData since =
  let longDate = Date.longView (Date.fromTime since) loggedData.translations
  in  div
        [ class "textual" ]
        [ 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
                       ]
                   )
            )
        ]

incomeView : LoggedData -> (IncomeId, Income) -> Html Msg
incomeView loggedData (incomeId, income) =
  li
    []
    [ text <| Date.shortView (Date.fromTime income.time) loggedData.translations
    , text "    −    "
    , text <| Format.price loggedData.conf income.amount
    , let dialogConfig =
            { className = "deleteIncomeDialog"
            , title = getMessage "ConfirmIncomeDelete" loggedData.translations
            , body = always <| text ""
            , confirm = getMessage "Confirm" loggedData.translations
            , confirmMsg = always <| Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.DeleteIncome incomeId
            , undo = getMessage "Undo" loggedData.translations
            }
      in  button
            [ onClick (Msg.Dialog <| Dialog.Open dialogConfig) ]
            [ FontAwesome.trash Color.chestnutRose 14 ]
    ]