articel amounts can no longer be negative

This commit is contained in:
nek0 2015-04-05 11:05:35 +02:00
parent d08b9d8aee
commit b1e108d257

View file

@ -26,6 +26,8 @@ postBuyR uId bId = do
((res, _), _) <- runFormPost buyForm ((res, _), _) <- runFormPost buyForm
case res of case res of
FormSuccess quant -> do FormSuccess quant -> do
case quant > beverageAmount bev of
False -> do
price <- return $ quant * (beveragePrice bev) price <- return $ quant * (beveragePrice bev)
sw <- return $ price > (userBalance user) sw <- return $ price > (userBalance user)
runDB $ update uId [UserBalance -=. price] runDB $ update uId [UserBalance -=. price]
@ -38,6 +40,9 @@ postBuyR uId bId = do
True -> do True -> do
setMessage "Achtung: Guthaben im negativen Bereich" setMessage "Achtung: Guthaben im negativen Bereich"
redirect $ HomeR redirect $ HomeR
True -> do
setMessage "So viele Artikel sind nicht vorhanden"
redirect $ BuyR uId bId
_ -> do _ -> do
setMessage "Etwas ist schief gelaufen" setMessage "Etwas ist schief gelaufen"
redirect $ HomeR redirect $ HomeR
@ -66,6 +71,8 @@ postBuyCashR bId = do
((res, _), _) <- runFormPost buyForm ((res, _), _) <- runFormPost buyForm
case res of case res of
FormSuccess quant -> do FormSuccess quant -> do
case quant > beverageAmount bev of
False -> do
master <- getYesod master <- getYesod
price <- return $ quant * (beveragePrice bev + 50) price <- return $ quant * (beveragePrice bev + 50)
runDB $ update bId [BeverageAmount -=. quant] runDB $ update bId [BeverageAmount -=. quant]
@ -77,6 +84,9 @@ postBuyCashR bId = do
`T.append` (appCurrency $ appSettings master) `T.append` (appCurrency $ appSettings master)
`T.append` " in die Kasse ein" `T.append` " in die Kasse ein"
redirect $ HomeR redirect $ HomeR
True -> do
setMessage "So viele Artikel sind nicht vorhanden"
redirect $ BuyCashR bId
_ -> do _ -> do
setMessage "Etwas ist schief gelaufen" setMessage "Etwas ist schief gelaufen"
redirect $ HomeR redirect $ HomeR