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

View File

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

View File

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

View File

@ -20,7 +20,10 @@ Transaction
deriving Typeable Show
Cashier
balance Int
created UTCTime default=now()
deriving Typeable Show
CashCheck
balance Int
time UTCTime
deriving Typeable Show
-- 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
<tr #check>
<td colspan="2">
Kassensturz vom #{formatTime defaultTimeLocale "%A %F %H:%M" $ cashierCreated cash}:
<td>#{formatIntCurrency (cashierBalance cash)} #{appCurrency $ appSettings master}
Kassensturz vom #{formatTime defaultTimeLocale "%A %F %H:%M" $ cashCheckTime cash}:
<td>#{formatIntCurrency (cashCheckBalance cash)} #{appCurrency $ appSettings master}
<tfoot>
<tr>
<td colspan="2">Gesamtbetrag: