Merge branch 'master' of ssh://lx-office.linet-services.de/~/lx-office-erp
[kivitendo-erp.git] / SL / ReportGenerator.pm
index e593a5e..2b37e78 100644 (file)
@@ -1,14 +1,11 @@
 package SL::ReportGenerator;
 
 use Data::Dumper;
-use IO::Wrap;
 use List::Util qw(max);
 use Text::CSV_XS;
 #use PDF::API2;    # these two eat up to .75s on startup. only load them if we actually need them
 #use PDF::Table;
 
-use SL::Form;
-
 use strict;
 
 # Cause locales.pl to parse these files:
@@ -427,7 +424,7 @@ sub generate_pdf_content {
   my (@data, @column_props, @cell_props);
 
   my ($data_row, $cell_props_row);
-  my @visible_columns = $self->get_visible_columns('HTML');
+  my @visible_columns = $self->get_visible_columns('PDF');
   my $num_columns     = scalar @visible_columns;
   my $num_header_rows = 1;
 
@@ -690,11 +687,10 @@ sub _print_content {
 }
 
 sub unescape_string {
-  my $self  = shift;
-  my $text  = shift;
+  my ($self, $text, $do_iconv) = @_;
 
-  $text     = $main::locale->unquote_special_chars('HTML', $text);
-  $text     = $::locale->{iconv}->convert($text);
+  $text = $main::locale->unquote_special_chars('HTML', $text);
+  $text = $::locale->{iconv}->convert($text) if $do_iconv;
 
   return $text;
 }
@@ -720,12 +716,15 @@ sub generate_csv_content {
                                 'quote_char'  => $quote_char,
                                 'eol'         => $eol, });
 
-  my $stdout          = wraphandle(\*STDOUT);
   my @visible_columns = $self->get_visible_columns('CSV');
 
+  my $stdout;
+  open $stdout, '>-';
+  binmode $stdout, ':encoding(utf8)' if $::locale->is_utf8;
+
   if ($opts->{headers}) {
     if (!$self->{custom_headers}) {
-      $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}) } @visible_columns ]);
+      $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}, 1) } @visible_columns ]);
 
     } else {
       foreach my $row (@{ $self->{custom_headers} }) {