added possibility to restock whole crates at once
This commit is contained in:
parent
f14072a882
commit
400775e925
1 changed files with 14 additions and 6 deletions
|
@ -42,14 +42,15 @@ postUpstockR :: BeverageId -> Handler Html
|
||||||
postUpstockR bId = do
|
postUpstockR bId = do
|
||||||
mBev <- runDB $ get bId
|
mBev <- runDB $ get bId
|
||||||
case mBev of
|
case mBev of
|
||||||
Just _ -> do
|
Just bev -> do
|
||||||
((res, _), _) <- runFormPost
|
((res, _), _) <- runFormPost
|
||||||
$ renderBootstrap3 BootstrapBasicForm upstockForm
|
$ renderBootstrap3 BootstrapBasicForm upstockForm
|
||||||
case res of
|
case res of
|
||||||
FormSuccess c ->
|
FormSuccess c ->
|
||||||
if c > 0
|
if upstockSingles c > 0 && upstockCrates c > 0
|
||||||
then do
|
then do
|
||||||
runDB $ update bId [BeverageAmount +=. c]
|
let total = upstockSingles c + (upstockCrates c * fromMaybe 0 $ perCrate bev)
|
||||||
|
runDB $ update bId [BeverageAmount +=. total]
|
||||||
setMessageI MsgStockedUp
|
setMessageI MsgStockedUp
|
||||||
redirect RestockR
|
redirect RestockR
|
||||||
else do
|
else do
|
||||||
|
@ -63,9 +64,16 @@ postUpstockR bId = do
|
||||||
setMessageI MsgItemUnknown
|
setMessageI MsgItemUnknown
|
||||||
redirect RestockR
|
redirect RestockR
|
||||||
|
|
||||||
upstockForm :: AForm Handler Int
|
data UpstockAmount = UpstockAmount
|
||||||
upstockForm = areq amountField (bfs MsgAmountAdded) (Just 1)
|
{ upstockSingles :: Int
|
||||||
<* bootstrapSubmit (msgToBSSubmit MsgFillup)
|
, upstockCrates :: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
upstockForm :: AForm Handler UpstockAmount
|
||||||
|
upstockForm = UpstockAmount
|
||||||
|
<$> areq amountField (bfs MsgAmountAdded) (Just 1)
|
||||||
|
<*> areq amountField (bfs MsgCrateAmountAdded) (Just 0)
|
||||||
|
<* bootstrapSubmit (msgToBSSubmit MsgFillup)
|
||||||
|
|
||||||
getNewArticleR :: Handler Html
|
getNewArticleR :: Handler Html
|
||||||
getNewArticleR = do
|
getNewArticleR = do
|
||||||
|
|
Loading…
Reference in a new issue