redirect pending payment report back to customer when the pending payment is resolved...
authorivan <ivan>
Thu, 19 Feb 2009 07:57:52 +0000 (07:57 +0000)
committerivan <ivan>
Thu, 19 Feb 2009 07:57:52 +0000 (07:57 +0000)
httemplate/search/cust_pay_pending.html
httemplate/search/elements/cust_pay_or_refund.html
httemplate/search/elements/search.html

index f0a3a01..f46e08a 100755 (executable)
@@ -10,6 +10,7 @@
                 'addl_fields'   => [ sub { time2str('%r', shift->_date ) },
                                      $status_sub,
                                    ],
+                'redirect_empty' => $redirect_empty,
           )
 %>
 <%init>
@@ -44,4 +45,13 @@ my $status_sub = sub {
   $return. qq! <FONT SIZE="-1">($link)</FONT>!;
 };
 
+my $redirect_empty = sub {
+  my $cgi = shift;
+  if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
+    $p. "view/cust_main.cgi?$1";
+  } else {
+    '';
+  }
+};
+
 </%init>
index 9e2eceb..add8427 100755 (executable)
@@ -3,45 +3,47 @@
 Examples:
 
   include( 'elements/cust_pay_or_refund.html',
-               'thing'         => 'pay',
-               'amount_field'  => 'paid',
-               'name_singular' => 'payment',
-               'name_verb'     => 'paid',
+               'thing'          => 'pay',
+               'amount_field'   => 'paid',
+               'name_singular'  => 'payment',
+               'name_verb'      => 'paid',
          )
 
   include( 'elements/cust_pay_or_refund.html',
-               'thing'         => 'refund',
-               'amount_field'  => 'refund',
-               'name_singular' => 'refund',
-               'name_verb'     => 'refunded',
+               'thing'          => 'refund',
+               'amount_field'   => 'refund',
+               'name_singular'  => 'refund',
+               'name_verb'      => 'refunded',
          )
 
   include( 'elements/cust_pay_or_refund.html',
-               'thing'         => 'pay_pending',
-               'amount_field'  => 'paid',
-               'name_singular' => 'pending payment',
-               'name_verb'     => 'pending',
-               'disable_link'  => 1,
-               'disable_by'    => 1,
-               'html_init'     => '',
-               'addl_header'   => [],
-               'addl_fields'   => [],
+               'thing'          => 'pay_pending',
+               'amount_field'   => 'paid',
+               'name_singular'  => 'pending payment',
+               'name_verb'      => 'pending',
+               'disable_link'   => 1,
+               'disable_by'     => 1,
+               'html_init'      => '',
+               'addl_header'    => [],
+               'addl_fields'    => [],
+               'redirect_empty' => $redirect_empty,
           )
 
 </%doc>
 <% include( 'search.html',
-                'title'         => $title,
-                'name_singular' => $name_singular,
-                'query'         => $sql_query,
-                'count_query'   => $count_query,
-                'count_addl'    => [ '$%.2f total '.$opt{name_verb}, ],
-                'header'        => [ "\u$name_singular",
-                                     'Amount',
-                                     'Date',
-                                     @header,
-                                     FS::UI::Web::cust_header(),
-                                   ],
-                'fields'      => [
+                'title'          => $title,
+                'name_singular'  => $name_singular,
+                'query'          => $sql_query,
+                'count_query'    => $count_query,
+                'count_addl'     => [ '$%.2f total '.$opt{name_verb}, ],
+                'redirect_empty' => $opt{'redirect_empty'},
+                'header'         => [ "\u$name_singular",
+                                      'Amount',
+                                      'Date',
+                                      @header,
+                                      FS::UI::Web::cust_header(),
+                                    ],
+                'fields'       => [
                   'payby_payinfo_pretty',
                   sub { sprintf('$%.2f', shift->$amount_field() ) },
                   sub { time2str('%b %d %Y', shift->_date ) },
@@ -96,13 +98,11 @@ my @header = ();
 my @fields = ();
 unless ( $opt{'disable_by'} ) {
   push @header, 'By';
-  push @fields, sub {
-                  sub { my $o = shift->otaker;
-                        $o = 'auto billing'          if $o eq 'fs_daily';
-                        $o = 'customer self-service' if $o eq 'fs_selfservice';
-                        $o;
-                      },
-  };
+  push @fields, sub { my $o = shift->otaker;
+                      $o = 'auto billing'          if $o eq 'fs_daily';
+                      $o = 'customer self-service' if $o eq 'fs_selfservice';
+                      $o;
+                    };
 }
 
 push @header, @{ $opt{'addl_header'} }
index 23fe8f4..8835f8c 100644 (file)
@@ -60,7 +60,15 @@ Example:
     #redirect if there's only one item...
     # listref of URL base and column name (or method)
     # or a coderef that returns the same
-    'redirect' =>
+    'redirect' => sub { my( $record, $cgi ) = @_;
+                        [ popurl(2).'view/item.html', 'primary_key' ];
+                      },
+
+    #redirect if there's no items
+    # scalar URL or a coderef that returns a URL
+    'redirect_empty' => sub { my( $cgi ) = @_;
+                              popurl(2).'view/item.html';
+                            },
    
     ###
     # optional
@@ -277,9 +285,18 @@ Example:
 %        && $type ne 'html-print'
 %      ) {
 %     my $redirect = $opt{'redirect'};
-%     $redirect = &{$redirect}($rows->[0]) if ref($redirect) eq 'CODE';
+%     $redirect = &{$redirect}($rows->[0], $cgi) if ref($redirect) eq 'CODE';
 %     my( $url, $method ) = @$redirect;
 %     redirect( $url. $rows->[0]->$method() );
+%   } elsif ( exists($opt{'redirect_empty'}) && ! scalar(@$rows) && $total == 0
+%             && $type ne 'html-print'
+%             && $opt{'redirect_empty'}
+%             && ( ref($opt{'redirect_empty'}) ne 'CODE'
+%                  || &{$opt{'redirect_empty'}}($cgi)    )
+%      ) {
+%     my $redirect = $opt{'redirect_empty'};
+%     $redirect = &{$redirect}($cgi) if ref($redirect) eq 'CODE';
+%     redirect( $redirect );
 %   } else {
 %     if ( $opt{'name_singular'} ) {
 %       $opt{'name'} = PL($opt{'name_singular'});