añadido mensajeria

This commit is contained in:
2025-05-21 21:25:02 +02:00
parent b500229b37
commit 2faa88297e
4 changed files with 288 additions and 4 deletions

View File

@ -13,7 +13,7 @@ class EmailService
// Si no estamos en producción, forzar el destinatario a uno fijo
if ($skEnv !== 'production') {
$recipient = env('MAIL_DEV_RECIPIENT', 'imnavajas@coit.es'); // fallback opcional
$recipient = env('MAIL_DEV_RECIPIENT', 'imnavajas@coit.es,info@jjimenez.eu'); // fallback opcional
}
$settings_model = model('App\Models\Configuracion\ConfigVariableModel');
@ -43,7 +43,13 @@ class EmailService
$email->setSubject($subject);
$email->setMessage($body);
return $email->send();
if (!$email->send()) {
log_message('error', 'Error enviando email: ' . $email->printDebugger(['headers', 'subject', 'body']));
return false;
}
return true;
} catch (\Throwable $e) {
log_message('error', 'EmailService failed: ' . $e->getMessage());
return false;

View File

@ -148,7 +148,7 @@ class LogisticaService
$builder = $db->table("({$subBuilder->getCompiledSelect(false)}) AS sub");
$builder->select('ot, fechaEncuadernado');
$builder->where('cantidad > unidades_enviadas');
return $builder;
}
@ -362,6 +362,81 @@ class LogisticaService
}
public static function sendConfirmacionEnvio($envio, $lineaEnvio, $isFerro = false)
{
$view = \Config\Services::renderer();
if ($isFerro)
$subject = '[Safekat]' . " El envio del ferro de su pedido se ha realizado";
else
$subject = '[Safekat]' . " El envio de su pedido se ha realizado";
$presupuestoModel = model('App\Models\Presupuestos\PresupuestoModel');
$presupuesto = $presupuestoModel->find($lineaEnvio->presupuesto_id);
$proveedorModel = model('App\Models\Compras\ProveedorModel');
$proveedor = $proveedorModel->find($envio->proveedor_id);
$userModel = model('App\Models\Usuarios\UserModel');
$datos_correo = $userModel->select("CONCAT(users.first_name, ' ', users.last_name) as comercial_nombre, auth_identities.secret as comercial_correo, clientes.email as cliente_email")
->join('auth_identities', 'auth_identities.user_id = users.id')
->join('clientes', 'clientes.comercial_id = users.id')
->where('clientes.id', $presupuesto->cliente_id)
->first();
$pedido = (object) [
'pedido_id' => $lineaEnvio->pedido_id,
'titulo' => $presupuesto->titulo,
'cp' => $envio->cp,
'proveedor_nombre' => $proveedor->nombre,
'codigo_seguimiento' => $envio->codigo_seguimiento,
'comercial_nombre' => $datos_correo->comercial_nombre,
'comercial_correo' => $datos_correo->comercial_correo,
];
if ($proveedor->nombre == "GLS") {
$pedido->url = 'https://m.asmred.com/e/' . $envio->codigo_seguimiento . '/' . $envio->cp;
}
$content = $view->setVar('datos_pedido', $pedido)
->render('themes/vuexy/mail/envio_pedido');
// Renderiza la plantilla completa
if ($isFerro)
$finalBody = $view->setVar('emailTitle2', "El ferro de su pedido " . $lineaEnvio->pedido_id . " ha sido enviado el " . date('d/m/Y'))
->setVar('content', $content)
->render('themes/vuexy/mail/mail_layout_2');
else
$finalBody = $view->setVar('emailTitle2', "Su pedido " . $lineaEnvio->pedido_id . " ha sido enviado el " . date('d/m/Y'))
->setVar('content', $content)
->render('themes/vuexy/mail/mail_layout_2');
$email = service('emailService');
$result = $email->send($subject, $finalBody, $datos_correo->cliente_email);
$chat = Service('chat');
$data = [
'chat_department_id' => 5,
'client' => $presupuesto->cliente_id,
'message' => "El pedido " . $lineaEnvio->pedido_id . " ha sido enviado el " . date('d/m/Y') . ".<br><br>" .
"CP:" . $envio->cp . ".<br>" .
"Proveedor envío: " . $proveedor->nombre . ".<br>" .
"Código de seguimiento: " . $envio->codigo_seguimiento . ".<br>"
];
if ($proveedor->nombre == "GLS") {
$data['message'] = $data['message'] . 'URL segumiento: <a style="color:white;" target="_blank" href="' . 'https://m.asmred.com/e/' . $envio->codigo_seguimiento . '/' . $envio->cp . ' ">' .
'https://m.asmred.com/e/' . $envio->codigo_seguimiento . '/' . $envio->cp . '</a>';
}
$chat->storeChatMessage(5, "pedido", $lineaEnvio->pedido_id, $data);
return [
'status' => $result,
'message' => $result ? lang('Logistica.success.emailSent') : lang('Logistica.errors.emailNotSent'),
];
}
public static function generateEnvio($ot_id, $direccion = null)
{
@ -606,8 +681,11 @@ class LogisticaService
"name" => "ferro_en_cliente_at",
"ferro_en_cliente_at" => date('Y-m-d H:i:s')
]);
LogisticaService::sendConfirmacionEnvio($envio, $linea, true);
} else {
if ($cantidad_enviada + $linea->unidades_envio == $pedido->total_tirada) {
if ($cantidad_enviada + $linea->unidades_envio >= $pedido->total_tirada) {
$otModel = model('App\Models\OrdenTrabajo\OrdenTrabajoModel');
$ot = $otModel->where('pedido_id', $linea->pedido_id)
->first();
@ -623,6 +701,9 @@ class LogisticaService
"name" => "envio_at",
"envio_at" => date('Y-m-d H:i:s')
]);
LogisticaService::sendConfirmacionEnvio($envio, $linea);
if ($finalizar_ot) {
$ps->updateOrdenTrabajo(
[

View File

@ -0,0 +1,41 @@
<table width="600" bgcolor="#ffffff">
<tr>
<td
style="font-family: Helvetica, arial, sans-serif; font-size: 15px; color: #333333; text-align:center; line-height: 15px;">
Número pedido: <?= esc($datos_pedido->pedido_id) ?></td>
</tr>
<tr>
<td
style="font-family: Helvetica, arial, sans-serif; font-size: 15px; color: #333333; text-align:center; line-height: 15px;">
Título: <?= esc($datos_pedido->titulo) ?></td>
</tr>
<tr>
<td
style="font-family: Helvetica, arial, sans-serif; font-size: 15px; color: #333333; text-align:center; line-height: 15px;">
CP: <?= esc($datos_pedido->cp) ?></td>
</tr>
<tr>
<td
style="font-family: Helvetica, arial, sans-serif; font-size: 15px; color: #333333; text-align:center; line-height: 15px;">
Proveedor envío: <?= esc($datos_pedido->proveedor_nombre) ?></td>
</tr>
<tr>
<td
style="font-family: Helvetica, arial, sans-serif; font-size: 15px; color: #333333; text-align:center; line-height: 15px;">
Código seguimiento: <?= esc($datos_pedido->codigo_seguimiento) ?></td>
</tr>
<?php if (!empty($datos_pedido->url)): ?>
<tr>
<td
style="font-family: Helvetica, arial, sans-serif; font-size: 15px; color: #333333; text-align:center; line-height: 15px;">
URL seguimiento: <a href="<?= esc($datos_pedido->url) ?>"><?= esc($datos_pedido->url) ?></a>
</td>
</tr>
<?php endif; ?>
<tr>
<td height="20" align="center">
<p style="margin-top: 20px;font-family: Helvetica, arial, sans-serif; font-size: 15px; color: #333333;">Consulte con su comercial <?= esc($datos_pedido->comercial_nombre) ?> en el correo
<?= esc($datos_pedido->comercial_correo) ?></p>
</td>
</tr>
</table>

View File

@ -0,0 +1,156 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><?= esc($emailTitle ?? 'Correo de Safekat') ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
/* Copia aquí todo el CSS de tu layout Blade */
body {
margin: 0;
padding: 0;
width: 100% !important;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
table {
border-collapse: collapse;
}
img {
border: none;
outline: none;
text-decoration: none;
display: block;
}
h2 {
font-family: Helvetica, Arial, sans-serif;
font-size: 30px;
color: #333;
text-align: center;
}
p {
font-family: Helvetica, Arial, sans-serif;
font-size: 16px;
color: #666;
text-align: center;
line-height: 30px;
}
@media only screen and (max-width: 640px) {
a[href^="tel"],
a[href^="sms"] {
text-decoration: none;
color: #0a8cce;
/* or whatever your want */
pointer-events: none;
cursor: default;
}
.mobile_link a[href^="tel"],
.mobile_link a[href^="sms"] {
text-decoration: default;
color: #0a8cce !important;
pointer-events: auto;
cursor: default;
}
table[class=devicewidth] {
width: 440px !important;
text-align: center !important;
}
table[class=devicewidthinner] {
width: 420px !important;
text-align: center !important;
}
img[class=banner] {
width: 440px !important;
height: 220px !important;
}
img[class=colimg2] {
width: 440px !important;
height: 220px !important;
}
}
/*IPHONE STYLES*/
@media only screen and (max-width: 480px) {
a[href^="tel"],
a[href^="sms"] {
text-decoration: none;
color: #0a8cce;
/* or whatever your want */
pointer-events: none;
cursor: default;
}
.mobile_link a[href^="tel"],
.mobile_link a[href^="sms"] {
text-decoration: default;
color: #0a8cce !important;
pointer-events: auto;
cursor: default;
}
table[class=devicewidth] {
width: 280px !important;
text-align: center !important;
}
table[class=devicewidthinner] {
width: 260px !important;
text-align: center !important;
}
img[class=banner] {
width: 280px !important;
height: 140px !important;
}
img[class=colimg2] {
width: 280px !important;
height: 140px !important;
}
}
</style>
</head>
<body>
<table width="100%" bgcolor="#ffffff">
<tr>
<td align="center">
<!-- Logo -->
<img src="<?= site_url('themes/vuexy/img/safekat/logos/sk-logo.png') ?>" alt="Safekat" width="108"
height="45">
</td>
</tr>
<tr>
<td height="20"></td>
</tr>
<tr>
<td align="center">
<h3><?= esc($emailTitle2 ?? '') ?></h3>
</td>
</tr>
<tr>
<td align="center">
<?= esc($content) ?>
</tr>
</table>
</body>
</html>