Split stripe payment/admin scripts
[hcoop/portal.git] / money.mlt
index fd3cc86..abd34a8 100644 (file)
--- a/money.mlt
+++ b/money.mlt
@@ -7,7 +7,7 @@ ref showNormal = true;
 if $"hist" <> "" then
        showNormal := false;
        val id = Web.stoi ($"hist") %>
-<table>
+<table class="data">
 <tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Amount</b></td> </tr>
 <% foreach (amount, trn) in Money.listUserTransactions id 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>
@@ -20,7 +20,7 @@ if $"hist" <> "" then
 
 <h3>Transactions</h3>
 
-<table>
+<table class="data">
 <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>
 <% foreach trn in Money.listTransactions () do %>
 <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>
@@ -42,10 +42,10 @@ end %>
 
 <h3>Primary Transactions</h3>
 
-<table>
+<table class="data">
 <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>
 <% foreach (amt, trn) in Money.listUserTransactions (valOf (Init.userNameToId "hcoop")) do %>
-<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>
+<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td style="text-align: right"><% #amount trn %></td> <td><% #stamp trn %></td>
 <% switch Money.listChargesWithNames (#id trn) of
          [(name, cha)] => %><td><a href="user?id=<% #usr cha %>"><% name %></a></td><%
        | _ => %><td><i>multi</i></td><%
@@ -285,6 +285,26 @@ end %></textarea></td> </tr>
 
        %><h3>Payment transaction added.</h3>
 
+<% elseif $"cmd" = "stripeApply" then
+        val stripePmt = Money.lookupStripePayment ($"stripeId");
+        val txid = Money.applyStripePayment stripePmt;
+%><h3>Stripe Payment Processed (Transaction <% txid %>)</h3>
+
+<% elseif $"cmd" = "stripeRejected" then
+%><h3>Stripe Payment Rejected!</h3>
+
+<% elseif $"cmd" = "stripeReject" then
+        Group.requireGroupName "money";
+        showNormal := false;
+%>
+<h3>Are you sure you want to reject Stripe Payment <% $"stripeChargeId" %>?</h3>
+<form method="post" action="/stripe/stripe-admin.cgi">
+        <input type="hidden" name="cmd" value="reject_member_payment" />
+        <input type="hidden" name="stripeChargeId" value="<% $"stripeChargeId" %>" />
+       <label>Reason for rejection <input type="text" name="reason" /></label>
+        <input type="submit" value="Really Reject Payment" />
+      </form>
+
 <% elseif $"modPay" <> "" then
        Group.requireGroupName "money";
        showNormal := false;
@@ -574,7 +594,7 @@ elseif $"cmd" = "checkout" then
 elseif $"cmd" = "delinq" then
        showNormal := false;
        val dqs = Money.delinquentPledgers () %>
-<table>
+<table class="data">
 <tr> <th>Member</th> <th>Pledge</th> <th>Balance</th> </tr>
 <% foreach dq in dqs do %>
 <tr> <td><a href="user?id=<% #id dq %>"><% #name dq %></a></td> <td><% #shares dq %></td> <td>$<% #balance dq %></td> </tr>
@@ -625,7 +645,9 @@ Co-op balance: $<% #amount (Balance.lookupBalance (valOf (Balance.balanceNameToI
 <!--h3>Your balance: $<% #amount bal %></h3-->
 
 <% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %><h3>Sum of all active balances: $<% Balance.sumOwnedBalances () %></h3><% end %>
-
+<div>
+<div class="payment-tile">
+  <h3>Financial Information</h3>
 <a href="money?cmd=list">List all transactions</a><br>
 <a href="money?cmd=primary">List primary transactions</a><br>
 <a href="money?cmd=bals">List active balances</a><br>
@@ -638,8 +660,9 @@ Co-op balance: $<% #amount (Balance.lookupBalance (valOf (Balance.balanceNameToI
 
 <a href="?cmd=delinq">Drop pledges of delinquent members</a><br>
 <a href="?lookback=20">Switch to regular member view</a><br>
-
-<br><b><u>New transaction:</u></b><br>
+</div>
+<div class="payment-tile">
+  <h3>New Transaction</h3>
 <a href="money?cmd=bill">Bill for the co-op</a><br>
 <a href="money?cmd=pay">Payment from member</a><br>
 <a href="money?cmd=dues">Monthly dues</a><br>
@@ -648,34 +671,66 @@ Co-op balance: $<% #amount (Balance.lookupBalance (valOf (Balance.balanceNameToI
 <br>
 <a href="money?cmd=equalize">Equalize balances</a><br>
 <br>
-
+</div>
+<div>
+<div class="payment-tile">
 <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>
+</div>
 
-<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>
 
+<div class="payment-tile">
 <h3>Look up a Real Name</h3>
 
 <form method="post">
 <input type="hidden" name="cmd" value="realname">
 <input name="rname"> <input type="submit" value="Look up">
 </form>
+</div>
+</div>
+
+<h3>Apply Stripe Payments</h3>
+
+<table class="data">
+<tr><td><strong>Date</strong></td><td><strong>Member</strong></td>
+    <td><strong>Name on Card</strong></td>
+    <td><strong>Amount</strong> (After Fees)</td><td><td></td>
+</tr>
+<% foreach stripePmt in Money.listAllPendingStripePayments () do %>
+
+<tr>
+  <td><% #name (Init.lookupUser (#webuser_id stripePmt)) %></td>
+  <td><% #paid_on stripePmt %></td>
+  <td><% #card_name stripePmt %></td>
+  <td style="text-align: right">$<% #net stripePmt %></td>
+  <td><form method="post">
+        <input type="hidden" name="cmd" value="stripeApply" />
+        <input type="hidden" name="stripeId" value="<% #charge_id stripePmt %>" />
+        <input type="submit" value="Apply to Balance" /> <!-- also, refund? -->
+      </form>
+  </td>
+  <td><form method="post">
+        <input type="hidden" name="cmd" value="stripeReject" />
+        <input type="hidden" name="stripeChargeId" value="<% #charge_id stripePmt %>" />
+        <input type="submit" value="Reject Payment" /> <!-- also, refund? -->
+      </form>
+  </td>
+</tr>
+<% end %>
+</table>
 
 <h3>Most recent transactions</h3>
 
-<table>
+
+
+<table class="data">
 <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>
 <% foreach trn in Money.listTransactionsLimit 20 do %>
-<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% #amount trn %></td>
+<tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td style="text-align: right"><% #amount trn %></td>
 <% switch Money.listChargesWithNames (#id trn) of
          [(name, cha)] => %><td><a href="user?id=<% #usr cha %>"><% name %></a></td><%
        | _ => %><td><i>multi</i></td><%
@@ -702,13 +757,13 @@ val trans = iff lookback = 0 then
         Money.listUserTransactions (Init.getUserId ())
     else
        Money.listUserTransactionsLimit (Init.getUserId (), lookback) %>
-<table>
+<table class="data">
 <tr> <td><b>Date</b></td> <td><b>Description</b></td> <td><b>Debit</b></td> <td><b>Credit</b></td> <td><b>Balance</b></td></tr>
 <% foreach (amount, trn) in trans do %>
 <tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td>
-<td align="right"><% if Util.lt (amount, 0.0) then %><% amount %><% end %></td>
-<td align="right"><% if Util.ge (amount, 0.0) then %><% amount %><% end %></td>
-<td><% running %></tr>
+<td style="text-align: right"><% if Util.lt (amount, 0.0) then %><% amount %><% end %></td>
+<td style="text-align: right"><% if Util.ge (amount, 0.0) then %><% amount %><% end %></td>
+<td style="text-align: right"><% running %></tr>
 <% running := Util.sub (running, amount)
 end %>
 </table>