Update proper Domtool username for package/security queries
[hcoop/zz_old/portal.git] / money.mlt
1 <% @header [("title", ["MoneyMatters"])];
2
3 ref showNormal = true;
4
5 if $"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
16 val admin = Group.inGroupName "money";
17 showNormal := false %>
18
19 <h3>Transactions</h3>
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
26 [(name, cha)] => %><td><a href="user?id=<% #usr cha %>"><% name %></a></td><%
27 | _ => %><td><i>multi</i></td><%
28 end;
29 if 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><%
32 end
33 %></tr><%
34 end %>
35 </table>
36
37 <% elseif $"cmd" = "bals" then
38 showNormal := false %>
39
40 <h3>Balances</h3>
41
42 <table>
43 <% foreach bal in Balance.listOwnedBalances () do %>
44 <tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
45 <% switch Balance.listBalanceUsers (#id bal) of
46 [] =>
47 | (user :: users) =>
48 %><a href="money?hist=<% #id user %>"><% Web.html (#name user) %></a><%
49 foreach user in users do
50 %>, <a href="money?hist=<% # id user %>"><% Web.html (#name user) %></a><%
51 end
52 end %></td> </tr>
53 <% end %>
54 </table>
55
56 <% elseif $"cmd" = "hosting" then
57 Group.requireGroupName "money";
58 showNormal := false %>
59
60 <h3>New hosting bill</h3>
61
62 <form action="money" method="post">
63 <input type="hidden" name="cmd" value="hosting2">
64 <table class="blanks">
65 <tr> <td>Description:</td> <td><input name="descr"></td> </tr>
66 <tr> <td>Date:</td> <td><input name="d"></td> </tr>
67 <tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
68 <tr> <td>Free bandwidth cutoff (MB):</td> <td><input name="cutoff" value="200"></td> </tr>
69 <tr> <td>Cost/GB:</td> <td><input name="cost" value="4"></td> </tr>
70 <tr> <td>Member usage:</td> <td><textarea wrap="soft" name="usage" rows="24" cols="80"></textarea></td> </tr>
71 <tr> <td><input type="submit" value="Add"></td> </tr>
72 </table>
73
74 <% elseif $"cmd" = "hosting2" then
75 Group.requireGroupName "money";
76 val id = Money.addTransaction ($"descr", Util.neg (Web.stor ($"amount")), $"d");
77 Money.addHostingCharges {trn = id, cutoff = 1000 * Web.stoi ($"cutoff"), cost = Web.stor ($"cost"), usage = $"usage"};
78
79 %><h3>Hosting transaction added.</h3>
80
81 <% elseif $"modHosting" <> "" then
82 Group.requireGroupName "money";
83 showNormal := false;
84 val id = Web.stoi ($"modHosting");
85 val trn = Money.lookupTransaction id %>
86
87 <h3>Modify hosting bill</h3>
88
89 <form action="money" method="post">
90 <input type="hidden" name="saveHosting" value="<% id %>">
91 <table class="blanks">
92 <tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
93 <tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
94 <tr> <td>Amount:</td> <td><input name="amount" value="<% Util.neg (#amount trn) %>"></td> </tr>
95 <tr> <td>Free bandwidth cutoff (MB):</td> <td><input name="cutoff" value="200"></td> </tr>
96 <tr> <td>Cost/GB:</td> <td><input name="cost" value="4"></td> </tr>
97 <tr> <td>Member usage:</td> <td><textarea wrap="soft" name="usage" rows="24" cols="80"><%
98 switch Money.lookupHostingUsage id of
99 SOME s => s
100 end %></textarea></td> </tr>
101 <tr> <td><input type="submit" value="Save"></td> </tr>
102 </table>
103
104 <% elseif $"saveHosting" <> "" then
105 Group.requireGroupName "money";
106 val id = Web.stoi ($"saveHosting");
107 val trn = Money.lookupTransaction id;
108
109 Money.clearCharges id;
110 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = Util.neg (Web.stor ($"amount"))};
111 Money.addHostingCharges {trn = id, cutoff = 1000 * Web.stoi ($"cutoff"), cost = Web.stor ($"cost"), usage = $"usage"};
112
113 %><h3>Hosting transaction modified.</h3>
114
115 <% elseif $"cmd" = "evenForm" then
116 Group.requireGroupName "money";
117 showNormal := false %>
118 <h3>New generic/even transaction</h3>
119 <form action="money" method="post">
120 <input type="hidden" name="cmd" value="even">
121 <table class="blanks">
122 <tr> <td>Description:</td> <td><input name="descr"></td> </tr>
123 <tr> <td>Date:</td> <td><input name="d"></td> </tr>
124 <tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
125 <tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
126 <% foreach usr in Init.listUsers () do %>
127 <option value="<% #id usr %>"><% #name usr %></option>
128 <% end %>
129 </select></td> </tr>
130 <tr> <td><input type="submit" value="Add"></td> </tr>
131 </table>
132 </form>
133
134 <% elseif $"cmd" = "pay" then
135 Group.requireGroupName "money";
136 showNormal := false %>
137
138 <h3>New member payment</h3>
139
140 <form action="money" method="post">
141 <input type="hidden" name="cmd" value="pay2">
142 <table class="blanks">
143 <tr> <td>Description:</td> <td><select name="descr">
144 <option selected>PayPal</option>
145 <option>Google Checkout</option>
146 <option>Check</option>
147 <option>Direct transfer</option>
148 <option value="">Other:</option>
149 </select> <input name="descr2"></td> </tr>
150 <tr> <td>Date:</td> <td><input name="d"></td> </tr>
151 <tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
152 <tr> <td>Member:</td> <td><select name="usr">
153 <% foreach usr in Init.listUsers () do %>
154 <option value="<% #id usr %>"><% #name usr %></option>
155 <% end %>
156 </select></td> </tr>
157 <tr> <td><input type="submit" value="Add"></td> </tr>
158 </table>
159 </form>
160
161 <% elseif $"cmd" = "pay2" then
162 Group.requireGroupName "money";
163 val amount = Web.stor ($"amount");
164 val descr = $"descr";
165 val descr = iff descr = "" then $"descr2" else descr;
166 val id = Money.addTransaction ($"descr", amount, $"d");
167 Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
168 Money.applyCharges id;
169
170 %><h3>Payment transaction added.</h3>
171
172 <% elseif $"modPay" <> "" then
173 Group.requireGroupName "money";
174 showNormal := false;
175 val id = Web.stoi ($"modPay");
176 val trn = Money.lookupTransaction id %>
177
178 <h3>Modify member payment</h3>
179
180 <form action="money" method="post">
181 <input type="hidden" name="savePay" value="<% id %>">
182 <table class="blanks">
183 <tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
184 <tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
185 <tr> <td>Amount:</td> <td><input name="amount" value="<% #amount trn %>"></td> </tr>
186 <tr> <td>Member:</td> <td><select name="usr">
187 <% foreach (sel, usr) in Money.listUsers (#id trn) do %>
188 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
189 <% end %>
190 </td></tr>
191 <tr> <td><input type="submit" value="Save"></td> </tr>
192 </table>
193
194 <% elseif $"savePay" <> "" then
195 Group.requireGroupName "money";
196 val id = Web.stoi ($"savePay");
197 val trn = Money.lookupTransaction id;
198
199 val amount = Web.stor ($"amount");
200 Money.clearCharges id;
201 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = amount};
202 Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
203 Money.applyCharges id;
204
205 %><h3>Member payment modified.</h3>
206
207 <% elseif $"cmd" = "evenForm" then
208 Group.requireGroupName "money";
209 showNormal := false %>
210 <h3>New generic/even transaction</h3>
211 <form action="money" method="post">
212 <input type="hidden" name="cmd" value="even">
213 <table class="blanks">
214 <tr> <td>Description:</td> <td><input name="descr"></td> </tr>
215 <tr> <td>Date:</td> <td><input name="d"></td> </tr>
216 <tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
217 <tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
218 <% foreach usr in Init.listUsers () do %>
219 <option value="<% #id usr %>"><% #name usr %></option>
220 <% end %>
221 </select></td> </tr>
222 <tr> <td><input type="submit" value="Add"></td> </tr>
223 </table>
224 </form>
225
226 <% elseif $"cmd" = "even" then
227 Group.requireGroupName "money";
228 val id = Money.addTransaction ($"descr", Web.stor ($"amount"), $"d");
229 Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs"))
230
231 %><h3>Even transaction added.</h3>
232
233 <% elseif $"modEven" <> "" then
234 Group.requireGroupName "money";
235 showNormal := false;
236 val trn = Money.lookupTransaction (Web.stoi ($"modEven")) %>
237 <h3>Modify even transaction</h3>
238
239 <form action="money" method="post">
240 <input type="hidden" name="saveEven" value="<% $"modEven" %>">
241 <table class="blanks">
242 <tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
243 <tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
244 <tr> <td>Amount:</td> <td><input name="amount" value="<% #amount trn %>"></td> </tr>
245 <tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
246 <% foreach (sel, usr) in Money.listUsers (#id trn) do %>
247 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
248 <% end %>
249 </select></td> </tr>
250 <tr> <td><input type="submit" value="Save"></td> </tr>
251 </table>
252 </form>
253
254 <% elseif $"saveEven" <> "" then
255 Group.requireGroupName "money";
256 val id = Web.stoi ($"saveEven");
257 val trn = Money.lookupTransaction id;
258 Money.clearCharges id;
259 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = Web.stor ($"amount")};
260 Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs"))
261
262 %><h3>Even transaction modified</h3>
263
264 <% elseif $"del" <> "" then
265 Group.requireGroupName "money";
266 showNormal := false;
267 val trn = Money.lookupTransaction (Web.stoi ($"del")) %>
268 <h3>Are you sure you want to delete transaction <a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a>?</h3>
269 <a href="money?del2=<% $"del" %>">Yes, delete <% Web.html (#descr trn) %>!</a>
270
271 <% elseif $"del2" <> "" then
272 Group.requireGroupName "money";
273 val id = Web.stoi ($"del2");
274 val trn = Money.lookupTransaction id;
275 Money.clearCharges id;
276 Money.deleteTransaction id %>
277 <h3><% Web.html (#descr trn) %> deleted!</h3>
278
279 <% elseif $"cmd" = "equalize" then
280 Group.requireGroupName "money";
281 Money.equalizeBalances ();
282 %><h3>Balances equalized</h3>
283
284 <% elseif $"trn" <> "" then
285 showNormal := false;
286 val id = Web.stoi ($"trn");
287 val trn = Money.lookupTransaction id %>
288 <table class="blanks">
289 <tr> <td>TRN#:</td> <td><% id %></td> </tr>
290 <tr> <td>Description:</td> <td><% Web.html (#descr trn) %></td> </tr>
291 <tr> <td>Date:</td> <td><% #d trn %></td> </tr>
292 <tr> <td>Amount:</td> <td>$<% #amount trn %></td> </tr>
293 <tr> <td>Distribution:</td>
294
295 <% ref first = true;
296 foreach (name, cha) in Money.listChargesWithNames id do
297 if first then
298 first := false
299 else
300 %><tr> <td></td> <%
301 end
302 %><td><a href="user?id=<% #usr cha %>"><% name %></a></td> <td>$<% #amount cha %></td> </tr><%
303 end %>
304 </table>
305
306 <% end %>
307
308 <% if showNormal then %>
309
310 <h3>Your balance:</b> $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %></h3>
311
312 <a href="money?cmd=list">List all transactions</a><br>
313 <a href="money?cmd=bals">List all balances</a><br>
314
315 <% if Group.inGroupName "money" then %>
316
317 <br><b><u>New transaction:</u></b><br>
318 <a href="money?cmd=hosting">Hosting bill</a><br>
319 <a href="money?cmd=pay">Payment from member</a><br>
320 <a href="money?cmd=evenForm">Generic/even</a><br>
321 <br>
322 <a href="money?cmd=equalize">Equalize balances</a><br>
323
324 <h3>Most recent transactions</h3>
325
326 <table>
327 <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>
328 <% foreach trn in Money.listTransactionsLimit 20 do %>
329 <tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% #amount trn %></td>
330 <% switch Money.listChargesWithNames (#id trn) of
331 [(name, cha)] => %><td><a href="user?id=<% #usr cha %>"><% name %></a></td><%
332 | _ => %><td><i>multi</i></td><%
333 end %>
334 <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>
335 <td><a href="money?del=<% #id trn %>">[Delete]</a></td> </tr>
336 <% end %>
337 </table>
338
339 <% else %>
340
341 <h3><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=payment@hcoop.net&item_name=Member+payment+for+<% Init.getUserName () %>">Add to your balance with PayPal</a></h3>
342
343 <h3>Your recent account activity</h3>
344
345 <table>
346 <tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr>
347 <% foreach (amount, trn) in Money.listUserTransactionsLimit (Init.getUserId (), 20) do %>
348 <tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
349 <% end %>
350 </table>
351
352 <% end
353 end %>
354
355 <% @footer [] %>