aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/LoggedIn/Home')
-rw-r--r--src/client/elm/LoggedIn/Home/Account/View.elm2
-rw-r--r--src/client/elm/LoggedIn/Home/AddPayment/View.elm4
-rw-r--r--src/client/elm/LoggedIn/Home/Model.elm3
-rw-r--r--src/client/elm/LoggedIn/Home/Model/Payer.elm130
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm2
5 files changed, 5 insertions, 136 deletions
diff --git a/src/client/elm/LoggedIn/Home/Account/View.elm b/src/client/elm/LoggedIn/Home/Account/View.elm
index bec75d5..dc72791 100644
--- a/src/client/elm/LoggedIn/Home/Account/View.elm
+++ b/src/client/elm/LoggedIn/Home/Account/View.elm
@@ -8,11 +8,11 @@ import Html.Attributes exposing (..)
import LoggedData exposing (LoggedData)
import LoggedIn.Home.Model as HomeModel
-import LoggedIn.Home.Model.Payer exposing (..)
import LoggedIn.View.Format as Format
import Model exposing (Model)
import Model.User exposing (getUserName)
+import Model.Payer exposing (..)
view : LoggedData -> HomeModel.Model -> Html
view loggedData homeModel =
diff --git a/src/client/elm/LoggedIn/Home/AddPayment/View.elm b/src/client/elm/LoggedIn/Home/AddPayment/View.elm
index 562f69b..96f3a6a 100644
--- a/src/client/elm/LoggedIn/Home/AddPayment/View.elm
+++ b/src/client/elm/LoggedIn/Home/AddPayment/View.elm
@@ -4,7 +4,7 @@ module LoggedIn.Home.AddPayment.View
import Result exposing (..)
-import Html as H exposing (..)
+import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
@@ -31,7 +31,7 @@ import Utils.Either exposing (toMaybeError)
view : LoggedData -> HomeModel.Model -> Html
view loggedData homeModel =
- H.form
+ Html.form
[ let update =
if homeModel.add.waitingServer
then
diff --git a/src/client/elm/LoggedIn/Home/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm
index 26af63c..217a851 100644
--- a/src/client/elm/LoggedIn/Home/Model.elm
+++ b/src/client/elm/LoggedIn/Home/Model.elm
@@ -3,10 +3,9 @@ module LoggedIn.Home.Model
, init
) where
-import LoggedIn.Home.Model.Payer exposing (Payers)
-
import Model.User exposing (Users, UserId)
import Model.Payment exposing (PaymentId, Payments, Frequency(..))
+import Model.Payer exposing (Payers)
import LoggedIn.Home.AddPayment.Model as AddPaymentModel
diff --git a/src/client/elm/LoggedIn/Home/Model/Payer.elm b/src/client/elm/LoggedIn/Home/Model/Payer.elm
deleted file mode 100644
index be40ffa..0000000
--- a/src/client/elm/LoggedIn/Home/Model/Payer.elm
+++ /dev/null
@@ -1,130 +0,0 @@
-module LoggedIn.Home.Model.Payer
- ( Payers
- , Payer
- , ExceedingPayer
- , getOrderedExceedingPayers
- ) where
-
-import Json.Decode as Json exposing (..)
-import Dict exposing (..)
-import List
-import Maybe
-import Time exposing (Time)
-import Date
-
-import Model.Payment exposing (Payments, totalPayments)
-import Model.User exposing (Users, UserId, userIdDecoder)
-import Model.Income exposing (..)
-
-import Utils.Dict exposing (mapValues)
-import Utils.Maybe exposing (isJust)
-
-type alias Payers = Dict UserId Payer
-
-type alias Payer =
- { preIncomePaymentSum : Int
- , postIncomePaymentSum : Int
- , incomes : List Income
- }
-
-type alias ExceedingPayer =
- { userId : UserId
- , amount : Int
- }
-
-getOrderedExceedingPayers : Time -> Users -> Incomes -> Payments -> List ExceedingPayer
-getOrderedExceedingPayers currentTime users incomes payments =
- let payers = getPayers currentTime users incomes payments
- exceedingPayersOnPreIncome =
- payers
- |> mapValues .preIncomePaymentSum
- |> Dict.toList
- |> exceedingPayersFromAmounts
- firstPaymentTime =
- payments
- |> List.map (Date.toTime << .creation)
- |> List.sort
- |> List.head
- incomesForAllTime = incomeDefinedForAll (Dict.keys users) incomes
- in case (firstPaymentTime, incomesForAllTime) of
- (Just paymentTime, Just incomeTime) ->
- let since = max paymentTime incomeTime
- postPaymentPayers = mapValues (getPostPaymentPayer currentTime since) payers
- mbMaxRatio =
- postPaymentPayers
- |> Dict.toList
- |> List.map (.ratio << snd)
- |> List.maximum
- in case mbMaxRatio of
- Just maxRatio ->
- postPaymentPayers
- |> mapValues (getFinalDiff maxRatio)
- |> Dict.toList
- |> exceedingPayersFromAmounts
- Nothing ->
- exceedingPayersOnPreIncome
- _ ->
- exceedingPayersOnPreIncome
-
-getPayers : Time -> Users -> Incomes -> Payments -> Payers
-getPayers currentTime users incomes payments =
- let userIds = Dict.keys users
- incomesDefined = incomeDefinedForAll userIds incomes
- in userIds
- |> List.map (\userId ->
- ( userId
- , { preIncomePaymentSum =
- totalPayments
- (\p -> (Date.toTime p.creation) < (Maybe.withDefault currentTime incomesDefined))
- userId
- payments
- , postIncomePaymentSum =
- totalPayments
- (\p ->
- case incomesDefined of
- Nothing -> False
- Just t -> (Date.toTime p.creation) >= t
- )
- userId
- payments
- , incomes = List.filter ((==) userId << .userId) (Dict.values incomes)
- }
- )
- )
- |> Dict.fromList
-
-exceedingPayersFromAmounts : List (UserId, Int) -> List ExceedingPayer
-exceedingPayersFromAmounts userAmounts =
- let mbMinAmount = List.minimum << List.map snd <| userAmounts
- in case mbMinAmount of
- Nothing ->
- []
- Just minAmount ->
- userAmounts
- |> List.map (\userAmount ->
- { userId = fst userAmount
- , amount = snd userAmount - minAmount
- }
- )
- |> List.filter (\payer -> payer.amount > 0)
-
-type alias PostPaymentPayer =
- { preIncomePaymentSum : Int
- , cumulativeIncome : Int
- , ratio : Float
- }
-
-getPostPaymentPayer : Time -> Time -> Payer -> PostPaymentPayer
-getPostPaymentPayer currentTime since payer =
- let cumulativeIncome = cumulativeIncomesSince currentTime since payer.incomes
- in { preIncomePaymentSum = payer.preIncomePaymentSum
- , cumulativeIncome = cumulativeIncome
- , ratio = toFloat payer.postIncomePaymentSum / toFloat cumulativeIncome
- }
-
-getFinalDiff : Float -> PostPaymentPayer -> Int
-getFinalDiff maxRatio payer =
- let postIncomeDiff =
- -1 * (maxRatio - payer.ratio) * toFloat payer.cumulativeIncome
- |> truncate
- in postIncomeDiff + payer.preIncomePaymentSum
diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm
index b669b6e..939ee55 100644
--- a/src/client/elm/LoggedIn/Home/View/Paging.elm
+++ b/src/client/elm/LoggedIn/Home/View/Paging.elm
@@ -45,7 +45,7 @@ truncatePages currentPage pages =
if currentPage <= showedLeftPages then
[1..showedPages]
else if currentPage > totalPages - showedRightPages then
- [(totalPages - showedPages)..totalPages]
+ [(totalPages - showedPages + 1)..totalPages]
else
[(currentPage - showedLeftPages)..(currentPage + showedRightPages)]
in List.filter (flip List.member pages) truncatedPages