{-# LANGUAGE ScopedTypeVariables #-} module Handler.Orders where import Import import Database.Persist.Sql import qualified Eve.Api.Char.MarketOrders as MO getOrdersR :: Handler Html getOrdersR = loginOrDo (\(uid,user) -> do -- using raw because model does not know about CCP-Data-Dump let sql = "select ??, t.\"typeName\", s.\"stationName\", s.\"regionID\" from \"order\" join \"invTypes\" t on (\"order\".type_id = t.\"typeID\") join \"staStations\" s on (\"order\".station_id = s.\"stationID\") where \"user\"=? order by \"order\".is_sell asc, t.\"typeName\" asc" (orders :: [(Entity Order, Single Text, Single Text, Single Text)]) <- runDB $ rawSql sql [toPersistValue uid] let f = \(a,_,_,_) -> a let sellorders = filter (\(Entity _ o, _, _, _) -> orderIsSell o && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders let sellsum = foldl' sumOrders 0 (f <$> sellorders) let sellescrow = foldl' sumEscrow 0 (f <$> sellorders) let buyorders = filter (\(Entity _ o, _, _, _) -> not (orderIsSell o) && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders let buysum = foldl' sumOrders 0 (f <$> buyorders) let buyescrow = foldl' sumEscrow 0 (f <$> buyorders) loginLayout user [whamlet|