<% @header [("title", ["MoneyMatters"])];
+val root = Group.inGroupNum 0;
+
ref showNormal = true;
if $"hist" <> "" then
<% elseif $"cmd" = "bals" then
showNormal := false %>
-<h3>Balances</h3>
+<h3>Active Balances</h3>
<table>
<% foreach bal in Balance.listOwnedBalances () do %>
<% end %>
</table>
+<% elseif $"cmd" = "deadbals" then
+ showNormal := false %>
+
+<h3>Retired Balances</h3>
+
+<table>
+<% foreach bal in Balance.listUnownedBalances () do %>
+<tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
+<% switch Balance.listBalanceUsers (#id bal) of
+ [] =>
+ | (user :: users) =>
+ %><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
+ foreach user in users do
+ %>, <a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
+ end
+end %></td> </tr>
+<% end %>
+</table>
+
+<% elseif $"cmd" = "nbals" then
+ showNormal := false;
+ val bals = Balance.listNegativeOwnedBalances () %>
+
+<h3>Negative Active Balances (<% length bals %>)</h3>
+
+<table>
+<% foreach bal in bals do %>
+<tr><td><% #name bal %></td> <td><% #amount bal %></td> <td>
+<% switch Balance.listBalanceUsers (#id bal) of
+ [] =>
+ | (user :: users) =>
+ %><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
+ foreach user in users do
+ %>, <a href="user?id=<% #id user %>"><% Web.html (#name user) %></a> <a href="money?hist=<% #id user %>">[History]</a><%
+ end
+end %></td> </tr>
+<% end %>
+</table>
+
<% elseif $"cmd" = "hosting" then
Group.requireGroupName "money";
showNormal := false %>
<% elseif $"cmd" = "pay" then
Group.requireGroupName "money";
+ val uid = (case $"user" of "" => ~1 | s => Web.stoi s);
showNormal := false %>
<h3>New member payment</h3>
<form action="money" method="post">
<input type="hidden" name="cmd" value="pay2">
<table class="blanks">
-<tr> <td>Description:</td> <td><input name="descr"></td> </tr>
-<tr> <td>Date:</td> <td><input name="d"></td> </tr>
+<tr> <td>Description:</td> <td><select name="descr">
+ <option<% if "checkout" = "" then %> selected<% end %>>PayPal</option>
+ <option<% if "checkout" <> "" then %> selected<% end %>>Google Checkout</option>
+ <option>Check</option>
+ <option>Direct transfer</option>
+ <option value="">Other:</option>
+</select> <input name="descr2"></td> </tr>
+<tr> <td>Date:</td> <td><input name="d" value="<% Web.html (Date.fmt "%B %d, %Y" (Date.fromTimeLocal (Time.now ()))) %>"></td> </tr>
<tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
<tr> <td>Member:</td> <td><select name="usr">
<% foreach usr in Init.listUsers () do %>
- <option value="<% #id usr %>"><% #name usr %></option>
+ <option value="<% #id usr %>"<% if #id usr = uid then %> selected<% end %>><% #name usr %></option>
<% end %>
</select></td> </tr>
<tr> <td><input type="submit" value="Add"></td> </tr>
<% elseif $"cmd" = "pay2" then
Group.requireGroupName "money";
val amount = Web.stor ($"amount");
+ val descr = $"descr";
+ val descr = iff descr = "" then $"descr2" else descr;
val id = Money.addTransaction ($"descr", amount, $"d");
Money.addCharge {trn = id, usr = Web.stoi ($"usr"), amount = amount};
Money.applyCharges id;
<tr> <td>Date:</td> <td><% #d trn %></td> </tr>
<tr> <td>Amount:</td> <td>$<% #amount trn %></td> </tr>
<tr> <td>Distribution:</td>
-x
+
<% ref first = true;
foreach (name, cha) in Money.listChargesWithNames id do
if first then
end %>
</table>
-<% end %>
+<% elseif $"cmd" = "paypal" then
+ showNormal := false;
+ val apps = App.searchPaypal ($"email");
+ val users = Init.searchPaypal ($"email");
+
+ switch apps of
+ _ :: _ =>
+ %><h3>Approved applications</h3>
+
+ <% foreach appl in apps do %>
+ <br><hr><br>
+ <table class="blanks">
+ <tr> <td>Received:</td> <td><% #applied appl %></td> </tr>
+ <tr> <td>Approved by:</td> <td><%
+ ref first = true;
+ ref found = false;
+ foreach (id, name) in App.votes (#id appl) do
+ if first then
+ first := false
+ else
+ %>, <%
+ end
+ %><a href="user?id=<% id %>"><% name %></a><%
+ end %> </td> </tr>
+ <tr> <td>Username:</td> <td><% #name appl %></td> </tr>
+ <tr> <td>Real name:</td> <td><% Web.html (#rname appl) %></td> </tr>
+ <tr> <td>E-mail address:</td> <td><a href="mailto:<% #email appl %>"><% #email appl %></a></td> </tr>
+ <% switch #paypal appl of
+ SOME s => %><tr> <td>PayPal:</td> <td><a href="mailto:<% s %>"><% s %></a></td> </tr>
+ <% end;
+ switch #checkout appl of
+ SOME s => %><tr> <td>Google Checkout:</td> <td><a href="mailto:<% s %>"><% s %></a></td> </tr>
+ <% end %>
+ <tr> <td>Forward e-mail?</td> <td><% if #forward appl then %>yes<% else %>no<% end %></td> </tr>
+ <tr> <td>Proposed uses:</td> <td><% Web.htmlNl (#uses appl) %></td> </tr>
+ <tr> <td>Other information:</td> <td><% Web.htmlNl (#other appl) %></td> </tr>
+ </table>
+
+ <% if root then %>
+ <a href="apps?add=<% #id appl %>">Add this member.</a><br>
+ <% end
+ end
+ end;
+
+ switch users of
+ _ :: _ =>
+ %><h3>Members</h3>
+
+ <% foreach user in users do %>
+ <li> <a href="user?id=<% #id user %>"><% #name user %></a> <a href="?cmd=pay&user=<% #id user %>">[add payment]</a></li>
+ <% end
+ end;
+
+ switch (apps, users) of
+ (nil, nil) => %>No matches.<%
+ end
+
+elseif $"cmd" = "checkout" then
+ showNormal := false;
+ val apps = App.searchCheckout ($"email");
+ val users = Init.searchCheckout ($"email");
+
+ switch apps of
+ _ :: _ =>
+ %><h3>Approved applications</h3>
+
+ <% foreach appl in apps do %>
+ <br><hr><br>
+ <table class="blanks">
+ <tr> <td>Received:</td> <td><% #applied appl %></td> </tr>
+ <tr> <td>Approved by:</td> <td><%
+ ref first = true;
+ ref found = false;
+ foreach (id, name) in App.votes (#id appl) do
+ if first then
+ first := false
+ else
+ %>, <%
+ end
+ %><a href="user?id=<% id %>"><% name %></a><%
+ end %> </td> </tr>
+ <tr> <td>Username:</td> <td><% #name appl %></td> </tr>
+ <tr> <td>Real name:</td> <td><% Web.html (#rname appl) %></td> </tr>
+ <tr> <td>E-mail address:</td> <td><a href="mailto:<% #email appl %>"><% #email appl %></a></td> </tr>
+ <% switch #paypal appl of
+ SOME s => %><tr> <td>PayPal:</td> <td><a href="mailto:<% s %>"><% s %></a></td> </tr>
+ <% end;
+ switch #checkout appl of
+ SOME s => %><tr> <td>Google Checkout:</td> <td><a href="mailto:<% s %>"><% s %></a></td> </tr>
+ <% end %>
+ <tr> <td>Forward e-mail?</td> <td><% if #forward appl then %>yes<% else %>no<% end %></td> </tr>
+ <tr> <td>Proposed uses:</td> <td><% Web.htmlNl (#uses appl) %></td> </tr>
+ <tr> <td>Other information:</td> <td><% Web.htmlNl (#other appl) %></td> </tr>
+ </table>
+
+ <% if root then %>
+ <a href="apps?add=<% #id appl %>">Add this member.</a><br>
+ <% end
+ end
+ end;
+
+ switch users of
+ _ :: _ =>
+ %><h3>Members</h3>
+
+ <% foreach user in users do %>
+ <li> <a href="user?id=<% #id user %>"><% #name user %></a> <a href="?cmd=pay&user=<% #id user %>&checkout=1">[add payment]</a></li>
+ <% end
+ end;
+
+ switch (apps, users) of
+ (nil, nil) => %>No matches.<%
+ end
+
+end %>
<% if showNormal then %>
-<h3>Your balance:</b> $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %></h3>
+<h3>Your balance: $<% #amount (Balance.lookupBalance (#bal (Init.getUser ()))) %></h3>
+<% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %><h3>Sum of all active balances: $<% Balance.sumOwnedBalances () %></h3><% end %>
<a href="money?cmd=list">List all transactions</a><br>
-<a href="money?cmd=bals">List all balances</a><br>
+<a href="money?cmd=bals">List active balances</a><br>
+<a href="money?cmd=nbals">List negative active balances</a><br>
+<a href="money?cmd=deadbals">List retired balances</a><br>
+
+<% if (Group.inGroupName "money" and $"lookback" = "") or $"audit" <> "" then %>
-<% if Group.inGroupName "money" then %>
+<a href="?lookback=20">Switch to regular member view</a><br>
<br><b><u>New transaction:</u></b><br>
<a href="money?cmd=hosting">Hosting bill</a><br>
<a href="money?cmd=evenForm">Generic/even</a><br>
<br>
<a href="money?cmd=equalize">Equalize balances</a><br>
+<br>
+
+<h3>Look up a PayPal e-mail address</h3>
+
+<form method="post">
+<input type="hidden" name="cmd" value="paypal">
+<input name="email"> <input type="submit" value="Look up">
+</form>
+
+<h3>Look up a Google Checkout e-mail address</h3>
+
+<form method="post">
+<input type="hidden" name="cmd" value="checkout">
+<input name="email"> <input type="submit" value="Look up">
+</form>
<h3>Most recent transactions</h3>
</table>
<% else %>
+<a href="?audit=1">Switch to audit view</a><br>
+<% val lookback = case $"lookback" of "" => 20 | lb => Web.stoi lb;
+ @payment [] %>
<h3>Your recent account activity</h3>
+<form>
+ Show <input name="lookback" size="5" value="<% lookback %>"> most recent transactions.
+ <input type="submit" value="Show">
+</form>
+
<table>
<tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr>
-<% foreach (amount, trn) in Money.listUserTransactionsLimit (Init.getUserId (), 20) do %>
+<% foreach (amount, trn) in Money.listUserTransactionsLimit (Init.getUserId (), lookback) do %>
<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
<% end %>
</table>