From 466c59448d7bb1abee78e7f3f231be194e73b5ea Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Mon, 18 Feb 2008 17:46:05 +0000 Subject: [PATCH] Subtract deposit amounts from displayed balances --- balance.sig | 4 +++- balance.sml | 15 +++++++++++++++ init.sml | 2 +- money.mlt | 8 ++++++-- portal.mlt | 4 +++- util.sig | 1 + util.sml | 1 + 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/balance.sig b/balance.sig index 2ce2b47..7d47b90 100644 --- a/balance.sig +++ b/balance.sig @@ -1,6 +1,6 @@ signature BALANCE = sig - type balance = {id :int, name : string, amount : real} + type balance = {id : int, name : string, amount : real} val addBalance : string -> int val lookupBalance : int -> balance @@ -17,4 +17,6 @@ sig val sumOwnedBalances : unit -> real val isNegative : balance -> bool + + val depositAmount : int -> real end diff --git a/balance.sml b/balance.sml index 98c8657..505cf47 100644 --- a/balance.sml +++ b/balance.sml @@ -105,4 +105,19 @@ fun sumOwnedBalances () = fun isNegative (bal : balance) = #amount bal < 0.0 +fun depositAmount bal = + let + val db = getDb () + + val totalShares = case C.oneRow db "SELECT SUM(shares) FROM WebUserPaying" of + [n] => C.intFromSql n + | row => Init.rowError ("Bad depositAmount share count result", row) + in + case C.oneRow db ($`SELECT 3.0 * 900.0 * SUM(shares) / ^(C.intToSql totalShares) + FROM WebUserPaying + WHERE bal = ^(C.intToSql bal)`) of + [amount] => C.realFromSql amount + | row => Init.rowError ("Bad depositAmount result", row) + end + end diff --git a/init.sml b/init.sml index cd066b1..b4d537b 100644 --- a/init.sml +++ b/init.sml @@ -151,7 +151,7 @@ fun modUser (user : user) = fun byPledge () = C.map (getDb ()) mkUserRow ($`SELECT id, name, rname, bal, joined, app, shares, paypal, checkout - FROM WebUser + FROM WebUserPaying WHERE shares > 1 ORDER BY shares DESC, name`) diff --git a/money.mlt b/money.mlt index cbc7a6f..e7413e5 100644 --- a/money.mlt +++ b/money.mlt @@ -461,9 +461,13 @@ elseif $"cmd" = "checkout" then end %> -<% if showNormal then %> +<% if showNormal then + val you = Init.getUser(); + val bal = Balance.lookupBalance (#bal you); + val deposit = Balance.depositAmount (#id bal) %> -

Your balance: $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %>

+

Your balance: $<% Util.sub (#amount bal, deposit) %>
+Deposit: $<% deposit %> (3 months of dues at your current pledge level)

<% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %>

Sum of all active balances: $<% Balance.sumOwnedBalances () %>

<% end %> List all transactions
diff --git a/portal.mlt b/portal.mlt index 3492692..03d8dbd 100644 --- a/portal.mlt +++ b/portal.mlt @@ -1,5 +1,6 @@ <% val you = Init.getUser(); val bal = Balance.lookupBalance (#bal you); +val deposit = Balance.depositAmount (#id bal); @header [] %> <% @payment [] %> @@ -12,7 +13,8 @@ val bal = Balance.lookupBalance (#bal you); <% #d trn %> <% Web.html (#descr trn) %> <% amount %>/<% #amount trn %> <% end %> -Balance: $<% #amount bal %> +Balance: $<% Util.sub (#amount bal, deposit) %>
+Deposit: $<% deposit %> (3 months of dues at your current pledge level) <% val polls = Poll.listCurrentPolls (); switch polls of diff --git a/util.sig b/util.sig index 71abe39..d6f9d5c 100644 --- a/util.sig +++ b/util.sig @@ -15,6 +15,7 @@ sig val makeSet : ('a -> string) -> 'a list -> string val neg : real -> real val add : real * real -> real + val sub : real * real -> real val mult : int * real -> real val validHost : string -> bool diff --git a/util.sml b/util.sml index 2193512..07793bb 100644 --- a/util.sml +++ b/util.sml @@ -29,6 +29,7 @@ fun makeSet f items = fun neg (r : real) = ~r fun add (r1 : real, r2) = r1 + r2 +fun sub (r1 : real, r2) = r1 - r2 fun mult (r1, r2) = real r1 * r2 fun isIdent ch = Char.isLower ch orelse Char.isDigit ch orelse ch = #"-" -- 2.20.1