cert.mlt: Update with new instructions
[hcoop/zz_old/portal.git] / money.mlt
CommitLineData
8d347a33 1<% @header [("title", ["MoneyMatters"])];
2
3ref showNormal = true;
4
d0dd06fa 5if $"hist" <> "" then
6 showNormal := false;
7 val id = Web.stoi ($"hist") %>
8<table>
9<tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr>
10<% foreach (amount, trn) in Money.listUserTransactions id do %>
11<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
12<% end %>
13</table>
14
15<% elseif $"cmd" = "list" then
f98251aa 16 val admin = Group.inGroupName "money";
8d347a33 17 showNormal := false %>
18
1fe415e0 19<h3>Transactions</h3>
8d347a33 20
21<table>
22<tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> <td><b>Last modified</b></td> <td><b>Participants</b></td> </tr>
23<% foreach trn in Money.listTransactions () do %>
24<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% #amount trn %></td> <td><% #stamp trn %></td>
25<% switch Money.listChargesWithNames (#id trn) of
f98251aa 26 [(name, cha)] => %><td><a href="user?id=<% #usr cha %>"><% name %></a></td><%
27 | _ => %><td><i>multi</i></td><%
28end;
29if admin then
30 %><td><a href="money?modHosting=<% #id trn %>">[Hosting]</a> <a href="money?modPay=<% #id trn %>">[Payment]</a> <a href="money?modEven=<% #id trn %>">[Other]</a></td>
31 <td><a href="money?del=<% #id trn %>">[Delete]</a></td><%
8d347a33 32end
f98251aa 33%></tr><%
8d347a33 34end %>
35</table>
36
37<% elseif $"cmd" = "bals" then
38 showNormal := false %>
39
b49e2370 40<h3>Active Balances</h3>
8d347a33 41
42<table>
a90420b4 43<% foreach bal in Balance.listOwnedBalances () do %>
8d347a33 44<tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
45<% switch Balance.listBalanceUsers (#id bal) of
46 [] =>
47 | (user :: users) =>
d0dd06fa 48 %><a href="money?hist=<% #id user %>"><% Web.html (#name user) %></a><%
8d347a33 49 foreach user in users do
d0dd06fa 50 %>, <a href="money?hist=<% # id user %>"><% Web.html (#name user) %></a><%
8d347a33 51 end
52end %></td> </tr>
53<% end %>
54</table>
55
b49e2370 56<% elseif $"cmd" = "deadbals" then
57 showNormal := false %>
58
59<h3>Retired Balances</h3>
60
61<table>
62<% foreach bal in Balance.listUnownedBalances () do %>
63<tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
64<% switch Balance.listBalanceUsers (#id bal) of
65 [] =>
66 | (user :: users) =>
bde01dd3 67 %><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
b49e2370 68 foreach user in users do
bde01dd3 69 %>, <a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
70 end
71end %></td> </tr>
72<% end %>
73</table>
74
75<% elseif $"cmd" = "nbals" then
76 showNormal := false;
77 val bals = Balance.listNegativeOwnedBalances () %>
78
79<h3>Negative Active Balances (<% length bals %>)</h3>
80
81<table>
82<% foreach bal in bals do %>
83<tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
84<% switch Balance.listBalanceUsers (#id bal) of
85 [] =>
86 | (user :: users) =>
87 %><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
88 foreach user in users do
89 %>, <a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
b49e2370 90 end
91end %></td> </tr>
92<% end %>
93</table>
94
8d347a33 95<% elseif $"cmd" = "hosting" then
96 Group.requireGroupName "money";
97 showNormal := false %>
98
1fe415e0 99<h3>New hosting bill</h3>
8d347a33 100
add44c00 101<form action="money" method="post">
8d347a33 102<input type="hidden" name="cmd" value="hosting2">
1fe415e0 103<table class="blanks">
104<tr> <td>Description:</td> <td><input name="descr"></td> </tr>
105<tr> <td>Date:</td> <td><input name="d"></td> </tr>
106<tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
107<tr> <td>Free bandwidth cutoff (MB):</td> <td><input name="cutoff" value="200"></td> </tr>
108<tr> <td>Cost/GB:</td> <td><input name="cost" value="4"></td> </tr>
109<tr> <td>Member usage:</td> <td><textarea wrap="soft" name="usage" rows="24" cols="80"></textarea></td> </tr>
8d347a33 110<tr> <td><input type="submit" value="Add"></td> </tr>
111</table>
112
113<% elseif $"cmd" = "hosting2" then
f1ea3762 114 Group.requireGroupName "money";
115 val id = Money.addTransaction ($"descr", Util.neg (Web.stor ($"amount")), $"d");
8d347a33 116 Money.addHostingCharges {trn = id, cutoff = 1000 * Web.stoi ($"cutoff"), cost = Web.stor ($"cost"), usage = $"usage"};
117
1fe415e0 118 %><h3>Hosting transaction added.</h3>
8d347a33 119
f1ea3762 120<% elseif $"modHosting" <> "" then
121 Group.requireGroupName "money";
122 showNormal := false;
123 val id = Web.stoi ($"modHosting");
124 val trn = Money.lookupTransaction id %>
125
1fe415e0 126<h3>Modify hosting bill</h3>
f1ea3762 127
add44c00 128<form action="money" method="post">
f1ea3762 129<input type="hidden" name="saveHosting" value="<% id %>">
1fe415e0 130<table class="blanks">
131<tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
132<tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
133<tr> <td>Amount:</td> <td><input name="amount" value="<% Util.neg (#amount trn) %>"></td> </tr>
134<tr> <td>Free bandwidth cutoff (MB):</td> <td><input name="cutoff" value="200"></td> </tr>
135<tr> <td>Cost/GB:</td> <td><input name="cost" value="4"></td> </tr>
136<tr> <td>Member usage:</td> <td><textarea wrap="soft" name="usage" rows="24" cols="80"><%
31b85852 137switch Money.lookupHostingUsage id of
138 SOME s => s
139end %></textarea></td> </tr>
f1ea3762 140<tr> <td><input type="submit" value="Save"></td> </tr>
141</table>
142
143<% elseif $"saveHosting" <> "" then
144 Group.requireGroupName "money";
145 val id = Web.stoi ($"saveHosting");
146 val trn = Money.lookupTransaction id;
147
148 Money.clearCharges id;
149 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = Util.neg (Web.stor ($"amount"))};
150 Money.addHostingCharges {trn = id, cutoff = 1000 * Web.stoi ($"cutoff"), cost = Web.stor ($"cost"), usage = $"usage"};
151
1fe415e0 152 %><h3>Hosting transaction modified.</h3>
f1ea3762 153
154<% elseif $"cmd" = "evenForm" then
155 Group.requireGroupName "money";
156 showNormal := false %>
1fe415e0 157<h3>New generic/even transaction</h3>
add44c00 158<form action="money" method="post">
f1ea3762 159<input type="hidden" name="cmd" value="even">
1fe415e0 160<table class="blanks">
161<tr> <td>Description:</td> <td><input name="descr"></td> </tr>
162<tr> <td>Date:</td> <td><input name="d"></td> </tr>
163<tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
164<tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
f1ea3762 165<% foreach usr in Init.listUsers () do %>
166 <option value="<% #id usr %>"><% #name usr %></option>
167<% end %>
168</select></td> </tr>
169<tr> <td><input type="submit" value="Add"></td> </tr>
170</table>
171</form>
172
173<% elseif $"cmd" = "pay" then
174 Group.requireGroupName "money";
175 showNormal := false %>
176
1fe415e0 177<h3>New member payment</h3>
f1ea3762 178
add44c00 179<form action="money" method="post">
f1ea3762 180<input type="hidden" name="cmd" value="pay2">
1fe415e0 181<table class="blanks">
e3896e51 182<tr> <td>Description:</td> <td><select name="descr">
183 <option selected>PayPal</option>
184 <option>Google Checkout</option>
185 <option>Check</option>
186 <option>Direct transfer</option>
187 <option value="">Other:</option>
188</select> <input name="descr2"></td> </tr>
1fe415e0 189<tr> <td>Date:</td> <td><input name="d"></td> </tr>
190<tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
191<tr> <td>Member:</td> <td><select name="usr">
f1ea3762 192<% foreach usr in Init.listUsers () do %>
193 <option value="<% #id usr %>"><% #name usr %></option>
194<% end %>
195</select></td> </tr>
196<tr> <td><input type="submit" value="Add"></td> </tr>
197</table>
198</form>
199
200<% elseif $"cmd" = "pay2" then
201 Group.requireGroupName "money";
202 val amount = Web.stor ($"amount");
e3896e51 203 val descr = $"descr";
204 val descr = iff descr = "" then $"descr2" else descr;
f1ea3762 205 val id = Money.addTransaction ($"descr", amount, $"d");
206 Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
207 Money.applyCharges id;
208
1fe415e0 209 %><h3>Payment transaction added.</h3>
f1ea3762 210
211<% elseif $"modPay" <> "" then
212 Group.requireGroupName "money";
213 showNormal := false;
214 val id = Web.stoi ($"modPay");
215 val trn = Money.lookupTransaction id %>
216
1fe415e0 217<h3>Modify member payment</h3>
f1ea3762 218
add44c00 219<form action="money" method="post">
f1ea3762 220<input type="hidden" name="savePay" value="<% id %>">
1fe415e0 221<table class="blanks">
222<tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
223<tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
224<tr> <td>Amount:</td> <td><input name="amount" value="<% #amount trn %>"></td> </tr>
225<tr> <td>Member:</td> <td><select name="usr">
f1ea3762 226<% foreach (sel, usr) in Money.listUsers (#id trn) do %>
227 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
228<% end %>
229</td></tr>
230<tr> <td><input type="submit" value="Save"></td> </tr>
231</table>
232
233<% elseif $"savePay" <> "" then
234 Group.requireGroupName "money";
235 val id = Web.stoi ($"savePay");
236 val trn = Money.lookupTransaction id;
237
238 val amount = Web.stor ($"amount");
239 Money.clearCharges id;
240 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = amount};
241 Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
242 Money.applyCharges id;
243
1fe415e0 244 %><h3>Member payment modified.</h3>
f1ea3762 245
8d347a33 246<% elseif $"cmd" = "evenForm" then
247 Group.requireGroupName "money";
248 showNormal := false %>
1fe415e0 249<h3>New generic/even transaction</h3>
add44c00 250<form action="money" method="post">
8d347a33 251<input type="hidden" name="cmd" value="even">
1fe415e0 252<table class="blanks">
253<tr> <td>Description:</td> <td><input name="descr"></td> </tr>
254<tr> <td>Date:</td> <td><input name="d"></td> </tr>
255<tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
256<tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
8d347a33 257<% foreach usr in Init.listUsers () do %>
258 <option value="<% #id usr %>"><% #name usr %></option>
259<% end %>
260</select></td> </tr>
261<tr> <td><input type="submit" value="Add"></td> </tr>
262</table>
263</form>
264
265<% elseif $"cmd" = "even" then
f1ea3762 266 Group.requireGroupName "money";
8d347a33 267 val id = Money.addTransaction ($"descr", Web.stor ($"amount"), $"d");
268 Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs"))
269
1fe415e0 270 %><h3>Even transaction added.</h3>
8d347a33 271
272<% elseif $"modEven" <> "" then
f1ea3762 273 Group.requireGroupName "money";
8d347a33 274 showNormal := false;
275 val trn = Money.lookupTransaction (Web.stoi ($"modEven")) %>
1fe415e0 276<h3>Modify even transaction</h3>
8d347a33 277
add44c00 278<form action="money" method="post">
8d347a33 279<input type="hidden" name="saveEven" value="<% $"modEven" %>">
1fe415e0 280<table class="blanks">
281<tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
282<tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
283<tr> <td>Amount:</td> <td><input name="amount" value="<% #amount trn %>"></td> </tr>
284<tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
8d347a33 285<% foreach (sel, usr) in Money.listUsers (#id trn) do %>
286 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
287<% end %>
288</select></td> </tr>
289<tr> <td><input type="submit" value="Save"></td> </tr>
290</table>
291</form>
292
293<% elseif $"saveEven" <> "" then
f1ea3762 294 Group.requireGroupName "money";
8d347a33 295 val id = Web.stoi ($"saveEven");
296 val trn = Money.lookupTransaction id;
297 Money.clearCharges id;
298 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = Web.stor ($"amount")};
299 Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs"))
300
1fe415e0 301 %><h3>Even transaction modified</h3>
8d347a33 302
303<% elseif $"del" <> "" then
f1ea3762 304 Group.requireGroupName "money";
8d347a33 305 showNormal := false;
306 val trn = Money.lookupTransaction (Web.stoi ($"del")) %>
1fe415e0 307 <h3>Are you sure you want to delete transaction <a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a>?</h3>
8d347a33 308 <a href="money?del2=<% $"del" %>">Yes, delete <% Web.html (#descr trn) %>!</a>
309
310<% elseif $"del2" <> "" then
f1ea3762 311 Group.requireGroupName "money";
8d347a33 312 val id = Web.stoi ($"del2");
313 val trn = Money.lookupTransaction id;
314 Money.clearCharges id;
315 Money.deleteTransaction id %>
1fe415e0 316 <h3><% Web.html (#descr trn) %> deleted!</h3>
8d347a33 317
f9d08b8c 318<% elseif $"cmd" = "equalize" then
319 Group.requireGroupName "money";
320 Money.equalizeBalances ();
1fe415e0 321 %><h3>Balances equalized</h3>
f9d08b8c 322
8d347a33 323<% elseif $"trn" <> "" then
324 showNormal := false;
325 val id = Web.stoi ($"trn");
326 val trn = Money.lookupTransaction id %>
1fe415e0 327<table class="blanks">
328<tr> <td>TRN#:</td> <td><% id %></td> </tr>
329<tr> <td>Description:</td> <td><% Web.html (#descr trn) %></td> </tr>
330<tr> <td>Date:</td> <td><% #d trn %></td> </tr>
331<tr> <td>Amount:</td> <td>$<% #amount trn %></td> </tr>
332<tr> <td>Distribution:</td>
29826664 333
8d347a33 334<% ref first = true;
335foreach (name, cha) in Money.listChargesWithNames id do
336 if first then
337 first := false
338 else
339 %><tr> <td></td> <%
340 end
341 %><td><a href="user?id=<% #usr cha %>"><% name %></a></td> <td>$<% #amount cha %></td> </tr><%
342end %>
343</table>
344
345<% end %>
346
347<% if showNormal then %>
348
b49e2370 349<h3>Your balance: $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %></h3>
0609a8e3 350<% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %><h3>Sum of all active balances: $<% Balance.sumOwnedBalances () %></h3><% end %>
0bb86812 351
8d347a33 352<a href="money?cmd=list">List all transactions</a><br>
b49e2370 353<a href="money?cmd=bals">List active balances</a><br>
bde01dd3 354<a href="money?cmd=nbals">List negative active balances</a><br>
b49e2370 355<a href="money?cmd=deadbals">List retired balances</a><br>
8d347a33 356
0609a8e3 357<% if (Group.inGroupName "money" and $"lookback" = "") or $"audit" <> "" then %>
924e9320 358
359<a href="?lookback=20">Switch to regular member view</a><br>
8d347a33 360
361<br><b><u>New transaction:</u></b><br>
362<a href="money?cmd=hosting">Hosting bill</a><br>
f1ea3762 363<a href="money?cmd=pay">Payment from member</a><br>
8d347a33 364<a href="money?cmd=evenForm">Generic/even</a><br>
f9d08b8c 365<br>
366<a href="money?cmd=equalize">Equalize balances</a><br>
8d347a33 367
1fe415e0 368<h3>Most recent transactions</h3>
8d347a33 369
370<table>
371<tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> <td><b>Participants</b></td> <td><b>Replace</b></td> <td><b>Delete</b></td> </tr>
372<% foreach trn in Money.listTransactionsLimit 20 do %>
373<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% #amount trn %></td>
374<% switch Money.listChargesWithNames (#id trn) of
375 [(name, cha)] => %><td><a href="user?id=<% #usr cha %>"><% name %></a></td><%
376 | _ => %><td><i>multi</i></td><%
377end %>
f1ea3762 378<td><a href="money?modHosting=<% #id trn %>">[Hosting]</a> <a href="money?modPay=<% #id trn %>">[Payment]</a> <a href="money?modEven=<% #id trn %>">[Other]</a></td>
379<td><a href="money?del=<% #id trn %>">[Delete]</a></td> </tr>
8d347a33 380<% end %>
381</table>
382
0609a8e3 383<% else %>
384<a href="?audit=1">Switch to audit view</a><br>
385<% val lookback = case $"lookback" of "" => 20 | lb => Web.stoi lb;
924e9320 386 @payment [] %>
6b78263e 387
1fe415e0 388<h3>Your recent account activity</h3>
8d347a33 389
924e9320 390<form>
391 Show <input name="lookback" size="5" value="<% lookback %>"> most recent transactions.
392 <input type="submit" value="Show">
393</form>
394
8d347a33 395<table>
396<tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr>
924e9320 397<% foreach (amount, trn) in Money.listUserTransactionsLimit (Init.getUserId (), lookback) do %>
8d347a33 398<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
399<% end %>
400</table>
401
402<% end
403end %>
404
405<% @footer [] %>