yammat/Handler/CashCheck.hs

30 lines
832 B
Haskell
Raw Normal View History

2015-04-09 15:45:52 +00:00
module Handler.CashCheck where
import Import
import Handler.Common
getCashCheckR :: Handler Html
getCashCheckR = do
2015-04-10 12:50:44 +00:00
(cashCheckWidget, enctype) <- generateFormPost createCashCheckForm
2015-04-09 15:45:52 +00:00
defaultLayout $ do
$(widgetFile "cashCheck")
postCashCheckR :: Handler Html
postCashCheckR = do
2015-04-10 12:50:44 +00:00
((res, _), _) <- runFormPost createCashCheckForm
2015-04-09 15:45:52 +00:00
case res of
FormSuccess c -> do
currentTime <- liftIO getCurrentTime
2015-04-09 15:45:52 +00:00
runDB $ insert_ c
runDB $ insert_ $ Cashier (cashCheckBalance c) currentTime
2015-04-09 22:40:58 +00:00
setMessageI MsgCashChecked
2015-04-09 15:45:52 +00:00
redirect $ HomeR
_ -> do
2015-04-09 22:40:58 +00:00
setMessageI MsgCashCheckError
2015-04-09 15:45:52 +00:00
redirect $ CashCheckR
2015-04-10 12:50:44 +00:00
createCashCheckForm :: Form CashCheck
createCashCheckForm = renderDivs $ CashCheck
2015-04-09 22:40:58 +00:00
<$> areq currencyField (fieldSettingsLabel MsgCountedValue) Nothing
2015-04-09 15:45:52 +00:00
<*> lift (liftIO getCurrentTime)