+ my ($current_dunning_rows, $previous_dunning_id, $first_row_for_dunning);
+
+ $current_dunning_rows = [];
+ $first_row_for_dunning = 1;
+ $form->{rowcount} = scalar @{ $form->{DUNNINGS} };
+
+ my $i = 0;
+
+ foreach my $ref (@{ $form->{DUNNINGS} }) {
+ $i++;
+
+ if ($previous_dunning_id != $ref->{dunning_id}) {
+ $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows });
+ $current_dunning_rows = [];
+ $first_row_for_dunning = 1;
+ }
+
+ if ($ref->{'language_id'}) {
+ $ref->{language} = SL::DB::Manager::Language->find_by('id' => $ref->{'language_id'})->{'description'};
+ }
+
+ my $row = { };
+ foreach my $column (keys %{ $ref }) {
+ $row->{$column} = {
+ 'data' => $first_row_for_dunning || (($column ne 'dunning_description') && ($column ne 'customername')) ? $ref->{$column} : '',
+
+ 'align' => $alignment{$column},
+
+ 'link' => ( $column eq 'invnumber' ? $edit_url->($ref)
+ : $column eq 'dunning_description' ? $print_url->($ref)
+ : ''),
+ };
+ }
+
+ $row->{checkbox} = !$first_row_for_dunning ? { } : {
+ 'raw_data' => $cgi->hidden('-name' => "dunning_id_$i", '-value' => $ref->{dunning_id})
+ . $cgi->checkbox('-name' => "selected_$i", '-value' => 1, '-label' => ''),
+ 'valign' => 'center',
+ 'align' => 'center',
+ };
+
+ if ($first_row_for_dunning) {
+ $row->{language} = {'raw_data' => $cgi->hidden('-name' => "language_id_$i", '-value' => $ref->{language_id})
+ . " $ref->{language}" };
+ } else {
+ $row->{language} = { };
+ }
+
+ push @{ $current_dunning_rows }, $row;
+
+ $previous_dunning_id = $ref->{dunning_id};
+ $first_row_for_dunning = 0;
+ }
+
+ $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows });
+
+ $report->set_options('raw_top_info_text' => $form->parse_html_template('dunning/show_dunning_top'),
+ 'raw_bottom_info_text' => $form->parse_html_template('dunning/show_dunning_bottom'),
+ 'output_format' => 'HTML',
+ 'attachment_basename' => $locale->text('dunning_list') . strftime('_%Y%m%d', localtime time),
+ );
+
+ $report->set_options_from_form();
+
+ $report->generate_with_headers();
+
+ $main::lxdebug->leave_sub();