yammat/Handler/CashCheck.hs

45 lines
1.5 KiB
Haskell
Raw Normal View History

2015-08-09 21:16:33 +02:00
-- yammat - Yet Another MateMAT
-- Copyright (C) 2015 Amedeo Molnár
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as published
-- by the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
--
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-04-09 17:45:52 +02:00
module Handler.CashCheck where
import Import
import Handler.Common
getCashCheckR :: Handler Html
getCashCheckR = do
2015-04-10 14:50:44 +02:00
(cashCheckWidget, enctype) <- generateFormPost createCashCheckForm
2015-04-09 17:45:52 +02:00
defaultLayout $ do
$(widgetFile "cashCheck")
postCashCheckR :: Handler Html
postCashCheckR = do
2015-04-10 14:50:44 +02:00
((res, _), _) <- runFormPost createCashCheckForm
2015-04-09 17:45:52 +02:00
case res of
FormSuccess c -> do
currentTime <- liftIO getCurrentTime
2015-04-09 17:45:52 +02:00
runDB $ insert_ c
runDB $ insert_ $ Cashier (cashCheckBalance c) currentTime
2015-04-10 00:40:58 +02:00
setMessageI MsgCashChecked
2015-04-09 17:45:52 +02:00
redirect $ HomeR
_ -> do
2015-04-10 00:40:58 +02:00
setMessageI MsgCashCheckError
2015-04-09 17:45:52 +02:00
redirect $ CashCheckR
2015-04-10 14:50:44 +02:00
createCashCheckForm :: Form CashCheck
createCashCheckForm = renderDivs $ CashCheck
2015-04-10 00:40:58 +02:00
<$> areq currencyField (fieldSettingsLabel MsgCountedValue) Nothing
2015-04-09 17:45:52 +02:00
<*> lift (liftIO getCurrentTime)