Listing negative balances
[hcoop/zz_old/portal.git] / money.mlt
index 2293821..74bc1f6 100644 (file)
--- a/money.mlt
+++ b/money.mlt
@@ -37,7 +37,7 @@ end %>
 <% elseif $"cmd" = "bals" then
        showNormal := false %>
 
-<h3>Balances</h3>
+<h3>Active Balances</h3>
 
 <table>
 <% foreach bal in Balance.listOwnedBalances () do %>
@@ -53,6 +53,45 @@ end %></td> </tr>
 <% 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 %>
@@ -140,7 +179,13 @@ end %></textarea></td> </tr>
 <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>Description:</td> <td><select name="descr">
+       <option selected>PayPal</option>
+       <option>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"></td> </tr>
 <tr> <td>Amount:</td> <td><input name="amount"></td> </tr>
 <tr> <td>Member:</td> <td><select name="usr">
@@ -155,6 +200,8 @@ end %></textarea></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;
@@ -283,7 +330,7 @@ end %></textarea></td> </tr>
 <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
@@ -299,12 +346,17 @@ 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>
@@ -329,12 +381,20 @@ end %>
 </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>