Carpeta helpers
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../helpers/crypto.php';
|
||||
|
||||
require_once __DIR__ . '/../libs/phpmailer/src/PHPMailer.php';
|
||||
require_once __DIR__ . '/../libs/phpmailer/src/SMTP.php';
|
||||
require_once __DIR__ . '/../libs/phpmailer/src/Exception.php';
|
||||
require_once __DIR__ . '/../controllers/configuracionController.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
function enviarMailServicioFinalizado($servicio, $insumos, $cliente) {
|
||||
|
||||
// VERIFICAMOS SI LAS NOTIFICACIONES ESTAN ACTIVADAS
|
||||
// OBTENEMOS MAIL Y CONTRASEÑA
|
||||
|
||||
$configuracionmodel = new configuracionModel();
|
||||
$datosConfig = $configuracionmodel->obtenerDatosEnvioMail();
|
||||
|
||||
if (isset($datosConfig['contrasenia_emisor'])) {
|
||||
$datosConfig['contrasenia_emisor'] = decryptData($datosConfig['contrasenia_emisor']);
|
||||
}
|
||||
|
||||
if ((int) $datosConfig['mail_automatico'] === 1) {
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
|
||||
// CONFIG SMTP
|
||||
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'smtp.gmail.com';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $datosConfig['email_emisor'];
|
||||
$mail->Password = $datosConfig['contrasenia_emisor'];
|
||||
$mail->SMTPSecure = 'tls';
|
||||
$mail->Port = 587;
|
||||
|
||||
// CODIFICACIÓN (evita problemas con tildes)
|
||||
|
||||
$mail->CharSet = 'UTF-8';
|
||||
|
||||
// REMITENTE
|
||||
|
||||
$mail->setFrom($datosConfig['email_emisor'], 'ByteCenter');
|
||||
|
||||
// DESTINATARIO
|
||||
|
||||
if (empty($cliente['email'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mail->addAddress($cliente['email'], $cliente['nombre'] . ' ' . $cliente['apellido']);
|
||||
|
||||
// DEFINIMOS ARRAY HTML DE INSUMOS UTILIZADOS
|
||||
|
||||
$productos = "";
|
||||
|
||||
if (!empty($insumos)) {
|
||||
|
||||
foreach ($insumos as $i) {
|
||||
$productos .= "
|
||||
<tr>
|
||||
<td style='text-align: center;'>{$i['marca']} {$i['modelo']}</td>
|
||||
<td style='text-align: right;'>$ {$i['precio_unitario']}</td>
|
||||
<td style='text-align: right;'>{$i['cantidad']}</td>
|
||||
<td style='text-align: right;'>$ {$i['subtotal']}</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
// POR SI LA LISTA VIENE VACIA
|
||||
|
||||
if (empty($insumos)) {
|
||||
$productos = "
|
||||
<tr>
|
||||
<td colspan='4' align='center' style='text-align:center; padding:10px;'>
|
||||
-
|
||||
</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
// SANEAMIENTO DE HORA (substraer segundos)
|
||||
|
||||
$datosConfig['hora_apertura_maniana'] = substr($datosConfig['hora_apertura_maniana'], 0, 5);
|
||||
$datosConfig['hora_cierre_maniana'] = substr($datosConfig['hora_cierre_maniana'], 0, 5);
|
||||
$datosConfig['hora_apertura_tarde'] = substr($datosConfig['hora_apertura_tarde'], 0, 5);
|
||||
$datosConfig['hora_cierre_tarde'] = substr($datosConfig['hora_cierre_tarde'], 0, 5);
|
||||
|
||||
// CONTENIDO
|
||||
|
||||
$numeroServicio = '0001-' . str_pad($servicio['id'], 8, '0', STR_PAD_LEFT);
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = 'ByteCenter - Servicio a Realizar - N° ' . $numeroServicio;
|
||||
|
||||
$mail->Body = "
|
||||
<h2>Servicio a Realizar</h2>
|
||||
|
||||
<p><strong>Cliente: </strong> ". $cliente['nombre'] . ' ' . $cliente['apellido'] ."</p>
|
||||
<p><strong>Equipo: </strong> ". $servicio['equipo'] ."</p>
|
||||
<p><strong>Problema: </strong> ". $servicio['problema']. "</p>
|
||||
|
||||
<br>
|
||||
<h2>Detalles de Servicio</h2>
|
||||
<h3>Trabajo a Relizar</h3>
|
||||
<p>". $servicio['detalle_realizado']. "</p>
|
||||
|
||||
<h3>Insumos a Utilizar</h3>
|
||||
|
||||
<table border='1' cellpadding='6' cellspacing='0' style='border-collapse: collapse; text-align: right;'>
|
||||
<tr>
|
||||
<th>Modelo</th>
|
||||
<th>Precio Unitario</th>
|
||||
<th>Cantidad</th>
|
||||
<th>Subtotal</th>
|
||||
</tr>
|
||||
$productos
|
||||
</table>
|
||||
|
||||
<h3>Totales</h3>
|
||||
<p><strong>Mano de obra: </strong> ". "$" . number_format($servicio['mano_obra'], 2, ',', '.'). "</p>
|
||||
<p><strong>Total: </strong> ". "$" . number_format($servicio['total'], 2, ',', '.'). "</p>
|
||||
|
||||
<br>
|
||||
<p>Esperamos su confirmación para la realización del servicio, en caso de cancelarlo podrá retirar el equipo en nuestro local ubicado en {$datosConfig['direccion']}, {$datosConfig['ciudad']} y abonar el monto por revisión y desarme: $ {$datosConfig['cargo_cancelacion_servicio']}.</p>
|
||||
<p>Nuestros horarios de atención son: {$datosConfig['hora_apertura_maniana']} - {$datosConfig['hora_cierre_maniana']} y {$datosConfig['hora_apertura_tarde']} - {$datosConfig['hora_cierre_tarde']}.</p>
|
||||
<p>Por cualquier duda o consulta: {$datosConfig['telefono']} - {$datosConfig['email']}.</p>
|
||||
<p>Gracias por confiar en nuestro servicio técnico.</p>
|
||||
<p>ByteCenter</p>
|
||||
";
|
||||
|
||||
// Versión texto plano (por compatibilidad)
|
||||
|
||||
$mail->AltBody = "Servicio finalizado - Total: $ {$servicio['total']}";
|
||||
|
||||
$mail->send();
|
||||
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
// Log interno
|
||||
|
||||
error_log($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user