release portal3 into production
[hcoop/portal.git] / balance.sml
index 5b0c684..59622de 100644 (file)
@@ -90,17 +90,34 @@ fun balanceNameToId name =
       | _ => NONE
 
 fun listBalanceUsers bal =
-    C.map (getDb ()) mkUserRow ($`SELECT id, name, rname, bal, joined, app, shares
+    C.map (getDb ()) mkUserRow ($`SELECT id, name, rname, bal, joined, app, shares, paypal, checkout
                                  FROM WebUser
                                  WHERE bal = ^(C.intToSql bal)
                                  ORDER BY name`)
 
 fun sumOwnedBalances () =
     case C.oneRow (getDb ()) ($`SELECT SUM(amount)
-                               FROM Balance JOIN WebUser
-                                 ON Balance.name = WebUser.name
-                                   AND WebUser.bal = Balance.id`) of
+                               FROM Balance JOIN WebUser
+                                 ON Balance.name = WebUser.name
+                                   AND WebUser.bal = Balance.id
+                               JOIN Membership
+                                 ON Membership.usr = WebUser.id
+                                   AND Membership.grp = 1`) of
        [amt] => C.realFromSql amt
       | _ => raise Fail "sumOwnedBalance: no rows"
 
+fun isNegative (bal : balance) = #amount bal < 0.0
+
+fun depositAmount _ = 7.0 * 3.0
+(*fun depositAmount bal =
+    let
+       val db = getDb ()
+
+       val totalShares = case C.oneRow db "SELECT SUM(shares) FROM WebUserPaying" of
+                             [n] => C.intFromSql n
+                           | row => Init.rowError ("Bad depositAmount share count result", row)
+    in
+       3.0 * 900.0 / real totalShares
+    end*)
+
 end