Support retiring balances of departed members
authoradamch <adamch>
Tue, 1 Nov 2005 14:54:55 +0000 (14:54 +0000)
committeradamch <adamch>
Tue, 1 Nov 2005 14:54:55 +0000 (14:54 +0000)
balance.sig
balance.sml
money.mlt
remind/remind.sml

index 9cd300a..6eb3349 100644 (file)
@@ -7,8 +7,9 @@ sig
     val modBalance : balance -> unit
     val deleteBalance : int -> unit
     val listBalances : unit -> balance list
+    val listOwnedBalances : unit -> balance list
     val listBalanceUsers : int -> Init.user list
 
     val validBalanceName : string -> bool
     val balanceNameToId : string -> int option
-end
\ No newline at end of file
+end
index 4e56812..bd5f4b0 100644 (file)
@@ -45,7 +45,14 @@ fun deleteBalance id =
 
 fun listBalances () =
     C.map (getDb ()) mkBalanceRow ($`SELECT id, name, amount FROM Balance
-                                  ORDER BY name`)
+                                    ORDER BY name`)
+
+fun listOwnedBalances () =
+    C.map (getDb ()) mkBalanceRow ($`SELECT Balance.id, Balance.name, amount
+                                    FROM Balance JOIN WebUser
+                                       ON Balance.name = WebUser.name
+                                          AND WebUser.bal = Balance.id
+                                    ORDER BY Balance.name`)
 
 fun validBalanceName name =
     size name <= 20
@@ -62,4 +69,4 @@ fun listBalanceUsers bal =
                                  WHERE bal = ^(C.intToSql bal)
                                  ORDER BY name`)
 
-end
\ No newline at end of file
+end
index 18a2765..c7756f5 100644 (file)
--- a/money.mlt
+++ b/money.mlt
@@ -40,7 +40,7 @@ end %>
 <h3><b>Balances</b></h3>
 
 <table>
-<% foreach bal in Balance.listBalances () do %>
+<% foreach bal in Balance.listOwnedBalances () do %>
 <tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
 <% switch Balance.listBalanceUsers (#id bal) of
          [] =>
index b1252c1..adfedf5 100644 (file)
@@ -12,7 +12,7 @@ fun main _ =
        fun getEmail [name] = C.stringFromSql name ^ emailSuffix
          | getEmail row = raise Fail "remind getName"
 
-       val names = C.map db getEmail "SELECT WebUser.name FROM WebUser JOIN Balance ON Balance.name = WebUser.name WHERE amount < 10"
+       val names = C.map db getEmail "SELECT WebUser.name FROM WebUser JOIN Balance ON Balance.name = WebUser.name AND bal = Balance.id WHERE amount < 10"
 
        val m = Mail.mopen ()
     in