]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Order.pm
Lieferantenstammdaten: Tab »Abweichende Rechnungsadressen« nicht anzeigen
[mfinanz.git] / SL / Controller / Order.pm
index 81f15e1d0beaf8b73683a3cf3a950f11ba2e9286..c8cc6ea24040fa4e7c5bc33216f5bd93d289fa3e 100644 (file)
@@ -330,7 +330,7 @@ sub action_print {
     $self->js->flash('info', t8('The document has been printed.'));
   }
 
-  my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $doc_filename);
+  my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $doc_filename, $formname);
   if (scalar @warnings) {
     $self->js->flash('warning', $_) for @warnings;
   }
@@ -474,19 +474,30 @@ sub action_send_email {
   $::form->{$_}     = $::form->{print_options}->{$_} for keys %{ $::form->{print_options} };
   $::form->{media}  = 'email';
 
-  if (($::form->{attachment_policy} // '') !~ m{^(?:old_file|no_file)$}) {
+  $::form->{attachment_policy} //= '';
+
+  # Is an old file version available?
+  my $attfile;
+  if ($::form->{attachment_policy} eq 'old_file') {
+    $attfile = SL::File->get_all(object_id     => $self->order->id,
+                                 object_type   => $self->type,
+                                 file_type     => 'document',
+                                 print_variant => $::form->{formname});
+  }
+
+  if ($::form->{attachment_policy} ne 'no_file' && !($::form->{attachment_policy} eq 'old_file' && $attfile)) {
     my $doc;
     my @errors = $self->generate_doc(\$doc, {media      => $::form->{media},
-                                            format     => $::form->{print_options}->{format},
-                                            formname   => $::form->{print_options}->{formname},
-                                            language   => $self->order->language,
-                                            printer_id => $::form->{print_options}->{printer_id},
-                                            groupitems => $::form->{print_options}->{groupitems}});
+                                             format     => $::form->{print_options}->{format},
+                                             formname   => $::form->{print_options}->{formname},
+                                             language   => $self->order->language,
+                                             printer_id => $::form->{print_options}->{printer_id},
+                                             groupitems => $::form->{print_options}->{groupitems}});
     if (scalar @errors) {
       return $self->js->flash('error', t8('Generating the document failed: #1', $errors[0]))->render($self);
     }
 
-    my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $::form->{attachment_filename});
+    my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $::form->{attachment_filename}, $::form->{formname});
     if (scalar @warnings) {
       flash_later('warning', $_) for @warnings;
     }
@@ -2127,6 +2138,7 @@ sub generate_doc {
           longdescription => 'html',
           partnotes       => 'html',
           notes           => 'html',
+          $::form->get_variable_content_types_for_cvars,
         },
       );
       1;
@@ -2314,7 +2326,7 @@ sub save_history {
 }
 
 sub store_doc_to_webdav_and_filemanagement {
-  my ($self, $content, $filename) = @_;
+  my ($self, $content, $filename, $variant) = @_;
 
   my $order = $self->order;
   my @errors;
@@ -2344,7 +2356,8 @@ sub store_doc_to_webdav_and_filemanagement {
                      source        => 'created',
                      file_type     => 'document',
                      file_name     => $filename,
-                     file_contents => $content);
+                     file_contents => $content,
+                     print_variant => $variant);
       1;
     } or do {
       push @errors, t8('Storing the document in the storage backend failed: #1', $@);