From: Bernd Bleßmann Date: Mon, 28 Mar 2022 14:28:17 +0000 (+0200) Subject: "alle" E-Mail-Adressen per Anhaken als Empfänger hinzufügen können X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~64 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5a07eafc9d215ad427e1d0e1f1682294703f45ce;p=kivitendo-erp.git "alle" E-Mail-Adressen per Anhaken als Empfänger hinzufügen können --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 4829790e5..43e8dc4eb 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -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 }; diff --git a/SL/DB/VC.pm b/SL/DB/VC.pm index c41f28788..3cc7490d9 100644 --- a/SL/DB/VC.pm +++ b/SL/DB/VC.pm @@ -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; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 4b6cf26c7..793099ff0 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -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 }; diff --git a/templates/webpages/common/_send_email_dialog.html b/templates/webpages/common/_send_email_dialog.html index b62164666..487943c6c 100644 --- a/templates/webpages/common/_send_email_dialog.html +++ b/templates/webpages/common/_send_email_dialog.html @@ -40,6 +40,21 @@ + [%- IF ALL_PARTNER_EMAIL_ADDRESSES.size %] + [%- FOREACH email = ALL_PARTNER_EMAIL_ADDRESSES %] + + + [%- IF loop.first %] + [% LxERP.t8("Other recipients") %] + [%- END %] + + + [% P.checkbox_tag("email_form.additional_to[]", label=email, value=email, checked="0") %] + + + [%- END %] + [%- END %] + [%- IF ALL_EMPLOYEES.size %] [% LxERP.t8("CC to Employee") %]