Henry Lyne (henrylyne) wrote in changelog,
Henry Lyne
henrylyne
changelog

[ljcom] r7215: Allow filtering of results by payment me...

Committer: henrylyne
Allow filtering of results by payment method.

U   trunk/htdocs/admin/accounts/paidsummary.bml
Modified: trunk/htdocs/admin/accounts/paidsummary.bml
===================================================================
--- trunk/htdocs/admin/accounts/paidsummary.bml	2009-04-16 08:17:34 UTC (rev 7214)
+++ trunk/htdocs/admin/accounts/paidsummary.bml	2009-04-16 19:10:47 UTC (rev 7215)
@@ -23,11 +23,22 @@
     # What's our view mode?  html or csv
     my $view_mode = $GET{view} eq 'csv' ? 'csv' : 'html';
 
+    # A list of the possible payment methods
+    my @pay_list = qw(cash cc check moneyorder paypal sms sup_sms sup_yandex webmoney);
+    # Check if valid payment method specified
+    my $pay_method = undef;
+    foreach my $method (@pay_list) {
+        if ($method eq $GET{pay_method}) {
+            $pay_method = $method;
+            last;
+        }
+    }
+
     # Get all the relevant dates: current date and date range for reporting
     my ($year, $month, $day, $date_low, $date_high) = get_dates();
 
     # Get the Payments
-    my $payments_ref = get_payments($date_low, $date_high);
+    my $payments_ref = get_payments($date_low, $date_high, $pay_method);
 
     # Get the Items for these Payments
     my ($payitems_ref, $payid_piids_ref, $piid_dates_ref) = get_payitems($payments_ref);
@@ -55,19 +66,20 @@
 
     # Generate the HTML
     my $ret;
-    $ret .= gen_search_form($year, $month, $day);
+    $ret .= gen_search_form($year, $month, $day, $pay_method);
     $ret .= gen_table_header();
-    $ret .= gen_payments_table(\%row_ctl);
+    $ret .= gen_payments_table(\%row_ctl, \@row_html);
 
     return $ret unless $row_ctl{count};                  # Bail if there are no payments
 
-    $ret .= gen_csv_link();
+    $ret .= gen_csv_link($pay_method);
     $ret .= gen_totals(\%stats);
     $ret .= gen_breakdown_tables(\%stats);
 
     return $ret;
 
     sub gen_csv_link {
+        my $method = shift;
         my $html;
 
         $html .= "<p><b>Statistics:</b>";
@@ -75,6 +87,7 @@
         # Link to CSV Report (which has content different from HTML)
         my $getargs = join('&', "view=csv",
                            map { "$_=$GET{$_}" } grep { $GET{$_} } qw(year month day skip));
+        $getargs .= "&pay_method=$method" if $method;
         $html .= " [<a href='?$getargs'>Generate CSV (Excludes Refunds)</a>]";
 
         return $html;
@@ -82,16 +95,17 @@
 
     sub gen_payments_table {
         my $row_ctl_ptr = shift;
+        my $row_html = shift;
         my $html;
 
         my $html_bar = gen_bar($row_ctl_ptr);
 
         # Load user info (from memcache)
-        my $u = LJ::load_userids( map { $_->[0] } @row_html );
+        my $u = LJ::load_userids( map { $_->[0] } @$row_html );
 
         # Combine page segments
         $html .= $html_bar;
-        $html .= join('', map { join($u->{$_->[0]}->{user}, @$_[1..3]) } @row_html);
+        $html .= join('', map { join($u->{$_->[0]}->{user}, @$_[1..3]) } @$row_html);
         $html .= $html_bar;
 
         $html .= "</table>\n";
@@ -123,13 +137,16 @@
     }
 
     sub gen_search_form {
-        my ($year, $month, $day) = @_;
+        my ($year, $month, $day, $method) = @_;
 
         my $html;
         $html .= "<form method='GET'>";
         $html .= "Year: "  . LJ::html_text({ 'name' => 'year',  'size' => 4, 'value' => $year }) . " ";
         $html .= "Month: " . LJ::html_text({ 'name' => 'month', 'size' => 2, 'value' => $month }) . " ";
         $html .= "Day: "   . LJ::html_text({ 'name' => 'day',   'size' => 2, 'value' => $day }) . " ";
+        $html .= "Method: "   . LJ::html_select({ 'name' => 'pay_method',
+                                                  'selected' => $method || ''},
+                                                  "", "", map { $_ => $_ } @pay_list) . " ";
         $html .= LJ::html_submit('View') . "</form> (enter * for day to get month report)";
 
         return $html;
@@ -307,10 +324,19 @@
     }
 
     sub get_payments {
-        my ($date_low, $date_high) = @_;
+        my ($date_low, $date_high, $method) = @_;
 
+        my $method_sql;
+        if ($method && $method ne '') {
+            $method_sql = "AND method='$method' ";
+        } else {
+            $method_sql = "AND method<>'free' ";
+        }
+
         # Get all the payments for the billing period
-        $sth = $dbh->prepare("SELECT * FROM payments WHERE used='Y' AND method<>'free' AND daterecv>$date_low AND daterecv<$date_high");
+        $sth = $dbh->prepare("SELECT * FROM payments WHERE used='Y' " .
+                             $method_sql .
+                             "AND daterecv>$date_low AND daterecv<$date_high");
         $sth->execute;
         $sth->{mysql_use_result} = 1;
         my %payids;

Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments