Cambios
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
require_once __DIR__ . '/../helpers/session.php';
|
||||
require_once __DIR__ . '/../../config/database.php';
|
||||
require_once __DIR__ . '/../helpers/crypto.php';
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
loadEnv();
|
||||
|
||||
// Función para obtener catálogos visibles del usuario
|
||||
function obtenerCatalogosVisibles($idUsuario)
|
||||
@@ -228,6 +234,21 @@ function vincular()
|
||||
}
|
||||
}
|
||||
|
||||
// Obtener información del importador y la agencia para el correo
|
||||
$infoSql = "SELECT
|
||||
u.nombre AS nombre_importador, u.email AS email_importador,
|
||||
a.nombre_agencia, a.email AS email_agencia,
|
||||
admin.email AS admin_email, admin.nombre AS admin_nombre
|
||||
FROM usuarios_sistema u
|
||||
CROSS JOIN agencias_aduanales a
|
||||
LEFT JOIN usuarios_sistema admin
|
||||
ON a.id_administrador = admin.id_usuario
|
||||
WHERE u.id_usuario = ?
|
||||
AND a.id_agencia = ?
|
||||
";
|
||||
$infoStmt = sqlsrv_query($conn, $infoSql, [$id_importador, $id_agencia]);
|
||||
$info = sqlsrv_fetch_array($infoStmt, SQLSRV_FETCH_ASSOC);
|
||||
|
||||
// Insertar la nueva solicitud
|
||||
$sql = "INSERT INTO solicitudes_vinculacion
|
||||
(id_importador, id_agencia, mensaje, estado, fecha_solicitud)
|
||||
@@ -237,6 +258,48 @@ function vincular()
|
||||
$stmt = sqlsrv_prepare($conn, $sql, $params);
|
||||
|
||||
if ($stmt && sqlsrv_execute($stmt)) {
|
||||
// Enviar notificación al administrador de la agencia
|
||||
if (!empty($info['admin_email'])) {
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'secure.emailsrvr.com';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = 'noreply@aduanasoft.com.mx';
|
||||
$mail->Password = $_ENV['SMTP_PASS'];
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mail->Port = 587;
|
||||
|
||||
$mail->setFrom('noreply@aduanasoft.com.mx', 'SIIH | Sistema Integral para Importadores de Hidrocarburos');
|
||||
$mail->addAddress($info['admin_email']);
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = 'Nueva solicitud de vinculación en SIIH';
|
||||
|
||||
$mail->Body = "
|
||||
<div style='font-family: Segoe UI, sans-serif; background-color: #f4f6f9; padding: 40px;'>
|
||||
<div style='max-width: 600px; margin: auto; background: #fff; border: 1px solid #ddd; border-radius: 10px; overflow: hidden;'>
|
||||
<div style='background: linear-gradient(to right, #003366, #0055A5); padding: 20px; text-align: center;'>
|
||||
<h2 style='color: white;'>¡Nueva solicitud de vinculación!</h2>
|
||||
</div>
|
||||
<div style='padding: 30px; color: #333; font-size: 16px;'>
|
||||
<p>El importador <strong>{$info['nombre_importador']}</strong> ha solicitado vincularse con su agencia <strong>{$info['nombre_agencia']}</strong>.</p>
|
||||
<p><strong>Correo del importador:</strong> {$info['email_importador']}</p>
|
||||
<p>Por favor, revise la solicitud en su panel de administración para aprobarla o rechazarla.</p>
|
||||
</div>
|
||||
<div style='background: #e9ecef; text-align: center; padding: 15px; font-size: 13px; color: #666;'>
|
||||
© " . date('Y') . " SIIH · Sistema Integral para Importadores de Hidrocarburos
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
";
|
||||
|
||||
$mail->send();
|
||||
} catch (Exception $e) {
|
||||
error_log("Error al enviar correo: " . $mail->ErrorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: /IMPORTADORES/vinculaciones/nuevaVinculacion?success=sended_request');
|
||||
exit;
|
||||
} else {
|
||||
@@ -257,6 +320,18 @@ function cancelarVinculacion()
|
||||
$id_importador = $_SESSION['usuario_id'];
|
||||
$id_agencia = (int) $_GET['id'];
|
||||
|
||||
// Obtener información para el correo
|
||||
$infoSql = "SELECT
|
||||
u.nombre AS nombre_importador, u.email AS email_importador,
|
||||
a.nombre_agencia
|
||||
FROM solicitudes_vinculacion sv
|
||||
JOIN usuarios_sistema u ON sv.id_importador = u.id_usuario
|
||||
JOIN agencias_aduanales a ON sv.id_agencia = a.id_agencia
|
||||
WHERE sv.id_importador = ? AND sv.id_agencia = ? AND sv.estado = 'PENDIENTE'";
|
||||
|
||||
$infoStmt = sqlsrv_query($conn, $infoSql, [$id_importador, $id_agencia]);
|
||||
$info = sqlsrv_fetch_array($infoStmt, SQLSRV_FETCH_ASSOC);
|
||||
|
||||
$sql = "UPDATE solicitudes_vinculacion
|
||||
SET estado = 'CANCELADA', fecha_respuesta = GETDATE()
|
||||
WHERE id_importador = ?
|
||||
@@ -267,6 +342,48 @@ function cancelarVinculacion()
|
||||
$stmt = sqlsrv_prepare($conn, $sql, $params);
|
||||
|
||||
if ($stmt && sqlsrv_execute($stmt)) {
|
||||
// Enviar notificación al importador
|
||||
if (!empty($info['email_importador'])) {
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'secure.emailsrvr.com';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = 'noreply@aduanasoft.com.mx';
|
||||
$mail->Password = $_ENV['SMTP_PASS'];
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mail->Port = 587;
|
||||
|
||||
$mail->setFrom('noreply@aduanasoft.com.mx', 'SIIH | Sistema Integral para Importadores de Hidrocarburos');
|
||||
$mail->addAddress($info['email_importador']);
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = 'Cancelación de solicitud de vinculación en SIIH';
|
||||
|
||||
$mail->Body = "
|
||||
<div style='font-family: Segoe UI, sans-serif; background-color: #f4f6f9; padding: 40px;'>
|
||||
<div style='max-width: 600px; margin: auto; background: #fff; border: 1px solid #ddd; border-radius: 10px; overflow: hidden;'>
|
||||
<div style='background: linear-gradient(to right, #003366, #0055A5); padding: 20px; text-align: center;'>
|
||||
<h2 style='color: white;'>Solicitud cancelada</h2>
|
||||
</div>
|
||||
<div style='padding: 30px; color: #333; font-size: 16px;'>
|
||||
<p>Estimado/a <strong>{$info['nombre_importador']}</strong>,</p>
|
||||
<p>Has cancelado tu solicitud de vinculación con la agencia <strong>{$info['nombre_agencia']}</strong>.</p>
|
||||
<p>Si esto fue un error, puedes volver a solicitar la vinculación desde tu panel de importador.</p>
|
||||
</div>
|
||||
<div style='background: #e9ecef; text-align: center; padding: 15px; font-size: 13px; color: #666;'>
|
||||
© " . date('Y') . " SIIH · Sistema Integral para Importadores de Hidrocarburos
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
";
|
||||
|
||||
$mail->send();
|
||||
} catch (Exception $e) {
|
||||
error_log("Error al enviar correo: " . $mail->ErrorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: /IMPORTADORES/vinculaciones/nuevaVinculacion?success=cancelled');
|
||||
exit;
|
||||
}
|
||||
@@ -296,12 +413,16 @@ function desvincularUsuario()
|
||||
|
||||
// 1. Verificar que la relación existe y pertenece a la agencia del admin
|
||||
$sqlVerificar = "SELECT
|
||||
ia.*, u.id_usuario, u.nombre as importador_nombre, aa.nombre_agencia
|
||||
ia.*, u.id_usuario, u.nombre as importador_nombre, u.email as importador_email,
|
||||
aa.nombre_agencia, aa.email as agencia_email,
|
||||
admin.email as admin_email, admin.nombre as admin_nombre
|
||||
FROM importador_agencia ia
|
||||
INNER JOIN usuarios_sistema u
|
||||
ON ia.id_importador = u.id_usuario
|
||||
INNER JOIN agencias_aduanales aa
|
||||
ON ia.id_agencia = aa.id_agencia
|
||||
LEFT JOIN usuarios_sistema admin
|
||||
ON aa.id_administrador = admin.id_usuario
|
||||
WHERE ia.id_relacion = ?
|
||||
AND ia.id_importador = ?
|
||||
";
|
||||
@@ -358,6 +479,93 @@ function desvincularUsuario()
|
||||
}
|
||||
}
|
||||
|
||||
// Enviar notificaciones por correo
|
||||
if (!empty($relacion['importador_email'])) {
|
||||
// Notificación al importador
|
||||
$mailImportador = new PHPMailer(true);
|
||||
try {
|
||||
$mailImportador->isSMTP();
|
||||
$mailImportador->Host = 'secure.emailsrvr.com';
|
||||
$mailImportador->SMTPAuth = true;
|
||||
$mailImportador->Username = 'noreply@aduanasoft.com.mx';
|
||||
$mailImportador->Password = $_ENV['SMTP_PASS'];
|
||||
$mailImportador->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mailImportador->Port = 587;
|
||||
|
||||
$mailImportador->setFrom('noreply@aduanasoft.com.mx', 'SIIH | Sistema Integral para Importadores de Hidrocarburos');
|
||||
$mailImportador->addAddress($relacion['importador_email']);
|
||||
$mailImportador->CharSet = 'UTF-8';
|
||||
$mailImportador->isHTML(true);
|
||||
$mailImportador->Subject = 'Confirmación de desvinculación en SIIH';
|
||||
|
||||
$mailImportador->Body = "
|
||||
<div style='font-family: Segoe UI, sans-serif; background-color: #f4f6f9; padding: 40px;'>
|
||||
<div style='max-width: 600px; margin: auto; background: #fff; border: 1px solid #ddd; border-radius: 10px; overflow: hidden;'>
|
||||
<div style='background: linear-gradient(to right, #003366, #0055A5); padding: 20px; text-align: center;'>
|
||||
<h2 style='color: white;'>Desvinculación completada</h2>
|
||||
</div>
|
||||
<div style='padding: 30px; color: #333; font-size: 16px;'>
|
||||
<p>Estimado/a <strong>{$relacion['importador_nombre']}</strong>,</p>
|
||||
<p>Has sido desvinculado de la agencia <strong>{$relacion['nombre_agencia']}</strong>.</p>
|
||||
<p><strong>Fecha de desvinculación:</strong> " . date('d/m/Y H:i:s') . "</p>
|
||||
<p>Si esto es un error, por favor contacta al administrador de la agencia.</p>
|
||||
</div>
|
||||
<div style='background: #e9ecef; text-align: center; padding: 15px; font-size: 13px; color: #666;'>
|
||||
© " . date('Y') . " SIIH · Sistema Integral para Importadores de Hidrocarburos
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
";
|
||||
|
||||
$mailImportador->send();
|
||||
} catch (Exception $e) {
|
||||
error_log("Error al enviar correo a importador: " . $mailImportador->ErrorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($relacion['admin_email'])) {
|
||||
// Notificación al administrador de la agencia
|
||||
$mailAdmin = new PHPMailer(true);
|
||||
try {
|
||||
$mailAdmin->isSMTP();
|
||||
$mailAdmin->Host = 'secure.emailsrvr.com';
|
||||
$mailAdmin->SMTPAuth = true;
|
||||
$mailAdmin->Username = 'noreply@aduanasoft.com.mx';
|
||||
$mailAdmin->Password = $_ENV['SMTP_PASS'];
|
||||
$mailAdmin->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mailAdmin->Port = 587;
|
||||
|
||||
$mailAdmin->setFrom('noreply@aduanasoft.com.mx', 'SIIH | Sistema Integral para Importadores de Hidrocarburos');
|
||||
$mailAdmin->addAddress($relacion['admin_email']);
|
||||
$mailAdmin->CharSet = 'UTF-8';
|
||||
$mailAdmin->isHTML(true);
|
||||
$mailAdmin->Subject = 'Notificación de desvinculación en SIIH';
|
||||
|
||||
$mailAdmin->Body = "
|
||||
<div style='font-family: Segoe UI, sans-serif; background-color: #f4f6f9; padding: 40px;'>
|
||||
<div style='max-width: 600px; margin: auto; background: #fff; border: 1px solid #ddd; border-radius: 10px; overflow: hidden;'>
|
||||
<div style='background: linear-gradient(to right, #003366, #0055A5); padding: 20px; text-align: center;'>
|
||||
<h2 style='color: white;'>Notificación de desvinculación</h2>
|
||||
</div>
|
||||
<div style='padding: 30px; color: #333; font-size: 16px;'>
|
||||
<p>Estimado/a <strong>{$relacion['admin_nombre']}</strong>,</p>
|
||||
<p>El importador <strong>{$relacion['importador_nombre']}</strong> se ha desvinculado de su agencia <strong>{$relacion['nombre_agencia']}</strong>.</p>
|
||||
<p><strong>Correo del importador:</strong> {$relacion['importador_email']}</p>
|
||||
<p><strong>Fecha de desvinculación:</strong> " . date('d/m/Y H:i:s') . "</p>
|
||||
</div>
|
||||
<div style='background: #e9ecef; text-align: center; padding: 15px; font-size: 13px; color: #666;'>
|
||||
© " . date('Y') . " SIIH · Sistema Integral para Importadores de Hidrocarburos
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
";
|
||||
|
||||
$mailAdmin->send();
|
||||
} catch (Exception $e) {
|
||||
error_log("Error al enviar correo a administrador: " . $mailAdmin->ErrorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Limpiar statements
|
||||
if (isset($stmtVerificar) && is_resource($stmtVerificar)) {
|
||||
sqlsrv_free_stmt($stmtVerificar);
|
||||
@@ -369,7 +577,6 @@ function desvincularUsuario()
|
||||
sqlsrv_free_stmt($stmtActualizarAgencia);
|
||||
}
|
||||
|
||||
|
||||
// Confirmar transacción
|
||||
sqlsrv_commit($conn);
|
||||
sqlsrv_close($conn);
|
||||
|
||||
Reference in New Issue
Block a user