"alle" E-Mail-Adressen per Anhaken als Empfänger hinzufügen können
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 28 Mar 2022 14:28:17 +0000 (16:28 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 4 Apr 2022 11:24:24 +0000 (13:24 +0200)
SL/Controller/Order.pm
SL/DB/VC.pm
bin/mozilla/io.pl
templates/webpages/common/_send_email_dialog.html

index 4829790..43e8dc4 100644 (file)
@@ -446,12 +446,16 @@ sub action_save_and_show_email_dialog {
     $user && !!trim($user->get_config_value('email'));
   } @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) };
 
+
+  my $all_partner_email_addresses = $self->order->customervendor->get_all_email_addresses();
+
   my $dialog_html = $self->render('common/_send_email_dialog', { output => 0 },
                                   email_form    => $email_form,
                                   show_bcc      => $::auth->assert('email_bcc', 'may fail'),
                                   FILES         => \%files,
                                   is_customer   => $self->cv eq 'customer',
                                   ALL_EMPLOYEES => \@employees_with_email,
+                                  ALL_PARTNER_EMAIL_ADDRESSES => $all_partner_email_addresses,
   );
 
   $self->js
@@ -477,6 +481,12 @@ sub action_send_email {
   $self->js_reset_order_and_item_ids_after_save;
 
   my $email_form  = delete $::form->{email_form};
+
+  if ($email_form->{additional_to}) {
+    $email_form->{to} = join ', ', grep { $_ } $email_form->{to}, @{$email_form->{additional_to}};
+    delete $email_form->{additional_to};
+  }
+
   my %field_names = (to => 'email');
 
   $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form };
index c41f287..3cc7490 100644 (file)
@@ -2,11 +2,13 @@ package SL::DB::VC;
 
 use strict;
 
-require Exporter;
+use List::MoreUtils qw(uniq);
 use SL::DBUtils;
 
+require Exporter;
+
 our @ISA    = qw(Exporter);
-our @EXPORT = qw(get_credit_remaining);
+our @EXPORT = qw(get_credit_remaining get_all_email_addresses);
 
 sub get_credit_remaining {
   my $vc               = shift;
@@ -50,4 +52,42 @@ SQL
   return $credit_remaining;
 }
 
+sub get_all_email_addresses {
+  my ($self) = @_;
+
+  my $is_sales = ref $self eq 'SL::DB::Customer';
+
+  my @addresses;
+
+  # billing address
+  push @addresses, $self->$_ for qw(email cc bcc);
+  if ($is_sales) {
+    push @addresses, $self->$_ for qw(delivery_order_mail invoice_mail);
+  }
+
+  # additional billing addresses
+  if ($is_sales) {
+    foreach my $additional_billing_address (@{ $self->additional_billing_addresses }) {
+      push @addresses, $additional_billing_address->$_ for qw(email);
+    }
+  }
+
+  # contacts
+  foreach my $contact (@{ $self->contacts }) {
+    push @addresses, $contact->$_ for qw(cp_email cp_privatemail);
+  }
+
+  # shiptos
+  foreach my $shipto (@{ $self->shipto }) {
+    push @addresses, $shipto->$_ for qw(shiptoemail);
+  }
+
+  # remove empty ones and duplicates
+  @addresses = grep { $_ } @addresses;
+  @addresses = uniq @addresses;
+
+
+  return \@addresses;
+}
+
 1;
index 4b6cf26..793099f 100644 (file)
@@ -2145,6 +2145,11 @@ sub show_sales_purchase_email_dialog {
   };
 
   my %files = _get_files_for_email_dialog();
+
+  my $all_partner_email_addresses;
+  $all_partner_email_addresses = SL::DB::Customer->load_cached($::form->{vc_id})->get_all_email_addresses() if 'customer' eq $::form->{vc};
+  $all_partner_email_addresses = SL::DB::Vendor  ->load_cached($::form->{vc_id})->get_all_email_addresses() if 'vendor'   eq $::form->{vc};
+
   my $html  = $::form->parse_html_template("common/_send_email_dialog", {
     email_form      => $email_form,
     show_bcc        => $::auth->assert('email_bcc', 'may fail'),
@@ -2152,6 +2157,7 @@ sub show_sales_purchase_email_dialog {
     is_customer     => $::form->{vc} eq 'customer',
     is_invoice_mail => ($record_email && $::form->{type} eq 'invoice'),
     ALL_EMPLOYEES   => \@employees_with_email,
+    ALL_PARTNER_EMAIL_ADDRESSES => $all_partner_email_addresses,
   });
 
   print $::form->ajax_response_header, $html;
@@ -2165,6 +2171,12 @@ sub send_sales_purchase_email {
                   :                                                    'is.pl';
 
   my $email_form  = delete $::form->{email_form};
+
+  if ($email_form->{additional_to}) {
+    $email_form->{to} = join ', ', grep { $_ } $email_form->{to}, @{$email_form->{additional_to}};
+    delete $email_form->{additional_to};
+  }
+
   my %field_names = (to => 'email');
 
   $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form };
index b621646..487943c 100644 (file)
    </td>
   </tr>
 
+  [%- IF ALL_PARTNER_EMAIL_ADDRESSES.size %]
+   [%- FOREACH email = ALL_PARTNER_EMAIL_ADDRESSES %]
+    <tr class="hidden" data-toggle-recipients="1">
+     <th align="right" nowrap>
+      [%- IF loop.first %]
+       [% LxERP.t8("Other recipients") %]
+      [%- END %]
+     </th>
+     <td>
+       [% P.checkbox_tag("email_form.additional_to[]", label=email, value=email, checked="0") %]
+     </td>
+    </tr>
+   [%- END %]
+  [%- END %]
+
  [%- IF ALL_EMPLOYEES.size %]
   <tr class="hidden" data-toggle-recipients="1">
    <th align="right" nowrap>[% LxERP.t8("CC to Employee") %]</th>