More fun for the new server\!
[hcoop/portal.git] / money.sml
index 6372fd5..be65cb0 100644 (file)
--- a/money.sml
+++ b/money.sml
@@ -226,14 +226,32 @@ 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
+
+end