Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b97742c6

Von Tamino Steinert vor 7 Tagen hinzugefügt

  • ID b97742c67c1286ba5d2fe4f68d6548cf74172d2d
  • Vorgänger 1111ec6b
  • Nachfolger c131da1a

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/Order.pm
500 500

  
501 501
  if (!$self->is_final_version) {
502 502
    $self->save();
503

  
504 503
    $self->js_reset_order_and_item_ids_after_save;
505 504
  }
506 505

  
507
  my $cv_method = $self->cv;
508

  
509
  if (!$self->order->$cv_method) {
510
    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'))
511
                    ->render($self);
512
  }
513

  
514
  my $email_form;
515
  $email_form->{to}   = $self->order->contact->cp_email if $self->order->contact;
516
  $email_form->{to} ||= $self->order->$cv_method->email;
517
  $email_form->{cc}   = $self->order->$cv_method->cc;
518
  $email_form->{bcc}  = join ', ', grep $_, $self->order->$cv_method->bcc;
519
  # Todo: get addresses from shipto, if any
506
  my $cv = $self->order->customervendor
507
    or return $self->js->flash('error',
508
      $self->type_data->properties('is_customer') ?
509
          t8('Cannot send E-mail without customer given')
510
        : t8('Cannot send E-mail without vendor given')
511
    )->render($self);
520 512

  
521 513
  my $form = Form->new;
522 514
  $form->{$self->nr_key()}  = $self->order->number;
......
528 520
  $form->{format}           = 'pdf';
529 521
  $form->{cp_id}            = $self->order->contact->cp_id if $self->order->contact;
530 522

  
523
  my $email_form;
524
  $email_form->{to} =
525
       ($self->order->contact ? $self->order->contact->cp_email : undef)
526
    ||  $cv->email;
527
  $email_form->{cc}  = $cv->cc;
528
  $email_form->{bcc} = join ', ', grep $_, $cv->bcc;
529
  # Todo: get addresses from shipto, if any
531 530
  $email_form->{subject}             = $form->generate_email_subject();
532 531
  $email_form->{attachment_filename} = $form->generate_attachment_filename();
533 532
  $email_form->{message}             = $form->generate_email_body();
......
540 539
    $user && !!trim($user->get_config_value('email'));
541 540
  } @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) };
542 541

  
543

  
544
  my $all_partner_email_addresses = $self->order->customervendor->get_all_email_addresses();
545

  
546
  my $dialog_html = $self->render('common/_send_email_dialog', { output => 0 },
547
                                  email_form    => $email_form,
548
                                  show_bcc      => $::auth->assert('email_bcc', 'may fail'),
549
                                  FILES         => \%files,
550
                                  is_customer   => $self->type_data->properties('is_customer'),
551
                                  ALL_EMPLOYEES => \@employees_with_email,
552
                                  ALL_PARTNER_EMAIL_ADDRESSES => $all_partner_email_addresses,
553
                                  is_final_version => $self->is_final_version,
542
  my $dialog_html = $self->render(
543
    'common/_send_email_dialog', { output => 0 },
544
    email_form    => $email_form,
545
    show_bcc      => $::auth->assert('email_bcc', 'may fail'),
546
    FILES         => \%files,
547
    is_customer   => $self->type_data->properties('is_customer'),
548
    ALL_EMPLOYEES => \@employees_with_email,
549
    ALL_PARTNER_EMAIL_ADDRESSES => $cv->get_all_email_addresses(),
550
    is_final_version => $self->is_final_version,
554 551
  );
555 552

  
556 553
  $self->js
557
      ->run('kivi.Order.show_email_dialog', $dialog_html)
558
      ->reinit_widgets
559
      ->render($self);
554
    ->run('kivi.Order.show_email_dialog', $dialog_html)
555
    ->reinit_widgets
556
    ->render($self);
560 557
}
561 558

  
562 559
# send email
......
571 568
      $self->js->run('kivi.Order.close_email_dialog');
572 569
      die $EVAL_ERROR;
573 570
    };
574

  
575
    $self->js_reset_order_and_item_ids_after_save;
576 571
  }
577 572

  
578 573
  my @redirect_params = (
......
593 588
      $::dispatcher->end_request;
594 589
  };
595 590

  
591
  # move $::form->{email_form} to $::form
596 592
  my $email_form  = delete $::form->{email_form};
597 593

  
598 594
  if ($email_form->{additional_to}) {
......
601 597
  }
602 598

  
603 599
  my %field_names = (to => 'email');
604

  
605 600
  $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form };
606 601

  
607 602
  # for Form::cleanup which may be called in Form::send_email
......
616 611
  # Is an old file version available?
617 612
  my $attfile;
