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.Payout
import Handler.Summary import Handler.Summary
import Handler.Modify import Handler.Modify
import Handler.CashCheck
-- This line actually creates our YesodDispatch instance. It is the second half -- 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 -- 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 :: Int -> Text -> Handler ()
updateCashier amount desc = do updateCashier amount desc = do
mCashier <- runDB $ selectFirst [] [Asc CashierId] mCashier <- runDB $ selectFirst [] [Desc CashierCreated]
trans <- liftIO $ (\time -> return $ Transaction desc amount time) =<< getCurrentTime trans <- liftIO $ (\time -> return $ Transaction desc amount time) =<< getCurrentTime
case mCashier of case mCashier of
Just entCash -> do Just entCash -> do
runDB $ update (entityKey entCash) [CashierBalance +=. amount] runDB $ update (entityKey entCash) [CashierBalance +=. amount]
runDB $ insert_ trans runDB $ insert_ trans
Nothing -> do Nothing -> do
runDB $ insert_ $ Cashier amount currentTime <- liftIO getCurrentTime
runDB $ insert_ $ Cashier amount currentTime
runDB $ insert_ trans runDB $ insert_ trans
getCashierBalance :: Handler Int getCashierBalance :: Handler Int
getCashierBalance = do getCashierBalance = do
mCashier <- runDB $ selectFirst [] [Asc CashierId] mCashier <- runDB $ selectFirst [] [Desc CashierCreated]
case mCashier of case mCashier of
Just cashier -> do Just cashier -> do
return $ cashierBalance $ entityVal cashier return $ cashierBalance $ entityVal cashier
Nothing -> do Nothing -> do
return 0 return 0
currencyField :: (RenderMessage (HandlerSite m) FormMessage, Show a, Monad m, Integral a) => Field m a currencyField :: (RenderMessage (HandlerSite m) FormMessage, Show a, Monad m, Integral a) => Field m a
currencyField = Field currencyField = Field

View file

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

View file

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

View file

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

View file

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