Fix some money bugs and add equalizeBalances
authorAdam Chlipala <adamc@hcoop.net>
Tue, 17 May 2005 19:24:55 +0000 (19:24 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Tue, 17 May 2005 19:24:55 +0000 (19:24 +0000)
money.mlt
money.sig
money.sml

index a0994f0..1e1f692 100644 (file)
--- a/money.mlt
+++ b/money.mlt
@@ -255,6 +255,11 @@ end %></td> </tr>
        Money.deleteTransaction id %>
        <h3><b><% Web.html (#descr trn) %> deleted!</b></h3>
 
+<% elseif $"cmd" = "equalize" then
+       Group.requireGroupName "money";
+       Money.equalizeBalances ();
+       %><h3><b>Balances equalized</b></h3>
+
 <% elseif $"trn" <> "" then
        showNormal := false;
        val id = Web.stoi ($"trn");
@@ -290,6 +295,8 @@ end %>
 <a href="money?cmd=hosting">Hosting bill</a><br>
 <a href="money?cmd=pay">Payment from member</a><br>
 <a href="money?cmd=evenForm">Generic/even</a><br>
+<br>
+<a href="money?cmd=equalize">Equalize balances</a><br>
 
 <h3><b>Most recent transactions</b></h3>
 
index 7ec8b7b..185ec4c 100644 (file)
--- a/money.sig
+++ b/money.sig
@@ -27,4 +27,6 @@ sig
 
     type hosting = {trn : int, cutoff : int, cost : real, usage : string}
     val addHostingCharges : hosting -> unit
+
+    val equalizeBalances : unit -> unit
 end
\ No newline at end of file
index 056b051..4a4adb7 100644 (file)
--- a/money.sml
+++ b/money.sml
@@ -204,7 +204,7 @@ fun addHostingCharges {trn, cutoff, cost, usage} =
                        in
                            walkNvs (rest,
                                     SM.insert (umap, name, extra),
-                                    amount - extra)
+                                    amount + extra)
                        end
                    else
                        walkNvs (rest, umap, amount)
@@ -221,7 +221,7 @@ fun addHostingCharges {trn, cutoff, cost, usage} =
                val (charge, umap) =
                    case SM.find (umap, #name usr) of
                        NONE => (even, umap)
-                     | SOME extra => (even + extra, #1 (SM.remove (umap, #name usr)))
+                     | SOME extra => (even - extra, #1 (SM.remove (umap, #name usr)))
            in
                addCharge {trn = trn, usr = #id usr, amount = charge};
                umap
@@ -232,4 +232,8 @@ fun addHostingCharges {trn, cutoff, cost, usage} =
        else
            raise Fail "Usage description contains an unknown username"
     end
+
+fun equalizeBalances () =
+    ignore (C.dml (getDb ()) ($`UPDATE Balance SET amount = (SELECT SUM(amount) FROM Charge JOIN WebUser ON usr = WebUser.id WHERE bal = Balance.id)`))
+
 end
\ No newline at end of file