+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
+
+ $report->set_options('std_column_visibility' => 1,
+ 'title' => $form->{title});
+ $report->set_export_options('show_dunning', @filter_field_list, qw(sort sortdir));
+
+ my %column_defs = (
+ 'checkbox' => { 'text' => '', 'visible' => 'HTML' },
+ 'dunning_description' => { 'text' => $locale->text('Dunning Level') },
+ 'customername' => { 'text' => $locale->text('Customername') },
+ 'language' => { 'text' => $locale->text('Language') },
+ 'invnumber' => { 'text' => $locale->text('Invnumber') },
+ 'transdate' => { 'text' => $locale->text('Invdate') },
+ 'duedate' => { 'text' => $locale->text('Invoice Duedate') },
+ 'amount' => { 'text' => $locale->text('Amount') },
+ 'dunning_date' => { 'text' => $locale->text('Dunning Date') },
+ 'dunning_duedate' => { 'text' => $locale->text('Dunning Duedate') },
+ 'fee' => { 'text' => $locale->text('Total Fees') },
+ 'interest' => { 'text' => $locale->text('Interest') },
+ 'salesman' => { 'text' => $locale->text('Salesperson'), 'visible' => $form->{l_salesman} ? 1 : 0 },
+ );
+
+ $report->set_columns(%column_defs);
+ $report->set_column_order(qw(checkbox dunning_description customername language invnumber transdate
+ duedate amount dunning_date dunning_duedate fee interest salesman));
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
+
+ my $edit_url = sub { build_std_url('script=' . ($_[0]->{invoice} ? 'is' : 'ar') . '.pl', 'action=edit', 'callback') . '&id=' . $::form->escape($_[0]->{id}) };
+ my $print_url = sub { build_std_url('action=print_dunning', 'format=pdf', 'media=screen', 'dunning_id='.$_[0]->{dunning_id}, 'language_id=' . $_[0]->{language_id}) };
+ my $sort_url = build_std_url('action=show_dunning', grep { $form->{$_} } @filter_field_list);
+
+ foreach my $name (qw(dunning_description customername invnumber transdate duedate dunning_date dunning_duedate salesman)) {
+ my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$name}->{link} = $sort_url . "&sort=$name&sortdir=$sortdir";
+ }
+
+ my %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest salesman);
+
+ 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)
+ : ''),
+ };
+ }