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/DeliveryOrder.pm
420 420
sub action_save_and_show_email_dialog {
421 421
  my ($self) = @_;
422 422

  
423
  if ( !$self->order->delivered ) {
423
  if (!$self->order->delivered) {
424 424
    $self->save();
425
    $self->js_reset_order_and_item_ids_after_save;
425 426
  }
426 427

  
427
  my $cv_method = $self->cv;
428

  
429
  my $cv = $self->order->customervendor;
430
  if (!$cv) {
431
    return $self->js->flash('error',
428
  my $cv = $self->order->customervendor
429
    or return $self->js->flash('error',
432 430
      $self->cv eq 'customer' ?
433 431
           t8('Cannot send E-mail without customer given')
434 432
         : t8('Cannot send E-mail without vendor given')
435 433
    )->render($self);
436
  }
437

  
438
  my $email_form;
439
  $email_form->{to} =
440
       ($self->order->contact ? $self->order->contact->cp_email : undef)
441
    || ($cv->is_customer ? $cv->delivery_order_mail : undef)
442
    ||  $cv->email;
443
  $email_form->{cc}   = $cv->cc;
444
  $email_form->{bcc}  = join ', ', grep $_, $cv->bcc;
445
  # Todo: get addresses from shipto, if any
446 434

  
447 435
  my $form = Form->new;
448 436
  $form->{$self->nr_key()}  = $self->order->number;
......
457 445
  $form->{cp_id}            =
458 446
    $self->order->contact->cp_id if $self->order->contact;
459 447

  
448
  my $email_form;
449
  $email_form->{to} =
450
       ($self->order->contact ? $self->order->contact->cp_email : undef)
451
    || ($cv->is_customer ? $cv->delivery_order_mail : undef)
452
    ||  $cv->email;
453
  $email_form->{cc}  = $cv->cc;
454
  $email_form->{bcc} = join ', ', grep $_, $cv->bcc;
455
  # Todo: get addresses from shipto, if any
460 456
  $email_form->{subject}             = $form->generate_email_subject();
461 457
  $email_form->{attachment_filename} = $form->generate_attachment_filename();
462 458
  $email_form->{message}             = $form->generate_email_body();
463 459
  $email_form->{js_send_function}    = 'kivi.DeliveryOrder.send_email()';
464 460

  
465 461
  my %files = $self->get_files_for_email_dialog();
466
  $self->{all_employees} = SL::DB::Manager::Employee->get_all(
467
    query => [ deleted => 0 ]
468
  );
462

  
463
  my @employees_with_email = grep {
464
    my $user = SL::DB::Manager::AuthUser->find_by(login => $_->login);
465
    $user && !!trim($user->get_config_value('email'));
466
  } @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) };
467

  
469 468
  my $dialog_html = $self->render(
470 469
    'common/_send_email_dialog', { output => 0 },
471 470
    email_form  => $email_form,
472 471
    show_bcc    => $::auth->assert('email_bcc', 'may fail'),
473 472
    FILES       => \%files,
474 473
    is_customer => $self->type_data->properties("is_customer"),
475
    ALL_EMPLOYEES => $self->{all_employees},
474
    ALL_EMPLOYEES => \@employees_with_email,
475
    ALL_PARTNER_EMAIL_ADDRESSES => $cv->get_all_email_addresses(),
476 476
  );
477 477

  
478 478
  $self->js
479
      ->run('kivi.DeliveryOrder.show_email_dialog', $dialog_html)
480
      ->reinit_widgets
481
      ->render($self);
479
    ->run('kivi.DeliveryOrder.show_email_dialog', $dialog_html)
480
    ->reinit_widgets
481
    ->render($self);
482 482
}
483 483

  
484 484
# send email
485
#
486
# Todo: handling error messages: flash is not displayed in dialog, but in the main form
487 485
sub action_send_email {
488 486
  my ($self) = @_;
489 487

  
490 488
  if ( !$self->order->delivered ) {
491
    $self->save();
492
    $self->js_reset_order_and_item_ids_after_save;
489
    eval {
490
      $self->save();
491
      1;
492
    } or do {
493
      $self->js->run('kivi.Order.close_email_dialog');
494
      die $EVAL_ERROR;
495
    };
493 496
  }
494 497

  
498
  my @redirect_params = (
499
    action => 'edit',
500
    type   => $self->type,
501
    id     => $self->order->id,
502
  );
503

  
504
  # Set the error handler to reload the document and display errors later,
505
  # because the document is already saved and saving can have some side effects
506
  # such as generating a document number, project number or record links,
507
  # which will be up to date when the document is reloaded.
508
  # Hint: Do not use "die" here and try to catch exceptions in subroutine
509
  # calls. You should use "$::form->error" which respects the error handler.
510
  local $::form->{__ERROR_HANDLER} = sub {
511
      flash_later('error', $_[0]);
512
      $self->redirect_to(@redirect_params);
513
      $::dispatcher->end_request;
514
  };
515

  
516
  # move $::form->{email_form} to $::form
495 517
  my $email_form  = delete $::form->{email_form};
496
  my %field_names = (to => 'email');
497 518

  
519
  if ($email_form->{additional_to}) {
520
    $email_form->{to} = join ', ', grep { $_ } $email_form->{to}, @{$email_form->{additional_to}};
521
    delete $email_form->{additional_to};
522
  }
523

  
524
  my %field_names = (to => 'email');
498 525
  $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form };
