Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0882a283

Von Moritz Bunkus vor etwa 4 Jahren hinzugefügt

Wiederkehrende Rechnungen: Druck-/E-Mail-Fehler in Zusammenfassungs-Mail

Unterschiede anzeigen:

SL/BackgroundJob/CreatePeriodicInvoices.pm
29 29
  my $self        = shift;
30 30
  $self->{db_obj} = shift;
31 31

  
32
  $self->{job_errors} = [];
32
  $self->{$_} = [] for qw(job_errors posted_invoices printed_invoices printed_failed emailed_invoices emailed_failed disabled_orders);
33

  
33 34
  if (!$self->{db_obj}->db->with_transaction(sub {
34 35
    1;                          # make Emacs happy
35 36

  
......
40 41
      _log_msg("Periodic invoice configuration ID " . $config->id . " extended through " . $new_end_date->strftime('%d.%m.%Y') . "\n") if $new_end_date;
41 42
    }
42 43

  
43
    my (@new_invoices, @invoices_to_print, @invoices_to_email, @disabled_orders);
44
    my (@invoices_to_print, @invoices_to_email);
44 45

  
45 46
    _log_msg("Number of configs: " . scalar(@{ $configs}));
46 47

  
......
61 62

  
62 63
        _log_msg("Invoice " . $data->{invoice}->invnumber . " posted for config ID " . $config->id . ", period start date " . $::locale->format_date(\%::myconfig, $date) . "\n");
63 64

  
64
        push @new_invoices,      $data;
65
        push @{ $self->{posted_invoices} }, $data->{invoice};
65 66
        push @invoices_to_print, $data if $config->print;
66 67
        push @invoices_to_email, $data if $config->send_email;
67 68

  
......
69 70
        if ($inactive_ordnumber) {
70 71
          # disable one time configs and skip eventual invoices
71 72
          _log_msg("Order " . $inactive_ordnumber . " deavtivated \n");
72
          push @disabled_orders, $inactive_ordnumber;
73
          push @{ $self->{disabled_orders} }, $inactive_ordnumber;
73 74
          last;
74 75
        }
75 76
      }
......
78 79
    foreach my $inv ( @invoices_to_print ) { $self->_print_invoice($inv); }
79 80
    foreach my $inv ( @invoices_to_email ) { $self->_email_invoice($inv); }
80 81

  
81
    $self->_send_summary_email(
82
      [ map { $_->{invoice} } @new_invoices      ],
83
      [ map { $_->{invoice} } @invoices_to_print ],
84
      [ map { $_->{invoice} } @invoices_to_email ],
85
                               \@disabled_orders  ,
86
    );
82
    $self->_send_summary_email;
87 83

  
88 84
      1;
89 85
    })) {
......
293 289
}
294 290

  
295 291
sub _send_summary_email {
296
  my ($self, $posted_invoices, $printed_invoices, $emailed_invoices,
297
      $disabled_orders) = @_;
292
  my ($self) = @_;
298 293
  my %config = %::lx_office_conf;
299 294

  
300
  return if !$config{periodic_invoices} || !$config{periodic_invoices}->{send_email_to} || !scalar @{ $posted_invoices };
295
  return if !$config{periodic_invoices} || !$config{periodic_invoices}->{send_email_to} || !scalar @{ $self->{posted_invoices} };
301 296

  
302
  my $user  = SL::DB::Manager::AuthUser->find_by(login => $config{periodic_invoices}->{send_email_to});
303
  my $email = $user ? $user->get_config_value('email') : undef;
297
  return if $config{periodic_invoices}->{send_for_errors_only} && !@{ $self->{printed_failed} } && !@{ $self->{emailed_failed} };
298

  
299
  my $email = $config{periodic_invoices}->{send_email_to};
300
  if ($email !~ m{\@}) {
301
    my $user = SL::DB::Manager::AuthUser->find_by(login => $email);
302
    $email   = $user ? $user->get_config_value('email') : undef;
303
  }
304

  
305
  _log_msg("_send_summary_email: about to send to '" . ($email || '') . "'");
304 306

  
305 307
  return unless $email;
306 308

  
......
314 316

  
315 317
  my $email_template = $config{periodic_invoices}->{email_template};
316 318
  my $filename       = $email_template || ( (SL::DB::Default->get->templates || "templates/webpages") . "/oe/periodic_invoices_email.txt" );
317
  my %params         = ( POSTED_INVOICES  => $posted_invoices,
318
                         PRINTED_INVOICES => $printed_invoices,
319
                         EMAILED_INVOICES => $emailed_invoices,
320
                         DISABLED_ORDERS  => $disabled_orders );
319
  my %params         = map { (uc($_) => $self->{$_}) } qw(posted_invoices printed_invoices printed_failed emailed_invoices emailed_failed disabled_orders);
321 320

  
322 321
  my $output;
323
  $template->process($filename, \%params, \$output);
322
  $template->process($filename, \%params, \$output) || die $template->error;
324 323

  
325 324
  my $mail              = Mailer->new;
326 325
  $mail->{from}         = $config{periodic_invoices}->{email_from};
......
379 378
  $form->throw_on_error(sub {
380 379
    eval {
381 380
      $form->parse_template(\%::myconfig);
381
      push @{ $self->{printed_invoices} }, $invoice;
382 382
      1;
383 383
    } or do {
384 384
      push @{ $self->{job_errors} }, $EVAL_ERROR->error;
385
      push @{ $self->{printed_failed} }, [ $invoice, $EVAL_ERROR->error ];
385 386
    };
386 387
  });
387 388
}
......
440 441
    }
