resolved cashCheck issue

This commit is contained in:
nek0 2015-04-10 14:50:44 +02:00
parent 1cc845215a
commit 3e6701b12e
5 changed files with 21 additions and 17 deletions

View file

@ -5,23 +5,24 @@ import Handler.Common
getCashCheckR :: Handler Html getCashCheckR :: Handler Html
getCashCheckR = do getCashCheckR = do
(cashCheckWidget, enctype) <- generateFormPost createCashierForm (cashCheckWidget, enctype) <- generateFormPost createCashCheckForm
defaultLayout $ do defaultLayout $ do
$(widgetFile "cashCheck") $(widgetFile "cashCheck")
postCashCheckR :: Handler Html postCashCheckR :: Handler Html
postCashCheckR = do postCashCheckR = do
((res, _), _) <- runFormPost createCashierForm ((res, _), _) <- runFormPost createCashCheckForm
case res of case res of
FormSuccess c -> do FormSuccess c -> do
runDB $ insert_ c runDB $ insert_ c
runDB $ insert_ $ Cashier (cashCheckBalance c)
setMessage "Kassensturz durchgeführt. Kasse aktualisiert" setMessage "Kassensturz durchgeführt. Kasse aktualisiert"
redirect $ HomeR redirect $ HomeR
_ -> do _ -> do
setMessage "Fehler im Kassensturz" setMessage "Fehler im Kassensturz"
redirect $ CashCheckR redirect $ CashCheckR
createCashierForm :: Form Cashier createCashCheckForm :: Form CashCheck
createCashierForm = renderDivs $ Cashier createCashCheckForm = renderDivs $ CashCheck
<$> areq currencyField "Gezählter Betrag" Nothing <$> areq currencyField "Gezählter Betrag" Nothing
<*> lift (liftIO getCurrentTime) <*> lift (liftIO getCurrentTime)

View file

@ -26,20 +26,19 @@ getRobotsR = return $ TypedContent typePlain
updateCashier :: Int -> Text -> Handler () updateCashier :: Int -> Text -> Handler ()
updateCashier amount desc = do updateCashier amount desc = do
mCashier <- runDB $ selectFirst [] [Desc CashierCreated] mCashier <- runDB $ selectFirst [] [Desc CashierId]
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
currentTime <- liftIO getCurrentTime runDB $ insert_ $ Cashier amount
runDB $ insert_ $ Cashier amount currentTime
runDB $ insert_ trans runDB $ insert_ trans
getCashierBalance :: Handler Int getCashierBalance :: Handler Int
getCashierBalance = do getCashierBalance = do
mCashier <- runDB $ selectFirst [] [Desc CashierCreated] mCashier <- runDB $ selectFirst [] [Desc CashierId]
case mCashier of case mCashier of
Just cashier -> do Just cashier -> do
return $ cashierBalance $ entityVal cashier return $ cashierBalance $ entityVal cashier

View file

@ -10,16 +10,17 @@ getJournalR = do
rawEntries <- runDB $ selectList [] [Desc TransactionId, LimitTo 30] rawEntries <- runDB $ selectList [] [Desc TransactionId, LimitTo 30]
entries <- return $ L.reverse rawEntries entries <- return $ L.reverse rawEntries
total <- return $ L.sum $ I.map (transactionAmount . entityVal) entries total <- return $ L.sum $ I.map (transactionAmount . entityVal) entries
timeLimit <- return $ transactionTime $ entityVal $ L.last $ entries timeLimit <- return $ transactionTime $ entityVal $ L.head $ entries
cashiers <- runDB $ selectList [CashierCreated <=. timeLimit] [Asc CashierId] cashChecks <- runDB $ selectList [CashCheckTime >=. timeLimit] [Asc CashCheckId]
list <- return $ merge entries cashiers list <- return $ merge entries cashChecks
cashBalance <- getCashierBalance cashBalance <- getCashierBalance
defaultLayout $ do defaultLayout $ do
$(widgetFile "journal") $(widgetFile "journal")
merge :: [Entity Transaction] -> [Entity Cashier] -> [Either Transaction Cashier] merge :: [Entity Transaction] -> [Entity CashCheck] -> [Either Transaction CashCheck]
merge [] [] = [] merge [] [] = []
merge [] (c:cs) = (Right $ entityVal c) : merge [] cs
merge (t:ts) [] = (Left $ entityVal t) : merge ts [] merge (t:ts) [] = (Left $ entityVal t) : merge ts []
merge (t:ts) (c:cs) merge (t:ts) (c:cs)
| transactionTime (entityVal t) < cashierCreated (entityVal c) = (Left $ entityVal t) : merge ts (c:cs) | transactionTime (entityVal t) < cashCheckTime (entityVal c) = (Left $ entityVal t) : merge ts (c:cs)
| transactionTime (entityVal t) > cashierCreated (entityVal c) = (Right $ entityVal c) : merge (t:ts) cs | transactionTime (entityVal t) > cashCheckTime (entityVal c) = (Right $ entityVal c) : merge (t:ts) cs

View file

@ -20,7 +20,10 @@ Transaction
deriving Typeable Show deriving Typeable Show
Cashier Cashier
balance Int balance Int
created UTCTime default=now() deriving Typeable Show
CashCheck
balance Int
time UTCTime
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

@ -19,8 +19,8 @@ $if not $ L.null entries
$of Right cash $of Right cash
<tr #check> <tr #check>
<td colspan="2"> <td colspan="2">
Kassensturz vom #{formatTime defaultTimeLocale "%A %F %H:%M" $ cashierCreated cash}: Kassensturz vom #{formatTime defaultTimeLocale "%A %F %H:%M" $ cashCheckTime cash}:
<td>#{formatIntCurrency (cashierBalance cash)} #{appCurrency $ appSettings master} <td>#{formatIntCurrency (cashCheckBalance cash)} #{appCurrency $ appSettings master}
<tfoot> <tfoot>
<tr> <tr>
<td colspan="2">Gesamtbetrag: <td colspan="2">Gesamtbetrag: