1 <% Group.requireGroupNum 0;
3 @header [("title", ["Balance management"])];
7 if $"cmd" = "Create" then
8 if not (Balance.validBalanceName ($"name")) then %>
9 <h3>Invalid balance name</h3>
10 <% else switch Balance.balanceNameToId ($"name") of
12 <h3>Balance name already in use</h3>
14 val id = Balance.addBalance ($"name") %>
15 <h3>Balance added</h3>
18 elseif $"mod" <> "" then
20 val balance = Balance.lookupBalance (Web.stoi ($"mod")) %>
21 <h3>Modify balance record</h3>
23 <form action="balances" method="post">
24 <input type="hidden" name="id" value="<% $"mod" %>">
25 <table class="blanks">
26 <tr> <td>Name:</td> <td><input name="name" value="<% #name balance %>"></td> </tr>
27 <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr>
31 <% elseif $"cmd" = "Save" then
32 val balance = Balance.lookupBalance (Web.stoi ($"id"));
33 Balance.modBalance {balance with name = $"name"} %>
34 <h3>Balance record saved.</h3>
36 <% elseif $"del" <> "" then
38 val balance = Balance.lookupBalance (Web.stoi ($"del")) %>
39 <h3>Are you sure you want to delete balance <% #name balance %></a>?</h3>
40 <a href="balances?del2=<% $"del" %>">Yes, delete <% #name balance %>!</a>
42 <% elseif $"del2" <> "" then
43 val balance = Balance.lookupBalance (Web.stoi ($"del2"));
44 Balance.deleteBalance (Web.stoi ($"del2")) %>
45 <h3><% #name balance %> deleted!</h3>
53 <form action="balances" method="post">
54 <table class="blanks">
55 <tr> <td>Name:</td> <td><input name="name"></td> </tr>
56 <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr>
60 <h3>Manage current balances</h3>
63 <% foreach balance in Balance.listBalances () do
64 total := Util.add (total, #amount balance) %>
65 <tr> <td><% Web.html (#name balance) %></td> <td><% #amount balance %></td> <td><a href="balances?mod=<% #id balance %>">[Modify]</a> <a href="balances?del=<% #id balance %>">[Delete]</a></td> </tr>
69 <br><b>Total</b>: $<% total %>