37 |
37 |
|
38 |
38 |
use SL::Common;
|
39 |
39 |
use SL::DBUtils;
|
|
40 |
use SL::DB::AuthUser;
|
40 |
41 |
use SL::DB::Default;
|
41 |
42 |
use SL::DB::Employee;
|
42 |
43 |
use SL::GenericTranslations;
|
... | ... | |
386 |
387 |
my $query =
|
387 |
388 |
qq|SELECT
|
388 |
389 |
dcfg.email_body, dcfg.email_subject, dcfg.email_attachment,
|
389 |
|
c.email AS recipient
|
390 |
|
|
|
390 |
COALESCE (NULLIF(c.invoice_mail, ''), c.email) AS recipient, c.name,
|
|
391 |
(SELECT login from employee where id = ar.employee_id) as invoice_employee_login
|
391 |
392 |
FROM dunning d
|
392 |
393 |
LEFT JOIN dunning_config dcfg ON (d.dunning_config_id = dcfg.id)
|
393 |
394 |
LEFT JOIN ar ON (d.trans_id = ar.id)
|
... | ... | |
396 |
397 |
LIMIT 1|;
|
397 |
398 |
my $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id);
|
398 |
399 |
|
399 |
|
if (!$ref || !$ref->{recipient} || !$myconfig->{email}) {
|
|
400 |
# without a recipient, we cannot send a mail
|
|
401 |
if (!$ref || !$ref->{recipient}) {
|
400 |
402 |
$main::lxdebug->leave_sub();
|
401 |
|
return;
|
|
403 |
$form->error($main::locale->text("No email recipient for customer #1 defined.", $ref->{name}));
|
|
404 |
}
|
|
405 |
|
|
406 |
# without a sender we cannot send a mail
|
|
407 |
# two cases: check mail from 1. current user OR 2. employee who created the invoice
|
|
408 |
my $from;
|
|
409 |
if ($::instance_conf->get_dunning_creator eq 'current_employee') {
|
|
410 |
$from = $myconfig->{email};
|
|
411 |
$form->error($main::locale->text('No email for current user #1 defined.', $myconfig->{name})) unless $from;
|
|
412 |
} else {
|
|
413 |
eval {
|
|
414 |
$from = SL::DB::Manager::AuthUser->find_by(login => $ref->{invoice_employee_login})->get_config_value("email");
|
|
415 |
1;
|
|
416 |
} or do { $form->error($main::locale->text('No email for user with login #1 defined.', $ref->{invoice_employee_login})) };
|
402 |
417 |
}
|
403 |
418 |
|
404 |
419 |
my $template = SL::Template::create(type => 'PlainText', form => $form, myconfig => $myconfig);
|
405 |
420 |
my $mail = Mailer->new();
|
406 |
421 |
$mail->{bcc} = $form->get_bcc_defaults($myconfig, $form->{bcc});
|
407 |
|
$mail->{from} = $myconfig->{email};
|
|
422 |
$mail->{from} = $from;
|
408 |
423 |
$mail->{to} = $ref->{recipient};
|
409 |
424 |
$mail->{subject} = $template->parse_block($ref->{email_subject});
|
410 |
425 |
$mail->{message} = $template->parse_block($ref->{email_body});
|
Zahlungserinnerung an Rechnungsadresse schicken - Weiche für Absender
Mail-Absender aus defaults.dunning_creator ableiten.
Falls die Rechnungsadresse E-Mail gesetzt ist, diese als Empfänger nehmen ansonsten die
globale E-Mail des Kunden (abwärtskompatibel).
Erweiterung um Fehlerbehandlung mit Hinweis an der Oberfläche, falls keine Sender oder
Empfänger-Adresse gefunden wird