499 526

  
500 527
  # for Form::cleanup which may be called in Form::send_email
......
509 536
  # Is an old file version available?
510 537
  my $attfile;
511 538
  if ($::form->{attachment_policy} eq 'old_file') {
512
    $attfile = SL::File->get_all(object_id   => $self->order->id,
513
                                 object_type => $::form->{formname},
514
                                 file_type   => 'document',
515
                                 print_variant => $::form->{formname});
539
    $attfile = SL::File->get_all(
540
      object_id   => $self->order->id,
541
      object_type => $::form->{formname},
542
      file_type   => 'document',
543
      print_variant => $::form->{formname},
544
    );
516 545
  }
517 546

  
518
  if ($::form->{attachment_policy} ne 'no_file' && !($::form->{attachment_policy} eq 'old_file' && $attfile)) {
547
  if (   $::form->{attachment_policy} ne 'no_file'
548
    && !($::form->{attachment_policy} eq 'old_file' && $attfile)) {
519 549
    my $pdf;
520 550
    my @errors = generate_pdf($self->order, \$pdf, {
521 551
        media      => $::form->{media},
......
526 556
        groupitems => $::form->{print_options}->{groupitems}},
527 557
    );
528 558
    if (scalar @errors) {
529
      return $self->js->flash('error',
530
        t8('Conversion to PDF failed: #1', $errors[0])
531
      )->render($self);
559
      $::form->error(t8('Generating the document failed: #1', $errors[0]));
532 560
    }
533 561

  
534 562
    my @warnings = store_pdf_to_webdav_and_filemanagement(
......
551 579
                                    # linked record to the mail
552 580
  $::form->send_email(\%::myconfig, 'pdf');
553 581

  
582
  $self->save_history('MAILED');
583
  flash_later('info', t8('The email has been sent.'));
584

  
554 585
  # internal notes unless no email journal
555 586
  unless ($::instance_conf->get_email_journal) {
556

  
557 587
    my $intnotes = $self->order->intnotes;
558 588
    $intnotes   .= "\n\n" if $self->order->intnotes;
559 589
    $intnotes   .= t8('[email]')                                . "\n";
......
565 595
    $intnotes   .= t8('Cc')         . ": " . $::form->{cc}      . "\n"    if $::form->{cc};
566 596
    $intnotes   .= t8('Bcc')        . ": " . $::form->{bcc}     . "\n"    if $::form->{bcc};
567 597
    $intnotes   .= t8('Subject')    . ": " . $::form->{subject} . "\n\n";
568
    $intnotes   .= t8('Message')    . ": " . $::form->{message};
598
    $intnotes   .= t8('Message')    . ": " . SL::HTML::Util->strip($::form->{message});
569 599

  
570 600
    $self->order->update_attributes(intnotes => $intnotes);
571 601
  }
572 602

  
573
  $self->save_history('MAILED');
574

  
575
  flash_later('info', t8('The email has been sent.'));
576

  
577
  my @redirect_params = (
578
    action => 'edit',
579
    type   => $self->type,
580
    id     => $self->order->id,
581
  );
582

  
583 603
  $self->redirect_to(@redirect_params);
584 604
}
585 605

  
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);
SL/Controller/Reclamation.pm
4 4
use parent qw(SL::Controller::Base);
5 5

  
6 6
use SL::Helper::Flash qw(flash_later);
7
use SL::HTML::Util;
7 8
use SL::Presenter::Tag qw(select_tag hidden_tag div_tag);
8 9
use SL::Presenter::ReclamationFilter qw(filter);
9 10
use SL::Locale::String qw(t8);
......
394 395
  my ($self) = @_;
395 396

  
396 397
  $self->save();
398
  $self->js_reset_reclamation_and_item_ids_after_save;
397 399

  
398
  unless ($self->reclamation->customervendor) {
399
    return $self->js->flash('error',
400
  my $cv = $self->reclamation->customervendor
401
    or return $self->js->flash('error',
400 402
      $self->type_data->properties('is_customer') ?
401 403
          t8('Cannot send E-mail without customer given')
402
        : t8('Cannot send E-mail without vendor given'))
403
      ->render($self);
404
  }
404
        : t8('Cannot send E-mail without vendor given')
405
    )->render($self);
405 406

  
406 407
  my $form = Form->new;
407 408
  $form->{record_number}    = $self->reclamation->record_number;
......
414 415
  $form->{cp_id}            = $self->reclamation->contact->cp_id if $self->reclamation->contact;
415 416

  
416 417
  my $email_form;
417
  $email_form->{to}   = $self->reclamation->contact->cp_email if $self->reclamation->contact;
418
  $email_form->{to} ||= $self->reclamation->customervendor->email;
419
  $email_form->{cc}   = $self->reclamation->customervendor->cc;
420
  $email_form->{bcc}  = join ', ', grep $_, $self->reclamation->customervendor->bcc;
418
  $email_form->{to} =
419
       ($self->reclamation->contact ? $self->reclamation->contact->cp_email : undef)
420
    ||  $cv->email;
421
  $email_form->{cc}  = $cv->cc;
422
  $email_form->{bcc} = join ', ', grep $_, $cv->bcc;
421 423
  # TODO: get addresses from shipto, if any
422 424
  $email_form->{subject}             = $form->generate_email_subject();
423 425
  $email_form->{attachment_filename} = $form->generate_attachment_filename();
......
425 427
  $email_form->{js_send_function}    = 'kivi.Reclamation.send_email()';
426 428

  
427 429
  my %files = $self->get_files_for_email_dialog();
428
  $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
429
  my $dialog_html = $self->render('common/_send_email_dialog', { output => 0 },
430
                                  email_form  => $email_form,
431
                                  show_bcc    => $::auth->assert('email_bcc', 'may fail'),
432
                                  FILES       => \%files,
433
                                  is_customer => $self->type_data->properties('is_customer'),
434
                                  ALL_EMPLOYEES => $self->{all_employees},
430

  
431
  my @employees_with_email = grep {
432
    my $user = SL::DB::Manager::AuthUser->find_by(login => $_->login);
433
    $user && !!trim($user->get_config_value('email'));
434
  } @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) };
