diff options
| author | Joris | 2015-10-04 20:48:32 +0200 | 
|---|---|---|
| committer | Joris | 2015-10-04 20:48:32 +0200 | 
| commit | 8c24464a4bd0a486cd0ddf846d3b5a323a7aaa9a (patch) | |
| tree | cdd1bb79846b3d8865d833a122152528b03a4746 /src/client/Model/View | |
| parent | 303dfd66c6434e19ba226a133a35a74a557b3e93 (diff) | |
Using incomes to compute a fair computation to designate the payer
Diffstat (limited to 'src/client/Model/View')
| -rw-r--r-- | src/client/Model/View/LoggedIn/Account.elm | 43 | ||||
| -rw-r--r-- | src/client/Model/View/LoggedInView.elm | 10 | 
2 files changed, 36 insertions, 17 deletions
| diff --git a/src/client/Model/View/LoggedIn/Account.elm b/src/client/Model/View/LoggedIn/Account.elm index 7f0fbe3..ab37b81 100644 --- a/src/client/Model/View/LoggedIn/Account.elm +++ b/src/client/Model/View/LoggedIn/Account.elm @@ -3,36 +3,57 @@ module Model.View.LoggedIn.Account    , IncomeEdition    , initAccount    , initIncomeEdition +  , getCurrentIncome    , validateIncome    ) where  import Result as Result exposing (Result(..)) +import Dict  import Utils.Validation exposing (..) +import Utils.Dict exposing (mapValues)  import Model.Translations exposing (..) -import Model.Payers exposing (..) +import Model.Payer exposing (..) +import Model.User exposing (UserId)  type alias Account = -  { payers : Payers -  , income : Maybe Int +  { me : UserId +  , payers : Payers    , visibleDetail : Bool    , incomeEdition : Maybe IncomeEdition    } +initAccount : UserId -> Payers -> Account +initAccount me payers = +  { me = me +  , payers = +      payers +        |> mapValues +             (\payer -> +               { payer | incomes <- List.sortBy .creation payer.incomes } +             ) +  , visibleDetail = False +  , incomeEdition = Nothing +  } + +getCurrentIncome : Account -> Maybe Int +getCurrentIncome account = +  case Dict.get account.me account.payers of +    Just payer -> +      payer.incomes +        |> List.sortBy .creation +        |> List.reverse +        |> List.head +        |> Maybe.map .amount +    Nothing -> +      Nothing +  type alias IncomeEdition =    { income : String    , error : Maybe String    } -initAccount : Payers -> Maybe Int -> Account -initAccount payers income = -  { payers = payers -  , income = income -  , visibleDetail = False -  , incomeEdition = Nothing -  } -  initIncomeEdition : Int -> IncomeEdition  initIncomeEdition income =    { income = toString income diff --git a/src/client/Model/View/LoggedInView.elm b/src/client/Model/View/LoggedInView.elm index 12a7294..122c4be 100644 --- a/src/client/Model/View/LoggedInView.elm +++ b/src/client/Model/View/LoggedInView.elm @@ -5,7 +5,7 @@ module Model.View.LoggedInView  import Model.User exposing (Users, UserId)  import Model.Payment exposing (Payments) -import Model.Payers exposing (Payers) +import Model.Payer exposing (Payers)  import Model.View.LoggedIn.Add exposing (..)  import Model.View.LoggedIn.Edition exposing (..)  import Model.View.LoggedIn.Monthly exposing (..) @@ -13,7 +13,6 @@ import Model.View.LoggedIn.Account exposing (..)  type alias LoggedInView =    { users : Users -  , me : UserId    , add : AddPayment    , monthly : Monthly    , account : Account @@ -23,13 +22,12 @@ type alias LoggedInView =    , currentPage : Int    } -initLoggedInView : Users -> UserId -> Payments -> Payments -> Int -> Payers -> Maybe Int -> LoggedInView -initLoggedInView users me monthlyPayments payments paymentsCount payers income = +initLoggedInView : Users -> UserId -> Payments -> Payments -> Int -> Payers -> LoggedInView +initLoggedInView users me monthlyPayments payments paymentsCount payers =    { users = users -  , me = me    , add = initAddPayment Punctual    , monthly = initMonthly monthlyPayments -  , account = initAccount payers income +  , account = initAccount me payers    , payments = payments    , paymentsCount = paymentsCount    , paymentEdition = Nothing | 
