now capable of holding more than one cashier

This commit is contained in:
nek0 2015-04-09 17:28:08 +02:00
parent cd782faacb
commit c625d65c41
6 changed files with 16 additions and 7 deletions

View file

@ -34,6 +34,7 @@ import Handler.Journal
import Handler.Payout
import Handler.Summary
import Handler.Modify
import Handler.CashCheck
-- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the

View file

@ -26,24 +26,25 @@ getRobotsR = return $ TypedContent typePlain
updateCashier :: Int -> Text -> Handler ()
updateCashier amount desc = do
mCashier <- runDB $ selectFirst [] [Asc CashierId]
mCashier <- runDB $ selectFirst [] [Desc CashierCreated]
trans <- liftIO $ (\time -> return $ Transaction desc amount time) =<< getCurrentTime
case mCashier of
Just entCash -> do
runDB $ update (entityKey entCash) [CashierBalance +=. amount]
runDB $ insert_ trans
Nothing -> do
runDB $ insert_ $ Cashier amount
currentTime <- liftIO getCurrentTime
runDB $ insert_ $ Cashier amount currentTime
runDB $ insert_ trans
getCashierBalance :: Handler Int
getCashierBalance = do
mCashier <- runDB $ selectFirst [] [Asc CashierId]
mCashier <- runDB $ selectFirst [] [Desc CashierCreated]
case mCashier of
Just cashier -> do
return $ cashierBalance $ entityVal cashier
Nothing -> do
return 0
return 0
currencyField :: (RenderMessage (HandlerSite m) FormMessage, Show a, Monad m, Integral a) => Field m a
currencyField = Field

View file

@ -20,6 +20,7 @@ Transaction
deriving Typeable Show
Cashier
balance Int
created UTCTime default=now()
deriving Typeable Show
-- By default this file is used in Model.hs (which is imported by Foundation.hs)

View file

@ -21,3 +21,4 @@
/summary SummaryR GET
/modify/#BeverageId ModifyR GET POST
/delete/#BeverageId DeleteBeverageR GET
/cashcheck CashCheckR GET POST

View file

@ -21,8 +21,12 @@ $if not $ L.null entries
<p>
Kassenbestand: #{formatIntCurrency (fromIntegral cashBalance)} #{appCurrency $ appSettings master}
<p>
<a href=@{PayoutR}>
Aus der Kasse auszahlen
<ul>
<li>
<a href=@{PayoutR}>
Aus der Kasse auszahlen
<li>
<a href=@{CashCheckR}>
Kassensturz
$else
<p>Noch keine Bewegungen zu verzeichnen

View file

@ -29,6 +29,7 @@ library
Handler.Payout
Handler.Summary
Handler.Modify
Handler.CashCheck
if flag(dev) || flag(library-only)
cpp-options: -DDEVELOPMENT