excel download fixes, #21937, #20337, etc.
authorMark Wells <mark@freeside.biz>
Thu, 2 May 2013 21:16:20 +0000 (14:16 -0700)
committerMark Wells <mark@freeside.biz>
Thu, 2 May 2013 21:16:20 +0000 (14:16 -0700)
httemplate/search/cust_pay_pending.html
httemplate/search/elements/cust_main_dayranges.html
httemplate/search/elements/search-xls.html
httemplate/search/h_cust_pay.html
httemplate/search/unapplied_cust_pay.html

index 2afce0c..54c9935 100755 (executable)
@@ -1,4 +1,4 @@
-<% include( 'elements/cust_pay_or_refund.html',
+<& elements/cust_pay_or_refund.html,
                 'thing'         => 'pay_pending',
                 'amount_field'  => 'paid',
                 'name_singular' => 'pending payment',
@@ -10,8 +10,7 @@
                                      $status_sub,
                                    ],
                 'redirect_empty' => $redirect_empty,
-          )
-%>
+&>
 <%init>
 
 my %statusaction = (
index cf2d495..4933652 100644 (file)
@@ -2,10 +2,10 @@
 
 Example:
 
-  include( 'elements/cust_main_dayranges.html',
+  <& elements/cust_main_dayranges.html,
                  'title'       => 'Accounts Receivable Aging Summary',
                  'range_sub'   => $mysub,
-         )
+  &>
 
   my $mysub = sub {
     my( $start, $end ) = @_;
@@ -44,7 +44,7 @@ Example:
                                              $row->{'rangecol_60_90'} ),
                                     sprintf( $money_char.'%.2f',
                                              $row->{'rangecol_90_0'} ),
-                                    sprintf( '<b>'. $money_char.'%.2f'. '</b>',
+                                    sprintf( '<b>'.$money_char.'%.2f</b>',
                                              $row->{'rangecol_0_0'} ),
                                     ('') x @pay_labels,
                                   ],
@@ -81,6 +81,9 @@ Example:
                                     '', '', '', '', 'b', 
                                     ( map '', @pay_labels ),
                                     ],
+                 'xls_format'  => [ (map '', FS::UI::Web::cust_styles),
+                                    '', '', '', '', { bold => 1 },
+                                  ],
                  'color'       => [
                                     FS::UI::Web::cust_colors(),
                                     '',
index 26a51c4..bc844a5 100644 (file)
@@ -6,6 +6,8 @@ my $header = $args{'header'};
 my $rows   = $args{'rows'};
 my %opt    = %{ $args{'opt'} };    
 
+my $style  = $opt{'style'};
+
 my $override = scalar(@$rows) >= 65536 ? 'XLSX' : '';
 
 my $format = $FS::CurrentUser::CurrentUser->spreadsheet_format($override);
@@ -42,6 +44,12 @@ my $header_format = $workbook->add_format(
   bg_color => 55, #22,
   bottom   => 3,
 );
+my $footer_format = $workbook->add_format(
+  italic   => 1,
+  locked   => 1,
+  bg_color => 55,
+  top      => 3,
+);
 my $default_format = $workbook->add_format(locked => 0);
 
 my %money_format;
@@ -50,10 +58,24 @@ my $money_char = FS::Conf->new->config('money_char') || '$';
 my %date_format;
 xl_parse_date_init();
 
+my %bold_format;
+
 my $writer = sub {
   # Wrapper for $worksheet->write.
   # Do any massaging of the value/format here.
   my ($r, $c, $value, $format) = @_;
+  #warn "writer called with format $format\n";
+
+  if ( $style->[$c] eq 'b' or $value =~ /<b>/i ) { # the only one in common use
+    $value =~ s[</?b>][]ig;
+    if ( !exists($bold_format{$format}) ) {
+      $bold_format{$format} = $workbook->add_format();
+      $bold_format{$format}->copy($format);
+      $bold_format{$format}->set_bold();
+    }
+    $format = $bold_format{$format};
+  }
+
   # convert HTML entities
   # both Spreadsheet::WriteExcel and Excel::Writer::XLSX accept UTF-8 strings
   $value = decode_entities($value);
@@ -86,6 +108,7 @@ my $writer = sub {
     # String: replace line breaks with newlines
     $value =~ s/<BR>/\n/gi;
   }
+  #warn "writing with format $format\n";
   $worksheet->write($r, $c, $value, $format);
 };
 
@@ -140,7 +163,7 @@ if ( $opt{'footer'} ) {
     if ( ref($item) eq 'CODE' ) {
       $item = &{$item}();
     }
-    $writer->( $r, $c++, $item, $header_format );
+    $writer->( $r, $c++, $item, $footer_format );
   }
 }
 
index 99330fa..6d2dd99 100755 (executable)
@@ -1,9 +1,8 @@
-<% include( 'elements/cust_pay_or_refund.html',
+<& elements/cust_pay_or_refund.html,
                 'table'         => 'h_cust_pay',
                 'amount_field'  => 'paid',
                 'name_singular' => 'payment',
                 'name_verb'     => 'paid',
                 'pre_header'    => [ 'Transaction',    'By' ],
                 'pre_fields'    => [ 'history_action', 'history_user' ],
-          )
-%>
+&>
index e232291..f5c2bf0 100755 (executable)
@@ -1,9 +1,8 @@
-<% include( 'elements/cust_main_dayranges.html',
+<& elements/cust_main_dayranges.html,
                  #'title'       => 'Prepaid Balance Aging Summary', #???
                  'title'       => 'Unapplied Payments Aging Summary',
                  'range_sub'   => \&unapplied_payments,
-          )
-%>
+&>
 <%init>
 
 die "access denied"