From cc839bbae9c4615a5d3d2b0c7edcfb0bae58b0ec Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 2 May 2013 14:16:20 -0700 Subject: [PATCH] excel download fixes, #21937, #20337, etc. --- httemplate/search/cust_pay_pending.html | 5 ++--- .../search/elements/cust_main_dayranges.html | 9 +++++--- httemplate/search/elements/search-xls.html | 25 +++++++++++++++++++++- httemplate/search/h_cust_pay.html | 5 ++--- httemplate/search/unapplied_cust_pay.html | 5 ++--- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/httemplate/search/cust_pay_pending.html b/httemplate/search/cust_pay_pending.html index 2afce0ce9..54c9935ef 100755 --- a/httemplate/search/cust_pay_pending.html +++ b/httemplate/search/cust_pay_pending.html @@ -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 = ( diff --git a/httemplate/search/elements/cust_main_dayranges.html b/httemplate/search/elements/cust_main_dayranges.html index cf2d495b1..493365281 100644 --- a/httemplate/search/elements/cust_main_dayranges.html +++ b/httemplate/search/elements/cust_main_dayranges.html @@ -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( ''. $money_char.'%.2f'. '', + sprintf( ''.$money_char.'%.2f', $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(), '', diff --git a/httemplate/search/elements/search-xls.html b/httemplate/search/elements/search-xls.html index 26a51c4c7..bc844a579 100644 --- a/httemplate/search/elements/search-xls.html +++ b/httemplate/search/elements/search-xls.html @@ -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 =~ //i ) { # the only one in common use + $value =~ s[][]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/
/\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 ); } } diff --git a/httemplate/search/h_cust_pay.html b/httemplate/search/h_cust_pay.html index 99330fadd..6d2dd9955 100755 --- a/httemplate/search/h_cust_pay.html +++ b/httemplate/search/h_cust_pay.html @@ -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' ], - ) -%> +&> diff --git a/httemplate/search/unapplied_cust_pay.html b/httemplate/search/unapplied_cust_pay.html index e232291fe..f5c2bf0f9 100755 --- a/httemplate/search/unapplied_cust_pay.html +++ b/httemplate/search/unapplied_cust_pay.html @@ -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" -- 2.11.0