Mahnungsbericht: Webdav-Dateien f. Mahnlauf anzeigen
[kivitendo-erp.git] / bin / mozilla / dn.pl
index e690bb9..1ac780f 100644 (file)
@@ -34,6 +34,8 @@
 
 use POSIX qw(strftime);
 
+use List::MoreUtils qw(none);
+
 use SL::IS;
 use SL::DN;
 use SL::DB::Department;
@@ -42,6 +44,7 @@ use SL::File;
 use SL::Helper::Flash qw(flash);
 use SL::Locale::String qw(t8);
 use SL::Presenter::FileObject;
+use SL::Presenter::WebdavObject;
 use SL::ReportGenerator;
 
 require "bin/mozilla/common.pl";
@@ -337,7 +340,7 @@ sub show_dunning {
 
   $main::auth->assert('dunning_edit');
 
-  my @filter_field_list = qw(customer_id customer dunning_level department_id invnumber ordnumber
+  my @filter_field_list = qw(customer_id customer dunning_id dunning_level department_id invnumber ordnumber
                              transdatefrom transdateto dunningfrom dunningto notes showold l_salesman salesman_id);
 
   report_generator_set_default_sort('customername', 1);
@@ -375,16 +378,18 @@ sub show_dunning {
     'transdate'           => { 'text' => $locale->text('Invdate') },
     'duedate'             => { 'text' => $locale->text('Invoice Duedate') },
     'amount'              => { 'text' => $locale->text('Amount') },
+    'dunning_id'          => { 'text' => $locale->text('Dunning number') },
     '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 },
-    'documents'           => { 'text' => $locale->text('Documents')  , 'visible' => $::instance_conf->get_doc_storage ? 1 : 0 },
+    'documents'           => { 'text' => $locale->text('Documents'),   'visible' => $::instance_conf->get_doc_storage ? 1 : 0 },
+    'webdav'              => { 'text' => $locale->text('WebDAV'),      'visible' => $::instance_conf->get_webdav      ? 1 : 0 },
   );
 
   $report->set_columns(%column_defs);
-  $report->set_column_order(qw(checkbox dunning_description customername language invnumber transdate
+  $report->set_column_order(qw(checkbox dunning_description dunning_id customername language invnumber transdate
                                duedate amount dunning_date dunning_duedate fee interest salesman));
   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
@@ -392,12 +397,12 @@ sub show_dunning {
   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)) {
+  foreach my $name (qw(dunning_description customername invnumber transdate duedate dunning_date dunning_duedate salesman dunning_id)) {
     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 %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest salesman dunning_id);
 
   my ($current_dunning_rows, $previous_dunning_id, $first_row_for_dunning);
 
@@ -423,12 +428,13 @@ sub show_dunning {
     my $row = { };
     foreach my $column (keys %{ $ref }) {
       $row->{$column} = {
-        'data'  => $first_row_for_dunning || (($column ne 'dunning_description') && ($column ne 'customername')) ? $ref->{$column} : '',
+        'data'  => $first_row_for_dunning || (none { $_ eq $column } qw(dunning_description customername dunning_id)) ? $ref->{$column} : '',
 
         'align' => $alignment{$column},
 
         'link'  => (  $column eq 'invnumber'           ? $edit_url->($ref)
                     : $column eq 'dunning_description' ? $print_url->($ref)
+                    : $column eq 'dunning_id'          ? $print_url->($ref)
                     :                                    ''),
       };
     }
@@ -447,7 +453,7 @@ sub show_dunning {
       $row->{language} = { };
     }
 
-    if ($::instance_conf->get_doc_storage) {
+    if ($::instance_conf->get_doc_storage && $first_row_for_dunning) {
       my @files  = SL::File->get_all_versions(object_id   => $ref->{dunning_id},
                                               object_type => 'dunning',
                                               file_type   => 'document',);
@@ -459,6 +465,20 @@ sub show_dunning {
         $row->{documents} = { };
       }
     }
+    if ($::instance_conf->get_webdav && $first_row_for_dunning) {
+      my $webdav = SL::Webdav->new(
+        type     => 'dunning',
+        number   => $ref->{dunning_id},
+      );
+      my @all_objects = $webdav->get_all_objects;
+      if (scalar @all_objects) {
+        my $html          = join '<br>', map { SL::Presenter::WebdavObject::webdav_object($_) } @all_objects;
+        my $text          = join "\n",   map { $_->filename                                   } @all_objects;
+        $row->{webdav}    = { 'raw_data' => $html, data => $text };
+      } else {
+        $row->{webdav}    = { };
+      }
+    }
 
     push @{ $current_dunning_rows }, $row;