added journal pagination

This commit is contained in:
nek0 2015-09-07 18:15:30 +02:00
parent dc68d0fd69
commit 7a08a78b8c
6 changed files with 40 additions and 1 deletions

View File

@ -23,6 +23,7 @@ getJournalR :: Handler Html
getJournalR = do
master <- getYesod
rawEntries <- runDB $ selectList [] [Desc TransactionId]
next <- runDB $ selectList [] [Desc TransactionId, OffsetBy 30]
entries <- return $ L.reverse $ L.take 30 rawEntries
total <- return $ L.sum $ I.map (transactionAmount . entityVal) rawEntries
timeLimit <- case L.null entries of
@ -41,3 +42,20 @@ merge (t:ts) [] = (Left $ entityVal t) : merge ts []
merge (t:ts) (c: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
getJournalPageR :: Int -> Handler Html
getJournalPageR p = do
master <- getYesod
rawEntries <- runDB $ selectList [] [Desc TransactionId, OffsetBy (p * 30)]
next <- runDB $ selectList [] [Desc TransactionId, OffsetBy ((p + 1) * 30)]
entries <- return $ L.reverse $ L.take 30 rawEntries
lTimeLimit <- case L.null entries of
False -> return $ transactionTime $ entityVal $ L.head $ entries
True -> liftIO getCurrentTime
uTimeLimit <- case L.null entries of
False -> return $ transactionTime $ entityVal $ L.last $ entries
True -> liftIO getCurrentTime
cashChecks <- runDB $ selectList [CashCheckTime >=. lTimeLimit, CashCheckTime <. uTimeLimit] [Asc CashCheckId]
list <- return $ merge entries cashChecks
defaultLayout $ do
$(widgetFile "journalPage")

View File

@ -17,6 +17,7 @@
/user/#UserId/buy/#BeverageId BuyR GET POST
!/user/cash/buy/#BeverageId BuyCashR GET POST
/journal JournalR GET
/journal/#Int JournalPageR GET
/payout PayoutR GET POST
/summary SummaryR GET
/summary.json SummaryJsonR GET

View File

@ -113,3 +113,5 @@ TransferTo: Guthaben transferieren an
NegativeTransfer: Keine negativen Beträge transferieren
TransferComplete: Transfer abgeschlossen
TransferError: Fehler beim Transfer
PreviousPage: vorherige Seite
NextPage: nächste Seite

View File

@ -113,3 +113,5 @@ TransferTo: Transfer credit to
NegativeTransfer: Please do not transfer negative amounts
TransferComplete: Transfer complete
TransferError: Transfer error
PreviousPage: previous page
NextPage: next page

View File

@ -19,6 +19,18 @@
text-align: right;
}
.left {
display: inline-block;
/*float: left;*/
padding: 2em;
}
.right {
display: inline-block;
/*float: right;*/
padding: 2em;
}
article#func.article {
background-color: #fff7bd;
}
@ -262,4 +274,4 @@ input[type] {
}
#barcodeContent {
text-align: center;
}
}

View File

@ -27,6 +27,10 @@ $if not $ L.null entries
<td>#{formatIntCurrency (fromIntegral total)} #{appCurrency $ appSettings master}
<p>
_{MsgCashStock}: #{formatIntCurrency (fromIntegral cashBalance)} #{appCurrency $ appSettings master}
$if not $ L.null next
<div>
<div .right>
<a href="@{JournalPageR 1}">_{MsgNextPage}
<ul>
<li>