added journal pagination

forgot template file
This commit is contained in:
nek0 2015-09-07 18:15:30 +02:00
parent dc68d0fd69
commit 522da12175
7 changed files with 77 additions and 1 deletions

View file

@ -23,6 +23,7 @@ getJournalR :: Handler Html
getJournalR = do getJournalR = do
master <- getYesod master <- getYesod
rawEntries <- runDB $ selectList [] [Desc TransactionId] rawEntries <- runDB $ selectList [] [Desc TransactionId]
next <- runDB $ selectList [] [Desc TransactionId, OffsetBy 30]
entries <- return $ L.reverse $ L.take 30 rawEntries entries <- return $ L.reverse $ L.take 30 rawEntries
total <- return $ L.sum $ I.map (transactionAmount . entityVal) rawEntries total <- return $ L.sum $ I.map (transactionAmount . entityVal) rawEntries
timeLimit <- case L.null entries of timeLimit <- case L.null entries of
@ -41,3 +42,20 @@ merge (t:ts) [] = (Left $ entityVal t) : merge ts []
merge (t:ts) (c:cs) merge (t:ts) (c:cs)
| transactionTime (entityVal t) < cashCheckTime (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) > cashCheckTime (entityVal c) = (Right $ entityVal c) : merge (t:ts) 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/#UserId/buy/#BeverageId BuyR GET POST
!/user/cash/buy/#BeverageId BuyCashR GET POST !/user/cash/buy/#BeverageId BuyCashR GET POST
/journal JournalR GET /journal JournalR GET
/journal/#Int JournalPageR GET
/payout PayoutR GET POST /payout PayoutR GET POST
/summary SummaryR GET /summary SummaryR GET
/summary.json SummaryJsonR GET /summary.json SummaryJsonR GET

View file

@ -113,3 +113,5 @@ TransferTo: Guthaben transferieren an
NegativeTransfer: Keine negativen Beträge transferieren NegativeTransfer: Keine negativen Beträge transferieren
TransferComplete: Transfer abgeschlossen TransferComplete: Transfer abgeschlossen
TransferError: Fehler beim Transfer 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 NegativeTransfer: Please do not transfer negative amounts
TransferComplete: Transfer complete TransferComplete: Transfer complete
TransferError: Transfer error TransferError: Transfer error
PreviousPage: previous page
NextPage: next page

View file

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

View file

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

View file

@ -0,0 +1,37 @@
$doctype 5
<h3>Journal
$if not $ L.null entries
<table>
<thead>
<tr>
<th>_{MsgTime}
<th>_{MsgDescription}
<th>_{MsgValueIn $ appCurrency $ appSettings master}
$forall (eTransCash) <- list
$case eTransCash
$of Left trans
<tr>
<td>#{formatTime defaultTimeLocale "%A %F %H:%M" $ transactionTime trans}
<td>#{transactionDescription trans}
<td>#{formatIntCurrency (transactionAmount trans)} #{appCurrency $ appSettings master}
$of Right cash
<tr #check>
<td colspan="2">
_{MsgCashCheckOf $ formatTime defaultTimeLocale "%A %F %H:%M" $ cashCheckTime cash}:
<td>#{formatIntCurrency (cashCheckBalance cash)} #{appCurrency $ appSettings master}
<div>
<div .left>
$case (p <= 1)
$of True
<a href="@{JournalR}">_{MsgPreviousPage}
$of False
<a href="@{JournalPageR (p - 1)}">_{MsgPreviousPage}
$if not $ L.null next
<div .right>
<a href="@{JournalPageR (p + 1)}">_{MsgNextPage}
$else
<p>_{MsgNothingToShow}