1 <% @header [("title", ["MoneyMatters"])];
7 val id = Web.stoi ($"hist") %>
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>
15 <% elseif $"cmd" = "list" then
16 val admin = Group.inGroupName "money";
17 showNormal := false %>
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><%
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><%
37 <% elseif $"cmd" = "bals" then
38 showNormal := false %>
40 <h3>Active Balances</h3>
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
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><%
56 <% elseif $"cmd" = "deadbals" then
57 showNormal := false %>
59 <h3>Retired Balances</h3>
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
67 %><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
68 foreach user in users do
69 %>, <a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
75 <% elseif $"cmd" = "nbals" then
77 val bals = Balance.listNegativeOwnedBalances () %>
79 <h3>Negative Active Balances (<% length bals %>)</h3>
82 <% foreach bal in bals do %>
83 <tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
84 <% switch Balance.listBalanceUsers (#id bal) of
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><%
95 <% elseif $"cmd" = "hosting" then
96 Group.requireGroupName "money";
97 showNormal := false %>
99 <h3>New hosting bill</h3>
101 <form action="money" method="post">
102 <input type="hidden" name="cmd" value="hosting2">
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>
110 <tr> <td><input type="submit" value="Add"></td> </tr>
113 <% elseif $"cmd" = "hosting2" then
114 Group.requireGroupName "money";
115 val id = Money.addTransaction ($"descr", Util.neg (Web.stor ($"amount")), $"d");
116 Money.addHostingCharges {trn = id, cutoff = 1000 * Web.stoi ($"cutoff"), cost = Web.stor ($"cost"), usage = $"usage"};
118 %><h3>Hosting transaction added.</h3>
120 <% elseif $"modHosting" <> "" then
121 Group.requireGroupName "money";
123 val id = Web.stoi ($"modHosting");
124 val trn = Money.lookupTransaction id %>
126 <h3>Modify hosting bill</h3>
128 <form action="money" method="post">
129 <input type="hidden" name="saveHosting" value="<% id %>">
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"><%
137 switch Money.lookupHostingUsage id of
139 end %></textarea></td> </tr>
140 <tr> <td><input type="submit" value="Save"></td> </tr>
143 <% elseif $"saveHosting" <> "" then
144 Group.requireGroupName "money";
145 val id = Web.stoi ($"saveHosting");
146 val trn = Money.lookupTransaction id;
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"};
152 %><h3>Hosting transaction modified.</h3>
154 <% elseif $"cmd" = "evenForm" then
155 Group.requireGroupName "money";
156 showNormal := false %>
157 <h3>New generic/even transaction</h3>
158 <form action="money" method="post">
159 <input type="hidden" name="cmd" value="even">
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>
165 <% foreach usr in Init.listUsers () do %>
166 <option value="<% #id usr %>"><% #name usr %></option>
169 <tr> <td><input type="submit" value="Add"></td> </tr>
173 <% elseif $"cmd" = "pay" then
174 Group.requireGroupName "money";
175 showNormal := false %>
177 <h3>New member payment</h3>
179 <form action="money" method="post">
180 <input type="hidden" name="cmd" value="pay2">
181 <table class="blanks">
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>
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">
192 <% foreach usr in Init.listUsers () do %>
193 <option value="<% #id usr %>"><% #name usr %></option>
196 <tr> <td><input type="submit" value="Add"></td> </tr>
200 <% elseif $"cmd" = "pay2" then
201 Group.requireGroupName "money";
202 val amount = Web.stor ($"amount");
203 val descr = $"descr";
204 val descr = iff descr = "" then $"descr2" else descr;
205 val id = Money.addTransaction ($"descr", amount, $"d");
206 Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
207 Money.applyCharges id;
209 %><h3>Payment transaction added.</h3>
211 <% elseif $"modPay" <> "" then
212 Group.requireGroupName "money";
214 val id = Web.stoi ($"modPay");
215 val trn = Money.lookupTransaction id %>
217 <h3>Modify member payment</h3>
219 <form action="money" method="post">
220 <input type="hidden" name="savePay" value="<% id %>">
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">
226 <% foreach (sel, usr) in Money.listUsers (#id trn) do %>
227 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
230 <tr> <td><input type="submit" value="Save"></td> </tr>
233 <% elseif $"savePay" <> "" then
234 Group.requireGroupName "money";
235 val id = Web.stoi ($"savePay");
236 val trn = Money.lookupTransaction id;
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;
244 %><h3>Member payment modified.</h3>
246 <% elseif $"cmd" = "evenForm" then
247 Group.requireGroupName "money";
248 showNormal := false %>
249 <h3>New generic/even transaction</h3>
250 <form action="money" method="post">
251 <input type="hidden" name="cmd" value="even">
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>
257 <% foreach usr in Init.listUsers () do %>
258 <option value="<% #id usr %>"><% #name usr %></option>
261 <tr> <td><input type="submit" value="Add"></td> </tr>
265 <% elseif $"cmd" = "even" then
266 Group.requireGroupName "money";
267 val id = Money.addTransaction ($"descr", Web.stor ($"amount"), $"d");
268 Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs"))
270 %><h3>Even transaction added.</h3>
272 <% elseif $"modEven" <> "" then
273 Group.requireGroupName "money";
275 val trn = Money.lookupTransaction (Web.stoi ($"modEven")) %>
276 <h3>Modify even transaction</h3>
278 <form action="money" method="post">
279 <input type="hidden" name="saveEven" value="<% $"modEven" %>">
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>
285 <% foreach (sel, usr) in Money.listUsers (#id trn) do %>
286 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
289 <tr> <td><input type="submit" value="Save"></td> </tr>
293 <% elseif $"saveEven" <> "" then
294 Group.requireGroupName "money";
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"))
301 %><h3>Even transaction modified</h3>
303 <% elseif $"del" <> "" then
304 Group.requireGroupName "money";
306 val trn = Money.lookupTransaction (Web.stoi ($"del")) %>
307 <h3>Are you sure you want to delete transaction <a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a>?</h3>
308 <a href="money?del2=<% $"del" %>">Yes, delete <% Web.html (#descr trn) %>!</a>
310 <% elseif $"del2" <> "" then
311 Group.requireGroupName "money";
312 val id = Web.stoi ($"del2");
313 val trn = Money.lookupTransaction id;
314 Money.clearCharges id;
315 Money.deleteTransaction id %>
316 <h3><% Web.html (#descr trn) %> deleted!</h3>
318 <% elseif $"cmd" = "equalize" then
319 Group.requireGroupName "money";
320 Money.equalizeBalances ();
321 %><h3>Balances equalized</h3>
323 <% elseif $"trn" <> "" then
325 val id = Web.stoi ($"trn");
326 val trn = Money.lookupTransaction id %>
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>
335 foreach (name, cha) in Money.listChargesWithNames id do
341 %><td><a href="user?id=<% #usr cha %>"><% name %></a></td> <td>$<% #amount cha %></td> </tr><%
347 <% if showNormal then %>
349 <h3>Your balance: $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %></h3>
350 <% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %><h3>Sum of all active balances: $<% Balance.sumOwnedBalances () %></h3><% end %>
352 <a href="money?cmd=list">List all transactions</a><br>
353 <a href="money?cmd=bals">List active balances</a><br>
354 <a href="money?cmd=nbals">List negative active balances</a><br>
355 <a href="money?cmd=deadbals">List retired balances</a><br>
357 <% if (Group.inGroupName "money" and $"lookback" = "") or $"audit" <> "" then %>
359 <a href="?lookback=20">Switch to regular member view</a><br>
361 <br><b><u>New transaction:</u></b><br>
362 <a href="money?cmd=hosting">Hosting bill</a><br>
363 <a href="money?cmd=pay">Payment from member</a><br>
364 <a href="money?cmd=evenForm">Generic/even</a><br>
366 <a href="money?cmd=equalize">Equalize balances</a><br>
368 <h3>Most recent transactions</h3>
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><%
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>
384 <a href="?audit=1">Switch to audit view</a><br>
385 <% val lookback = case $"lookback" of "" => 20 | lb => Web.stoi lb;
388 <h3>Your recent account activity</h3>
391 Show <input name="lookback" size="5" value="<% lookback %>"> most recent transactions.
392 <input type="submit" value="Show">
396 <tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr>
397 <% foreach (amount, trn) in Money.listUserTransactionsLimit (Init.getUserId (), lookback) do %>
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>