2015-04-04 04:46:33 +00:00
|
|
|
module Handler.Journal where
|
|
|
|
|
|
|
|
import Import as I
|
|
|
|
import Data.List as L
|
|
|
|
import Handler.Common
|
|
|
|
|
|
|
|
getJournalR :: Handler Html
|
|
|
|
getJournalR = do
|
2015-04-04 06:25:10 +00:00
|
|
|
master <- getYesod
|
2015-04-09 19:39:39 +00:00
|
|
|
rawEntries <- runDB $ selectList [] [Desc TransactionId, LimitTo 30]
|
|
|
|
entries <- return $ L.reverse rawEntries
|
2015-04-04 04:46:33 +00:00
|
|
|
total <- return $ L.sum $ I.map (transactionAmount . entityVal) entries
|
2015-04-09 19:39:39 +00:00
|
|
|
timeLimit <- return $ transactionTime $ entityVal $ L.last $ entries
|
|
|
|
cashiers <- runDB $ selectList [CashierCreated <=. timeLimit] [Asc CashierId]
|
|
|
|
list <- return $ merge entries cashiers
|
2015-04-04 04:46:33 +00:00
|
|
|
cashBalance <- getCashierBalance
|
|
|
|
defaultLayout $ do
|
|
|
|
$(widgetFile "journal")
|
2015-04-09 19:39:39 +00:00
|
|
|
|
|
|
|
merge :: [Entity Transaction] -> [Entity Cashier] -> [Either Transaction Cashier]
|
|
|
|
merge [] [] = []
|
|
|
|
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
|