From 8ffa2c9e02d6876b95564d4d515a4661cc65e94e Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 13 Sep 2007 18:29:32 +0000 Subject: [PATCH] Add all-balance summing and listing of retired balances --- balance.sig | 3 +++ balance.sml | 16 ++++++++++++++++ money.mlt | 27 ++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/balance.sig b/balance.sig index 6eb3349..06726a5 100644 --- a/balance.sig +++ b/balance.sig @@ -8,8 +8,11 @@ sig val deleteBalance : int -> unit val listBalances : unit -> balance list val listOwnedBalances : unit -> balance list + val listUnownedBalances : unit -> balance list val listBalanceUsers : int -> Init.user list val validBalanceName : string -> bool val balanceNameToId : string -> int option + + val sumOwnedBalances : unit -> real end diff --git a/balance.sml b/balance.sml index 9a1f8b6..9943944 100644 --- a/balance.sml +++ b/balance.sml @@ -54,6 +54,14 @@ fun listOwnedBalances () = AND WebUser.bal = Balance.id ORDER BY Balance.name`) +fun listUnownedBalances () = + C.map (getDb ()) mkBalanceRow ($`SELECT Balance.id, Balance.name, amount + FROM Balance LEFT OUTER JOIN WebUser + ON Balance.name = WebUser.name + AND WebUser.bal = Balance.id + WHERE WebUser.id IS NULL + ORDER BY Balance.name`) + fun validBalanceName name = size name <= 20 andalso CharVector.all (fn ch => Char.isAlpha ch orelse ch = #"+") name @@ -69,4 +77,12 @@ fun listBalanceUsers bal = WHERE bal = ^(C.intToSql bal) ORDER BY name`) +fun sumOwnedBalances () = + case C.oneRow (getDb ()) ($`SELECT SUM(amount) + FROM Balance JOIN WebUser + ON Balance.name = WebUser.name + AND WebUser.bal = Balance.id`) of + [amt] => C.realFromSql amt + | _ => raise Fail "sumOwnedBalance: no rows" + end diff --git a/money.mlt b/money.mlt index 08aaa4b..bd532be 100644 --- a/money.mlt +++ b/money.mlt @@ -37,7 +37,7 @@ end %> <% elseif $"cmd" = "bals" then showNormal := false %> -

Balances

+

Active Balances

<% foreach bal in Balance.listOwnedBalances () do %> @@ -53,6 +53,25 @@ end %> <% end %>
+<% elseif $"cmd" = "deadbals" then + showNormal := false %> + +

Retired Balances

+ + +<% foreach bal in Balance.listUnownedBalances () do %> + +<% end %> +
<% #name bal %> <% #amount bal %> +<% switch Balance.listBalanceUsers (#id bal) of + [] => + | (user :: users) => + %><% Web.html (#name user) %><% + foreach user in users do + %>, <% Web.html (#name user) %><% + end +end %>
+ <% elseif $"cmd" = "hosting" then Group.requireGroupName "money"; showNormal := false %> @@ -307,10 +326,12 @@ end %> <% if showNormal then %> -

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

+

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

+<% if Group.inGroupName "money" then %>

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

<% end %> List all transactions
-List all balances
+List active balances
+List retired balances
<% if Group.inGroupName "money" then %> -- 2.20.1