From d19b69eeeb0c24ee7e4a75b0da32eefba1d43928 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 4 Apr 2016 23:59:23 +0200 Subject: Begin cumulative income at first payment and not before --- src/client/elm/LoggedIn/Home/Model/Payer.elm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/client/elm/LoggedIn/Home/Model') diff --git a/src/client/elm/LoggedIn/Home/Model/Payer.elm b/src/client/elm/LoggedIn/Home/Model/Payer.elm index aabe50a..be40ffa 100644 --- a/src/client/elm/LoggedIn/Home/Model/Payer.elm +++ b/src/client/elm/LoggedIn/Home/Model/Payer.elm @@ -40,9 +40,16 @@ getOrderedExceedingPayers currentTime users incomes payments = |> mapValues .preIncomePaymentSum |> Dict.toList |> exceedingPayersFromAmounts - in case incomeDefinedForAll (Dict.keys users) incomes of - Just since -> - let postPaymentPayers = mapValues (getPostPaymentPayer currentTime since) payers + 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 @@ -56,7 +63,7 @@ getOrderedExceedingPayers currentTime users incomes payments = |> exceedingPayersFromAmounts Nothing -> exceedingPayersOnPreIncome - Nothing -> + _ -> exceedingPayersOnPreIncome getPayers : Time -> Users -> Incomes -> Payments -> Payers -- cgit v1.2.3