441 442

  
442 443
    my $global_bcc = SL::DB::Default->get->global_bcc;
444
    my $overall_error;
443 445

  
444 446
    for my $recipient (@recipients) {
445 447
      my $mail             = Mailer->new;
......
457 459

  
458 460
      my $error        = $mail->send;
459 461

  
460
      push @{ $self->{job_errors} }, $error if $error;
462
      if ($error) {
463
        push @{ $self->{job_errors} }, $error;
464
        push @{ $self->{emailed_failed} }, [ $data->{invoice}, $error ];
465
        $overall_error = 1;
466
      }
461 467
    }
462 468

  
469
    push @{ $self->{emailed_invoices} }, $data->{invoice} unless $overall_error;
470

  
463 471
    1;
464 472

  
465 473
  } or do {
466 474
    push @{ $self->{job_errors} }, $EVAL_ERROR;
475
    push @{ $self->{emailed_failed} }, [ $data->{invoice}, $EVAL_ERROR ];
467 476
  };
468 477

  
469 478
  unlink $pdf_file_name if $pdf_file_name;
config/kivitendo.conf.default
220 220
email_template = templates/webpages/task_server/failure_notification_email.txt
221 221

  
222 222
[periodic_invoices]
223
# The user name a report about the posted and printed invoices is sent
224
# to.
225
send_email_to  = mb
223
# The user name or email address a report about the posted and printed
224
# invoices is sent to.
225
send_email_to  =
226 226
# The "From:" header for said email.
227 227
email_from     = kivitendo Daemon <root@localhost>
228 228
# The subject for said email.
229 229
email_subject  = Benachrichtigung: automatisch erstellte Rechnungen
230 230
# The template file used for the email's body.
231 231
email_template = templates/webpages/oe/periodic_invoices_email.txt
232
# Whether to always send the mail (0), or only if there were errors
233
# (1).
234
send_for_errors_only = 0
232 235

  
233 236
[self_test]
234 237

  
doc/changelog
27 27
   Variablen im Betreff & Text der E-Mails genutzt werden
28 28
   (z.B. <%invnumber%> für die Rechnungsnummer oder
29 29
   <%transaction_description%> für die Vorgangsbezeichnung).
30
 - Wiederkehrende Rechnungen: die optionale Zusammenfassungs-E-Mail
31
   enthält nun auch eine Auflistung von Rechnungsnummern, für die das
32
   automatische Drucken oder der automatische Versand per E-Mail
33
   fehlgeschlagen ist zusammen mit der jeweils aufgetretenen
34
   Fehlermeldung.
35
 - Wiederkehrende Rechnungen: für die Empfangsadresse der optionalen
36
   Zusammenfassungs-E-Mail kann in der Konfiguration nun anstelle
37
   eines Loginnamens auch eine E-Mail-Adresse verwendet werden. Es ist
38
   nicht nötig, dass diese Adresse einem der Anwenderkonten zugeordnet
39
   ist.
30 40

  
31 41
Bugfixes (Tracker: https://www.kivitendo.de/redmine):
32 42
97 Benutzer löschen unter System->Benutzer funktioniert nicht
templates/webpages/oe/periodic_invoices_email.txt
21 21

  
22 22
[% FOREACH disabled_order = DISABLED_ORDERS %][% disabled_order %] [% END %]
23 23
[%- END %]
24
[% IF PRINTED_FAILED.size %]
25

  
26
Beim Drucken der folgenden Rechnungen gab es Fehler:
27

  
28
[% FOREACH invoice = PRINTED_FAILED %]
29
* [% invoice.0.invnumber %]: [% invoice.1 %]
30
[% END %]
31
[% END %]
32
[% IF EMAILED_FAILED.size %]
33

  
34
Beim Versand der folgenden Rechnungen per E-Mail gab es Fehler:
35

  
36
[% FOREACH invoice = EMAILED_FAILED %]
37
* [% invoice.0.invnumber %]: [% invoice.1 %]
38
[% END %]
39
[% END %]

Auch abrufbar als: Unified diff