- Mejora el manejo de errores en la generación de PDF - Corrige problemas de sintaxis y estructura del código - Optimiza el rendimiento de DOMPDF - Mejora los mensajes de error para facilitar la depuración
809 lines
22 KiB
PHP
Executable File
809 lines
22 KiB
PHP
Executable File
<?php
|
|
// Usar DOMPDF
|
|
use Dompdf\Dompdf;
|
|
use Dompdf\Options;
|
|
|
|
// Configuración de manejo de errores
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 0);
|
|
ini_set('log_errors', 1);
|
|
ini_set('error_log', '/var/www/html/ventas/logs/php_errors.log');
|
|
ini_set('max_execution_time', 300); // Aumentar tiempo de ejecución para PDFs grandes
|
|
ini_set('memory_limit', '512M'); // Aumentar límite de memoria
|
|
|
|
// Definir constantes para rutas
|
|
define('TEMP_DIR', sys_get_temp_dir() . '/dompdf_');
|
|
@mkdir(TEMP_DIR, 0755, true);
|
|
|
|
// Función para manejar errores fatales
|
|
register_shutdown_function(function() {
|
|
$error = error_get_last();
|
|
if ($error !== null && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
|
|
$message = "Error fatal (" . $error['type'] . "): " . $error['message'] . " en " . $error['file'] . " línea " . $error['line'];
|
|
error_log($message);
|
|
http_response_code(500);
|
|
echo "Ha ocurrido un error inesperado. Por favor, intente nuevamente más tarde.";
|
|
}
|
|
});
|
|
|
|
// Función para manejar excepciones no capturadas
|
|
set_exception_handler(function($exception) {
|
|
$message = "Excepción no capturada: " . $exception->getMessage() . " en " . $exception->getFile() . " línea " . $exception->getLine();
|
|
error_log($message);
|
|
http_response_code(500);
|
|
echo "Ha ocurrido un error inesperado. Por favor, intente nuevamente más tarde.";
|
|
});
|
|
|
|
// Función para manejar errores
|
|
set_error_handler(function($errno, $errstr, $errfile, $errline) {
|
|
$message = "Error (" . $errno . "): " . $errstr . " en " . $errfile . " línea " . $errline;
|
|
error_log($message);
|
|
return true;
|
|
});
|
|
|
|
try {
|
|
// Validar autenticación
|
|
if (!isset($empresa) || !method_exists($empresa, 'AuthUser')) {
|
|
throw new Exception('Error de autenticación: Objeto empresa no válido');
|
|
}
|
|
$empresa->AuthUser();
|
|
|
|
// Cargar el autoloader de Composer
|
|
$autoloadPath = DOC_ROOT . '/vendor/autoload.php';
|
|
if (!file_exists($autoloadPath)) {
|
|
throw new Exception('No se encontró el archivo autoload.php de Composer');
|
|
}
|
|
require_once $autoloadPath;
|
|
|
|
// Inicializar variables
|
|
$html = '';
|
|
$ivaPorc = 0;
|
|
$pedidoId = 0;
|
|
$mode = isset($_GET['mode']) ? $_GET['mode'] : '';
|
|
|
|
if(isset($_GET['cancelarId'])){
|
|
$pedidoId = intval($_GET['cancelarId']);
|
|
$mode = 'cancelar';
|
|
}elseif(isset($_GET['show-pdf'])){
|
|
$pedidoId = intval($_GET['show-pdf']);
|
|
$mode = 'show';
|
|
}elseif(isset($_GET['id'])){
|
|
$pedidoId = intval($_GET['id']);
|
|
$mode = 'send';
|
|
}else{
|
|
header('Location: '.WEB_ROOT);
|
|
exit;
|
|
}
|
|
|
|
if(WEB_ROOT == 'http://novomoda.ddns.net/html')
|
|
$enProduccion = false;
|
|
else
|
|
$enProduccion = true;
|
|
|
|
$pedido->setPedidoId($pedidoId);
|
|
$info = $pedido->Info();
|
|
|
|
$rfc->setRfcId(1);
|
|
$infE = $util->EncodeRow($rfc->Info());
|
|
|
|
$direccion = $infE['calle'];
|
|
|
|
if($infE['noExt'] != '')
|
|
$direccion .= ' No. Ext. '.$infE['noExt'];
|
|
if($infE['noInt'] != '')
|
|
$direccion .= ', No. Int. '.$infE['noInt'];
|
|
if($infE['colonia'] != '')
|
|
$direccion .= ', Col. '.$infE['colonia'];
|
|
if($infE['localidad'] != '')
|
|
$direccion .= ', '.$infE['localidad'];
|
|
if($infE['ciudad'] != '')
|
|
$direccion .= ', '.$infE['ciudad'];
|
|
if($infE['municipio'] != '')
|
|
$direccion .= ', '.$infE['municipio'];
|
|
if($infE['estado'] != '')
|
|
$direccion .= ', '.$infE['estado'];
|
|
if(isset($infE['codigoPostal']) && $infE['codigoPostal'] != '')
|
|
$direccion .= 'C.P. '.$infE['codigoPostal'];
|
|
|
|
$infE['direccion'] = $direccion;
|
|
|
|
$proveedor->setProveedorId($info['proveedorId']);
|
|
$infPv = $util->EncodeRow($proveedor->Info());
|
|
|
|
$fecha = date('d-m-Y',strtotime($info['fecha']));
|
|
$info['fecha'] = $fecha;
|
|
|
|
$fechaEntrega = date('d-m-Y',strtotime($info['fechaEntrega']));
|
|
$info['fechaEntrega'] = $fechaEntrega;
|
|
|
|
if($info['fechaEntregaF']){
|
|
$fechaEntregaF = date('d-m-Y',strtotime($info['fechaEntregaF']));
|
|
$info['fechaEntrega'] .= ' al '.$fechaEntregaF;
|
|
}
|
|
|
|
if($info['metodoCompra'] == 'conIva')
|
|
$info['metodoCompra'] = 'IVA Incluido';
|
|
else
|
|
$info['metodoCompra'] = 'IVA No Incluido';
|
|
|
|
//Distribuciones
|
|
|
|
$resProducts = $pedido->GetProdsDistribucion();
|
|
|
|
$dist = array();
|
|
$sucIds = array();
|
|
foreach($resProducts as $res){
|
|
$productoId = $res['productoId'];
|
|
$sucursalId = $res['sucursalId'];
|
|
|
|
$pedido->setProductoId($productoId);
|
|
$infPP['status'] = $pedido->GetInfoStatusProd();
|
|
|
|
if($infPP['status'] == 'Sugerencia'){
|
|
$pedido->setSucursalId($sucursalId);
|
|
$infPS['cantidad'] = $pedido->GetInfoCantProdSug();
|
|
$res['cantidad'] = $infPS['cantidad'];
|
|
}
|
|
|
|
if($res['cantidad'] == 0)
|
|
continue;
|
|
|
|
$dist[$productoId][$sucursalId]['cantidad'] = $res['cantidad'];
|
|
$dist[$productoId][$sucursalId]['pedDistId'] = $res['pedDistId'];
|
|
|
|
if(!in_array($sucursalId, $sucIds))
|
|
$sucIds[] = $sucursalId;
|
|
}
|
|
|
|
//Sucursales
|
|
|
|
$sucursals = array();
|
|
$tiendas = array();
|
|
foreach($sucIds as $sucursalId){
|
|
|
|
$res['sucursalId'] = $sucursalId;
|
|
|
|
$sucursal->setSucursalId($sucursalId);
|
|
$infS = $sucursal->Info();
|
|
|
|
$res['noSuc'] = $infS['noSuc'];
|
|
|
|
$tiendas[] = $res;
|
|
}
|
|
|
|
if(count($tiendas) > 0){
|
|
// $tiendas = $util->orderMultiDimensionalArray($tiendas, 'noSuc'); // Método no disponible - comentado
|
|
$sucursals[] = $tiendas;
|
|
}
|
|
|
|
//Productos
|
|
|
|
$resProducts = $pedido->GetProductos();
|
|
|
|
$sugerencias = 0;
|
|
$subtotalP = 0;
|
|
$products = array();
|
|
foreach($resProducts as $card){
|
|
|
|
$prodCatId = $card['prodCatId'];
|
|
$prodSubcatId = $card['prodSubcatId'];
|
|
$productoId = $card['productoId'];
|
|
|
|
$card['productoId'] = $productoId;
|
|
$card['prodCatId'] = $prodCatId;
|
|
$card['prodSubcatId'] = $prodSubcatId;
|
|
|
|
$prodCat->setProdCatId($prodCatId);
|
|
$card['departamento'] = $prodCat->GetNameById();
|
|
|
|
$prodSubcat->setProdSubcatId($prodSubcatId);
|
|
$card['linea'] = $prodSubcat->GetNameById();
|
|
|
|
$producto->setProductoId($productoId);
|
|
$infP = $producto->Info();
|
|
$card['modelo'] = $infP['modelo'].' '.$infP['descripcion'];
|
|
$card['imagen'] = $infP['imagen'];
|
|
$card['codigoBarra'] = $infP['codigoBarra'];
|
|
$card['precioVentaIva'] = $infP['precioVentaIva'];
|
|
|
|
$card['atributos'] = $producto->GetAtributosAll();
|
|
|
|
$card['cantidad'] = $card['totalLote'] * $card['cantLotes'];
|
|
$totalP = $card['costo'] * $card['cantidad'];
|
|
$card['total'] = number_format($totalP,2);
|
|
|
|
$subtotalP += $totalP;
|
|
|
|
//PROPORCIONES
|
|
|
|
//Colores
|
|
|
|
$producto->setProductoId($productoId);
|
|
$resColores = $producto->GetColores();
|
|
|
|
$colores = array();
|
|
foreach($resColores as $res){
|
|
|
|
$colorId = $res['colorId'];
|
|
|
|
$pedido->setColorId($colorId);
|
|
$pedido->setProductoId($productoId);
|
|
$cantidad = $pedido->GetProporcionByColor();
|
|
|
|
$proporcionC[$colorId] = $cantidad;
|
|
|
|
$res['cantidad'] = $cantidad;
|
|
|
|
$atribVal->setAtribValId($res['colorId']);
|
|
$res['nombre'] = $atribVal->GetNameById();
|
|
|
|
$colores[$colorId] = $res;
|
|
|
|
}//foreach
|
|
|
|
//Tallas
|
|
|
|
$producto->setProductoId($productoId);
|
|
$resTallas = $producto->GetTallas();
|
|
|
|
$tallas = array();
|
|
foreach($resTallas as $res){
|
|
|
|
$tallaId = $res['tallaId'];
|
|
|
|
$pedido->setTallaId($tallaId);
|
|
$pedido->setProductoId($productoId);
|
|
$cantidad = $pedido->GetProporcionByTalla();
|
|
|
|
$proporcionT[$tallaId] = $cantidad;
|
|
|
|
$res['cantidad'] = $cantidad;
|
|
|
|
$atribVal->setAtribValId($tallaId);
|
|
$res['nombre'] = $atribVal->GetNameById();
|
|
|
|
$tallas[$tallaId] = $res;
|
|
|
|
}//foreach
|
|
|
|
//Obtenemos Totales
|
|
|
|
$totales = array();
|
|
$subtotales = array();
|
|
foreach($tallas as $idT => $t){
|
|
|
|
$cantT = $t['cantidad'];
|
|
|
|
$total = 0;
|
|
foreach($colores as $idC => $c){
|
|
|
|
$cantC = $c['cantidad'];
|
|
|
|
$subtotal = $cantC * $cantT;
|
|
$total += $subtotal;
|
|
|
|
$subtotales[$idT][$idC] = $subtotal;
|
|
}
|
|
|
|
$totales[$idT] = $total;
|
|
|
|
}//foreach
|
|
|
|
$card['tallas'] = $tallas;
|
|
$card['colores'] = $colores;
|
|
$card['totales'] = $totales;
|
|
$card['subtotales'] = $subtotales;
|
|
$card['proporcionT'] = $proporcionT;
|
|
$card['proporcionC'] = $proporcionC;
|
|
|
|
//FIN PROPORCIONES
|
|
|
|
if($card['status'] == 'Sugerencia')
|
|
$sugerencias++;
|
|
|
|
$products[] = $card;
|
|
|
|
}//foreach
|
|
|
|
$info['subtotal'] = number_format($info['subtotal'],2);
|
|
$info['iva'] = number_format($info['iva'],2);
|
|
$info['total'] = number_format($info['total'],2);
|
|
|
|
//HTML - PDF
|
|
|
|
$html .= '
|
|
<html>
|
|
<head>
|
|
<style type="text/css">
|
|
body{
|
|
font-family:Verdana, Arial, Helvetica, sans-serif;
|
|
font-size:10px;
|
|
}
|
|
.titulo {
|
|
color: #FFFFFF;
|
|
font-family: Verdana, Arial, Helvetica, sans-serif;
|
|
font-weight: bold;
|
|
font-size: 12px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="550" border="0" cellpadding="0" cellspacing="0">
|
|
<tr>
|
|
<td width="430">
|
|
<p><b>'.strtoupper($infE['razonSocial']).'</b><br />
|
|
'.$infE['direccion'].'
|
|
</td>
|
|
<td>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<table width="550" border="0" cellpadding="0" cellspacing="0">
|
|
<tr>
|
|
<td>
|
|
<table width="550" border="1" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td width="" align="center"><b>No. PEDIDO</b></td>
|
|
<td width="25%" align="center"><b>METODO COMPRA</b></td>
|
|
<td width="25%" align="center"><b>FECHA DE SOLICITUD</b></td>
|
|
<td width="26%" align="center"><b>FECHA DE ENTREGA</b></td>
|
|
</tr>
|
|
<tr>
|
|
<td height="15" align="center">'.$info['noPedido'].'</td>
|
|
<td align="center">'.$info['metodoCompra'].'</td>
|
|
<td align="center">'.$info['fecha'].'</td>
|
|
<td align="center">'.$info['fechaEntrega'].'</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>';
|
|
|
|
//DATOS DEL PROVEEDOR
|
|
|
|
$html .= '
|
|
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td colspan="4" align="center" bgcolor="#809829"><span class="titulo">DATOS DEL PROVEEDOR</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td width="23%"><b>Razón Social</b></td>
|
|
<td width="26%">'.$infPv['nombre'].'</td>
|
|
<td width="27%"><b>Calle</b></td>
|
|
<td width="">'.$infPv['calle'].'</td>
|
|
</tr>
|
|
<tr>
|
|
<td><b>RFC</b></td>
|
|
<td>'.$infPv['rfc'].'</td>
|
|
<td><b>Colonia</b></td>
|
|
<td>'.$infPv['colonia'].'</td>
|
|
</tr>
|
|
<tr>
|
|
<td><b>Teléfonos</b></td>
|
|
<td>'.(isset($infPv['phone']) ? $infPv['phone'] : '').'</td>
|
|
<td><b>Delegación o Municipio</b></td>
|
|
<td>'.(isset($infPv['municipio']) ? $infPv['municipio'] : '').'</td>
|
|
</tr>
|
|
<tr>
|
|
<td><b>C.P.</b></td>
|
|
<td>'.(isset($infS['codigoPostal']) ? $infS['codigoPostal'] : '').'</td>
|
|
<td><b>Estado</b></td>
|
|
<td>'.$infS['estado'].'</td>
|
|
</tr>
|
|
</table>';
|
|
|
|
//PRODUCTOS
|
|
|
|
$html .= '
|
|
<br>
|
|
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td colspan="5" align="center" bgcolor="#809829"><span class="titulo">PRODUCTOS</span></td>
|
|
</tr>
|
|
</table>
|
|
<br>';
|
|
|
|
foreach($products as $res){
|
|
|
|
//Tallas
|
|
|
|
$hTallas = '<br>
|
|
<table width="" cellpadding="0" cellspacing="0" border="1" align="center">
|
|
<tr>
|
|
<td colspan="'.count($res['tallas']).'" align="center"><b>Proporción Tallas</b></td>
|
|
</tr>
|
|
<tr>';
|
|
foreach($res['tallas'] as $val)
|
|
$hTallas .= '<td align="center" width="30">'.$val['nombre'].'<br>'.$val['cantidad'].'</td>';
|
|
|
|
$hTallas .= '
|
|
</tr>
|
|
</table>';
|
|
|
|
//Colores
|
|
|
|
$hColores = '<br>
|
|
<table width="" cellpadding="0" cellspacing="0" border="1" align="center">
|
|
<tr>
|
|
<td colspan="'.count($res['colores']).'" align="center"><b>Proporción Colores</b></td>
|
|
</tr>
|
|
<tr>';
|
|
foreach($res['colores'] as $val)
|
|
$hColores .= '<td align="center" width="30">'.$val['nombre'].'<br>'.$val['cantidad'].'</td>';
|
|
|
|
$hColores .= '
|
|
</tr>
|
|
</table>';
|
|
|
|
//Producto
|
|
|
|
$html .= '
|
|
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td width="13%" align="center" bgcolor="#CCCCCC">CODIGO BARRA</td>
|
|
<td width="" align="center" bgcolor="#CCCCCC">MODELO</td>
|
|
<td width="14%" align="center" bgcolor="#CCCCCC">COSTO UNITARIO</td>
|
|
<td width="14%" align="center" bgcolor="#CCCCCC">PRECIO VENTA</td>
|
|
<td width="14%" align="center" bgcolor="#CCCCCC">CANTIDAD</td>
|
|
<td width="14%" align="center" bgcolor="#CCCCCC">TOTAL</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center">'.$res['codigoBarra'].'</td>
|
|
<td align="center">'.$res['modelo'].'</td>
|
|
<td align="center">$'.$res['costo'].'</td>
|
|
<td align="center">$'.$res['precioVentaIva'].'</td>
|
|
<td align="center">'.$res['cantidad'].'</td>
|
|
<td align="right">$'.$res['total'].'</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td>'.$hTallas.'</td>
|
|
<td>'.$hColores.'</td>
|
|
</tr>
|
|
</table>
|
|
';
|
|
|
|
//Distribucion
|
|
|
|
$html .= '<br>
|
|
<div align="center"><b>DISTRIBUCION</b></div>
|
|
<br>
|
|
<table width="" cellpadding="0" cellspacing="0" border="1" align="center">
|
|
';
|
|
|
|
$html .= '<tr>';
|
|
$bloque = 0;
|
|
foreach($sucursals as $sucursales){
|
|
//$html .= '<tr>';
|
|
|
|
foreach($sucursales as $val){
|
|
|
|
$productoId = $res['productoId'];
|
|
$sucursalId = $val['sucursalId'];
|
|
|
|
$sucursal->setSucursalId($sucursalId);
|
|
$infS = $sucursal->Info();
|
|
$noSuc = $infS['noSuc'];
|
|
|
|
$distP = $dist[$productoId][$sucursalId];
|
|
|
|
if($distP['cantidad'] > 0){
|
|
$html .= '<td align="center" width="40">Suc. '.$noSuc.'<br>'.$distP['cantidad'].'</td>';
|
|
$bloque++;
|
|
}
|
|
|
|
if($bloque == 11){
|
|
$html .= '</tr><tr>';
|
|
$bloque = 0;
|
|
}
|
|
|
|
}//foreach
|
|
|
|
}//foreach $sucursals
|
|
|
|
if($bloque == 0)
|
|
$falta = 0;
|
|
else
|
|
$falta = 11 - $bloque;
|
|
|
|
for($k=1; $k<=$falta; $k++)
|
|
$html .= '<td align="center" width="40"></td>';
|
|
|
|
$html .= '</tr>';
|
|
|
|
$html .= '</table>';
|
|
|
|
}//foreach
|
|
|
|
//PRODUCTOS
|
|
|
|
$html .= '
|
|
<br>
|
|
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td colspan="5" align="center" bgcolor="#809829"><span class="titulo">PIEZAS POR CAJA</span></td>
|
|
</tr>
|
|
</table>
|
|
<br>';
|
|
|
|
$html .= '
|
|
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td width="15%" align="center" bgcolor="#CCCCCC">CODIGO BARRA</td>
|
|
<td width="" align="center" bgcolor="#CCCCCC">MODELO</td>
|
|
<td width="20%" align="center" bgcolor="#CCCCCC">CANTIDAD</td>
|
|
</tr>
|
|
';
|
|
|
|
foreach($products as $res){
|
|
|
|
$html .= '
|
|
<tr>
|
|
<td align="center">'.$res['codigoBarra'].'</td>
|
|
<td align="left">'.$res['modelo'].'</td>
|
|
<td align="center">'.$res['piezasCaja'].'</td>
|
|
</tr>';
|
|
}
|
|
|
|
$html .= '</table>';
|
|
|
|
//TOTALES
|
|
|
|
$html .= '
|
|
<br>
|
|
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td colspan="5" align="center" bgcolor="#809829"><span class="titulo">TOTALES</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td width="20%"></td>
|
|
<td width=""></td>
|
|
<td width="16%"> </td>
|
|
<td width="16%" valign="top">
|
|
<b>SUBTOTAL</b> <br>
|
|
<b>IVA '.(isset($ivaPorc) ? $ivaPorc : 0).'%</b> <br>
|
|
<b>TOTAL</b>
|
|
</td>
|
|
<td width="16%" align="right" valign="top">
|
|
$'.$info['subtotal'].'<br>
|
|
$'.$info['iva'].'<br>
|
|
$'.$info['total'].'
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</body>
|
|
</html>
|
|
';
|
|
|
|
// Configuración optimizada de DOMPDF
|
|
try {
|
|
$options = new Options([
|
|
'isRemoteEnabled' => true,
|
|
'isHtml5ParserEnabled' => true,
|
|
'isPhpEnabled' => true,
|
|
'isJavascriptEnabled' => false,
|
|
'defaultFont' => 'Arial',
|
|
'tempDir' => TEMP_DIR,
|
|
'fontCache' => TEMP_DIR,
|
|
'chroot' => realpath('.'),
|
|
'debugPng' => false,
|
|
'debugKeepTemp' => false,
|
|
'debugCss' => false,
|
|
'debugLayout' => false
|
|
]);
|
|
|
|
$dompdf = new Dompdf($options);
|
|
$dompdf->setPaper('letter', 'portrait');
|
|
} catch (Exception $e) {
|
|
error_log('Error al configurar DOMPDF: ' . $e->getMessage());
|
|
throw new Exception('Error al configurar el generador de PDF');
|
|
}
|
|
|
|
// Deshabilitar errores durante el renderizado
|
|
$old_error_reporting = error_reporting(0);
|
|
$old_display_errors = ini_set('display_errors', '0');
|
|
|
|
try {
|
|
// Validar que el HTML no esté vacío
|
|
if (empty($html)) {
|
|
throw new Exception('El contenido HTML para el PDF está vacío');
|
|
}
|
|
|
|
// Cargar el HTML con manejo de errores
|
|
$dompdf->loadHtml($html, 'UTF-8');
|
|
|
|
// Renderizar el PDF con manejo de memoria
|
|
try {
|
|
$dompdf->render();
|
|
} catch (Exception $e) {
|
|
error_log('Error al renderizar PDF: ' . $e->getMessage());
|
|
throw new Exception('Error al generar el PDF. Por favor, verifica el formato del contenido.');
|
|
}
|
|
|
|
// Limpiar buffer de salida
|
|
while (ob_get_level() > 0) {
|
|
if (!@ob_end_clean()) {
|
|
error_log('No se pudo limpiar el buffer de salida');
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Configurar encabezados para mostrar el PDF
|
|
$filename = 'orden_compra_' . $pedidoId . '_' . date('Y-m-d') . '.pdf';
|
|
|
|
header('Content-Type: application/pdf');
|
|
header('Content-Disposition: inline; filename="' . $filename . '"');
|
|
header('Cache-Control: private, max-age=0, must-revalidate');
|
|
header('Pragma: public');
|
|
|
|
// Enviar el PDF al navegador
|
|
echo $dompdf->output();
|
|
exit(0);
|
|
|
|
} catch (Exception $e) {
|
|
error_log('Error en pedidos-enviar-prov: ' . $e->getMessage());
|
|
http_response_code(500);
|
|
echo 'Error al generar el PDF: ' . htmlspecialchars($e->getMessage());
|
|
exit(1);
|
|
}
|
|
|
|
// Configurar encabezados
|
|
$filename = 'orden_compra_' . $pedidoId . '_' . date('Y-m-d') . '.pdf';
|
|
|
|
header('Content-Type: application/pdf');
|
|
header('Content-Disposition: inline; filename="' . $filename . '"');
|
|
header('Cache-Control: private, max-age=0, must-revalidate');
|
|
header('Pragma: public');
|
|
|
|
// Enviar el PDF
|
|
$output = $dompdf->output();
|
|
|
|
// Guardar una copia temporal si es necesario para el correo
|
|
$tempPdfPath = DOC_ROOT . '/temp/orden_compra.pdf';
|
|
@file_put_contents($tempPdfPath, $output);
|
|
|
|
// Enviar la salida al navegador
|
|
echo $output;
|
|
|
|
// Limpiar memoria
|
|
unset($output, $html);
|
|
|
|
if (function_exists('gc_collect_cycles')) {
|
|
gc_collect_cycles();
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
throw new Exception('Error al generar el PDF: ' . $e->getMessage(), 0, $e);
|
|
} finally {
|
|
// Restaurar configuración de errores
|
|
error_reporting($old_error_reporting);
|
|
ini_set('display_errors', $old_display_errors);
|
|
}
|
|
|
|
$_mail = new PHPMailer(true);
|
|
|
|
//Configurando el servidor SMTP
|
|
|
|
$_mail->IsSMTP();
|
|
$_mail->SMTPAuth = true;
|
|
$_mail->Host = SMTP_HOST;
|
|
$_mail->Username = SMTP_USER;
|
|
$_mail->Password = SMTP_PASS;
|
|
$_mail->Port = SMTP_PORT;
|
|
|
|
//Enviamos el mensaje
|
|
|
|
$email = $infPv['emailVtas'];
|
|
$proveedor = $infPv['nombre'];
|
|
|
|
if($mode == 'cancelar'){
|
|
$subject = 'Cancelacion Orden de Compra No. '.$info['noPedido'];
|
|
$message = 'Por medio de la presente le informamos que la Orden de Compra No. '.$info['noPedido'];
|
|
$message .= 'ha sido cancelada.';
|
|
$message .= '<br><br>Lamentamos los inconvenientes que esto pudiera ocasionar.';
|
|
}else{
|
|
$subject = 'Envio Orden de Compra No. '.$info['noPedido'];
|
|
$message = 'Por medio de la presente le hacemos llegar la Orden de Compra No. '.$info['noPedido'];
|
|
}
|
|
|
|
$message .= '<br><br>Por su atención';
|
|
$message .='<br><br>Gracias';
|
|
|
|
$html = '<html>
|
|
<body>
|
|
'.$message.'
|
|
</body>
|
|
</html>';
|
|
|
|
try {
|
|
$_mail->AddAddress($email, $proveedor);
|
|
|
|
if($enProduccion){
|
|
$_mail->AddBCC('silvano.cruz@novomoda.com.mx');
|
|
$_mail->AddBCC('sonia.velazquez@novomoda.com.mx');
|
|
}
|
|
|
|
$_mail->AddBCC('sistemas@novomoda.com.mx');
|
|
$_mail->SetFrom('contacto@novomoda.com.mx', 'Novomoda');
|
|
$_mail->Subject = $subject;
|
|
$_mail->MsgHTML($html);
|
|
$_mail->AddAttachment(DOC_ROOT.'/temp/orden_compra.pdf'); // attachment
|
|
$_mail->Send();
|
|
|
|
$emailSent = 1;
|
|
|
|
} catch (phpmailerException $e) {
|
|
$emailSent = 2;
|
|
} catch (Exception $e) {
|
|
$emailSent = 2;
|
|
}
|
|
|
|
|
|
@unlink(DOC_ROOT.'/temp/orden_compra.pdf');
|
|
|
|
header('Location: '.WEB_ROOT.'/pedidos');
|
|
exit;
|
|
$_mail->SMTPAuth = true;
|
|
$_mail->Host = SMTP_HOST;
|
|
$_mail->Username = SMTP_USER;
|
|
$_mail->Password = SMTP_PASS;
|
|
$_mail->Port = SMTP_PORT;
|
|
|
|
//Enviamos el mensaje
|
|
|
|
$email = $infPv['emailVtas'];
|
|
$proveedor = $infPv['nombre'];
|
|
|
|
if($mode == 'cancelar'){
|
|
$subject = 'Cancelacion Orden de Compra No. '.$info['noPedido'];
|
|
$message = 'Por medio de la presente le informamos que la Orden de Compra No. '.$info['noPedido'];
|
|
$message .= 'ha sido cancelada.';
|
|
$message .= '<br><br>Lamentamos los inconvenientes que esto pudiera ocasionar.';
|
|
}else{
|
|
$subject = 'Envio Orden de Compra No. '.$info['noPedido'];
|
|
$message = 'Por medio de la presente le hacemos llegar la Orden de Compra No. '.$info['noPedido'];
|
|
}
|
|
|
|
$message .= '<br><br>Por su atención';
|
|
$message .='<br><br>Gracias';
|
|
|
|
$html = '<html>
|
|
<body>
|
|
'.$message.'
|
|
</body>
|
|
</html>';
|
|
|
|
try {
|
|
$_mail->AddAddress($email, $proveedor);
|
|
|
|
if($enProduccion){
|
|
$_mail->AddBCC('silvano.cruz@novomoda.com.mx');
|
|
$_mail->AddBCC('sonia.velazquez@novomoda.com.mx');
|
|
}
|
|
|
|
$_mail->AddBCC('sistemas@novomoda.com.mx');
|
|
$_mail->SetFrom('contacto@novomoda.com.mx', 'Novomoda');
|
|
$_mail->Subject = $subject;
|
|
$_mail->MsgHTML($html);
|
|
$_mail->AddAttachment(DOC_ROOT.'/temp/orden_compra.pdf'); // attachment
|
|
$_mail->Send();
|
|
|
|
$emailSent = 1;
|
|
|
|
} catch (phpmailerException $e) {
|
|
$emailSent = 2;
|
|
} catch (Exception $e) {
|
|
$emailSent = 2;
|
|
}
|
|
|
|
|
|
@unlink(DOC_ROOT.'/temp/orden_compra.pdf');
|
|
|
|
header('Location: '.WEB_ROOT.'/pedidos');
|
|
exit;
|
|
|