Change granter.sh to give permissions to user specified on command line
[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
1fe415e0 40<h3>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
56<% elseif $"cmd" = "hosting" then
57 Group.requireGroupName "money";
58 showNormal := false %>
59
1fe415e0 60<h3>New hosting bill</h3>
8d347a33 61
add44c00 62<form action="money" method="post">
8d347a33 63<input type="hidden" name="cmd" value="hosting2">
1fe415e0 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>
8d347a33 71<tr> <td><input type="submit" value="Add"></td> </tr>
72</table>
73
74<% elseif $"cmd" = "hosting2" then
f1ea3762 75 Group.requireGroupName "money";
76 val id = Money.addTransaction ($"descr", Util.neg (Web.stor ($"amount")), $"d");
8d347a33 77 Money.addHostingCharges {trn = id, cutoff = 1000 * Web.stoi ($"cutoff"), cost = Web.stor ($"cost"), usage = $"usage"};
78
1fe415e0 79 %><h3>Hosting transaction added.</h3>
8d347a33 80
f1ea3762 81<% elseif $"modHosting" <> "" then
82 Group.requireGroupName "money";
83 showNormal := false;
84 val id = Web.stoi ($"modHosting");
85 val trn = Money.lookupTransaction id %>
86
1fe415e0 87<h3>Modify hosting bill</h3>
f1ea3762 88
add44c00 89<form action="money" method="post">
f1ea3762 90<input type="hidden" name="saveHosting" value="<% id %>">
1fe415e0 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"><%
31b85852 98switch Money.lookupHostingUsage id of
99 SOME s => s
100end %></textarea></td> </tr>
f1ea3762 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
1fe415e0 113 %><h3>Hosting transaction modified.</h3>
f1ea3762 114
115<% elseif $"cmd" = "evenForm" then
116 Group.requireGroupName "money";
117 showNormal := false %>
1fe415e0 118<h3>New generic/even transaction</h3>
add44c00 119<form action="money" method="post">
f1ea3762 120<input type="hidden" name="cmd" value="even">
1fe415e0 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>
f1ea3762 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
1fe415e0 138<h3>New member payment</h3>
f1ea3762 139
add44c00 140<form action="money" method="post">
f1ea3762 141<input type="hidden" name="cmd" value="pay2">
1fe415e0 142<table class="blanks">
143<tr> <td>Description:</td> <td><input name="descr"></td> </tr>
144<tr> <td>Date:</td> <td><input name="d"></td> </tr>
145<tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
146<tr> <td>Member:</td> <td><select name="usr">
f1ea3762 147<% foreach usr in Init.listUsers () do %>
148 <option value="<% #id usr %>"><% #name usr %></option>
149<% end %>
150</select></td> </tr>
151<tr> <td><input type="submit" value="Add"></td> </tr>
152</table>
153</form>
154
155<% elseif $"cmd" = "pay2" then
156 Group.requireGroupName "money";
157 val amount = Web.stor ($"amount");
158 val id = Money.addTransaction ($"descr", amount, $"d");
159 Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
160 Money.applyCharges id;
161
1fe415e0 162 %><h3>Payment transaction added.</h3>
f1ea3762 163
164<% elseif $"modPay" <> "" then
165 Group.requireGroupName "money";
166 showNormal := false;
167 val id = Web.stoi ($"modPay");
168 val trn = Money.lookupTransaction id %>
169
1fe415e0 170<h3>Modify member payment</h3>
f1ea3762 171
add44c00 172<form action="money" method="post">
f1ea3762 173<input type="hidden" name="savePay" value="<% id %>">
1fe415e0 174<table class="blanks">
175<tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
176<tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
177<tr> <td>Amount:</td> <td><input name="amount" value="<% #amount trn %>"></td> </tr>
178<tr> <td>Member:</td> <td><select name="usr">
f1ea3762 179<% foreach (sel, usr) in Money.listUsers (#id trn) do %>
180 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
181<% end %>
182</td></tr>
183<tr> <td><input type="submit" value="Save"></td> </tr>
184</table>
185
186<% elseif $"savePay" <> "" then
187 Group.requireGroupName "money";
188 val id = Web.stoi ($"savePay");
189 val trn = Money.lookupTransaction id;
190
191 val amount = Web.stor ($"amount");
192 Money.clearCharges id;
193 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = amount};
194 Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
195 Money.applyCharges id;
196
1fe415e0 197 %><h3>Member payment modified.</h3>
f1ea3762 198
8d347a33 199<% elseif $"cmd" = "evenForm" then
200 Group.requireGroupName "money";
201 showNormal := false %>
1fe415e0 202<h3>New generic/even transaction</h3>
add44c00 203<form action="money" method="post">
8d347a33 204<input type="hidden" name="cmd" value="even">
1fe415e0 205<table class="blanks">
206<tr> <td>Description:</td> <td><input name="descr"></td> </tr>
207<tr> <td>Date:</td> <td><input name="d"></td> </tr>
208<tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
209<tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
8d347a33 210<% foreach usr in Init.listUsers () do %>
211 <option value="<% #id usr %>"><% #name usr %></option>
212<% end %>
213</select></td> </tr>
214<tr> <td><input type="submit" value="Add"></td> </tr>
215</table>
216</form>
217
218<% elseif $"cmd" = "even" then
f1ea3762 219 Group.requireGroupName "money";
8d347a33 220 val id = Money.addTransaction ($"descr", Web.stor ($"amount"), $"d");
221 Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs"))
222
1fe415e0 223 %><h3>Even transaction added.</h3>
8d347a33 224
225<% elseif $"modEven" <> "" then
f1ea3762 226 Group.requireGroupName "money";
8d347a33 227 showNormal := false;
228 val trn = Money.lookupTransaction (Web.stoi ($"modEven")) %>
1fe415e0 229<h3>Modify even transaction</h3>
8d347a33 230
add44c00 231<form action="money" method="post">
8d347a33 232<input type="hidden" name="saveEven" value="<% $"modEven" %>">
1fe415e0 233<table class="blanks">
234<tr> <td>Description:</td> <td><input name="descr" value="<% Web.html (#descr trn) %>"></td> </tr>
235<tr> <td>Date:</td> <td><input name="d" value="<% Web.html (#d trn) %>"></td> </tr>
236<tr> <td>Amount:</td> <td><input name="amount" value="<% #amount trn %>"></td> </tr>
237<tr> <td>Members:</td> <td><select name="usrs" size="5" multiple>
8d347a33 238<% foreach (sel, usr) in Money.listUsers (#id trn) do %>
239 <option value="<% #id usr %>"<% if sel then %> selected<% end %>><% #name usr %></option>
240<% end %>
241</select></td> </tr>
242<tr> <td><input type="submit" value="Save"></td> </tr>
243</table>
244</form>
245
246<% elseif $"saveEven" <> "" then
f1ea3762 247 Group.requireGroupName "money";
8d347a33 248 val id = Web.stoi ($"saveEven");
249 val trn = Money.lookupTransaction id;
250 Money.clearCharges id;
251 Money.modTransaction {trn with descr = $"descr", d = $"d", amount = Web.stor ($"amount")};
252 Money.addEvenCharges (id, map Web.stoi (Web.getMultiParam "usrs"))
253
1fe415e0 254 %><h3>Even transaction modified</h3>
8d347a33 255
256<% elseif $"del" <> "" then
f1ea3762 257 Group.requireGroupName "money";
8d347a33 258 showNormal := false;
259 val trn = Money.lookupTransaction (Web.stoi ($"del")) %>
1fe415e0 260 <h3>Are you sure you want to delete transaction <a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a>?</h3>
8d347a33 261 <a href="money?del2=<% $"del" %>">Yes, delete <% Web.html (#descr trn) %>!</a>
262
263<% elseif $"del2" <> "" then
f1ea3762 264 Group.requireGroupName "money";
8d347a33 265 val id = Web.stoi ($"del2");
266 val trn = Money.lookupTransaction id;
267 Money.clearCharges id;
268 Money.deleteTransaction id %>
1fe415e0 269 <h3><% Web.html (#descr trn) %> deleted!</h3>
8d347a33 270
f9d08b8c 271<% elseif $"cmd" = "equalize" then
272 Group.requireGroupName "money";
273 Money.equalizeBalances ();
1fe415e0 274 %><h3>Balances equalized</h3>
f9d08b8c 275
8d347a33 276<% elseif $"trn" <> "" then
277 showNormal := false;
278 val id = Web.stoi ($"trn");
279 val trn = Money.lookupTransaction id %>
1fe415e0 280<table class="blanks">
281<tr> <td>TRN#:</td> <td><% id %></td> </tr>
282<tr> <td>Description:</td> <td><% Web.html (#descr trn) %></td> </tr>
283<tr> <td>Date:</td> <td><% #d trn %></td> </tr>
284<tr> <td>Amount:</td> <td>$<% #amount trn %></td> </tr>
285<tr> <td>Distribution:</td>
29826664 286
8d347a33 287<% ref first = true;
288foreach (name, cha) in Money.listChargesWithNames id do
289 if first then
290 first := false
291 else
292 %><tr> <td></td> <%
293 end
294 %><td><a href="user?id=<% #usr cha %>"><% name %></a></td> <td>$<% #amount cha %></td> </tr><%
295end %>
296</table>
297
298<% end %>
299
300<% if showNormal then %>
301
1fe415e0 302<h3>Your balance:</b> $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %></h3>
0bb86812 303
8d347a33 304<a href="money?cmd=list">List all transactions</a><br>
305<a href="money?cmd=bals">List all balances</a><br>
306
307<% if Group.inGroupName "money" then %>
308
309<br><b><u>New transaction:</u></b><br>
310<a href="money?cmd=hosting">Hosting bill</a><br>
f1ea3762 311<a href="money?cmd=pay">Payment from member</a><br>
8d347a33 312<a href="money?cmd=evenForm">Generic/even</a><br>
f9d08b8c 313<br>
314<a href="money?cmd=equalize">Equalize balances</a><br>
8d347a33 315
1fe415e0 316<h3>Most recent transactions</h3>
8d347a33 317
318<table>
319<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>
320<% foreach trn in Money.listTransactionsLimit 20 do %>
321<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% #amount trn %></td>
322<% switch Money.listChargesWithNames (#id trn) of
323 [(name, cha)] => %><td><a href="user?id=<% #usr cha %>"><% name %></a></td><%
324 | _ => %><td><i>multi</i></td><%
325end %>
f1ea3762 326<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>
327<td><a href="money?del=<% #id trn %>">[Delete]</a></td> </tr>
8d347a33 328<% end %>
329</table>
330
331<% else %>
332
6b78263e 333<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>
334
1fe415e0 335<h3>Your recent account activity</h3>
8d347a33 336
337<table>
338<tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr>
339<% foreach (amount, trn) in Money.listUserTransactionsLimit (Init.getUserId (), 20) do %>
340<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
341<% end %>
342</table>
343
344<% end
345end %>
346
347<% @footer [] %>