]> wagnertech.de Git - mfinanz.git/blobdiff - SL/ReportGenerator.pm
Bug in Auflistung von Lieferscheinen: Gibt es mehrere Aufträge mit der gleichen Auftr...
[mfinanz.git] / SL / ReportGenerator.pm
index cd9caea1ca172f55d9efbf1ef1caac339c97114b..2273c2e6b94b70dee83e4d330728a92c38e4179a 100644 (file)
@@ -322,7 +322,14 @@ sub prepare_html_content {
     foreach my $row (@{ $row_set }) {
       $inner_idx++;
 
+      my $output_columns = [ ];
+      my $skip_next      = 0;
       foreach my $col_name (@visible_columns) {
+        if ($skip_next) {
+          $skip_next--;
+          next;
+        }
+
         my $col = $row->{$col_name};
         $col->{CELL_ROWS} = [ ];
         foreach my $i (0 .. scalar(@{ $col->{data} }) - 1) {
@@ -339,10 +346,13 @@ sub prepare_html_content {
         } elsif ((1 == scalar @{ $col->{CELL_ROWS} }) && (!defined $col->{CELL_ROWS}->[0]->{data} || ($col->{CELL_ROWS}->[0]->{data} eq ''))) {
           $col->{CELL_ROWS}->[0]->{data} = ' ';
         }
+
+        push @{ $output_columns }, $col;
+        $skip_next = $col->{colspan} ? $col->{colspan} - 1 : 0;
       }
 
       my $row_data = {
-        'COLUMNS'       => [ map { $row->{$_} } @visible_columns ],
+        'COLUMNS'       => $output_columns,
         'outer_idx'     => $outer_idx,
         'outer_idx_odd' => $outer_idx % 2,
         'inner_idx'     => $inner_idx,
@@ -396,7 +406,12 @@ sub _cm2bp {
   return $_[0] * 72 / 2.54;
 }
 
-sub render_pdf_with_pdf_api2 {
+sub generate_pdf_content {
+  eval {
+    require PDF::API2;
+    require PDF::Table;
+  };
+
   my $self       = shift;
   my $variables  = $self->prepare_html_content();
   my $form       = $self->{form};
@@ -439,8 +454,17 @@ sub render_pdf_with_pdf_api2 {
       push @cell_props, $cell_props_row;
 
       foreach my $custom_header_col (@{ $custom_header_row }) {
-        push @{ $data_row },       $custom_header_col->{text};
-        push @{ $cell_props_row }, {};
+        push @{ $data_row }, $custom_header_col->{text};
+
+        my $num_output  = ($custom_header_col->{colspan} * 1 > 1) ? $custom_header_col->{colspan} : 1;
+        if ($num_output > 1) {
+          push @{ $data_row },       ('') x ($num_output - 1);
+          push @{ $cell_props_row }, { 'colspan' => $num_output };
+          push @{ $cell_props_row }, ({ }) x ($num_output - 1);
+
+        } else {
+          push @{ $cell_props_row }, {};
+        }
       }
     }
   }
@@ -463,8 +487,11 @@ sub render_pdf_with_pdf_api2 {
     }
 
     foreach my $row (@{ $row_set }) {
-      $data_row = [];
-      push @data, $data_row;
+      $data_row       = [];
+      $cell_props_row = [];
+
+      push @data,       $data_row;
+      push @cell_props, $cell_props_row;
 
       my $col_idx = 0;
       foreach my $col_name (@visible_columns) {
@@ -473,14 +500,14 @@ sub render_pdf_with_pdf_api2 {
 
         $column_props[$col_idx]->{justify} = 'right' if ($col->{align} eq 'right');
 
-        $col_idx++;
-      }
+        my $cell_props = { };
+        push @{ $cell_props_row }, $cell_props;
 
-      $cell_props_row = [];
-      push @cell_props, $cell_props_row;
+        if ($col->{colspan} && $col->{colspan} > 1) {
+          $cell_props->{colspan} = $col->{colspan};
+        }
 
-      foreach (0 .. $num_columns - 1) {
-        push @{ $cell_props_row }, { };
+        $col_idx++;
       }
     }
   }
@@ -580,6 +607,7 @@ sub render_pdf_with_pdf_api2 {
                 },
                 'column_props'          => \@column_props,
                 'cell_props'            => \@cell_props,
+                'max_word_length'       => 60,
     );
 
   foreach my $page_num (1..$pdf->pages()) {
@@ -651,14 +679,6 @@ sub _print_content {
   }
 }
 
-sub generate_pdf_content {
-  my $self = shift;
-
-  eval { require PDF::API2; require PDF::Table; };
-
-  return $self->render_pdf_with_pdf_api2(@_);
-}
-
 sub unescape_string {
   my $self  = shift;
   my $text  = shift;
@@ -699,8 +719,15 @@ sub generate_csv_content {
       $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}) } @visible_columns ]);
 
     } else {
-      foreach my $custom_header_row (@{ $self->{custom_headers} }) {
-        $csv->print($stdout, [ map { $self->unescape_string($_->{text}) } @{ $custom_header_row } ]);
+      foreach my $row (@{ $self->{custom_headers} }) {
+        my $fields = [ ];
+
+        foreach my $col (@{ $row }) {
+          my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1;
+          push @{ $fields }, ($self->unescape_string($col->{text})) x $num_output;
+        }
+
+        $csv->print($stdout, $fields);
       }
     }
   }
@@ -709,9 +736,20 @@ sub generate_csv_content {
     next if ('ARRAY' ne ref $row_set);
     foreach my $row (@{ $row_set }) {
       my @data;
+      my $skip_next = 0;
       foreach my $col (@visible_columns) {
+        if ($skip_next) {
+          $skip_next--;
+          next;
+        }
+
+        my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1;
+        $skip_next     = $num_output - 1;
+
         push @data, join($eol, map { s/\r?\n/$eol/g; $_ } @{ $row->{$col}->{data} });
+        push @data, ('') x $skip_next if ($skip_next);
       }
+
       $csv->print($stdout, \@data);
     }
   }