2015-04-04 04:46:33 +00:00
|
|
|
module Handler.Payout where
|
|
|
|
|
|
|
|
import Import
|
|
|
|
import Handler.Common
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
data Payment = Payment
|
|
|
|
{ paymentAmount :: Int
|
|
|
|
, paymentDesc :: T.Text
|
|
|
|
}
|
|
|
|
|
|
|
|
getPayoutR :: Handler Html
|
|
|
|
getPayoutR = do
|
|
|
|
(payoutWidget, enctype) <- generateFormPost payoutForm
|
|
|
|
defaultLayout $ do
|
|
|
|
$(widgetFile "payout")
|
|
|
|
|
|
|
|
postPayoutR :: Handler Html
|
|
|
|
postPayoutR = do
|
|
|
|
((res, _), _) <- runFormPost payoutForm
|
|
|
|
case res of
|
|
|
|
FormSuccess payment -> do
|
2015-04-09 22:40:58 +00:00
|
|
|
msg <- renderMessage' $ MsgPayout $ paymentDesc payment
|
|
|
|
updateCashier (- (paymentAmount payment)) msg
|
|
|
|
setMessageI MsgPaidOut
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ HomeR
|
|
|
|
_ -> do
|
2015-04-09 22:40:58 +00:00
|
|
|
setMessageI MsgNotPaidOut
|
2015-04-04 04:46:33 +00:00
|
|
|
redirect $ JournalR
|
|
|
|
|
|
|
|
payoutForm :: Form Payment
|
|
|
|
payoutForm = renderDivs $ Payment
|
2015-04-09 22:40:58 +00:00
|
|
|
<$> areq currencyField (fieldSettingsLabel MsgValue) Nothing
|
|
|
|
<*> areq textField (fieldSettingsLabel MsgDescription) Nothing
|