Initial revision
[hcoop/portal.git] / balances.mlt
CommitLineData
208e2cbc
AC
1<% Group.requireGroupNum 0;
2
3@header [("title", ["Balance management"])];
4
5ref showNormal = true;
6
7if $"cmd" = "Create" then
8 if not (Balance.validBalanceName ($"name")) then %>
9 <h3><b>Invalid balance name</b></h3>
10 <% else switch Balance.balanceNameToId ($"name") of
11 SOME _ => %>
12 <h3><b>Balance name already in use</b></h3>
13<% | NONE =>
14 val id = Balance.addBalance ($"name") %>
15 <h3><b>Balance added</b></h3>
16<% end
17 end
18elseif $"mod" <> "" then
19 showNormal := false;
20 val balance = Balance.lookupBalance (Web.stoi ($"mod")) %>
21<h3><b>Modify balance record</b></h3>
22
23<form action="balances">
24<input type="hidden" name="id" value="<% $"mod" %>">
25<table>
26<tr> <td align="right"><b>Name</b>:</td> <td><input name="name" value="<% #name balance %>"></td> </tr>
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"} %>
34 <h3><b>Balance record saved.</b></h3>
35
36<% elseif $"del" <> "" then
37 showNormal := false;
38 val balance = Balance.lookupBalance (Web.stoi ($"del")) %>
39 <h3><b>Are you sure you want to delete balance <% #name balance %></a>?</b></h3>
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")) %>
45 <h3><b><% #name balance %> deleted!</b></h3>
46
47<% end %>
48
49<% if showNormal then %>
50<h3><b>New balance</b></h3>
51
52<form action="balances">
53<table>
54<tr> <td align="right"><b>Name</b>:</td> <td><input name="name"></td> </tr>
55<tr> <td><input type="submit" name="cmd" value="Create"></td> </tr>
56</table>
57</form>
58
59<h3><b>Manage current balances</b></h3>
60
61<table>
62<% foreach balance in Balance.listBalances () do %>
63 <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>
64<% end %>
65</table>
66
67<% end %>
68
69<% @footer [] %>