Commit | Line | Data |
---|---|---|
208e2cbc AC |
1 | <% @header [("title", ["MoneyMatters"])]; |
2 | ||
3 | ref showNormal = true; | |
4 | ||
d1d096bb AC |
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 | |
9bda1e7f | 16 | val admin = Group.inGroupName "money"; |
208e2cbc AC |
17 | showNormal := false %> |
18 | ||
b6dd1aaf | 19 | <h3>Transactions</h3> |
208e2cbc AC |
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 | |
9bda1e7f AC |
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><% | |
208e2cbc | 32 | end |
9bda1e7f | 33 | %></tr><% |
208e2cbc AC |
34 | end %> |
35 | </table> | |
36 | ||
37 | <% elseif $"cmd" = "bals" then | |
38 | showNormal := false %> | |
39 | ||
8ffa2c9e | 40 | <h3>Active Balances</h3> |
208e2cbc AC |
41 | |
42 | <table> | |
afc975d0 | 43 | <% foreach bal in Balance.listOwnedBalances () do %> |
208e2cbc AC |
44 | <tr><td><% #name bal %></td> <td><% #amount bal %></td> <td> |
45 | <% switch Balance.listBalanceUsers (#id bal) of | |
46 | [] => | |
47 | | (user :: users) => | |
d1d096bb | 48 | %><a href="money?hist=<% #id user %>"><% Web.html (#name user) %></a><% |
208e2cbc | 49 | foreach user in users do |
d1d096bb | 50 | %>, <a href="money?hist=<% # id user %>"><% Web.html (#name user) %></a><% |
208e2cbc AC |
51 | end |
52 | end %></td> </tr> | |
53 | <% end %> | |
54 | </table> | |
55 | ||
8ffa2c9e AC |
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 | ||
208e2cbc AC |
75 | <% elseif $"cmd" = "hosting" then |
76 | Group.requireGroupName "money"; | |
77 | showNormal := false %> | |
78 | ||
b6dd1aaf | 79 | <h3>New hosting bill</h3> |
208e2cbc | 80 | |
a4ccdb5e | 81 | <form action="money" method="post"> |
208e2cbc | 82 | <input type="hidden" name="cmd" value="hosting2"> |
b6dd1aaf AC |
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> | |
208e2cbc AC |
90 | <tr> <td><input type="submit" value="Add"></td> </tr> |
91 | </table> | |
92 | ||
93 | <% elseif $"cmd" = "hosting2" then | |
f49e1088 AC |
94 | Group.requireGroupName "money"; |
95 | val id = Money.addTransaction ($"descr", Util.neg (Web.stor ($"amount")), $"d"); | |
208e2cbc AC |
96 | Money.addHostingCharges {trn = id, cutoff = 1000 * Web.stoi ($"cutoff"), cost = Web.stor ($"cost"), usage = $"usage"}; |
97 | ||
b6dd1aaf | 98 | %><h3>Hosting transaction added.</h3> |
208e2cbc | 99 | |
f49e1088 AC |
100 | <% elseif $"modHosting" <> "" then |
101 | Group.requireGroupName "money"; | |
102 | showNormal := false; | |
103 | val id = Web.stoi ($"modHosting"); | |
104 | val trn = Money.lookupTransaction id %> | |
105 | ||
b6dd1aaf | 106 | <h3>Modify hosting bill</h3> |
f49e1088 | 107 | |
a4ccdb5e | 108 | <form action="money" method="post"> |
f49e1088 | 109 | <input type="hidden" name="saveHosting" value="<% id %>"> |
b6dd1aaf AC |
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"><% | |
e84acecc AC |
117 | switch Money.lookupHostingUsage id of |
118 | SOME s => s | |
119 | end %></textarea></td> </tr> | |
f49e1088 AC |
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 | ||
b6dd1aaf | 132 | %><h3>Hosting transaction modified.</h3> |
f49e1088 AC |
133 | |
134 | <% elseif $"cmd" = "evenForm" then | |
135 | Group.requireGroupName "money"; | |
136 | showNormal := false %> | |
b6dd1aaf | 137 | <h3>New generic/even transaction</h3> |
a4ccdb5e | 138 | <form action="money" method="post"> |
f49e1088 | 139 | <input type="hidden" name="cmd" value="even"> |
b6dd1aaf AC |
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> | |
f49e1088 AC |
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 | ||
b6dd1aaf | 157 | <h3>New member payment</h3> |
f49e1088 | 158 | |
a4ccdb5e | 159 | <form action="money" method="post"> |
f49e1088 | 160 | <input type="hidden" name="cmd" value="pay2"> |
b6dd1aaf | 161 | <table class="blanks"> |
dcfe5198 AC |
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> | |
b6dd1aaf AC |
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"> | |
f49e1088 AC |
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"); | |
dcfe5198 AC |
183 | val descr = $"descr"; |
184 | val descr = iff descr = "" then $"descr2" else descr; | |
f49e1088 AC |
185 | val id = Money.addTransaction ($"descr", amount, $"d"); |
186 | Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount}; | |
187 | Money.applyCharges id; | |
188 | ||
b6dd1aaf | 189 | %><h3>Payment transaction added.</h3> |
f49e1088 AC |
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 | ||
b6dd1aaf | 197 | <h3>Modify member payment</h3> |
f49e1088 | 198 | |
a4ccdb5e | 199 | <form action="money" method="post"> |
f49e1088 | 200 | <input type="hidden" name="savePay" value="<% id %>"> |
b6dd1aaf AC |
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"> | |
f49e1088 AC |
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 | ||
b6dd1aaf | 224 | %><h3>Member payment modified.</h3> |
f49e1088 | 225 | |
208e2cbc AC |
226 | <% elseif $"cmd" = "evenForm" then |
227 | Group.requireGroupName "money"; | |
228 | showNormal := false %> | |
b6dd1aaf | 229 | <h3>New generic/even transaction</h3> |
a4ccdb5e | 230 | <form action="money" method="post"> |
208e2cbc | 231 | <input type="hidden" name="cmd" value="even"> |
b6dd1aaf AC |
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> | |
208e2cbc AC |
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 | |
f49e1088 | 246 | Group.requireGroupName "money"; |
208e2cbc AC |
247 | val id = Money.addTransaction ($"descr", Web.stor ($"amount"), $"d"); |
248 | Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs")) | |
249 | ||
b6dd1aaf | 250 | %><h3>Even transaction added.</h3> |
208e2cbc AC |
251 | |
252 | <% elseif $"modEven" <> "" then | |
f49e1088 | 253 | Group.requireGroupName "money"; |
208e2cbc AC |
254 | showNormal := false; |
255 | val trn = Money.lookupTransaction (Web.stoi ($"modEven")) %> | |
b6dd1aaf | 256 | <h3>Modify even transaction</h3> |
208e2cbc | 257 | |
a4ccdb5e | 258 | <form action="money" method="post"> |
208e2cbc | 259 | <input type="hidden" name="saveEven" value="<% $"modEven" %>"> |
b6dd1aaf AC |
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> | |
208e2cbc AC |
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 | |
f49e1088 | 274 | Group.requireGroupName "money"; |
208e2cbc AC |
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 | ||
b6dd1aaf | 281 | %><h3>Even transaction modified</h3> |
208e2cbc AC |
282 | |
283 | <% elseif $"del" <> "" then | |
f49e1088 | 284 | Group.requireGroupName "money"; |
208e2cbc AC |
285 | showNormal := false; |
286 | val trn = Money.lookupTransaction (Web.stoi ($"del")) %> | |
b6dd1aaf | 287 | <h3>Are you sure you want to delete transaction <a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a>?</h3> |
208e2cbc AC |
288 | <a href="money?del2=<% $"del" %>">Yes, delete <% Web.html (#descr trn) %>!</a> |
289 | ||
290 | <% elseif $"del2" <> "" then | |
f49e1088 | 291 | Group.requireGroupName "money"; |
208e2cbc AC |
292 | val id = Web.stoi ($"del2"); |
293 | val trn = Money.lookupTransaction id; | |
294 | Money.clearCharges id; | |
295 | Money.deleteTransaction id %> | |
b6dd1aaf | 296 | <h3><% Web.html (#descr trn) %> deleted!</h3> |
208e2cbc | 297 | |
2d795343 AC |
298 | <% elseif $"cmd" = "equalize" then |
299 | Group.requireGroupName "money"; | |
300 | Money.equalizeBalances (); | |
b6dd1aaf | 301 | %><h3>Balances equalized</h3> |
2d795343 | 302 | |
208e2cbc AC |
303 | <% elseif $"trn" <> "" then |
304 | showNormal := false; | |
305 | val id = Web.stoi ($"trn"); | |
306 | val trn = Money.lookupTransaction id %> | |
b6dd1aaf AC |
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> | |
af6f6078 | 313 | |
208e2cbc AC |
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 | ||
8ffa2c9e AC |
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 %> | |
ee5c7008 | 331 | |
208e2cbc | 332 | <a href="money?cmd=list">List all transactions</a><br> |
8ffa2c9e AC |
333 | <a href="money?cmd=bals">List active balances</a><br> |
334 | <a href="money?cmd=deadbals">List retired balances</a><br> | |
208e2cbc | 335 | |
cf10853e AC |
336 | <% if Group.inGroupName "money" and $"lookback" = "" then %> |
337 | ||
338 | <a href="?lookback=20">Switch to regular member view</a><br> | |
208e2cbc AC |
339 | |
340 | <br><b><u>New transaction:</u></b><br> | |
341 | <a href="money?cmd=hosting">Hosting bill</a><br> | |
f49e1088 | 342 | <a href="money?cmd=pay">Payment from member</a><br> |
208e2cbc | 343 | <a href="money?cmd=evenForm">Generic/even</a><br> |
2d795343 AC |
344 | <br> |
345 | <a href="money?cmd=equalize">Equalize balances</a><br> | |
208e2cbc | 346 | |
b6dd1aaf | 347 | <h3>Most recent transactions</h3> |
208e2cbc AC |
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 %> | |
f49e1088 AC |
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> | |
208e2cbc AC |
359 | <% end %> |
360 | </table> | |
361 | ||
cf10853e AC |
362 | <% else |
363 | val lookback = case $"lookback" of "" => 20 | lb => Web.stoi lb; | |
364 | @payment [] %> | |
b251872c | 365 | |
b6dd1aaf | 366 | <h3>Your recent account activity</h3> |
208e2cbc | 367 | |
cf10853e AC |
368 | <form> |
369 | Show <input name="lookback" size="5" value="<% lookback %>"> most recent transactions. | |
370 | <input type="submit" value="Show"> | |
371 | </form> | |
372 | ||
208e2cbc AC |
373 | <table> |
374 | <tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr> | |
cf10853e | 375 | <% foreach (amount, trn) in Money.listUserTransactionsLimit (Init.getUserId (), lookback) do %> |
208e2cbc AC |
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 [] %> |