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,18 +26,23 @@ postBuyR uId bId = do
((res, _), _) <- runFormPost buyForm ((res, _), _) <- runFormPost buyForm
case res of case res of
FormSuccess quant -> do FormSuccess quant -> do
price <- return $ quant * (beveragePrice bev) case quant > beverageAmount bev of
sw <- return $ price > (userBalance user)
runDB $ update uId [UserBalance -=. price]
runDB $ update bId [BeverageAmount -=. quant]
checkAlert bId
case sw of
False -> do False -> do
setMessage "Viel Vergnügen" price <- return $ quant * (beveragePrice bev)
redirect $ HomeR sw <- return $ price > (userBalance user)
runDB $ update uId [UserBalance -=. price]
runDB $ update bId [BeverageAmount -=. quant]
checkAlert bId
case sw of
False -> do
setMessage "Viel Vergnügen"
redirect $ HomeR
True -> do
setMessage "Achtung: Guthaben im negativen Bereich"
redirect $ HomeR
True -> do True -> do
setMessage "Achtung: Guthaben im negativen Bereich" setMessage "So viele Artikel sind nicht vorhanden"
redirect $ HomeR redirect $ BuyR uId bId
_ -> do _ -> do
setMessage "Etwas ist schief gelaufen" setMessage "Etwas ist schief gelaufen"
redirect $ HomeR redirect $ HomeR
@ -66,17 +71,22 @@ postBuyCashR bId = do
((res, _), _) <- runFormPost buyForm ((res, _), _) <- runFormPost buyForm
case res of case res of
FormSuccess quant -> do FormSuccess quant -> do
master <- getYesod case quant > beverageAmount bev of
price <- return $ quant * (beveragePrice bev + 50) False -> do
runDB $ update bId [BeverageAmount -=. quant] master <- getYesod
updateCashier price "Barzahlung" price <- return $ quant * (beveragePrice bev + 50)
checkAlert bId runDB $ update bId [BeverageAmount -=. quant]
setMessage $ Content $ Text $ "Viel Vergnügen. Bitte Zahle " updateCashier price "Barzahlung"
`T.append` (T.pack $ show ((fromIntegral price) / 100)) checkAlert bId
`T.append` " " setMessage $ Content $ Text $ "Viel Vergnügen. Bitte Zahle "
`T.append` (appCurrency $ appSettings master) `T.append` (T.pack $ show ((fromIntegral price) / 100))
`T.append` " in die Kasse ein" `T.append` " "
redirect $ HomeR `T.append` (appCurrency $ appSettings master)
`T.append` " in die Kasse ein"
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