moved stuff around, added probelematic field to transactions
This commit is contained in:
@ -76,8 +76,10 @@ getUpdateR = loginOrDo (\(uid,user) -> do
|
||||
runDB $ rawExecute sql [toPersistValue uid]
|
||||
-- calculate profits
|
||||
runDB $ do
|
||||
trans <- updateProfits <$> selectList [TransactionUser ==. uid, TransactionInStock !=. 0] [Asc TransactionDateTime]
|
||||
trans <- updateProfits <$> selectList [TransactionUser ==. uid, TransactionInStock !=. 0, TransactionProblematic ==. False] [Asc TransactionDateTime]
|
||||
mapM_ (\(Entity eid t) -> replace eid t) trans
|
||||
let updateProblemSql = "update transaction t set problematic=true where t.trans_is_sell and t.in_stock < 0"
|
||||
runDB $ rawExecute updateProblemSql []
|
||||
redirect WalletR
|
||||
)
|
||||
|
||||
@ -131,7 +133,7 @@ migrateTransaction :: UserId -> WT.Transaction -> Transaction
|
||||
migrateTransaction u (WT.Transaction dt tid q tn ti pc ci cn si sn tt tf jti) =
|
||||
Transaction u dt tid q (if tis tt then -q else q) tn ti
|
||||
(fromIntegral pc) ci cn si sn (tis tt) (tfc tf) jti
|
||||
Nothing Nothing Nothing Nothing False
|
||||
Nothing Nothing Nothing Nothing False False
|
||||
where
|
||||
tis :: WT.TransactionType -> Bool
|
||||
tis WT.Sell = True
|
||||
|
@ -5,7 +5,6 @@ module Handler.Wallet where
|
||||
|
||||
import Import
|
||||
|
||||
import Data.List (unfoldr)
|
||||
import Data.Time.Clock
|
||||
import Text.Printf
|
||||
import Database.Persist.Sql
|
||||
@ -89,7 +88,7 @@ getWalletDetailsR hrs days = loginOrDo (\(uid,user) -> do
|
||||
<th .text-center>
|
||||
$forall Entity _ t <- trans
|
||||
<tr>
|
||||
<td>#{show $ utctDay $ transactionDateTime $ t} #{showTime $ round $ utctDayTime $ transactionDateTime $ t}
|
||||
<td>#{showDateTime $ transactionDateTime $ t}
|
||||
$if transactionTransForCorp t
|
||||
<td .corpTransaction .text-center>C
|
||||
$else
|
||||
@ -182,21 +181,6 @@ profitPercent' p bf tt s = if s == 0 then Nothing
|
||||
profitPercent :: Int64 -> Transaction -> String
|
||||
profitPercent p t = printf "%.2f" $ (100*(fromIntegral p) / (fromIntegral (transactionQuantity t * transactionPriceCents t)) :: Double)
|
||||
|
||||
prettyISK :: Int64 -> String
|
||||
prettyISK isk = signIsk++pretty++","++ printf "%02u" cents
|
||||
where
|
||||
signIsk = if isk >= 0 then "" else "-"
|
||||
(isk',cents) = divMod (abs isk) 100
|
||||
thousands = unfoldr (\b -> if b == 0 then Nothing else Just (b `mod` 1000, b `div` 1000)) isk'
|
||||
pretty = case reverse thousands of
|
||||
(ht:t) -> intercalate "." $ [show ht] ++ (printf "%03u" <$> t)
|
||||
[] -> "0"
|
||||
|
||||
showTime :: Int64 -> String
|
||||
showTime t = printf "%2u" hours ++ ":" ++ printf "%02u" minutes ++ ":" ++ printf "%02u" seconds
|
||||
where
|
||||
(hours, minutes') = divMod t 3600
|
||||
(minutes, seconds) = divMod minutes' 60
|
||||
|
||||
showSecsToSell :: Int64 -> String
|
||||
showSecsToSell t
|
||||
|
Reference in New Issue
Block a user