Dialogbuchen - Abteilung nutzt immer L.select_tag als Dropdown
[kivitendo-erp.git] / bin / mozilla / ap.pl
index 00ab618..4ceb128 100644 (file)
@@ -40,10 +40,11 @@ use SL::AP;
 use SL::FU;
 use SL::IR;
 use SL::IS;
-use SL::PE;
 use SL::ReportGenerator;
 use SL::DB::Default;
 use SL::DB::PurchaseInvoice;
+use SL::Webdav;
+use SL::Locale::String qw(t8);
 
 require "bin/mozilla/arap.pl";
 require "bin/mozilla/common.pl";
@@ -126,6 +127,19 @@ sub display_form {
 
   $main::auth->assert('ap_transactions');
 
+  # get all files stored in the webdav folder
+  if ($form->{invnumber} && $::instance_conf->get_webdav) {
+    my $webdav = SL::Webdav->new(
+      type     => 'accounts_payable',
+      number   => $form->{invnumber},
+    );
+    my $webdav_path = $webdav->webdav_path;
+    my @all_objects = $webdav->get_all_objects;
+    @{ $form->{WEBDAV} } = map { { name => $_->filename,
+                                   type => t8('File'),
+                                   link => File::Spec->catfile($_->full_filedescriptor),
+                               } } @all_objects;
+  }
   &form_header;
   &form_footer;
 
@@ -496,6 +510,12 @@ sub mark_as_paid {
   $main::lxdebug->leave_sub();
 }
 
+sub show_draft {
+  $::form->{transdate} = DateTime->today_local->to_kivitendo if !$::form->{transdate};
+  $::form->{gldate}    = $::form->{transdate} if !$::form->{gldate};
+  update();
+}
+
 sub update {
   $main::lxdebug->enter_sub();
 
@@ -723,6 +743,12 @@ sub post {
   $form->{id} = 0 if $form->{postasnew};
 
   if (AP->post_transaction(\%myconfig, \%$form)) {
+    # create webdav folder
+    if ($::instance_conf->get_webdav) {
+      SL::Webdav->new(type     => 'accounts_payable',
+                      number   => $form->{invnumber},
+                     )->webdav_path;
+    }
     # saving the history
     if(!exists $form->{addition} && $form->{id} ne "") {
       $form->{snumbers}  = qq|invnumber_| . $form->{invnumber};