RT#866: links to process payments from aging report
authormark <mark>
Thu, 1 Apr 2010 04:44:20 +0000 (04:44 +0000)
committermark <mark>
Thu, 1 Apr 2010 04:44:20 +0000 (04:44 +0000)
FS/FS/UI/Web.pm
httemplate/search/elements/cust_main_dayranges.html
httemplate/search/elements/search-html.html
httemplate/search/elements/search.html
httemplate/search/report_receivables.cgi

index 5e98742..c9264a0 100644 (file)
@@ -362,6 +362,7 @@ setting is supplied, the <B>cust-fields</B> configuration value.
 
 =cut
 
+
 sub cust_fields {
   my $record = shift;
   warn "FS::UI::Web::cust_fields called for $record ".
@@ -370,8 +371,9 @@ sub cust_fields {
 
   #cust_header(@_) unless @cust_fields; #now need to cache to keep cust_fields
   #                                     #override incase we were passed as a sub
-
+  
   my $seen_unlinked = 0;
+
   map { 
     if ( $record->custnum ) {
       warn "  $record -> $_" if $DEBUG > 1;
@@ -383,6 +385,38 @@ sub cust_fields {
   } @cust_fields;
 }
 
+=item cust_fields_subs
+
+Returns an array of subroutine references for returning customer field values.
+This is similar to cust_fields, but returns each field's sub as a distinct 
+element.
+
+=cut
+
+sub cust_fields_subs {
+  my $unlinked_warn = 0;
+  return map { 
+    my $f = $_;
+    if( $unlinked_warn++ ) {
+      sub {
+        my $record = shift;
+        if( $record->custnum ) {
+          $record->$f(@_);
+        }
+        else {
+          '(unlinked)'
+        };
+      }
+    } 
+    else {
+      sub {
+        my $record = shift;
+        $record->$f(@_) if $record->custnum;
+      }
+    }
+  } @cust_fields;
+}
+
 =item cust_colors
 
 Returns an array of subroutine references (or empty strings) for returning
index f759278..6bfe10e 100644 (file)
@@ -18,8 +18,9 @@ Example:
                  'name'        => 'customers',
                  'query'       => $sql_query,
                  'count_query' => $count_sql,
-                 'header'      => [
+                 'header'      => [ 
                                     FS::UI::Web::cust_header(),
+                                    @pay_head,
                                     '0-30',
                                     '30-60',
                                     '60-90',
@@ -31,8 +32,9 @@ Example:
                                     ( map '',
                                           ( 1 .. 
                                             scalar(FS::UI::Web::cust_header()-1)
-                                          )
+                                          ), @pay_labels
                                     ),
+                                    
                                     sprintf( $money_char.'%.2f',
                                              $row->{'rangecol_0_30'} ),
                                     sprintf( $money_char.'%.2f',
@@ -45,7 +47,8 @@ Example:
                                              $row->{'rangecol_0_0'} ),
                                   ],
                  'fields'      => [
-                                    \&FS::UI::Web::cust_fields,
+                                    FS::UI::Web::cust_fields_subs(),
+                                    @pay_labels,
                                     format_rangecol('0_30'),
                                     format_rangecol('30_60'),
                                     format_rangecol('60_90'),
@@ -56,6 +59,7 @@ Example:
                                     ( map { $_ ne 'Cust. Status' ? $clink : '' }
                                           FS::UI::Web::cust_header()
                                     ),
+                                    @pay_links,
                                     '',
                                     '',
                                     '',
@@ -67,13 +71,17 @@ Example:
                  #'size'        => [ '', '', '-1', '-1', '', '', '', '',  '', ],
                  #'style'       => [ '', '',  'b',  'b', '', '', '', '', 'b', ],
                  'size'        => [ ( map '', FS::UI::Web::cust_header() ),
+                                    ( map '', @pay_labels ),
                                     #'-1', '', '', '', '',  '', ],
-                                    '', '', '', '',  '', ],
+                                    '', '', '', '', '',  '', ],
                  'style'       => [ FS::UI::Web::cust_styles(),
+                                    ( map '', @pay_labels ),
                                     #'b', '', '', '', '', 'b', ],
                                     '', '', '', '', 'b', ],
                  'color'       => [
                                     FS::UI::Web::cust_colors(),
+                                    ( map '', @pay_labels ),
+                                    '',
                                     '',
                                     '',
                                     '',
@@ -166,6 +174,7 @@ my $sql_query = {
                    $range_cols,
                    $packages_cols,
                    FS::UI::Web::cust_sql_fields(),
+                   'payby',
                  ),
   'extra_sql' => $where,
   'order_by'  => "order by coalesce(lower(company), ''), lower(last)",
@@ -182,10 +191,25 @@ my $row = $total_sth->fetchrow_hashref();
 
 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
 
+my (@pay_head, @pay_labels, @pay_links);
+
+if($opt{'payment_links'} && $curuser->access_right('Process payment')) {
+  @pay_head = ({ label => 'Process', nodownload => 1, colspan => 2 },
+                { nodownload => 1 });
+
+  @pay_labels = (map { my ($payby,$label) = @$_; 
+                        sub {($payby eq $_[0]->payby) ? "<b>$label</b>" : $label}
+                     } ([CARD => 'Card'], [CHEK => 'ACH']) );
+
+  @pay_links = (map { [ "${p}misc/payment.cgi?payby=$_;custnum=", 'custnum' ] }
+                         'CARD', 'CHEK' );
+}
+
 </%init>
 <%once>
 
 my $conf = new FS::Conf;
+my $curuser = $FS::CurrentUser::CurrentUser;
 
 my $money_char = $conf->config('money_char') || '$';
 
index 6b915a6..3d4a4b0 100644 (file)
 
                 <TR>
 %                 my $h2 = 0;
+%                 my $colspan = 0;
 %                 foreach my $header ( @{ $opt{header} } ) { 
+%                   $colspan-- if $colspan > 0;
+%                   next if $colspan;
+%
 %                   my $label = ref($header) ? $header->{label} : $header;
+%                   $colspan = ref($header) ? $header->{colspan} : 0;
 %                   my $rowspan = 1;
 %                   my $style = '';
 %                   if ( $opt{header2} ) {
                     <TH CLASS   = "grid"
                         BGCOLOR = "#cccccc"
                         ROWSPAN = "<% $rowspan %>"
+                        <% $colspan ? 'COLSPAN = "'.$colspan.'"' : '' %>
                         <% $style %>
 
                     >
index 4bfe8b0..1312cac 100644 (file)
@@ -194,6 +194,9 @@ my(%opt) = @_;
 
 my $curuser = $FS::CurrentUser::CurrentUser;
 
+my $type = $cgi->param('_type') =~ /^(csv|\w*\.xls|select|html(-print)?)$/
+           ? $1 : 'html' ;
+
 my %align = (
   'l' => 'left',
   'r' => 'right',
@@ -204,6 +207,22 @@ my %align = (
 $opt{align} = [ map $align{$_}, split(//, $opt{align}) ],
   unless !$opt{align} || ref($opt{align});
 
+if($type =~ /csv|xls/) {
+  my $h = $opt{'header'};
+  my @del;
+  my $i = 0;
+  do {
+    if( ref($h->[$i]) and exists($h->[$i]->{'nodownload'}) ) {
+      splice(@{$opt{$_}}, $i, 1) foreach
+        qw(header footer fields links link_onclicks
+           align color size style cell_style xls_format);
+    }
+    else {
+      $i++;
+    }
+  } while ( exists($h->[$i]) );
+}
+
 $opt{disable_download} = 0
   if $opt{disable_download} && $curuser->access_right('Configuration download');
 
@@ -291,25 +310,22 @@ if ( $opt{'disableable'} ) {
   if ( $cgi->param('showdisabled') ) {
     $cgi->param('showdisabled', 0);
     $opt{'html_posttotal'} .=
-      '( <a href="'. $cgi->self_url. qq!">hide disabled $items</a> )!;
+      '( <a href="'. $cgi->self_url. qq!">hide disabled $items</a> )!; #"
     $cgi->param('showdisabled', 1);
   } else {
     $cgi->param('showdisabled', 1);
     $opt{'html_posttotal'} .=
-      '( <a href="'. $cgi->self_url. qq!">show disabled $items</a> )!;
+      '( <a href="'. $cgi->self_url. qq!">show disabled $items</a> )!; #"
     $cgi->param('showdisabled', 0);
   }
 
 }
 
-my $type = $cgi->param('_type') =~ /^(csv|\w*\.xls|select|html(-print)?)$/
-           ? $1 : 'html';
-
 my $limit = '';
 my($confmax, $maxrecords, $offset );
 
-unless ( $type =~ /^(csv|\w*\.xls)$/ ) {
-
+if ( !$type =~ /^(csv|\w*.xls)$/) {
+# html mode
   unless (exists($opt{count_query}) && length($opt{count_query})) {
     ( $opt{count_query} = $opt{query} ) =~
       s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i; #silly vim:/
index 5326184..73ebee4 100755 (executable)
@@ -1,6 +1,7 @@
 <% include( 'elements/cust_main_dayranges.html',
                  'title'       => 'Accounts Receivable Aging Summary',
                  'range_sub'   => \&balance,
+                 'payment_links' => 1,
           )
 %>
 <%init>