Subtract deposit amounts from displayed balances
authorAdam Chlipala <adamc@hcoop.net>
Mon, 18 Feb 2008 17:46:05 +0000 (17:46 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Mon, 18 Feb 2008 17:46:05 +0000 (17:46 +0000)
balance.sig
balance.sml
init.sml
money.mlt
portal.mlt
util.sig
util.sml

index 2ce2b47..7d47b90 100644 (file)
@@ -1,6 +1,6 @@
 signature BALANCE =
 sig
-    type balance = {id :int, name : string, amount : real}
+    type balance = {id : int, name : string, amount : real}
 
     val addBalance : string -> int
     val lookupBalance : int -> balance
@@ -17,4 +17,6 @@ sig
 
     val sumOwnedBalances : unit -> real
     val isNegative : balance -> bool
+
+    val depositAmount : int -> real
 end
index 98c8657..505cf47 100644 (file)
@@ -105,4 +105,19 @@ fun sumOwnedBalances () =
 
 fun isNegative (bal : balance) = #amount bal < 0.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
+       case C.oneRow db ($`SELECT 3.0 * 900.0 * SUM(shares) / ^(C.intToSql totalShares)
+                           FROM WebUserPaying
+                           WHERE bal = ^(C.intToSql bal)`) of
+           [amount] => C.realFromSql amount
+         | row => Init.rowError ("Bad depositAmount result", row)
+    end
+
 end
index cd066b1..b4d537b 100644 (file)
--- a/init.sml
+++ b/init.sml
@@ -151,7 +151,7 @@ fun modUser (user : user) =
 
 fun byPledge () =
     C.map (getDb ()) mkUserRow ($`SELECT id, name, rname, bal, joined, app, shares, paypal, checkout
-                                 FROM WebUser
+                                 FROM WebUserPaying
                                  WHERE shares > 1
                                  ORDER BY shares DESC, name`)
 
index cbc7a6f..e7413e5 100644 (file)
--- a/money.mlt
+++ b/money.mlt
@@ -461,9 +461,13 @@ elseif $"cmd" = "checkout" then
 
 end %>
 
-<% if showNormal then %>
+<% if showNormal then
+   val you = Init.getUser();
+   val bal = Balance.lookupBalance (#bal you);
+   val deposit = Balance.depositAmount (#id bal) %>
 
-<h3>Your balance: $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %></h3>
+<h3>Your balance: $<% Util.sub (#amount bal, deposit) %><br>
+Deposit: $<% deposit %></b> (3 months of dues at your current <a href="pledge">pledge level</a>)</h3>
 <% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %><h3>Sum of all active balances: $<% Balance.sumOwnedBalances () %></h3><% end %>
 
 <a href="money?cmd=list">List all transactions</a><br>
index 3492692..03d8dbd 100644 (file)
@@ -1,5 +1,6 @@
 <% val you = Init.getUser();
 val bal = Balance.lookupBalance (#bal you);
+val deposit = Balance.depositAmount (#id bal);
 @header [] %>
 
 <% @payment [] %>
@@ -12,7 +13,8 @@ val bal = Balance.lookupBalance (#bal you);
 <tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
 <% end %>
 </table>
-<b>Balance: $<% #amount bal %></b>
+<b>Balance: $<% Util.sub (#amount bal, deposit) %></b><br>
+<b>Deposit: $<% deposit %></b> (3 months of dues at your current <a href="pledge">pledge level</a>)
 
 <% val polls = Poll.listCurrentPolls ();
 switch polls of
index 71abe39..d6f9d5c 100644 (file)
--- a/util.sig
+++ b/util.sig
@@ -15,6 +15,7 @@ sig
     val makeSet : ('a -> string) -> 'a list -> string
     val neg : real -> real
     val add : real * real -> real
+    val sub : real * real -> real
     val mult : int * real -> real
 
     val validHost : string -> bool
index 2193512..07793bb 100644 (file)
--- a/util.sml
+++ b/util.sml
@@ -29,6 +29,7 @@ fun makeSet f items =
 
 fun neg (r : real) = ~r
 fun add (r1 : real, r2) = r1 + r2
+fun sub (r1 : real, r2) = r1 - r2
 fun mult (r1, r2) = real r1 * r2
 
 fun isIdent ch = Char.isLower ch orelse Char.isDigit ch orelse ch = #"-"