getMessage(),
$exception->getFile(),
$exception->getLine(),
$exception->getTraceAsString()
);
error_log($message);
if (!headers_sent()) {
http_response_code(500);
header('Content-Type: text/plain; charset=utf-8');
}
echo "Ha ocurrido un error inesperado. Por favor, intente nuevamente más tarde.\n";
exit(1);
});
// Función para manejar errores
set_error_handler(function($errno, $errstr, $errfile, $errline) {
// No manejar errores que estén enmascarados con @
if (error_reporting() === 0) {
return false;
}
$message = sprintf(
"[%s] Error (%s): %s en %s línea %s\nStack trace:\n%s",
date('Y-m-d H:i:s'),
$errno,
$errstr,
$errfile,
$errline,
json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), JSON_PRETTY_PRINT)
);
error_log($message);
// No ejecutar el gestor de errores interno de PHP
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
$subtotales = [];
$html = '';
$impBrutoG = 0.0;
$impNetoG = 0.0;
$cantTotal = 0.0;
$descGlobal = 0.0;
$totalGlobal = 0.0;
$porcDesc = 0.0;
$infS = [];
$porcDesc = 0; // Inicializar variable faltante
$pedidoId = $_GET['pedidoId'];
$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['metodoCompra'] == 'conIva')
$info['metodoCompra'] = 'IVA Incluido';
else
$info['metodoCompra'] = 'IVA No Incluido';
*/
//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'];
$card['imagen'] = $infP['imagen'];
$card['codigoBarra'] = $infP['codigoBarra'];
$card['atributos'] = $producto->GetAtributosAll();
if($card['prendasComp'] == 1)
$card['cantidad'] = $card['totalLote'] * $card['cantLotes'];
else
$card['cantidad'] = $card['prendasRec'];
$totalP = $card['costo'] * $card['cantidad'];
$card['total'] = number_format($totalP,2,'.','');
$subtotalP += $totalP;
$card['subtotales'] = isset($subtotales) ? $subtotales : array();
$products[] = $card;
}//foreach
if($info['fechaFolio'] == "0000-00-00")
{
$fechaP = "---";
}
else
{
$fechaP = date('d-m-Y',strtotime($info['fechaFolio']));
}
if($info['fechaOrdenCompIng'] == "0000-00-00")
{
$fechaP1 = "---";
}
else
{
$fechaP1 = date('d-m-Y',strtotime($info['fechaOrdenCompIng']));
}
if($info['fechaOrdenCompIng'] == "0000-00-00")
{
$horaP1 = "---";
}
else
{
$horaP1 = date('H:i:s',strtotime($info['fechaOrdenCompIng']));
}
if($fechaP1 == "---")
{
$fechaV = "---";
}
else
{
$fechaV = date('d-m-Y',strtotime($fechaP1.' + 90 days'));
}
$porcDesc = $info['porcPub'] + $info['porcFlete'] + $info['porcDes'] + $info['porcEsp'];
$foliosP = array();
if($info['folioProv'])
$foliosP[] = $info['folioProv'];
if($info['folioProv2'])
$foliosP[] = $info['folioProv2'];
if($info['folioProv3'])
$foliosP[] = $info['folioProv3'];
if($info['folioProv4'])
$foliosP[] = $info['folioProv4'];
if($info['folioProv5'])
$foliosP[] = $info['folioProv5'];
$foliosProv = implode('
',$foliosP);
//HTML - PDF
// Inicializar la variable $html
$html = '';
// Construir el HTML
$html .= '';
$html .= '';
$html .= '
| ';
$html .= 'CEDIS '; $html .= 'COMERCIALIZADORA NOVOMODA, S.A. DE C.V. '; $html .= htmlspecialchars($infE['direccion'], ENT_QUOTES, 'UTF-8'); $html .= ' | ';
$html .= ''; $html .= ' |
| ORDEN COMPRA | '; $html .= 'FECHA EXP. | '; $html .= 'CONDICIONES | '; $html .= 'FECHA VECTO. | '; $html .= 'FACT/REM. | '; $html .= 'FECHA REG. | '; $html .= 'HORA REG. | '; $html .= '
| ' . htmlspecialchars($info['noPedido'], ENT_QUOTES, 'UTF-8') . ' | '; $html .= '' . htmlspecialchars($fechaP, ENT_QUOTES, 'UTF-8') . ' | '; $html .= '90 Dias | '; $html .= '' . htmlspecialchars($fechaV, ENT_QUOTES, 'UTF-8') . ' | '; $html .= '' . htmlspecialchars($foliosProv, ENT_QUOTES, 'UTF-8') . ' | '; $html .= '' . htmlspecialchars($fechaP, ENT_QUOTES, 'UTF-8') . ' | '; $html .= '' . htmlspecialchars($horaP1, ENT_QUOTES, 'UTF-8') . ' | '; $html .= '
| NO. PROV. | '; $html .= 'T. MONEDA. | '; $html .= 'CONC. INV. | '; $html .= 'CONC. CXP. | '; $html .= ''; $html .= ' | '; $html .= ' | '; $html .= ' |
| ' . htmlspecialchars($info['proveedorId'], ENT_QUOTES, 'UTF-8') . ' | '; $html .= 'MONEDA NACIONAL | '; $html .= 'ENT X COMPR | '; $html .= 'COMPRAS | '; $html .= '--- | '; $html .= '--- | '; $html .= '--- | '; $html .= '
| DATOS DEL PROVEEDOR | '; $html .= '|||
| Razón Social | '; $html .= 'Calle | '; $html .= '' . htmlspecialchars($infPv['calle'], ENT_QUOTES, 'UTF-8') . ' | '; $html .= '|
| RFC | '; $html .= '' . htmlspecialchars($infPv['rfc'], ENT_QUOTES, 'UTF-8') . ' | '; $html .= 'Colonia | '; $html .= '' . htmlspecialchars($infPv['colonia'], ENT_QUOTES, 'UTF-8') . ' | '; $html .= 'Teléfonos | '; $html .= '' . (isset($infPv['phone']) ? htmlspecialchars($infPv['phone'], ENT_QUOTES, 'UTF-8') : '') . ' | '; $html .= 'Delegación o Municipio | '; $html .= '' . (isset($infPv['municipio']) ? htmlspecialchars($infPv['municipio'], ENT_QUOTES, 'UTF-8') : '') . ' | '; $html .= ''; $html .= '
| C.P. | '; $html .= '' . (isset($infS['codigoPostal']) ? htmlspecialchars($infS['codigoPostal'], ENT_QUOTES, 'UTF-8') : '') . ' | '; $html .= 'Estado | '; $html .= '' . (isset($infS['estado']) ? htmlspecialchars($infS['estado'], ENT_QUOTES, 'UTF-8') : '') . ' | '; $html .= '
| PRODUCTOS | '; $html .= '
| DESCRIPCION | '; $html .= 'T.U. | '; $html .= 'CANTIDAD | '; $html .= 'PRECIO | '; $html .= 'DESC. | '; $html .= 'IMP. BRUTO | '; $html .= 'IMP. NETO | '; $html .= '|
| ' . (isset($res['codigoBarras']) ? htmlspecialchars($res['codigoBarras'], ENT_QUOTES, 'UTF-8') : '') . ' | '; $html .= '' . (isset($res['nombre']) ? htmlspecialchars($res['nombre'], ENT_QUOTES, 'UTF-8') : '') . ' | '; $html .= '' . (isset($res['unidad']) ? htmlspecialchars($res['unidad'], ENT_QUOTES, 'UTF-8') : '') . ' | '; $html .= '' . (isset($res['cantidad']) ? number_format((float)$res['cantidad'], 2, '.', '') : '0.00') . ' | '; $html .= '$ ' . (isset($res['precio']) ? number_format((float)$res['precio'], 2, '.', ',') : '0.00') . ' | '; $html .= '$ ' . number_format($totalDesc, 2, '.', ',') . ' | '; $html .= '$ ' . number_format($impBruto, 2, '.', ',') . ' | '; $html .= '$ ' . number_format($impNeto, 2, '.', ',') . ' | '; $cantTotal = (float)$cantTotal + (isset($res['cantidad']) ? (float)$res['cantidad'] : 0.0); $impBrutoG = (float)$impBrutoG + $impBruto; $impNetoG = (float)$impNetoG + $impNeto; } // Agregar fila de totales $html .= '
| '; $html .= ' | '; $html .= ' | TOTALES | '; $html .= '' . number_format($cantTotal, 0) . ' | '; $html .= ''; $html .= ' | '; $html .= ' | $' . number_format($impNetoG, 2) . ' | '; $html .= '
';
$html .= '
| ';
$html .= '
| ';
$html .= '________________________________ '; $html .= 'NOMBRE Y FIRMA DE QUIEN RECIBE'; $html .= ' | ';
$html .= '';
$html .= '________________________________ '; $html .= 'NOMBRE Y FIRMA DE QUIEN AUTORIZA'; $html .= ' | ';
$html .= '';
$html .= '________________________________ '; $html .= 'NOMBRE Y FIRMA DE QUIEN ENTREGA'; $html .= ' | ';
$html .= '
| TOTALES | '; $html .= '
| '; $html .= ' | ';
if($porcDesc > 0)
$html .= 'DESCUENTO '; if($info['metodoCompra'] == 'conIva') $html .= 'SUBTOTAL IVA '.$ivaPorc.'% '; $html .= 'TOTAL'; $html .= ' |
';
if($porcDesc > 0)
$html .= '$'.number_format($descGlobal,2).' '; if($info['metodoCompra'] == 'conIva') $html .= '$'.$info['subtotal'].' $'.$info['iva'].' '; $html .= number_format((float)$info['total'], 2, '.', ','); $html .= ' | ';
$html .= '