Change granter.sh to give permissions to user specified on command line
[hcoop/zz_old/portal.git] / money.sml
index 6372fd5..4689491 100644 (file)
--- a/money.sml
+++ b/money.sml
@@ -86,7 +86,7 @@ val mkUserRow' =
      | row => Init.rowError ("listUsers", row)
 
 fun listUsers trn =
-    C.map (getDb ()) mkUserRow' ($`SELECT trn, id, name, rname, bal, joined, app
+    C.map (getDb ()) mkUserRow' ($`SELECT trn, id, name, rname, bal, joined, app, shares
                                   FROM WebUser LEFT OUTER JOIN Charge ON usr = id AND trn = ^(C.intToSql trn)
                                   ORDER BY name`)
 
@@ -226,14 +226,37 @@ fun addHostingCharges {trn, cutoff, cost, usage} =
                addCharge {trn = trn, usr = #id usr, amount = charge};
                umap
            end
+
+       val _ = if SM.numItems (foldl doUser umap payers) = 0 then
+                   applyCharges trn
+               else
+                   raise Fail "Usage description contains an unknown username"
+
+       val usageFile = TextIO.openOut (Init.scratchDir ^ "/usage/" ^ Int.toString trn)
     in
-       if SM.numItems (foldl doUser umap payers) = 0 then
-           applyCharges trn
-       else
-           raise Fail "Usage description contains an unknown username"
+       TextIO.output (usageFile, usage);
+       TextIO.closeOut usageFile
     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
+fun lookupHostingUsage trn =
+    let
+       val usageFile = TextIO.openIn (Init.scratchDir ^ "/usage/" ^ Int.toString trn)
+
+       fun loop acc =
+           case TextIO.inputLine usageFile of
+               NONE => String.concat (List.rev acc)
+             | SOME line => loop (line :: acc)
+    in
+       SOME (loop [])
+       before TextIO.closeIn usageFile
+    end handle _ => NONE
+
+fun costBase amt =
+    case C.oneRow (getDb ()) ($`SELECT ^(C.realToSql amt) / SUM(shares) FROM WebUserPaying`) of
+       [share] => C.realFromSql share
+      | row => Init.rowError ("Bad costBase result", row)
+
+end