E-Mails als HTML verschicken: Versand in Einkaufs-/Verkaufsbelegen
[kivitendo-erp.git] / SL / Controller / Order.pm
index 5c14971..e709336 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use parent qw(SL::Controller::Base);
 
 use SL::Helper::Flash qw(flash_later);
+use SL::HTML::Util;
 use SL::Presenter::Tag qw(select_tag hidden_tag div_tag);
 use SL::Locale::String qw(t8);
 use SL::SessionFile::Random;
@@ -330,7 +331,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;
   }
@@ -479,24 +480,25 @@ sub action_send_email {
   # 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 => $::form->{formname},
-                                 file_type   => 'document');
+    $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_pdf(\$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}});
+    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}});
     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;
     }
@@ -521,7 +523,7 @@ sub action_send_email {
   $intnotes   .= t8('Cc')         . ": " . $::form->{cc}                                                              . "\n"    if $::form->{cc};
   $intnotes   .= t8('Bcc')        . ": " . $::form->{bcc}                                                             . "\n"    if $::form->{bcc};
   $intnotes   .= t8('Subject')    . ": " . $::form->{subject}                                                         . "\n\n";
-  $intnotes   .= t8('Message')    . ": " . $::form->{message};
+  $intnotes   .= t8('Message')    . ": " . SL::HTML::Util->strip($::form->{message});
 
   $self->order->update_attributes(intnotes => $intnotes);
 
@@ -765,8 +767,10 @@ sub action_show_customer_vendor_details_dialog {
   $details{payment_terms}       = $cv->payment->description       if $cv->payment;
   $details{pricegroup}          = $cv->pricegroup->pricegroup     if $is_customer && $cv->pricegroup;
 
-  foreach my $entry (@{ $cv->additional_billing_addresses }) {
-    push @{ $details{ADDITIONAL_BILLING_ADDRESSES} },   { map { $_ => $entry->$_ } @{$entry->meta->columns} };
+  if ($is_customer) {
+    foreach my $entry (@{ $cv->additional_billing_addresses }) {
+      push @{ $details{ADDITIONAL_BILLING_ADDRESSES} },   { map { $_ => $entry->$_ } @{$entry->meta->columns} };
+    }
   }
   foreach my $entry (@{ $cv->shipto }) {
     push @{ $details{SHIPTO} },   { map { $_ => $entry->$_ } @{$entry->meta->columns} };
@@ -1340,6 +1344,8 @@ sub build_contact_select {
 sub build_billing_address_select {
   my ($self) = @_;
 
+  return '' if $self->cv ne 'customer';
+
   select_tag('order.billing_address_id',
              [ {displayable_id => '', id => ''}, $self->order->{$self->cv}->additional_billing_addresses ],
              value_key  => 'id',
@@ -2325,7 +2331,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;
@@ -2355,7 +2361,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', $@);