435

  
436
  my $dialog_html = $self->render(
437
    'common/_send_email_dialog', { output => 0 },
438
    email_form  => $email_form,
439
    show_bcc    => $::auth->assert('email_bcc', 'may fail'),
440
    FILES       => \%files,
441
    is_customer => $self->type_data->properties('is_customer'),
442
    ALL_EMPLOYEES => \@employees_with_email,
443
    ALL_PARTNER_EMAIL_ADDRESSES => $cv->get_all_email_addresses(),
435 444
  );
436 445

  
437 446
  $self->js
438
      ->run('kivi.Reclamation.show_email_dialog', $dialog_html)
439
      ->reinit_widgets
440
      ->render($self);
447
    ->run('kivi.Reclamation.show_email_dialog', $dialog_html)
448
    ->reinit_widgets
449
    ->render($self);
441 450
}
442 451

  
443 452
# send email
444
#
445
# TODO: handling error messages: flash is not displayed in dialog, but in the main form
446 453
sub action_send_email {
447 454
  my ($self) = @_;
448 455

  
......
454 461
    die $EVAL_ERROR;
455 462
  };
456 463

  
457
  $self->js_reset_reclamation_and_item_ids_after_save;
464
  my @redirect_params = (
465
    action => 'edit',
466
    type   => $self->type,
467
    id     => $self->reclamation->id,
468
  );
