show refund reason on report and make it searchable, #39398
authorMark Wells <mark@freeside.biz>
Tue, 15 Dec 2015 00:26:05 +0000 (16:26 -0800)
committerMark Wells <mark@freeside.biz>
Tue, 15 Dec 2015 01:04:14 +0000 (17:04 -0800)
httemplate/elements/menu.html
httemplate/search/cust_pay_pending.html
httemplate/search/cust_pay_void.html
httemplate/search/elements/cust_pay_or_refund.html
httemplate/search/elements/report_cust_pay_or_refund.html
httemplate/search/report_cust_refund.html

index 0988b98..fd77d9d 100644 (file)
@@ -684,12 +684,12 @@ if ( $curuser->access_right('Configuration') ) {
      if $conf->exists('enable_taxproducts');
   $config_billing{'Tax classes'} = [ $fsurl. 'browse/part_pkg_taxclass.html', 'Tax classes' ];
 
+  $config_billing{'separator5'} = ''; #its a separator!
   $config_billing{'Credit reasons'}  = [ $fsurl.'browse/reason.html?class=R', 'Credit reasons explain why a credit was issued.' ];
   $config_billing{'Credit reason types'}  = [ $fsurl.'browse/reason_type.html?class=R', 'Credit reason types define groups of reasons.' ];
   $config_billing{'Credit void reasons'}  = [ $fsurl.'browse/reason.html?class=X', 'Credit void reasons explain why a credit was voided.' ];
   $config_billing{'Credit void reason types'}  = [ $fsurl.'browse/reason_type.html?class=X', 'Credit void reason types define groups of reasons.' ];
   
-  $config_billing{'separator5'} = ''; #its a separator!
   $config_billing{'Refund reasons'}  = [ $fsurl.'browse/reason.html?class=F', 'Refund reasons explain why a refund was issued.' ];
   $config_billing{'Refund reason types'}  = [ $fsurl.'browse/reason_type.html?class=F', 'Refund reason types define groups of reasons.' ];
 }
index 54c9935..942085c 100755 (executable)
@@ -9,6 +9,7 @@
                 'addl_fields'   => [ sub { time2str('%r', shift->_date ) },
                                      $status_sub,
                                    ],
+                'addl_sort_fields' => [ 'status' ],
                 'redirect_empty' => $redirect_empty,
 &>
 <%init>
index 5b24736..c639706 100755 (executable)
@@ -8,4 +8,5 @@
                 'addl_fields'   => [
                   sub { time2str('%b %d %Y', shift->void_date ) },
                 ],
+                'addl_sort_fields' => [ 'void_date' ],
 &>
index 1fea67c..ffc6afe 100755 (executable)
@@ -26,6 +26,7 @@ Examples:
                'html_init'      => '',
                'addl_header'    => [],
                'addl_fields'    => [],
+               'addl_sort_fields' => [],
                'redirect_empty' => $redirect_empty,
           )
 
@@ -80,6 +81,8 @@ die "access denied"
 
 my $table = $opt{'table'} || 'cust_'.$opt{'thing'};
 
+my $has_reason = dbdef->table($table)->column('reasonnum') ? 1 : 0;
+
 my $amount_field = $opt{'amount_field'};
 my $name_singular = $opt{'name_singular'};
 
@@ -217,6 +220,7 @@ unless ( $opt{'disable_by'} ) {
                       $o = 'customer self-service' if $o eq 'fs_selfservice';
                       $o;
                     };
+  push @sort_fields, '';
 }
 
 if ( $tax_names ) {
@@ -233,6 +237,7 @@ if ( $tax_names ) {
                                    split('\|', shift->tax_names)
                            );
                     };
+  push @sort_fields, '', '';
 }
 
 push @header, FS::UI::Web::cust_header();
@@ -242,11 +247,14 @@ push @links, map { $_ ne 'Cust. Status' ? $cust_link : '' }
 my @color = ( ( map '', @fields ), FS::UI::Web::cust_colors() );
 my @style = ( ( map '', @fields ), FS::UI::Web::cust_styles() );
 push @fields, \&FS::UI::Web::cust_fields;
+push @sort_fields, FS::UI::Web::cust_sort_fields;
 
 push @header, @{ $opt{'addl_header'} }
   if $opt{'addl_header'};
 push @fields, @{ $opt{'addl_fields'} }
   if $opt{'addl_fields'};
+push @sort_fields, @{ $opt{'addl_sort_fields'} }
+  if $opt{'addl_sort_fields'};
 
 my( $count_query, $sql_query, @count_addl );
 if ( $cgi->param('magic') ) {
@@ -432,6 +440,7 @@ if ( $cgi->param('magic') ) {
       push @search, "($table.auth LIKE '$1%') OR ($table.order_number LIKE '$1%')";
       push @fields, 'auth', 'order_number';
       push @header, 'Auth #', 'Transaction #';
+      push @sort_fields, '', '';
       $align .= 'rr';
 
     }
@@ -513,6 +522,18 @@ if ( $cgi->param('magic') ) {
   my $addl_from = FS::UI::Web::join_cust_main($table);
   my $group_by = '';
 
+  # reasons, for refunds and voided payments
+  if ( $has_reason ) {
+    push @select, "reason.reason";
+    $addl_from .= " LEFT JOIN reason USING (reasonnum)\n";
+    push @fields, 'reason';
+    push @sort_fields, 'reason.reason';
+    push @header, emt('Reason');
+    if ( $cgi->param('reasonnum') =~ /^(\d+)$/ ) {
+      push @search, "COALESCE(reasonnum, 0) = $1";
+    }
+  }
+
   if ( $cgi->param('tax_names') ) {
     if ( dbh->{Driver}->{Name} =~ /^Pg/i ) {
 
index 70727c0..a25e696 100644 (file)
@@ -23,7 +23,7 @@ Examples:
 
   <TR>
     <TH CLASS="background" COLSPAN=2 ALIGN="left">
-      <FONT SIZE="+1"><% mt('Payment search options') |h %></FONT>
+      <FONT SIZE="+1"><% mt('[_1] search options', ucfirst($name_singular)) |h %></FONT>
     </TH>
   </TR>
 
@@ -51,6 +51,20 @@ Examples:
 
   <& /elements/tr-select-user.html &>
 
+% if ( $has_reason ) {
+%   # limit to reasons that are in use for the table being reported on
+%   # (maybe order by count(*) desc?)
+  <& /elements/tr-select-table.html,
+    label       => emt('Reason'),
+    field       => 'reasonnum',
+    id          => 'reasonnum',
+    table       => 'reason',
+    name_col    => 'reason',
+    extra_sql   => " WHERE EXISTS(SELECT 1 FROM $table WHERE $table.reasonnum = reason.reasonnum) ",
+    empty_label => emt('any'),
+  &>
+% }
+
   <TR>
     <TD ALIGN="right" VALIGN="center"><% mt(ucfirst($name_singular). ' date') |h %></TD>
     <TD>
@@ -166,6 +180,8 @@ my $title = $void ? "Voided $name_singular report" :
             "\u$name_singular report" ;
 $table .= '_void' if $void;
 
+my $has_reason = dbdef->table($table)->column('reasonnum');
+
 tie (my %payby, 'Tie::IxHash',
   'CARD-VisaMC'    => 'credit card (Visa/MasterCard)',
   'CARD-Amex'      => 'credit card (American Express)',
index fe84cf6..98b31a1 100644 (file)
@@ -1,4 +1,5 @@
 <& elements/report_cust_pay_or_refund.html,
               'thing'          => 'refund',
               'name_singular'  => emt('refund'),
+              'reason_class'   => 'F',
 &>