Most of lowering of pledges for delinquents
authorAdam Chlipala <adamc@hcoop.net>
Sun, 24 Feb 2008 17:11:02 +0000 (17:11 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sun, 24 Feb 2008 17:11:02 +0000 (17:11 +0000)
money.mlt
money.sig
money.sml

index 2af1635..9c50d10 100644 (file)
--- a/money.mlt
+++ b/money.mlt
@@ -459,6 +459,23 @@ elseif $"cmd" = "checkout" then
      (nil, nil) => %>No matches.<%
    end
 
+elseif $"cmd" = "delinq" then
+       showNormal := false;
+       val dqs = Money.delinquentPledgers () %>
+<table>
+<tr> <th>Member</th> <th>Pledge</th> <th>Balance</th> </tr>
+<% foreach dq in dqs do %>
+<tr> <td><a href="user?id=<% #id dq %>"><% #name dq %></a></td> <td><% #shares dq %></td> <td>$<% #balance dq %></td> </tr>
+<% end %>
+</table>
+
+<a href="?lower=<% String.concatWith "," (List.map (fn dq => Int.toString (#id dq)) dqs) %>">Lower these pledges to 1</a>
+
+<% elseif $"lower" <> "" then
+   Money.resetPledges (List.map Web.stoi (String.tokens (fn ch => ch = #",") ($"lower")))
+
+   %><h3>Pledges reset.</h3><%
+
 end %>
 
 <% if showNormal then
@@ -480,6 +497,7 @@ Deposit: $<% deposit %></b> (3 months of dues at your current <a href="pledge">p
 
 <% if (Group.inGroupName "money" and $"lookback" = "") or $"audit" <> "" then %>
 
+<a href="?cmd=delinq">Drop pledges of delinquent members</a><br>
 <a href="?lookback=20">Switch to regular member view</a><br>
 
 <br><b><u>New transaction:</u></b><br>
index 235c3d8..087666d 100644 (file)
--- a/money.sig
+++ b/money.sig
@@ -33,4 +33,7 @@ sig
     val equalizeBalances : unit -> unit
 
     val costBase : real -> real
+
+    val delinquentPledgers : unit -> { id : int, name : string, shares : int, balance : real } list
+    val resetPledges : int list -> unit
 end
index f4423ac..1b569c8 100644 (file)
--- a/money.sml
+++ b/money.sml
@@ -273,4 +273,25 @@ fun costBase amt =
        [share] => C.realFromSql share
       | row => Init.rowError ("Bad costBase result", row)
 
+val monthlyCost = 900.0
+val graceMonths = 1
+
+fun delinquentPledgers () =
+    let
+       val costBase = costBase monthlyCost
+
+       fun makeRow [id, name, shares, amount] = {id = C.intFromSql id, name = C.stringFromSql name,
+                                                 shares = C.intFromSql shares, balance = C.realFromSql amount}
+         | makeRow row = Init.rowError ("Bad delinquentPledgers", row)
+    in
+       C.map (getDb ()) makeRow ($`SELECT WebUserPaying.id, WebUserPaying.name, shares, amount
+                                   FROM WebUserPaying JOIN Balance ON Balance.id = bal
+                                   WHERE amount < shares * ^(C.realToSql costBase) * ^(C.intToSql graceMonths)
+                                     AND shares > 1
+                                   ORDER BY name`)
+    end
+
+fun resetPledges ids =
+    raise Fail ($`UPDATE WebUser SET shares = 1 WHERE id IN (^(String.concatWith ", " (List.map C.intToSql ids)))`)
+
 end