From c625d65c41f9d23444c9f70254607ba48ead718b Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 9 Apr 2015 17:28:08 +0200 Subject: [PATCH] now capable of holding more than one cashier --- Application.hs | 1 + Handler/Common.hs | 9 +++++---- config/models | 1 + config/routes | 1 + templates/journal.hamlet | 10 +++++++--- yammat.cabal | 1 + 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Application.hs b/Application.hs index 90b6769..cb95dc5 100644 --- a/Application.hs +++ b/Application.hs @@ -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 diff --git a/Handler/Common.hs b/Handler/Common.hs index e24c111..122b445 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs @@ -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 diff --git a/config/models b/config/models index 81c3183..4442ad4 100644 --- a/config/models +++ b/config/models @@ -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) diff --git a/config/routes b/config/routes index 1c4e2f0..59755ae 100644 --- a/config/routes +++ b/config/routes @@ -21,3 +21,4 @@ /summary SummaryR GET /modify/#BeverageId ModifyR GET POST /delete/#BeverageId DeleteBeverageR GET +/cashcheck CashCheckR GET POST diff --git a/templates/journal.hamlet b/templates/journal.hamlet index 9aa008c..d6a686e 100644 --- a/templates/journal.hamlet +++ b/templates/journal.hamlet @@ -21,8 +21,12 @@ $if not $ L.null entries

Kassenbestand: #{formatIntCurrency (fromIntegral cashBalance)} #{appCurrency $ appSettings master} -

- - Aus der Kasse auszahlen +