X-Git-Url: https://git.hcoop.net/hcoop/portal.git/blobdiff_plain/4ac8f6393ed3c9f055168063490fc7503fb71762..e84aceccd570655fbd36593ca20302456e1b501a:/money.sml diff --git a/money.sml b/money.sml index 6372fd5..be65cb0 100644 --- 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