|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) 2021 Joe Nilson <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Lesser General Public License as |
|
7
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
8
|
|
|
* License, or (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Lesser General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
require_once 'extras/phpmailer/class.phpmailer.php'; |
|
19
|
|
|
require_once 'extras/phpmailer/class.smtp.php'; |
|
20
|
|
|
|
|
21
|
|
|
class ResidentesEnviarMail |
|
22
|
|
|
{ |
|
23
|
|
|
public $log; |
|
24
|
|
|
public $rc; |
|
25
|
|
|
public function __construct() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->log = new fs_core_log(); |
|
|
|
|
|
|
28
|
|
|
$this->rc = new residentes_controller(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function invoiceEmail(&$companyInformation, &$invoice, &$customer, $user, $archivo) |
|
32
|
|
|
{ |
|
33
|
|
|
if (file_exists('tmp/'.FS_TMP_NAME.'enviar/'.$archivo)) { |
|
34
|
|
|
$mail = $companyInformation->new_mail(); |
|
35
|
|
|
$mail->FromName = (is_object($user)) ? $user->get_agente_fullname() : $companyInformation->nombre; |
|
36
|
|
|
$email = $customer->email; |
|
37
|
|
|
$this->log->new_message('Enviando factura a: '.$email); |
|
38
|
|
|
$mail->addAddress($email, $customer->nombre); |
|
39
|
|
|
$elSubject = ' - Su Factura ' . $invoice->codigo . ' ' . $invoice->numero2; |
|
40
|
|
|
$mail->Subject = fs_fix_html($companyInformation->nombre) . $elSubject; |
|
41
|
|
|
$mail->AltBody = plantilla_email( |
|
|
|
|
|
|
42
|
|
|
'factura', |
|
43
|
|
|
$invoice->codigo . ' ' . $invoice->numero2, |
|
44
|
|
|
$companyInformation->email_config['mail_firma'] |
|
45
|
|
|
); |
|
46
|
|
|
$this->emailAdditionalInfo($mail, $customer); |
|
47
|
|
|
$mail->msgHTML(nl2br($mail->AltBody)); |
|
48
|
|
|
$mail->isHTML(true); |
|
49
|
|
|
$mail->addAttachment('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); |
|
50
|
|
|
$this->emailAdditionalAttachments($mail); |
|
51
|
|
|
if ($companyInformation->mail_connect($mail) && $mail->send()) { |
|
52
|
|
|
$invoice->femail = \date('d-m-Y');; |
|
53
|
|
|
$invoice->save(); |
|
54
|
|
|
$companyInformation->save_mail($mail); |
|
55
|
|
|
} else { |
|
56
|
|
|
$this->log->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo); |
|
57
|
|
|
} |
|
58
|
|
|
unlink('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); |
|
59
|
|
|
} else { |
|
60
|
|
|
$this->log->new_error_msg('Imposible generar el PDF.'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function emailAdditionalInfo(&$mail, $customer) |
|
65
|
|
|
{ |
|
66
|
|
|
if (trim($this->rc->filter_request('email_copia')) !== '') { |
|
|
|
|
|
|
67
|
|
|
if ($this->rc->filter_request('cco') !== null) { |
|
|
|
|
|
|
68
|
|
|
$mail->addBCC( |
|
69
|
|
|
trim($this->rc->filter_request('email_copia')), |
|
70
|
|
|
$customer->nombre |
|
71
|
|
|
); |
|
72
|
|
|
} else { |
|
73
|
|
|
$mail->addCC( |
|
74
|
|
|
trim($this->rc->filter_request('email_copia')), |
|
75
|
|
|
$customer->nombre |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function emailAdditionalAttachments(&$mail) |
|
82
|
|
|
{ |
|
83
|
|
|
if (isset($_FILES['adjunto']) && is_uploaded_file($_FILES['adjunto']['tmp_name'])) { |
|
84
|
|
|
$mail->addAttachment($_FILES['adjunto']['tmp_name'], $_FILES['adjunto']['name']); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function accountStatusEmail(&$empresa, &$customer, $user, $archivo) |
|
89
|
|
|
{ |
|
90
|
|
|
$mail = $empresa->new_mail(); |
|
91
|
|
|
$mail->FromName = (is_object($user)) ? $user->get_agente_fullname() : $empresa->nombre; |
|
92
|
|
|
$email = (trim($this->rc->filter_request('email')) !== '') |
|
|
|
|
|
|
93
|
|
|
? $this->rc->filter_request('email') |
|
94
|
|
|
: $customer->email; |
|
95
|
|
|
$this->log->new_message('Enviando Estado de cuenta a: '.$email); |
|
96
|
|
|
$mail->addAddress($email, $customer->nombre); |
|
97
|
|
|
$elSubject = ': Su Estado de cuenta al '. \date('d-m-Y'); |
|
98
|
|
|
$mail->Subject = fs_fix_html($empresa->nombre) . $elSubject; |
|
99
|
|
|
$mail->AltBody = strip_tags($_POST['mensaje']); |
|
100
|
|
|
$this->emailAdditionalAttachments($mail); |
|
101
|
|
|
$mail->msgHTML(nl2br($mail->AltBody)); |
|
102
|
|
|
$mail->isHTML(true); |
|
103
|
|
|
$mail->addAttachment('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); |
|
104
|
|
|
$this->emailAdditionalAttachments($mail); |
|
105
|
|
|
if ($empresa->mail_connect($mail) && $mail->send()) { |
|
106
|
|
|
$empresa->save_mail($mail); |
|
107
|
|
|
} else { |
|
108
|
|
|
$this->log->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo); |
|
109
|
|
|
} |
|
110
|
|
|
unlink('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); |
|
111
|
|
|
} |
|
112
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths