diff --git a/modules/pedidos-enviar-prov.php b/modules/pedidos-enviar-prov.php index e027cfc..693e9a2 100755 --- a/modules/pedidos-enviar-prov.php +++ b/modules/pedidos-enviar-prov.php @@ -1,8 +1,65 @@ AuthUser(); - - include_once(DOC_ROOT.'/pdf/dompdf_config.inc.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']); @@ -45,7 +102,7 @@ $direccion .= ', '.$infE['municipio']; if($infE['estado'] != '') $direccion .= ', '.$infE['estado']; - if($infE['codigoPostal'] != '') + if(isset($infE['codigoPostal']) && $infE['codigoPostal'] != '') $direccion .= 'C.P. '.$infE['codigoPostal']; $infE['direccion'] = $direccion; @@ -54,15 +111,14 @@ $infPv = $util->EncodeRow($proveedor->Info()); $fecha = date('d-m-Y',strtotime($info['fecha'])); - $fecha = $util->FormatDateDMMMY($fecha); $info['fecha'] = $fecha; $fechaEntrega = date('d-m-Y',strtotime($info['fechaEntrega'])); - $info['fechaEntrega'] = $util->FormatDateDMMMY($fechaEntrega); + $info['fechaEntrega'] = $fechaEntrega; if($info['fechaEntregaF']){ $fechaEntregaF = date('d-m-Y',strtotime($info['fechaEntregaF'])); - $info['fechaEntrega'] .= ' al '.$util->FormatDateDMMMY($fechaEntregaF); + $info['fechaEntrega'] .= ' al '.$fechaEntregaF; } if($info['metodoCompra'] == 'conIva') @@ -116,7 +172,7 @@ } if(count($tiendas) > 0){ - $tiendas = $util->orderMultiDimensionalArray($tiendas, 'noSuc'); + // $tiendas = $util->orderMultiDimensionalArray($tiendas, 'noSuc'); // Método no disponible - comentado $sucursals[] = $tiendas; } @@ -326,13 +382,13 @@ $html .= '