aboutsummaryrefslogtreecommitdiff
path: root/server/src/Controller/Payment.hs
diff options
context:
space:
mode:
authorJoris2020-05-30 15:02:24 +0200
committerJoris2020-05-30 15:02:26 +0200
commit706635ed16266962de75f15a83453cfa1b1bab83 (patch)
treea8e2a5e8bb58f8f765751ec0608781f67cbb940b /server/src/Controller/Payment.hs
parent80d0a1f5207378f80e7c851fba13396b6f78f785 (diff)
downloadbudget-706635ed16266962de75f15a83453cfa1b1bab83.tar.gz
budget-706635ed16266962de75f15a83453cfa1b1bab83.tar.bz2
budget-706635ed16266962de75f15a83453cfa1b1bab83.zip
Compute cumulative income until now
Previously, last payment date was used to compute the cumulative income. It resulted in big differences of cumulative incomes, if no payment have been added for some days.
Diffstat (limited to 'server/src/Controller/Payment.hs')
-rw-r--r--server/src/Controller/Payment.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/server/src/Controller/Payment.hs b/server/src/Controller/Payment.hs
index d6aa34f..4fb4d54 100644
--- a/server/src/Controller/Payment.hs
+++ b/server/src/Controller/Payment.hs
@@ -9,6 +9,7 @@ module Controller.Payment
import Control.Monad.IO.Class (liftIO)
import qualified Data.Map as M
import Data.Text (Text)
+import qualified Data.Time.Clock as Clock
import qualified Data.Time.Calendar as Calendar
import Data.Validation (Validation (Failure, Success))
import Web.Scotty (ActionM)
@@ -34,7 +35,8 @@ import qualified Validation.Payment as PaymentValidation
list :: Frequency -> Int -> Int -> Text -> ActionM ()
list frequency page perPage search =
- Secure.loggedAction (\_ ->
+ Secure.loggedAction (\_ -> do
+ currentUtctDay <- liftIO $ Clock.utctDay <$> Clock.getCurrentTime
(liftIO . Query.run $ do
count <- PaymentPersistence.count frequency search
payments <- PaymentPersistence.listActivePage frequency page perPage search
@@ -46,8 +48,8 @@ list frequency page perPage search =
cumulativeIncome <-
case (incomeDefinedForAll, paymentRange) of
- (Just incomeStart, Just (paymentStart, paymentEnd)) ->
- IncomePersistence.getCumulativeIncome (max incomeStart paymentStart) paymentEnd
+ (Just incomeStart, Just (paymentStart, _)) ->
+ IncomePersistence.getCumulativeIncome (max incomeStart paymentStart) currentUtctDay
_ ->
return M.empty