2015-09-17 22:41:37 +00:00
|
|
|
module Handler.Item where
|
|
|
|
|
|
|
|
import Import
|
|
|
|
|
|
|
|
itemsPerPage :: Int
|
|
|
|
itemsPerPage = 100
|
|
|
|
|
|
|
|
getItemR :: Int64 -> Handler Html
|
2015-09-17 23:08:15 +00:00
|
|
|
getItemR transactionTypeId = getItemPagedR transactionTypeId 1
|
2015-09-17 22:41:37 +00:00
|
|
|
|
|
|
|
getItemPagedR :: Int64 -> Int -> Handler Html
|
2015-09-17 23:08:15 +00:00
|
|
|
getItemPagedR tid page
|
|
|
|
| page < 1 = getItemPagedR tid 1
|
|
|
|
| otherwise = loginOrDo (\(uid,user) -> do
|
|
|
|
items <- runDB $ selectList [TransactionTypeId ==. tid] [Desc TransactionDateTime, LimitTo itemsPerPage, OffsetBy (itemsPerPage*(page-1))]
|
2015-09-17 22:41:37 +00:00
|
|
|
total <- runDB $ count [TransactionTypeId ==. tid]
|
|
|
|
let offset = itemsPerPage * page
|
2015-09-17 23:08:15 +00:00
|
|
|
let maxPages = total `div` itemsPerPage
|
|
|
|
let paginatePages = [1..maxPages+1]
|
2015-09-17 22:41:37 +00:00
|
|
|
loginLayout user $ [whamlet|
|
|
|
|
<div .panel .panel-default>
|
|
|
|
$if page > 0
|
2015-09-17 23:08:15 +00:00
|
|
|
<div .panel-heading>#{itemsPerPage} Transactions (starting at #{offset}) of #{total}
|
2015-09-17 22:41:37 +00:00
|
|
|
$else
|
2015-09-17 23:08:15 +00:00
|
|
|
<div .panel-heading>#{itemsPerPage} Transactions of #{total}
|
2015-09-17 22:41:37 +00:00
|
|
|
<table .table .table-condensed .small>
|
|
|
|
<tr>
|
|
|
|
<th .text-center>Time
|
|
|
|
<th .text-center>P/C
|
|
|
|
<th .text-center>B/S
|
|
|
|
<th .text-center>Item
|
|
|
|
<th .text-center>##
|
|
|
|
<th .text-center>ISK/Item
|
|
|
|
<th .text-center>ISK total
|
|
|
|
<th .text-center>ISK profit
|
|
|
|
<th .text-center>%
|
|
|
|
<th .text-center>Time
|
|
|
|
<th .text-center>Client
|
|
|
|
<th .text-center>Station
|
|
|
|
<th .text-center>?
|
|
|
|
<th .text-center>
|
|
|
|
$forall Entity _ t <- items
|
|
|
|
<tr>
|
|
|
|
<td>#{showDateTime $ transactionDateTime $ t}
|
|
|
|
$if transactionTransForCorp t
|
|
|
|
<td .corpTransaction .text-center>C
|
|
|
|
$else
|
|
|
|
<td .personalTransaction .text-center>P
|
|
|
|
$if transactionTransIsSell t
|
|
|
|
<td .sellTransaction .text-center>S
|
|
|
|
$else
|
|
|
|
<td .buyTransaction .text-center>B
|
|
|
|
<td>#{transactionTypeName t}
|
|
|
|
<td .numeric>#{transactionQuantity t}
|
|
|
|
<td .numeric>#{prettyISK $ transactionPriceCents t}
|
|
|
|
<td .numeric>#{prettyISK $ transactionQuantity t * transactionPriceCents t}
|
|
|
|
$maybe profit <- transRealProfit t
|
|
|
|
$if (&&) (transactionTransIsSell t) (profit > 0)
|
|
|
|
<td .numeric .profit>
|
|
|
|
#{prettyISK $ profit}
|
|
|
|
$elseif (&&) (transactionTransIsSell t) (profit < 0)
|
|
|
|
<td .numeric .loss>
|
|
|
|
#{prettyISK $ profit}
|
|
|
|
$elseif not (transactionTransIsSell t)
|
|
|
|
<td .numeric .buyfee>
|
|
|
|
#{prettyISK $ profit}
|
|
|
|
$else
|
|
|
|
<td .numeric>
|
|
|
|
#{prettyISK $ profit}
|
|
|
|
<td .numeric>
|
|
|
|
#{profitPercent profit t}%
|
|
|
|
$nothing
|
|
|
|
<td>
|
|
|
|
-
|
|
|
|
<td>
|
|
|
|
<td .duration>
|
|
|
|
$maybe secs <- transactionSecondsToSell t
|
|
|
|
#{showSecsToSell secs}
|
|
|
|
$nothing
|
|
|
|
|
|
|
|
<td>#{transactionClientName t}
|
|
|
|
<td>#{transactionStationName t}
|
|
|
|
<td>
|
|
|
|
<td>
|
2015-09-17 23:08:15 +00:00
|
|
|
<ul class="pagination">
|
|
|
|
$forall p <- paginatePages
|
|
|
|
$if p == page
|
|
|
|
<li .active><a href="@{ItemPagedR tid p}">#{p}</a>
|
|
|
|
$else
|
|
|
|
<li><a href="@{ItemPagedR tid p}">#{p}</a>
|
2015-09-17 22:41:37 +00:00
|
|
|
|]
|
|
|
|
)
|
|
|
|
|