2015-04-26 20:18:24 +00:00
|
|
|
module Handler.Wallet where
|
|
|
|
|
|
|
|
import Import
|
|
|
|
|
2015-08-07 21:41:37 +00:00
|
|
|
import Data.List (unfoldr)
|
2015-08-06 22:07:48 +00:00
|
|
|
import Data.Time.Clock
|
2015-08-07 21:41:37 +00:00
|
|
|
import Text.Printf
|
2015-07-24 19:12:18 +00:00
|
|
|
|
2015-04-26 20:18:24 +00:00
|
|
|
getWalletR :: Handler Html
|
2015-08-06 22:07:48 +00:00
|
|
|
getWalletR = getWalletDetailsR 6 7
|
|
|
|
|
|
|
|
getWalletDetailsR :: Int64 -> Int64 -> Handler Html
|
|
|
|
getWalletDetailsR hrs days = loginOrDo (\(uid,user) -> do
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
trans <- runDB $ selectList [TransactionDateTime >. (addUTCTime ((fromIntegral $ -(hrs*3600)) :: NominalDiffTime) now)] [Desc TransactionDateTime]
|
2015-07-20 20:10:30 +00:00
|
|
|
defaultLayout $ [whamlet|
|
2015-08-06 22:07:48 +00:00
|
|
|
<a href=@{WalletDetailsR 168 days}>show last 7 days
|
|
|
|
<h1>Transactions in the last #{hrs} hours
|
2015-08-07 21:41:37 +00:00
|
|
|
<table .table>
|
2015-08-07 00:26:16 +00:00
|
|
|
<tr>
|
|
|
|
<th>Time
|
2015-08-07 21:41:37 +00:00
|
|
|
<th>P/C
|
|
|
|
<th>B/S
|
|
|
|
<th>Item
|
|
|
|
<th>Quantity
|
|
|
|
<th>ISK/Item
|
|
|
|
<th>ISK total
|
|
|
|
<th>ISK profit
|
|
|
|
<th>%
|
|
|
|
<th>Time
|
|
|
|
<th>Client
|
|
|
|
<th>Station
|
|
|
|
<th>?
|
|
|
|
<th>
|
2015-08-06 22:07:48 +00:00
|
|
|
$forall Entity _ t <- trans
|
|
|
|
<tr>
|
2015-08-07 21:41:37 +00:00
|
|
|
<td>#{show $ utctDay $ transactionDateTime $ t} #{show $ utctDayTime $ transactionDateTime $ t}
|
|
|
|
$if transactionTransForCorp t
|
|
|
|
<td .corpTransaction>C
|
|
|
|
$else
|
|
|
|
<td .personalTransaction>P
|
|
|
|
$if transactionTransIsSell t
|
|
|
|
<td .sellTransaction>S
|
|
|
|
$else
|
|
|
|
<td .buyTransaction>B
|
|
|
|
<td>#{transactionTypeName t}
|
|
|
|
<td>#{transactionQuantity t}
|
|
|
|
<td>#{prettyISK $ transactionPriceCents t}
|
|
|
|
<td>#{prettyISK $ transactionQuantity t * transactionPriceCents t}
|
|
|
|
$maybe profit <- transRealProfit t
|
|
|
|
<td>
|
|
|
|
#{prettyISK $ profit}
|
|
|
|
<td>
|
|
|
|
#{profitPercent profit t}
|
|
|
|
$nothing
|
|
|
|
<td>
|
|
|
|
-
|
|
|
|
<td>
|
2015-08-07 00:26:16 +00:00
|
|
|
<td>
|
2015-08-07 21:41:37 +00:00
|
|
|
$maybe secs <- transactionSecondsToSell t
|
|
|
|
#{secs}
|
2015-08-07 00:26:16 +00:00
|
|
|
$nothing
|
2015-08-07 21:41:37 +00:00
|
|
|
|
|
|
|
<td>#{transactionClientName t}
|
|
|
|
<td>#{transactionStationName t}
|
|
|
|
<td>
|
|
|
|
<td>
|
2015-07-20 20:10:30 +00:00
|
|
|
|
2015-08-06 22:07:48 +00:00
|
|
|
<h1>Statistices for the last #{days} days
|
2015-07-24 19:12:18 +00:00
|
|
|
|]
|
|
|
|
)
|
2015-07-20 20:10:30 +00:00
|
|
|
|
2015-08-07 00:26:16 +00:00
|
|
|
transRealProfit :: Transaction -> Maybe Int64
|
|
|
|
transRealProfit t = (\a b c -> a - b - c) <$> transactionProfit t <*> transactionFee t <*> transactionTax t
|
2015-08-07 21:41:37 +00:00
|
|
|
|
|
|
|
profitPercent :: Int64 -> Transaction -> String
|
|
|
|
profitPercent p t = printf "%.2f" $ (100*(fromIntegral p) / (fromIntegral (transactionQuantity t * transactionPriceCents t)) :: Double)
|
|
|
|
|
|
|
|
prettyISK :: Int64 -> String
|
|
|
|
prettyISK isk = pretty++","++ printf "%02u" cents
|
|
|
|
where
|
|
|
|
(isk',cents) = divMod isk 100
|
|
|
|
thousands = unfoldr (\b -> if b == 0 then Nothing else Just (b `mod` 1000, b `div` 1000)) isk'
|
|
|
|
(ht:t) = reverse thousands
|
|
|
|
pretty = intercalate "." $ [show ht] ++ (printf "%03u" <$> t)
|
|
|
|
|
|
|
|
|