2015-04-04 04:46:33 +00:00
|
|
|
module Handler.Restock where
|
|
|
|
|
|
|
|
import Import
|
|
|
|
import Handler.Common
|
|
|
|
|
|
|
|
getRestockR :: Handler Html
|
|
|
|
getRestockR = do
|
2015-04-09 11:47:27 +00:00
|
|
|
beverages <- runDB $ selectList [] [Asc BeverageIdent]
|
2015-04-04 04:46:33 +00:00
|
|
|
defaultLayout $ do
|
|
|
|
$(widgetFile "restock")
|
|
|
|
|
|
|
|
getUpstockR :: BeverageId -> Handler Html
|
|
|
|
getUpstockR bId = do
|
|
|
|
mBev <- runDB $ get bId
|
|
|
|
case mBev of
|
|
|
|
Just bev -> do
|
|
|
|
(upstockWidget, enctype) <- generateFormPost upstockForm
|
|
|
|
defaultLayout $ do
|
|
|
|
$(widgetFile "upstock")
|
|
|
|
Nothing -> do
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgItemUnknown
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ HomeR
|
|
|
|
|
|
|
|
postUpstockR :: BeverageId -> Handler Html
|
|
|
|
postUpstockR bId = do
|
|
|
|
mBev <- runDB $ get bId
|
|
|
|
case mBev of
|
|
|
|
Just bev -> do
|
|
|
|
((res, _), _) <- runFormPost upstockForm
|
|
|
|
case res of
|
|
|
|
FormSuccess c -> do
|
|
|
|
case c > 0 of
|
|
|
|
True -> do
|
|
|
|
runDB $ update bId [BeverageAmount +=. c]
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgStockedUp
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ HomeR
|
|
|
|
False -> do
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgNotStockedUp
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ UpstockR bId
|
|
|
|
_ -> do
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgStockupError
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ UpstockR bId
|
|
|
|
Nothing -> do
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgItemUnknown
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ HomeR
|
|
|
|
|
|
|
|
upstockForm :: Form Int
|
|
|
|
upstockForm = renderDivs
|
2015-04-09 22:40:58 +00:00
|
|
|
$ areq amountField (fieldSettingsLabel MsgAmountAdded) (Just 0)
|
2015-04-04 04:46:33 +00:00
|
|
|
|
|
|
|
getNewArticleR :: Handler Html
|
|
|
|
getNewArticleR = do
|
|
|
|
(newArticleWidget, enctype) <- generateFormPost newArticleForm
|
|
|
|
defaultLayout $ do
|
|
|
|
$(widgetFile "newArticle")
|
|
|
|
|
|
|
|
postNewArticleR :: Handler Html
|
|
|
|
postNewArticleR = do
|
|
|
|
((result, _), _) <- runFormPost newArticleForm
|
|
|
|
case result of
|
|
|
|
FormSuccess bev -> do
|
|
|
|
runDB $ insert_ bev
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgItemAdded
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ HomeR
|
|
|
|
_ -> do
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgItemNotAdded
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ HomeR
|
|
|
|
|
|
|
|
newArticleForm :: Form Beverage
|
|
|
|
newArticleForm = renderDivs $ Beverage
|
2015-04-09 22:40:58 +00:00
|
|
|
<$> areq textField (fieldSettingsLabel MsgName) Nothing
|
|
|
|
<*> areq currencyField (fieldSettingsLabel MsgPrice) (Just 100)
|
|
|
|
<*> areq amountField (fieldSettingsLabel MsgAmount) (Just 0)
|
|
|
|
<*> areq amountField (fieldSettingsLabel MsgAmountWarning) (Just 0)
|