469

  
470
  # Set the error handler to reload the document and display errors later,
471
  # because the document is already saved and saving can have some side effects
472
  # such as generating a document number, project number or record links,
473
  # which will be up to date when the document is reloaded.
474
  # Hint: Do not use "die" here and try to catch exceptions in subroutine
475
  # calls. You should use "$::form->error" which respects the error handler.
476
  local $::form->{__ERROR_HANDLER} = sub {
477
      flash_later('error', $_[0]);
478
      $self->redirect_to(@redirect_params);
479
      $::dispatcher->end_request;
480
  };
458 481

  
459 482
  # move $::form->{email_form} to $::form
460 483
  my $email_form  = delete $::form->{email_form};
484

  
485
  if ($email_form->{additional_to}) {
486
    $email_form->{to} = join ', ', grep { $_ } $email_form->{to}, @{$email_form->{additional_to}};
487
    delete $email_form->{additional_to};
488
  }
489

  
461 490
  my %field_names = (to => 'email');
462 491
  $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form };
463 492

  
......
468 497
  $::form->{$_}     = $::form->{print_options}->{$_} for keys %{$::form->{print_options}};
469 498
  $::form->{media}  = 'email';
470 499

  
471
  if (($::form->{attachment_policy} // '') !~ m{^(?:old_file|no_file)$}) {
500
  $::form->{attachment_policy} //= '';
501

  
502
  # Is an old file version available?
503
  my $attfile;
504
  if ($::form->{attachment_policy} eq 'old_file') {
505
    $attfile = SL::File->get_all(
506
      object_id     => $self->reclamaiton->id,
507
      object_type   => $self->type,
508
      print_variant => $::form->{formname},
509
    );
510
  }
511

  
512
  if (   $::form->{attachment_policy} ne 'no_file'
513
    && !($::form->{attachment_policy} eq 'old_file' && $attfile)
514
  ) {
472 515
    my $pdf;
473
    my @errors = generate_pdf($self->reclamation, \$pdf, {
474
                               media      => $::form->{media},
475
                               format     => $::form->{print_options}->{format},
476
                               formname   => $::form->{print_options}->{formname},
477
                               language   => $self->reclamation->language,
478
                               printer_id => $::form->{print_options}->{printer_id},
479
                               groupitems => $::form->{print_options}->{groupitems}
480
                             });
516
    my @errors = generate_pdf(
517
      $self->reclamation, \$pdf, {
518
        media      => $::form->{media},
519
        format     => $::form->{print_options}->{format},
520
        formname   => $::form->{print_options}->{formname},
521
        language   => $self->reclamation->language,
522
        printer_id => $::form->{print_options}->{printer_id},
523
        groupitems => $::form->{print_options}->{groupitems},
524
      });
481 525
    if (scalar @errors) {
482
      return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self);
526
      $::form->error(t8('Generating the document failed: #1', $errors[0]));
483 527
    }
484 528

  
485
    my @warnings = store_pdf_to_webdav_and_filemanagement($self->reclamation, $pdf, $::form->{attachment_filename});
529
    my @warnings = store_pdf_to_webdav_and_filemanagement(
530
      $self->reclamation, $pdf, $::form->{attachment_filename}
531
    );
486 532
    if (scalar @warnings) {
487 533
      flash_later('warning', $_) for @warnings;
488 534
    }
......
492 538
    $sfile->fh->close;
493 539

  
494 540
    $::form->{tmpfile} = $sfile->file_name;
495
    $::form->{tmpdir}  = $sfile->get_path; # for Form::cleanup which may be called in Form::send_email
541
    $::form->{tmpdir}  = $sfile->get_path; # for Form::cleanup which may be
542
                                           # called in Form::send_email
496 543
  }
497 544

  
498
  $::form->{id} = $self->reclamation->id; # this is used in SL::Mailer to create a linked record to the mail
545
  $::form->{id} = $self->reclamation->id; # this is used in SL::Mailer to
546
                                          # create a linked record to the mail
499 547
  $::form->send_email(\%::myconfig, 'pdf');
500 548

  
501
  # internal notes
502
  my $intnotes = $self->reclamation->intnotes;
503
  $intnotes   .= "\n\n" if $self->reclamation->intnotes;
504
  $intnotes   .= t8('[email]')                                       . "\n";
505
  $intnotes   .= t8('Date')       . ": " . $::locale->format_date_object(
506
                                             DateTime->now_local,
507
                                             precision => 'seconds') . "\n";
508
  $intnotes   .= t8('To (email)') . ": " . $::form->{email}          . "\n";
509
  $intnotes   .= t8('Cc')         . ": " . $::form->{cc}             . "\n"    if $::form->{cc};
510
  $intnotes   .= t8('Bcc')        . ": " . $::form->{bcc}            . "\n"    if $::form->{bcc};
511
  $intnotes   .= t8('Subject')    . ": " . $::form->{subject}        . "\n\n";
512
  $intnotes   .= t8('Message')    . ": " . $::form->{message};
513

  
514
  $self->reclamation->update_attributes(intnotes => $intnotes);
515

  
516
  $self->save_history('MAILED');
517

  
518 549
  flash_later('info', t8('The email has been sent.'));
550
  $self->save_history('MAILED');
519 551

  
520
  my @redirect_params = (
521
    action => 'edit',
522
    type   => $self->type,
523
    id     => $self->reclamation->id,
524
  );
552
  # internal notes unless no email journal
553
  unless ($::instance_conf->get_email_journal) {
554
    my $intnotes = $self->reclamation->intnotes;
555
    $intnotes   .= "\n\n" if $self->reclamation->intnotes;
556
    $intnotes   .= t8('[email]')                                       . "\n";
557
    $intnotes   .= t8('Date')       . ": " . $::locale->format_date_object(
558
                                               DateTime->now_local,
559
                                               precision => 'seconds') . "\n";
560
    $intnotes   .= t8('To (email)') . ": " . $::form->{email}          . "\n";
561
    $intnotes   .= t8('Cc')         . ": " . $::form->{cc}             . "\n"    if $::form->{cc};
562
    $intnotes   .= t8('Bcc')        . ": " . $::form->{bcc}            . "\n"    if $::form->{bcc};
563
    $intnotes   .= t8('Subject')    . ": " . $::form->{subject}        . "\n\n";
564
    $intnotes   .= t8('Message')    . ": " . SL::HTML::Util->strip($::form->{message});
565

  
566
    $self->reclamation->update_attributes(intnotes => $intnotes);
567
  }
525 568

  
526 569
  $self->redirect_to(@redirect_params);
527 570
}

Auch abrufbar als: Unified diff