From 6a0c5087f716ed6c876a666db6573491bfd3e094 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 12 Jun 2016 23:54:17 +0200 Subject: Design income form --- src/client/elm/Model/Income.elm | 24 ++++++++++++------------ src/client/elm/Model/Payer.elm | 4 ++-- src/client/elm/Model/Payment.elm | 6 +++--- src/client/elm/Model/Translations.elm | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/client/elm/Model') diff --git a/src/client/elm/Model/Income.elm b/src/client/elm/Model/Income.elm index c0039e9..7eaa77f 100644 --- a/src/client/elm/Model/Income.elm +++ b/src/client/elm/Model/Income.elm @@ -25,7 +25,7 @@ type alias IncomeId = Int type alias Income = { userId : UserId - , creation : Time + , time : Float , amount : Int } @@ -45,15 +45,15 @@ incomeDecoder : Json.Decoder Income incomeDecoder = Json.object3 Income ("userId" := userIdDecoder) - ("creation" := timeDecoder) + ("day" := timeDecoder) ("amount" := Json.int) incomeDefinedForAll : List UserId -> Incomes -> Maybe Time incomeDefinedForAll userIds incomes = let userIncomes = List.map (\userId -> List.filter ((==) userId << .userId) << Dict.values <| incomes) userIds - firstIncomes = map (head << sortBy .creation) userIncomes + firstIncomes = map (head << sortBy .time) userIncomes in if all isJust firstIncomes - then head << reverse << List.sort << map .creation << catMaybes <| firstIncomes + then head << reverse << List.sort << map .time << catMaybes <| firstIncomes else Nothing userCumulativeIncomeSince : Time -> Time -> Incomes -> UserId -> Int @@ -70,26 +70,26 @@ cumulativeIncomesSince currentTime since incomes = getOrderedIncomesSince : Time -> List Income -> List Income getOrderedIncomesSince time incomes = let mbStarterIncome = getIncomeAt time incomes - orderedIncomesSince = filter (\income -> income.creation >= time) incomes + orderedIncomesSince = filter (\income -> income.time >= time) incomes in (maybeToList mbStarterIncome) ++ orderedIncomesSince getIncomeAt : Time -> List Income -> Maybe Income getIncomeAt time incomes = case incomes of [x] -> - if x.creation < time - then Just { userId = x.userId, creation = time, amount = x.amount } + if x.time < time + then Just { userId = x.userId, time = time, amount = x.amount } else Nothing x1 :: x2 :: xs -> - if x1.creation < time && x2.creation > time - then Just { userId = x2.userId, creation = time, amount = x2.amount } + if x1.time < time && x2.time > time + then Just { userId = x2.userId, time = time, amount = x2.amount } else getIncomeAt time (x2 :: xs) [] -> Nothing cumulativeIncome : Time -> List Income -> Int cumulativeIncome currentTime incomes = - getIncomesWithDuration currentTime (List.sortBy .creation incomes) + getIncomesWithDuration currentTime (List.sortBy .time incomes) |> map durationIncome |> sum @@ -99,9 +99,9 @@ getIncomesWithDuration currentTime incomes = [] -> [] [income] -> - [(currentTime - income.creation, income.amount)] + [(currentTime - income.time, income.amount)] (income1 :: income2 :: xs) -> - (income2.creation - income1.creation, income1.amount) :: (getIncomesWithDuration currentTime (income2 :: xs)) + (income2.time - income1.time, income1.amount) :: (getIncomesWithDuration currentTime (income2 :: xs)) durationIncome : (Float, Int) -> Int durationIncome (duration, income) = diff --git a/src/client/elm/Model/Payer.elm b/src/client/elm/Model/Payer.elm index 2c067bc..fb9940a 100644 --- a/src/client/elm/Model/Payer.elm +++ b/src/client/elm/Model/Payer.elm @@ -74,8 +74,8 @@ useIncomesFrom users incomes payments = |> List.map (Date.toTime << .creation) |> List.sort |> List.head - incomesForAllTime = incomeDefinedForAll (Dict.keys users) incomes - in case (firstPaymentTime, incomesForAllTime) of + mbIncomeTime = incomeDefinedForAll (Dict.keys users) incomes + in case (firstPaymentTime, mbIncomeTime) of (Just paymentTime, Just incomeTime) -> Just (max paymentTime incomeTime) _ -> diff --git a/src/client/elm/Model/Payment.elm b/src/client/elm/Model/Payment.elm index d9a5d68..7a6c630 100644 --- a/src/client/elm/Model/Payment.elm +++ b/src/client/elm/Model/Payment.elm @@ -15,6 +15,7 @@ module Model.Payment exposing ) import Date exposing (..) +import Date.Extra.Core exposing (monthToInt, intToMonth) import Json.Decode as Json exposing ((:=)) import String @@ -22,7 +23,6 @@ import Model.User exposing (UserId, userIdDecoder) import Model.Date exposing (dateDecoder) import Utils.List as List -import Utils.Date as Date perPage : Int perPage = 8 @@ -91,9 +91,9 @@ monthly userId = List.filter (\p -> p.frequency == Monthly && p.userId == userId groupAndSortByMonth : Payments -> List ((Month, Int), Payments) groupAndSortByMonth payments = payments - |> List.groupBy (\payment -> (Date.year payment.creation, Date.monthToNum << Date.month <| payment.creation)) + |> List.groupBy (\payment -> (Date.year payment.creation, monthToInt << Date.month <| payment.creation)) |> List.sortBy fst - |> List.map (\((year, month), payments) -> ((Date.numToMonth month, year), payments)) + |> List.map (\((year, month), payments) -> ((intToMonth month, year), payments)) |> List.reverse sortedFiltredPunctual : String -> Payments -> Payments diff --git a/src/client/elm/Model/Translations.elm b/src/client/elm/Model/Translations.elm index 705cb66..9499dde 100644 --- a/src/client/elm/Model/Translations.elm +++ b/src/client/elm/Model/Translations.elm @@ -23,7 +23,7 @@ type alias Translation = getTranslation : String -> Translations -> Maybe (List MessagePart) getTranslation key translations = translations - |> List.filter (\translation -> translation.key == key) + |> List.filter (\translation -> String.toLower translation.key == String.toLower key) |> List.head |> Maybe.map .message -- cgit v1.2.3