618 613
  if ($::form->{attachment_policy} eq 'old_file') {
619
    $attfile = SL::File->get_all(object_id     => $self->order->id,
620
                                 object_type   => $self->type,
621
                                 file_type     => 'document',
622
                                 print_variant => $::form->{formname});
614
    $attfile = SL::File->get_all(
615
      object_id     => $self->order->id,
616
      object_type   => $self->type,
617
      print_variant => $::form->{formname},
618
    );
623 619
  }
624 620

  
625 621
  if ($self->is_final_version && $::form->{attachment_policy} eq 'old_file' && !$attfile) {
626 622
    $::form->error(t8('Re-sending a final version was requested, but the latest version of the document could not be found'));
627 623
  }
628 624

  
629
  if (!$self->is_final_version && $::form->{attachment_policy} ne 'no_file' && !($::form->{attachment_policy} eq 'old_file' && $attfile)) {
625
  if ( !$self->is_final_version
626
    &&   $::form->{attachment_policy} ne 'no_file'
627
    && !($::form->{attachment_policy} eq 'old_file' && $attfile)
628
  ) {
630 629
    my $doc;
631
    my @errors = $self->generate_doc(\$doc, {media      => $::form->{media},
632
                                             format     => $::form->{print_options}->{format},
633
                                             formname   => $::form->{print_options}->{formname},
634
                                             language   => $self->order->language,
635
                                             printer_id => $::form->{print_options}->{printer_id},
636
                                             groupitems => $::form->{print_options}->{groupitems}});
630
    my @errors = $self->generate_doc(\$doc, {
631
        media      => $::form->{media},
632
        format     => $::form->{print_options}->{format},
633
        formname   => $::form->{print_options}->{formname},
634
        language   => $self->order->language,
635
        printer_id => $::form->{print_options}->{printer_id},
636
        groupitems => $::form->{print_options}->{groupitems},
637
      });
637 638
    if (scalar @errors) {
638 639
      $::form->error(t8('Generating the document failed: #1', $errors[0]));
639 640
    }
640 641

  
641
    my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $::form->{attachment_filename}, $::form->{formname});
642
    my @warnings = $self->store_doc_to_webdav_and_filemanagement(
643
      $doc, $::form->{attachment_filename}, $::form->{formname}
644
    );
642 645
    if (scalar @warnings) {
643 646
      flash_later('warning', $_) for @warnings;
644 647
    }
......
648 651
    $sfile->fh->close;
649 652

  
650 653
    $::form->{tmpfile} = $sfile->file_name;
651
    $::form->{tmpdir}  = $sfile->get_path; # for Form::cleanup which may be called in Form::send_email
654
    $::form->{tmpdir}  = $sfile->get_path; # for Form::cleanup which may be
655
                                           # called in Form::send_email
652 656
  }
653 657

  
654
  $::form->{id} = $self->order->id; # this is used in SL::Mailer to create a linked record to the mail
658
  $::form->{id} = $self->order->id; # this is used in SL::Mailer to create a
659
                                    # linked record to the mail
655 660
  $::form->send_email(\%::myconfig, $::form->{print_options}->{format});
656 661

  
657 662
  flash_later('info', t8('The email has been sent.'));
663
  $self->save_history('MAILED');
658 664

  
659 665
  # internal notes unless no email journal
660 666
  unless ($::instance_conf->get_email_journal) {
661 667
    my $intnotes = $self->order->intnotes;
662 668
    $intnotes   .= "\n\n" if $self->order->intnotes;
663
    $intnotes   .= t8('[email]')                                                                                        . "\n";
664
    $intnotes   .= t8('Date')       . ": " . $::locale->format_date_object(DateTime->now_local, precision => 'seconds') . "\n";
665
    $intnotes   .= t8('To (email)') . ": " . $::form->{email}                                                           . "\n";
666
    $intnotes   .= t8('Cc')         . ": " . $::form->{cc}                                                              . "\n"    if $::form->{cc};
667
    $intnotes   .= t8('Bcc')        . ": " . $::form->{bcc}                                                             . "\n"    if $::form->{bcc};
668
    $intnotes   .= t8('Subject')    . ": " . $::form->{subject}                                                         . "\n\n";
669
    $intnotes   .= t8('[email]')                                       . "\n";
670
    $intnotes   .= t8('Date')       . ": " . $::locale->format_date_object(
671
                                               DateTime->now_local,
672
                                               precision => 'seconds') . "\n";
673
    $intnotes   .= t8('To (email)') . ": " . $::form->{email}          . "\n";
674
    $intnotes   .= t8('Cc')         . ": " . $::form->{cc}             . "\n"    if $::form->{cc};
675
    $intnotes   .= t8('Bcc')        . ": " . $::form->{bcc}            . "\n"    if $::form->{bcc};
676
    $intnotes   .= t8('Subject')    . ": " . $::form->{subject}        . "\n\n";
669 677
    $intnotes   .= t8('Message')    . ": " . SL::HTML::Util->strip($::form->{message});
670 678

  
671 679
    $self->order->update_attributes(intnotes => $intnotes);

Auch abrufbar als: Unified diff