8d347a33 |
1 | <% Group.requireGroupNum 0; |
2 | |
3 | @header [("title", ["Balance management"])]; |
4 | |
5 | ref showNormal = true; |
6 | |
7 | if $"cmd" = "Create" then |
8 | if not (Balance.validBalanceName ($"name")) then %> |
1fe415e0 |
9 | <h3>Invalid balance name</h3> |
8d347a33 |
10 | <% else switch Balance.balanceNameToId ($"name") of |
11 | SOME _ => %> |
1fe415e0 |
12 | <h3>Balance name already in use</h3> |
8d347a33 |
13 | <% | NONE => |
14 | val id = Balance.addBalance ($"name") %> |
1fe415e0 |
15 | <h3>Balance added</h3> |
8d347a33 |
16 | <% end |
17 | end |
18 | elseif $"mod" <> "" then |
19 | showNormal := false; |
20 | val balance = Balance.lookupBalance (Web.stoi ($"mod")) %> |
1fe415e0 |
21 | <h3>Modify balance record</h3> |
8d347a33 |
22 | |
add44c00 |
23 | <form action="balances" method="post"> |
8d347a33 |
24 | <input type="hidden" name="id" value="<% $"mod" %>"> |
1fe415e0 |
25 | <table class="blanks"> |
26 | <tr> <td>Name:</td> <td><input name="name" value="<% #name balance %>"></td> </tr> |
8d347a33 |
27 | <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr> |
28 | </table> |
29 | </form> |
30 | |
31 | <% elseif $"cmd" = "Save" then |
32 | val balance = Balance.lookupBalance (Web.stoi ($"id")); |
33 | Balance.modBalance {balance with name = $"name"} %> |
1fe415e0 |
34 | <h3>Balance record saved.</h3> |
8d347a33 |
35 | |
36 | <% elseif $"del" <> "" then |
37 | showNormal := false; |
38 | val balance = Balance.lookupBalance (Web.stoi ($"del")) %> |
1fe415e0 |
39 | <h3>Are you sure you want to delete balance <% #name balance %></a>?</h3> |
8d347a33 |
40 | <a href="balances?del2=<% $"del" %>">Yes, delete <% #name balance %>!</a> |
41 | |
42 | <% elseif $"del2" <> "" then |
43 | val balance = Balance.lookupBalance (Web.stoi ($"del2")); |
44 | Balance.deleteBalance (Web.stoi ($"del2")) %> |
1fe415e0 |
45 | <h3><% #name balance %> deleted!</h3> |
8d347a33 |
46 | |
47 | <% end %> |
48 | |
f98251aa |
49 | <% if showNormal then |
50 | ref total = 0.0 %> |
1fe415e0 |
51 | <h3>New balance</h3> |
8d347a33 |
52 | |
add44c00 |
53 | <form action="balances" method="post"> |
1fe415e0 |
54 | <table class="blanks"> |
55 | <tr> <td>Name:</td> <td><input name="name"></td> </tr> |
8d347a33 |
56 | <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr> |
57 | </table> |
58 | </form> |
59 | |
1fe415e0 |
60 | <h3>Manage current balances</h3> |
8d347a33 |
61 | |
62 | <table> |
f98251aa |
63 | <% foreach balance in Balance.listBalances () do |
64 | total := Util.add (total, #amount balance) %> |
8d347a33 |
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> |
66 | <% end %> |
67 | </table> |
68 | |
f98251aa |
69 | <br><b>Total</b>: $<% total %> |
70 | |
8d347a33 |
71 | <% end %> |
72 | |
73 | <% @footer [] %> |