2015-08-09 19:16:33 +00: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-04 04:46:33 +00:00
|
|
|
module Handler.Select where
|
|
|
|
|
|
|
|
import Import
|
|
|
|
import Handler.Common
|
|
|
|
import qualified Data.Text as T
|
2015-04-16 00:51:08 +00:00
|
|
|
import Data.Maybe
|
2015-04-04 04:46:33 +00:00
|
|
|
|
|
|
|
getSelectR :: UserId -> Handler Html
|
2016-05-23 18:35:14 +00:00
|
|
|
getSelectR uId =
|
|
|
|
isUser uId HomeR >>= (\user -> do
|
|
|
|
master <- getYesod
|
|
|
|
beverages <- runDB $ selectList [BeverageAmount >. 0] [Asc BeverageIdent]
|
2017-02-12 10:58:54 +00:00
|
|
|
defaultLayout $ do
|
|
|
|
addScript $ StaticR js_barcode_js
|
2016-05-23 18:35:14 +00:00
|
|
|
$(widgetFile "select")
|
|
|
|
)
|
2015-04-04 04:46:33 +00:00
|
|
|
|
|
|
|
getSelectCashR :: Handler Html
|
|
|
|
getSelectCashR = do
|
2015-04-09 11:10:23 +00:00
|
|
|
beverages <- runDB $ selectList [BeverageAmount >. 0] [Asc BeverageIdent]
|
2017-02-12 10:58:54 +00:00
|
|
|
defaultLayout $ do
|
|
|
|
addScript $ StaticR js_barcode_js
|
2015-04-04 04:46:33 +00:00
|
|
|
$(widgetFile "selectCash")
|
|
|
|
|
|
|
|
getRechargeR :: UserId -> Handler Html
|
2016-05-23 18:35:14 +00:00
|
|
|
getRechargeR uId =
|
|
|
|
isUser uId HomeR >>= (\user -> do
|
|
|
|
(rechargeWidget, enctype) <- generateFormPost
|
|
|
|
$ renderBootstrap3 BootstrapBasicForm rechargeForm
|
|
|
|
currency <- appCurrency <$> appSettings <$> getYesod
|
|
|
|
defaultLayout $
|
|
|
|
$(widgetFile "recharge")
|
|
|
|
)
|
2015-04-04 04:46:33 +00:00
|
|
|
|
|
|
|
postRechargeR :: UserId -> Handler Html
|
2016-05-23 18:35:14 +00:00
|
|
|
postRechargeR uId =
|
|
|
|
isUser uId HomeR >>= (\user -> do
|
|
|
|
((res, _), _) <- runFormPost
|
|
|
|
$ renderBootstrap3 BootstrapBasicForm rechargeForm
|
|
|
|
case res of
|
|
|
|
FormSuccess amount ->
|
2017-08-13 17:51:20 +00:00
|
|
|
if amount <= 0
|
2016-05-23 18:35:14 +00:00
|
|
|
then do
|
|
|
|
setMessageI MsgNegativeRecharge
|
|
|
|
redirect $ RechargeR uId
|
|
|
|
else do
|
|
|
|
updateCashier amount ("Guthaben: " `T.append` userIdent user)
|
|
|
|
today <- liftIO $ return . utctDay =<< getCurrentTime
|
|
|
|
runDB $ update uId [UserBalance +=. amount, UserTimestamp =. today]
|
|
|
|
setMessageI MsgRecharged
|
|
|
|
redirect HomeR
|
|
|
|
_ -> do
|
|
|
|
setMessageI MsgRechargeError
|
|
|
|
redirect HomeR
|
|
|
|
)
|
2015-04-04 04:46:33 +00:00
|
|
|
|
2015-10-22 21:57:27 +00:00
|
|
|
rechargeForm :: AForm Handler Int
|
|
|
|
rechargeForm = areq currencyField (bfs MsgValue) (Just 0)
|
|
|
|
<* bootstrapSubmit (msgToBSSubmit MsgRecharge)
|