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