History-Eintrag auch für Auftrags-Import erzeugen.
[kivitendo-erp.git] / SL / Form.pm
index 8ae6ed4..04ac43c 100644 (file)
@@ -472,6 +472,7 @@ sub header {
 
   $layout->use_javascript("$_.js") for (qw(
     jquery jquery-ui jquery.cookie jquery.checkall jquery.download
+    jquery/jquery.form client_js
     common part_selection switchmenuframe autocomplete_part
   ), "jquery/ui/i18n/jquery.ui.datepicker-$::myconfig{countrycode}");
 
@@ -1074,7 +1075,7 @@ sub parse_template {
 
   close OUT if $self->{OUT};
 
-  my $copy_to_webdav = $::instance_conf->get_webdav && $::instance_conf->get_webdav_documents && !$self->{preview};
+  my $copy_to_webdav = $::instance_conf->get_webdav && $::instance_conf->get_webdav_documents && !$self->{preview} && $self->{tmpdir} && $self->{tmpfile} && $self->{type};
 
   if ($self->{media} eq 'file') {
     copy(join('/', $self->{cwd}, $userspath, $self->{tmpfile}), $out =~ m|^/| ? $out : join('/', $self->{cwd}, $out)) if $template->uses_temp_file;
@@ -1155,16 +1156,22 @@ sub parse_template {
         seek  IN, 0, 0;
 
       } else {
-        $self->{attachment_filename} = ($self->{attachment_filename})
-                                     ? $self->{attachment_filename}
-                                     : $self->generate_attachment_filename();
-
-        # launch application
-        print qq|Content-Type: | . $template->get_mime_type() . qq|
-Content-Disposition: attachment; filename="$self->{attachment_filename}"
-Content-Length: $numbytes
+        my %headers = ('-type'       => $template->get_mime_type,
+                       '-connection' => 'close',
+                       '-charset'    => 'UTF-8');
+
+        $self->{attachment_filename} ||= $self->generate_attachment_filename;
+
+        if ($self->{attachment_filename}) {
+          %headers = (
+            %headers,
+            '-attachment'     => $self->{attachment_filename},
+            '-content-length' => $numbytes,
+            '-charset'        => '',
+          );
+        }
 
-|;
+        print $::request->cgi->header(%headers);
 
         $::locale->with_raw_io(\*STDOUT, sub { print while <IN> });
       }
@@ -1415,7 +1422,7 @@ sub date_closed {
   $main::lxdebug->enter_sub();
 
   my ($self, $date, $myconfig) = @_;
-  my $dbh = $self->dbconnect($myconfig);
+  my $dbh = $self->get_standard_dbh;
 
   my $query = "SELECT 1 FROM defaults WHERE ? < closedto";
   my $sth = prepare_execute_query($self, $dbh, $query, conv_date($date));
@@ -1448,7 +1455,7 @@ sub date_max_future {
   $main::lxdebug->enter_sub();
 
   my ($self, $date, $myconfig) = @_;
-  my $dbh = $self->dbconnect($myconfig);
+  my $dbh = $self->get_standard_dbh;
 
   my $query = "SELECT 1 FROM defaults WHERE ? - current_date > max_future_booking_interval";
   my $sth = prepare_execute_query($self, $dbh, $query, conv_date($date));
@@ -1937,7 +1944,7 @@ sub get_duedate {
               : $self->{vendor_id}   ? SL::DB::Vendor     ->new(id => $self->{vendor_id})  ->load->payment
               :                        croak("Missing field in \$::form: payment_id, customer_id or vendor_id");
 
-  my $duedate = $terms->calc_date(reference_date => $reference_date)->to_kivitendo;
+  my $duedate = $terms ? $terms->calc_date(reference_date => $reference_date)->to_kivitendo : undef;
 
   $main::lxdebug->leave_sub();