Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b2f213b2

Von Tamino Steinert vor 4 Monaten hinzugefügt

  • ID b2f213b226e6fde2830507b4c3ff83a5176b281a
  • Vorgänger acfb1186
  • Nachfolger 7c24733f

E-Mail-Versand für Auftrag, Lieferschein und Reklamation angleichen

Features/Fixes, die nun alle habe:
- Fehler sichtbar anzeigen
- Zusätzliche E-Mail-Adressen von Kunden/Lieferant auswählbar
- Nur Angestellte mit E-Mail-Adresse anzeigen
- Historyeintrag bei E-Mail-Versand
- interne Notizen nur wenn kein E-Mail-Journal aktiviert
- HTML für interne Notizen entfernen

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
sub action_save_and_show_email_dialog {
my ($self) = @_;
if ( !$self->order->delivered ) {
if (!$self->order->delivered) {
$self->save();
$self->js_reset_order_and_item_ids_after_save;
}
my $cv_method = $self->cv;
my $cv = $self->order->customervendor;
if (!$cv) {
return $self->js->flash('error',
my $cv = $self->order->customervendor
or return $self->js->flash('error',
$self->cv eq 'customer' ?
t8('Cannot send E-mail without customer given')
: t8('Cannot send E-mail without vendor given')
)->render($self);
}
my $email_form;
$email_form->{to} =
($self->order->contact ? $self->order->contact->cp_email : undef)
|| ($cv->is_customer ? $cv->delivery_order_mail : undef)
|| $cv->email;
$email_form->{cc} = $cv->cc;
$email_form->{bcc} = join ', ', grep $_, $cv->bcc;
# Todo: get addresses from shipto, if any
my $form = Form->new;
$form->{$self->nr_key()} = $self->order->number;
......
$form->{cp_id} =
$self->order->contact->cp_id if $self->order->contact;
my $email_form;
$email_form->{to} =
($self->order->contact ? $self->order->contact->cp_email : undef)
|| ($cv->is_customer ? $cv->delivery_order_mail : undef)
|| $cv->email;
$email_form->{cc} = $cv->cc;
$email_form->{bcc} = join ', ', grep $_, $cv->bcc;
# Todo: get addresses from shipto, if any
$email_form->{subject} = $form->generate_email_subject();
$email_form->{attachment_filename} = $form->generate_attachment_filename();
$email_form->{message} = $form->generate_email_body();
$email_form->{js_send_function} = 'kivi.DeliveryOrder.send_email()';
my %files = $self->get_files_for_email_dialog();
$self->{all_employees} = SL::DB::Manager::Employee->get_all(
query => [ deleted => 0 ]
);
my @employees_with_email = grep {
my $user = SL::DB::Manager::AuthUser->find_by(login => $_->login);
$user && !!trim($user->get_config_value('email'));
} @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) };
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->type_data->properties("is_customer"),
ALL_EMPLOYEES => $self->{all_employees},
ALL_EMPLOYEES => \@employees_with_email,
ALL_PARTNER_EMAIL_ADDRESSES => $cv->get_all_email_addresses(),
);
$self->js
->run('kivi.DeliveryOrder.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
->run('kivi.DeliveryOrder.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
}
# send email
#
# Todo: handling error messages: flash is not displayed in dialog, but in the main form
sub action_send_email {
my ($self) = @_;
if ( !$self->order->delivered ) {
$self->save();
$self->js_reset_order_and_item_ids_after_save;
eval {
$self->save();
1;
} or do {
$self->js->run('kivi.Order.close_email_dialog');
die $EVAL_ERROR;
};
}
my @redirect_params = (
action => 'edit',
type => $self->type,
id => $self->order->id,
);
# Set the error handler to reload the document and display errors later,
# because the document is already saved and saving can have some side effects
# such as generating a document number, project number or record links,
# which will be up to date when the document is reloaded.
# Hint: Do not use "die" here and try to catch exceptions in subroutine
# calls. You should use "$::form->error" which respects the error handler.
local $::form->{__ERROR_HANDLER} = sub {
flash_later('error', $_[0]);
$self->redirect_to(@redirect_params);
$::dispatcher->end_request;
};
# move $::form->{email_form} to $::form
my $email_form = delete $::form->{email_form};
my %field_names = (to => 'email');
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 };
# for Form::cleanup which may be called in Form::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',
print_variant => $::form->{formname});
$attfile = SL::File->get_all(
object_id => $self->order->id,
object_type => $::form->{formname},
file_type => 'document',
print_variant => $::form->{formname},
);
}
if ($::form->{attachment_policy} ne 'no_file' && !($::form->{attachment_policy} eq 'old_file' && $attfile)) {
if ( $::form->{attachment_policy} ne 'no_file'
&& !($::form->{attachment_policy} eq 'old_file' && $attfile)) {
my $pdf;
my @errors = generate_pdf($self->order, \$pdf, {
media => $::form->{media},
......
groupitems => $::form->{print_options}->{groupitems}},
);
if (scalar @errors) {
return $self->js->flash('error',
t8('Conversion to PDF failed: #1', $errors[0])
)->render($self);
$::form->error(t8('Generating the document failed: #1', $errors[0]));
}
my @warnings = store_pdf_to_webdav_and_filemanagement(
......
# linked record to the mail
$::form->send_email(\%::myconfig, 'pdf');
$self->save_history('MAILED');
flash_later('info', t8('The email has been sent.'));
# internal notes unless no email journal
unless ($::instance_conf->get_email_journal) {
my $intnotes = $self->order->intnotes;
$intnotes .= "\n\n" if $self->order->intnotes;
$intnotes .= t8('[email]') . "\n";
......
$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);
}
$self->save_history('MAILED');
flash_later('info', t8('The email has been sent.'));
my @redirect_params = (
action => 'edit',
type => $self->type,
id => $self->order->id,
);
$self->redirect_to(@redirect_params);
}
SL/Controller/Order.pm
if (!$self->is_final_version) {
$self->save();
$self->js_reset_order_and_item_ids_after_save;
}
my $cv_method = $self->cv;
if (!$self->order->$cv_method) {
return $self->js->flash('error', $self->cv eq 'customer' ? t8('Cannot send E-mail without customer given') : t8('Cannot send E-mail without vendor given'))
->render($self);
}
my $email_form;
$email_form->{to} = $self->order->contact->cp_email if $self->order->contact;
$email_form->{to} ||= $self->order->$cv_method->email;
$email_form->{cc} = $self->order->$cv_method->cc;
$email_form->{bcc} = join ', ', grep $_, $self->order->$cv_method->bcc;
# Todo: get addresses from shipto, if any
my $cv = $self->order->customervendor
or return $self->js->flash('error',
$self->type_data->properties('is_customer') ?
t8('Cannot send E-mail without customer given')
: t8('Cannot send E-mail without vendor given')
)->render($self);
my $form = Form->new;
$form->{$self->nr_key()} = $self->order->number;
......
$form->{format} = 'pdf';
$form->{cp_id} = $self->order->contact->cp_id if $self->order->contact;
my $email_form;
$email_form->{to} =
($self->order->contact ? $self->order->contact->cp_email : undef)
|| $cv->email;
$email_form->{cc} = $cv->cc;
$email_form->{bcc} = join ', ', grep $_, $cv->bcc;
# Todo: get addresses from shipto, if any
$email_form->{subject} = $form->generate_email_subject();
$email_form->{attachment_filename} = $form->generate_attachment_filename();
$email_form->{message} = $form->generate_email_body();
......
$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->type_data->properties('is_customer'),
ALL_EMPLOYEES => \@employees_with_email,
ALL_PARTNER_EMAIL_ADDRESSES => $all_partner_email_addresses,
is_final_version => $self->is_final_version,
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->type_data->properties('is_customer'),
ALL_EMPLOYEES => \@employees_with_email,
ALL_PARTNER_EMAIL_ADDRESSES => $cv->get_all_email_addresses(),
is_final_version => $self->is_final_version,
);
$self->js
->run('kivi.Order.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
->run('kivi.Order.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
}
# send email
......
$self->js->run('kivi.Order.close_email_dialog');
die $EVAL_ERROR;
};
$self->js_reset_order_and_item_ids_after_save;
}
my @redirect_params = (
......
$::dispatcher->end_request;
};
# move $::form->{email_form} to $::form
my $email_form = delete $::form->{email_form};
if ($email_form->{additional_to}) {
......
}
my %field_names = (to => 'email');
$::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form };
# for Form::cleanup which may be called in Form::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 => $self->type,
file_type => 'document',
print_variant => $::form->{formname});
$attfile = SL::File->get_all(
object_id => $self->order->id,
object_type => $self->type,
print_variant => $::form->{formname},
);
}
if ($self->is_final_version && $::form->{attachment_policy} eq 'old_file' && !$attfile) {
$::form->error(t8('Re-sending a final version was requested, but the latest version of the document could not be found'));
}
if (!$self->is_final_version && $::form->{attachment_policy} ne 'no_file' && !($::form->{attachment_policy} eq 'old_file' && $attfile)) {
if ( !$self->is_final_version
&& $::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}});
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) {
$::form->error(t8('Generating the document failed: #1', $errors[0]));
}
my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $::form->{attachment_filename}, $::form->{formname});
my @warnings = $self->store_doc_to_webdav_and_filemanagement(
$doc, $::form->{attachment_filename}, $::form->{formname}
);
if (scalar @warnings) {
flash_later('warning', $_) for @warnings;
}
......
$sfile->fh->close;
$::form->{tmpfile} = $sfile->file_name;
$::form->{tmpdir} = $sfile->get_path; # for Form::cleanup which may be called in Form::send_email
$::form->{tmpdir} = $sfile->get_path; # for Form::cleanup which may be
# called in Form::send_email
}
$::form->{id} = $self->order->id; # this is used in SL::Mailer to create a linked record to the mail
$::form->{id} = $self->order->id; # this is used in SL::Mailer to create a
# linked record to the mail
$::form->send_email(\%::myconfig, $::form->{print_options}->{format});
flash_later('info', t8('The email has been sent.'));
$self->save_history('MAILED');
# internal notes unless no email journal
unless ($::instance_conf->get_email_journal) {
my $intnotes = $self->order->intnotes;
$intnotes .= "\n\n" if $self->order->intnotes;
$intnotes .= t8('[email]') . "\n";
$intnotes .= t8('Date') . ": " . $::locale->format_date_object(DateTime->now_local, precision => 'seconds') . "\n";
$intnotes .= t8('To (email)') . ": " . $::form->{email} . "\n";
$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('[email]') . "\n";
$intnotes .= t8('Date') . ": " . $::locale->format_date_object(
DateTime->now_local,
precision => 'seconds') . "\n";
$intnotes .= t8('To (email)') . ": " . $::form->{email} . "\n";
$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') . ": " . SL::HTML::Util->strip($::form->{message});
$self->order->update_attributes(intnotes => $intnotes);
SL/Controller/Reclamation.pm
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::Presenter::ReclamationFilter qw(filter);
use SL::Locale::String qw(t8);
......
my ($self) = @_;
$self->save();
$self->js_reset_reclamation_and_item_ids_after_save;
unless ($self->reclamation->customervendor) {
return $self->js->flash('error',
my $cv = $self->reclamation->customervendor
or return $self->js->flash('error',
$self->type_data->properties('is_customer') ?
t8('Cannot send E-mail without customer given')
: t8('Cannot send E-mail without vendor given'))
->render($self);
}
: t8('Cannot send E-mail without vendor given')
)->render($self);
my $form = Form->new;
$form->{record_number} = $self->reclamation->record_number;
......
$form->{cp_id} = $self->reclamation->contact->cp_id if $self->reclamation->contact;
my $email_form;
$email_form->{to} = $self->reclamation->contact->cp_email if $self->reclamation->contact;
$email_form->{to} ||= $self->reclamation->customervendor->email;
$email_form->{cc} = $self->reclamation->customervendor->cc;
$email_form->{bcc} = join ', ', grep $_, $self->reclamation->customervendor->bcc;
$email_form->{to} =
($self->reclamation->contact ? $self->reclamation->contact->cp_email : undef)
|| $cv->email;
$email_form->{cc} = $cv->cc;
$email_form->{bcc} = join ', ', grep $_, $cv->bcc;
# TODO: get addresses from shipto, if any
$email_form->{subject} = $form->generate_email_subject();
$email_form->{attachment_filename} = $form->generate_attachment_filename();
......
$email_form->{js_send_function} = 'kivi.Reclamation.send_email()';
my %files = $self->get_files_for_email_dialog();
$self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
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->type_data->properties('is_customer'),
ALL_EMPLOYEES => $self->{all_employees},
my @employees_with_email = grep {
my $user = SL::DB::Manager::AuthUser->find_by(login => $_->login);
$user && !!trim($user->get_config_value('email'));
} @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) };
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->type_data->properties('is_customer'),
ALL_EMPLOYEES => \@employees_with_email,
ALL_PARTNER_EMAIL_ADDRESSES => $cv->get_all_email_addresses(),
);
$self->js
->run('kivi.Reclamation.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
->run('kivi.Reclamation.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
}
# send email
#
# TODO: handling error messages: flash is not displayed in dialog, but in the main form
sub action_send_email {
my ($self) = @_;
......
die $EVAL_ERROR;
};
$self->js_reset_reclamation_and_item_ids_after_save;
my @redirect_params = (
action => 'edit',
type => $self->type,
id => $self->reclamation->id,
);
# Set the error handler to reload the document and display errors later,
# because the document is already saved and saving can have some side effects
# such as generating a document number, project number or record links,
# which will be up to date when the document is reloaded.
# Hint: Do not use "die" here and try to catch exceptions in subroutine
# calls. You should use "$::form->error" which respects the error handler.
local $::form->{__ERROR_HANDLER} = sub {
flash_later('error', $_[0]);
$self->redirect_to(@redirect_params);
$::dispatcher->end_request;
};
# move $::form->{email_form} to $::form
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 };
......
$::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->reclamaiton->id,
object_type => $self->type,
print_variant => $::form->{formname},
);
}
if ( $::form->{attachment_policy} ne 'no_file'
&& !($::form->{attachment_policy} eq 'old_file' && $attfile)
) {
my $pdf;
my @errors = generate_pdf($self->reclamation, \$pdf, {
media => $::form->{media},
format => $::form->{print_options}->{format},
formname => $::form->{print_options}->{formname},
language => $self->reclamation->language,
printer_id => $::form->{print_options}->{printer_id},
groupitems => $::form->{print_options}->{groupitems}
});
my @errors = generate_pdf(
$self->reclamation, \$pdf, {
media => $::form->{media},
format => $::form->{print_options}->{format},
formname => $::form->{print_options}->{formname},
language => $self->reclamation->language,
printer_id => $::form->{print_options}->{printer_id},
groupitems => $::form->{print_options}->{groupitems},
});
if (scalar @errors) {
return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self);
$::form->error(t8('Generating the document failed: #1', $errors[0]));
}
my @warnings = store_pdf_to_webdav_and_filemanagement($self->reclamation, $pdf, $::form->{attachment_filename});
my @warnings = store_pdf_to_webdav_and_filemanagement(
$self->reclamation, $pdf, $::form->{attachment_filename}
);
if (scalar @warnings) {
flash_later('warning', $_) for @warnings;
}
......
$sfile->fh->close;
$::form->{tmpfile} = $sfile->file_name;
$::form->{tmpdir} = $sfile->get_path; # for Form::cleanup which may be called in Form::send_email
$::form->{tmpdir} = $sfile->get_path; # for Form::cleanup which may be
# called in Form::send_email
}
$::form->{id} = $self->reclamation->id; # this is used in SL::Mailer to create a linked record to the mail
$::form->{id} = $self->reclamation->id; # this is used in SL::Mailer to
# create a linked record to the mail
$::form->send_email(\%::myconfig, 'pdf');
# internal notes
my $intnotes = $self->reclamation->intnotes;
$intnotes .= "\n\n" if $self->reclamation->intnotes;
$intnotes .= t8('[email]') . "\n";
$intnotes .= t8('Date') . ": " . $::locale->format_date_object(
DateTime->now_local,
precision => 'seconds') . "\n";
$intnotes .= t8('To (email)') . ": " . $::form->{email} . "\n";
$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};
$self->reclamation->update_attributes(intnotes => $intnotes);
$self->save_history('MAILED');
flash_later('info', t8('The email has been sent.'));
$self->save_history('MAILED');
my @redirect_params = (
action => 'edit',
type => $self->type,
id => $self->reclamation->id,
);
# internal notes unless no email journal
unless ($::instance_conf->get_email_journal) {
my $intnotes = $self->reclamation->intnotes;
$intnotes .= "\n\n" if $self->reclamation->intnotes;
$intnotes .= t8('[email]') . "\n";
$intnotes .= t8('Date') . ": " . $::locale->format_date_object(
DateTime->now_local,
precision => 'seconds') . "\n";
$intnotes .= t8('To (email)') . ": " . $::form->{email} . "\n";
$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') . ": " . SL::HTML::Util->strip($::form->{message});
$self->reclamation->update_attributes(intnotes => $intnotes);
}
$self->redirect_to(@redirect_params);
}

Auch abrufbar als: Unified diff