aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Model')
-rw-r--r--src/client/elm/Model/Income.elm24
-rw-r--r--src/client/elm/Model/Payer.elm4
-rw-r--r--src/client/elm/Model/Payment.elm6
-rw-r--r--src/client/elm/Model/Translations.elm2
4 files changed, 18 insertions, 18 deletions
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