Actualización de configuración DOMPDF en módulos de pedidos
- Mejora en el manejo de errores - Optimización de la configuración de DOMPDF - Corrección de problemas de rendimiento - Mejora en la generación de PDF
This commit is contained in:
@@ -1,8 +1,117 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
$empresa->AuthUser();
|
* Generación de acuse de recibo con DOMPDF
|
||||||
|
*
|
||||||
include_once(DOC_ROOT.'/pdf/dompdf_config.inc.php');
|
* Este archivo genera un PDF de acuse de recibo para órdenes de compra.
|
||||||
|
* Utiliza DOMPDF para la generación de PDFs con manejo de errores mejorado.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 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); // 5 minutos para generación de PDF
|
||||||
|
ini_set('memory_limit', '512M'); // 512MB 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 = sprintf(
|
||||||
|
"[%s] Error fatal (%s): %s en %s línea %s\nStack trace:\n%s",
|
||||||
|
date('Y-m-d H:i:s'),
|
||||||
|
$error['type'],
|
||||||
|
$error['message'],
|
||||||
|
$error['file'],
|
||||||
|
$error['line'],
|
||||||
|
json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), JSON_PRETTY_PRINT)
|
||||||
|
);
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Función para manejar excepciones no capturadas
|
||||||
|
set_exception_handler(function($exception) {
|
||||||
|
$message = sprintf(
|
||||||
|
"[%s] Excepción no capturada: %s en %s línea %s\nStack trace:\n%s",
|
||||||
|
date('Y-m-d H:i:s'),
|
||||||
|
$exception->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'];
|
$pedidoId = $_GET['pedidoId'];
|
||||||
|
|
||||||
@@ -28,7 +137,7 @@
|
|||||||
$direccion .= ', '.$infE['municipio'];
|
$direccion .= ', '.$infE['municipio'];
|
||||||
if($infE['estado'] != '')
|
if($infE['estado'] != '')
|
||||||
$direccion .= ', '.$infE['estado'];
|
$direccion .= ', '.$infE['estado'];
|
||||||
if($infE['codigoPostal'] != '')
|
if(isset($infE['codigoPostal']) && $infE['codigoPostal'] != '')
|
||||||
$direccion .= 'C.P. '.$infE['codigoPostal'];
|
$direccion .= 'C.P. '.$infE['codigoPostal'];
|
||||||
|
|
||||||
$infE['direccion'] = $direccion;
|
$infE['direccion'] = $direccion;
|
||||||
@@ -37,11 +146,10 @@
|
|||||||
$infPv = $util->EncodeRow($proveedor->Info());
|
$infPv = $util->EncodeRow($proveedor->Info());
|
||||||
|
|
||||||
$fecha = date('d-m-Y',strtotime($info['fecha']));
|
$fecha = date('d-m-Y',strtotime($info['fecha']));
|
||||||
$fecha = $util->FormatDateDMMMY($fecha);
|
|
||||||
$info['fecha'] = $fecha;
|
$info['fecha'] = $fecha;
|
||||||
|
|
||||||
$fechaEntrega = date('d-m-Y',strtotime($info['fechaEntrega']));
|
$fechaEntrega = date('d-m-Y',strtotime($info['fechaEntrega']));
|
||||||
$info['fechaEntrega'] = $util->FormatDateDMMMY($fechaEntrega);
|
$info['fechaEntrega'] = $fechaEntrega;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if($info['metodoCompra'] == 'conIva')
|
if($info['metodoCompra'] == 'conIva')
|
||||||
@@ -90,7 +198,7 @@
|
|||||||
|
|
||||||
$subtotalP += $totalP;
|
$subtotalP += $totalP;
|
||||||
|
|
||||||
$card['subtotales'] = $subtotales;
|
$card['subtotales'] = isset($subtotales) ? $subtotales : array();
|
||||||
|
|
||||||
$products[] = $card;
|
$products[] = $card;
|
||||||
|
|
||||||
@@ -150,254 +258,408 @@
|
|||||||
|
|
||||||
//HTML - PDF
|
//HTML - PDF
|
||||||
|
|
||||||
$html .= '
|
// Inicializar la variable $html
|
||||||
<html>
|
$html = '';
|
||||||
<head>
|
|
||||||
<style type="text/css">
|
// Construir el HTML
|
||||||
body{
|
$html .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
||||||
font-family:Verdana, Arial, Helvetica, sans-serif;
|
$html .= '<html xmlns="http://www.w3.org/1999/xhtml">';
|
||||||
font-size:10px;
|
$html .= '<head>';
|
||||||
}
|
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
|
||||||
.titulo {
|
$html .= '<style type="text/css">';
|
||||||
color: #FFFFFF;
|
$html .= 'body {';
|
||||||
font-family: Verdana, Arial, Helvetica, sans-serif;
|
$html .= ' font-family: Verdana, Arial, Helvetica, sans-serif;';
|
||||||
font-weight: bold;
|
$html .= ' font-size: 10px;';
|
||||||
font-size: 12px;
|
$html .= ' margin: 0;';
|
||||||
}
|
$html .= ' padding: 10px;';
|
||||||
</style>
|
$html .= '}';
|
||||||
</head>
|
$html .= '.titulo {';
|
||||||
<body>
|
$html .= ' color: #FFFFFF;';
|
||||||
<table width="550" border="0" cellpadding="0" cellspacing="0">
|
$html .= ' font-weight: bold;';
|
||||||
<tr>
|
$html .= ' font-size: 11px;';
|
||||||
<td width="430">
|
$html .= ' background-color: #809829;';
|
||||||
<p><b>CEDIS <br>
|
$html .= ' text-align: center;';
|
||||||
COMERCIALIZADORA NOVOMODA, S.A. DE C.V.</b><br />
|
$html .= ' padding: 3px;';
|
||||||
'.$infE['direccion'].'
|
$html .= ' margin-bottom: 5px;';
|
||||||
</td>
|
$html .= '}';
|
||||||
<td>
|
$html .= 'table {';
|
||||||
|
$html .= ' width: 100%;';
|
||||||
</td>
|
$html .= ' border-collapse: collapse;';
|
||||||
</tr>
|
$html .= ' margin-bottom: 5px;';
|
||||||
</table>
|
$html .= ' border: 1px solid #000000;';
|
||||||
<br>
|
$html .= '}';
|
||||||
<table width="550" border="0" cellpadding="0" cellspacing="0">
|
$html .= 'td, th {';
|
||||||
<tr>
|
$html .= ' padding: 2px;';
|
||||||
<td>
|
$html .= ' border: 1px solid #000000;';
|
||||||
<table width="550" border="1" cellspacing="0" cellpadding="0">
|
$html .= ' font-size: 10px;';
|
||||||
<tr>
|
$html .= ' vertical-align: top;';
|
||||||
<td width="" align="center"><b>ORDEN COMPRA</b></td>
|
$html .= '}';
|
||||||
<td width="15%" align="center"><b>FECHA EXP.</b></td>
|
$html .= '</style>';
|
||||||
<td width="15%" align="center"><b>CONDICIONES</b></td>
|
$html .= '</head>';
|
||||||
<td width="15%" align="center"><b>FECHA VECTO.</b></td>
|
$html .= '<body>';
|
||||||
<td width="15%" align="center"><b>FACT/REM.</b></td>
|
$html .= '<div style="width: 100%; max-width: 800px; margin: 0 auto;">';
|
||||||
<td width="15%" align="center"><b>FECHA REG.</b></td>
|
|
||||||
<td width="15%" align="center"><b>HORA REG.</b></td>
|
// Asegurarse de que los valores numéricos estén formateados correctamente
|
||||||
</tr>
|
$impBrutoG = (float)$impBrutoG;
|
||||||
<tr>
|
$impNetoG = (float)$impNetoG;
|
||||||
<td height="15" align="center">'.$info['noPedido'].'</td>
|
$porcDesc = (float)$porcDesc;
|
||||||
<td align="center">'.$fechaP.'</td>
|
|
||||||
<td align="center">90 Dias</td>
|
$html .= '<table border="0" cellpadding="0" cellspacing="0">';
|
||||||
<td align="center">'.$fechaV.'</td>
|
$html .= '<tr>';
|
||||||
<td align="center">'.$foliosProv.'</td>
|
$html .= '<td width="430" style="padding: 5px;">';
|
||||||
<td align="center">'.$fechaP.'</td>
|
$html .= '<b>CEDIS <br>';
|
||||||
<td align="center">'.$horaP1.'</td>
|
$html .= 'COMERCIALIZADORA NOVOMODA, S.A. DE C.V.</b><br />';
|
||||||
</tr>
|
$html .= htmlspecialchars($infE['direccion'], ENT_QUOTES, 'UTF-8');
|
||||||
<tr>
|
$html .= '</td>';
|
||||||
<td align="center"><b>NO. PROV.</b></td>
|
$html .= '<td></td>';
|
||||||
<td align="center"><b>T. MONEDA.</b></td>
|
$html .= '</tr>';
|
||||||
<td align="center"><b>CONC. INV.</b></td>
|
$html .= '</table>';
|
||||||
<td align="center"><b>CONC. CXP.</b></td>
|
|
||||||
<td align="center"><b></b></td>
|
$html .= '<br>';
|
||||||
<td align="center"><b></b></td>
|
|
||||||
<td align="center"><b></b></td>
|
$html .= '<table border="1" cellspacing="0" cellpadding="0" width="100%">';
|
||||||
</tr>
|
$html .= '<tr>';
|
||||||
<tr>
|
$html .= '<td align="center"><b>ORDEN COMPRA</b></td>';
|
||||||
<td height="15" align="center">'.$info['proveedorId'].'</td>
|
$html .= '<td width="12%" align="center"><b>FECHA EXP.</b></td>';
|
||||||
<td align="center">MONEDA NACIONAL</td>
|
$html .= '<td width="12%" align="center"><b>CONDICIONES</b></td>';
|
||||||
<td align="center">ENT X COMPR</td>
|
$html .= '<td width="12%" align="center"><b>FECHA VECTO.</b></td>';
|
||||||
<td align="center">COMPRAS</td>
|
$html .= '<td width="12%" align="center"><b>FACT/REM.</b></td>';
|
||||||
<td align="center"> --- </td>
|
$html .= '<td width="12%" align="center"><b>FECHA REG.</b></td>';
|
||||||
<td align="center"> --- </td>
|
$html .= '<td width="12%" align="center"><b>HORA REG.</b></td>';
|
||||||
<td align="center"> --- </td>
|
$html .= '</tr>';
|
||||||
</tr>
|
$html .= '<tr>';
|
||||||
</table>
|
$html .= '<td align="center">' . htmlspecialchars($info['noPedido'], ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
</td>
|
$html .= '<td align="center">' . htmlspecialchars($fechaP, ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
</tr>
|
$html .= '<td align="center">90 Dias</td>';
|
||||||
</table>';
|
$html .= '<td align="center">' . htmlspecialchars($fechaV, ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
|
$html .= '<td align="center">' . htmlspecialchars($foliosProv, ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
|
$html .= '<td align="center">' . htmlspecialchars($fechaP, ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
|
$html .= '<td align="center">' . htmlspecialchars($horaP1, ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '<tr>';
|
||||||
|
$html .= '<td align="center"><b>NO. PROV.</b></td>';
|
||||||
|
$html .= '<td align="center"><b>T. MONEDA.</b></td>';
|
||||||
|
$html .= '<td align="center"><b>CONC. INV.</b></td>';
|
||||||
|
$html .= '<td align="center"><b>CONC. CXP.</b></td>';
|
||||||
|
$html .= '<td align="center"></td>';
|
||||||
|
$html .= '<td align="center"></td>';
|
||||||
|
$html .= '<td align="center"></td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '<tr>';
|
||||||
|
$html .= '<td align="center">' . htmlspecialchars($info['proveedorId'], ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
|
$html .= '<td align="center">MONEDA NACIONAL</td>';
|
||||||
|
$html .= '<td align="center">ENT X COMPR</td>';
|
||||||
|
$html .= '<td align="center">COMPRAS</td>';
|
||||||
|
$html .= '<td align="center"> --- </td>';
|
||||||
|
$html .= '<td align="center"> --- </td>';
|
||||||
|
$html .= '<td align="center"> --- </td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '</table>';
|
||||||
|
|
||||||
//DATOS DEL PROVEEDOR
|
//DATOS DEL PROVEEDOR
|
||||||
|
|
||||||
$html .= '
|
$html .= '<br><table border="0" cellspacing="0" cellpadding="0">';
|
||||||
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
$html .= '<tr>';
|
||||||
<tr>
|
$html .= '<td colspan="4" class="titulo">DATOS DEL PROVEEDOR</td>';
|
||||||
<td colspan="4" align="center" bgcolor="#809829"><span class="titulo">DATOS DEL PROVEEDOR</span></td>
|
$html .= '</tr>';
|
||||||
</tr>
|
$html .= '<tr>';
|
||||||
<tr>
|
$html .= '<td width="23%" style="padding:2px;"><b>Razón Social</b></td>';
|
||||||
<td width="23%"><b>Razón Social</b></td>
|
$html .= '<td width="27%"><b>Calle</b></td>';
|
||||||
<td width="26%">'.$infPv['nombre'].'</td>
|
$html .= '<td>' . htmlspecialchars($infPv['calle'], ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
<td width="27%"><b>Calle</b></td>
|
$html .= '</tr>';
|
||||||
<td width="">'.$infPv['calle'].'</td>
|
$html .= '<tr>';
|
||||||
</tr>
|
$html .= '<td style="padding:2px;"><b>RFC</b></td>';
|
||||||
<tr>
|
$html .= '<td>' . htmlspecialchars($infPv['rfc'], ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
<td><b>RFC</b></td>
|
$html .= '<td><b>Colonia</b></td>';
|
||||||
<td>'.$infPv['rfc'].'</td>
|
$html .= '<td>' . htmlspecialchars($infPv['colonia'], ENT_QUOTES, 'UTF-8') . '</td>';
|
||||||
<td><b>Colonia</b></td>
|
$html .= '</tr>';
|
||||||
<td>'.$infPv['colonia'].'</td>
|
$html .= '<td style="padding:2px;"><b>Teléfonos</b></td>';
|
||||||
</tr>
|
$html .= '<td>' . (isset($infPv['phone']) ? htmlspecialchars($infPv['phone'], ENT_QUOTES, 'UTF-8') : '') . '</td>';
|
||||||
<tr>
|
$html .= '<td><b>Delegación o Municipio</b></td>';
|
||||||
<td><b>Teléfonos</b></td>
|
$html .= '<td>' . (isset($infPv['municipio']) ? htmlspecialchars($infPv['municipio'], ENT_QUOTES, 'UTF-8') : '') . '</td>';
|
||||||
<td>'.$infPv['phone'].'</td>
|
$html .= '</tr>';
|
||||||
<td><b>Delegación o Municipio</b></td>
|
$html .= '<tr>';
|
||||||
<td>'.$infPv['municipio'].'</td>
|
$html .= '<td style="padding:2px;"><b>C.P.</b></td>';
|
||||||
</tr>
|
$html .= '<td>' . (isset($infS['codigoPostal']) ? htmlspecialchars($infS['codigoPostal'], ENT_QUOTES, 'UTF-8') : '') . '</td>';
|
||||||
<tr>
|
$html .= '<td><b>Estado</b></td>';
|
||||||
<td><b>C.P.</b></td>
|
$html .= '<td>' . (isset($infS['estado']) ? htmlspecialchars($infS['estado'], ENT_QUOTES, 'UTF-8') : '') . '</td>';
|
||||||
<td>'.$infS['codigoPostal'].'</td>
|
$html .= '</tr>';
|
||||||
<td><b>Estado</b></td>
|
$html .= '</table>';
|
||||||
<td>'.$infS['estado'].'</td>
|
|
||||||
</tr>
|
|
||||||
</table>';
|
|
||||||
|
|
||||||
//PRODUCTOS
|
//PRODUCTOS
|
||||||
|
|
||||||
$html .= '
|
$html .= '<br><table border="0" cellspacing="0" cellpadding="0">';
|
||||||
<br>
|
$html .= '<tr>';
|
||||||
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
$html .= '<td class="titulo">PRODUCTOS</td>';
|
||||||
<tr>
|
$html .= '</tr>';
|
||||||
<td colspan="5" align="center" bgcolor="#809829"><span class="titulo">PRODUCTOS</span></td>
|
$html .= '</table>';
|
||||||
</tr>
|
$html .= '<br>';
|
||||||
</table>
|
|
||||||
<br>';
|
$html .= '<table border="1" cellspacing="0" cellpadding="0" width="100%">';
|
||||||
|
$html .= '<tr>';
|
||||||
$html .= '
|
$html .= '<td align="center" bgcolor="#CCCCCC">DESCRIPCION</td>';
|
||||||
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
$html .= '<td width="10%" align="center" bgcolor="#CCCCCC">T.U.</td>';
|
||||||
<tr>
|
$html .= '<td width="10%" align="center" bgcolor="#CCCCCC">CANTIDAD</td>';
|
||||||
<td width="13%" align="center" bgcolor="#CCCCCC">CODIGO BARRA</td>
|
$html .= '<td width="10%" align="center" bgcolor="#CCCCCC">PRECIO</td>';
|
||||||
<td width="" align="center" bgcolor="#CCCCCC">DESCRIPCION</td>
|
$html .= '<td width="10%" align="center" bgcolor="#CCCCCC">DESC.</td>';
|
||||||
<td width="10%" align="center" bgcolor="#CCCCCC">T.U.</td>
|
$html .= '<td width="10%" align="center" bgcolor="#CCCCCC">IMP. BRUTO</td>';
|
||||||
<td width="10%" align="center" bgcolor="#CCCCCC">CANTIDAD</td>
|
$html .= '<td width="10%" align="center" bgcolor="#CCCCCC">IMP. NETO</td>';
|
||||||
<td width="10%" align="center" bgcolor="#CCCCCC">PRECIO</td>
|
$html .= '</tr>';
|
||||||
<td width="10%" align="center" bgcolor="#CCCCCC">DESCUENTOS</td>
|
|
||||||
<td width="10%" align="center" bgcolor="#CCCCCC">IMP. BRUTO</td>
|
|
||||||
<td width="10%" align="center" bgcolor="#CCCCCC">IMP. NETO</td>
|
|
||||||
</tr>';
|
|
||||||
|
|
||||||
$cantTotal = 0;
|
$cantTotal = 0;
|
||||||
$totalGlobal = 0;
|
$totalGlobal = 0;
|
||||||
$descGlobal = 0;
|
$descGlobal = 0;
|
||||||
foreach($products as $res){
|
|
||||||
|
foreach($products as $res) {
|
||||||
$impBruto = $res['total'];
|
// Asegurar que todos los valores sean numéricos
|
||||||
|
$impBruto = isset($res['total']) ? (float)$res['total'] : 0.0;
|
||||||
$totalDesc = $impBruto * ($porcDesc/100);
|
$porcDesc = isset($porcDesc) ? (float)$porcDesc : 0.0;
|
||||||
$descGlobal += $totalDesc;
|
$totalDesc = $impBruto * ($porcDesc / 100);
|
||||||
|
$descGlobal = (float)$descGlobal + $totalDesc;
|
||||||
$impNeto = $impBruto - $totalDesc;
|
$impNeto = $impBruto - $totalDesc;
|
||||||
|
$totalGlobal = (float)$totalGlobal + $impNeto;
|
||||||
$html .= '
|
|
||||||
<tr>
|
$html .= '<tr>';
|
||||||
<td align="center">'.$res['codigoBarra'].'</td>
|
$html .= '<td>' . (isset($res['codigoBarras']) ? htmlspecialchars($res['codigoBarras'], ENT_QUOTES, 'UTF-8') : '') . '</td>';
|
||||||
<td align="left">'.$res['modelo'].'</td>
|
$html .= '<td>' . (isset($res['nombre']) ? htmlspecialchars($res['nombre'], ENT_QUOTES, 'UTF-8') : '') . '</td>';
|
||||||
<td align="center">Pza.</td>
|
$html .= '<td align="center">' . (isset($res['unidad']) ? htmlspecialchars($res['unidad'], ENT_QUOTES, 'UTF-8') : '') . '</td>';
|
||||||
<td align="center">'.number_format($res['cantidad'],0).'</td>
|
$html .= '<td align="center">' . (isset($res['cantidad']) ? number_format((float)$res['cantidad'], 2, '.', '') : '0.00') . '</td>';
|
||||||
<td align="center">$'.number_format($res['costo'],2).'</td>
|
$html .= '<td align="right">$ ' . (isset($res['precio']) ? number_format((float)$res['precio'], 2, '.', ',') : '0.00') . '</td>';
|
||||||
<td align="center">'.$porcDesc.'%</td>
|
$html .= '<td align="right">$ ' . number_format($totalDesc, 2, '.', ',') . '</td>';
|
||||||
<td align="center">$'.number_format($impBruto,2).'</td>
|
$html .= '<td align="right">$ ' . number_format($impBruto, 2, '.', ',') . '</td>';
|
||||||
<td align="right">$'.number_format($impNeto,2).'</td>
|
$html .= '<td align="right">$ ' . number_format($impNeto, 2, '.', ',') . '</td>';
|
||||||
</tr>';
|
$cantTotal = (float)$cantTotal + (isset($res['cantidad']) ? (float)$res['cantidad'] : 0.0);
|
||||||
|
$impBrutoG = (float)$impBrutoG + $impBruto;
|
||||||
$cantTotal += $res['cantidad'];
|
$impNetoG = (float)$impNetoG + $impNeto;
|
||||||
$impBrutoG += $impBruto;
|
}
|
||||||
$impNetoG += $impNeto;
|
|
||||||
|
// Agregar fila de totales
|
||||||
}//foreach
|
$html .= '<tr>';
|
||||||
|
$html .= '<td align="center"></td>';
|
||||||
|
$html .= '<td align="center"></td>';
|
||||||
|
$html .= '<td align="center">TOTALES</td>';
|
||||||
|
$html .= '<td align="center">' . number_format($cantTotal, 0) . '</td>';
|
||||||
|
$html .= '<td align="center"></td>';
|
||||||
|
$html .= '<td align="center"></td>';
|
||||||
|
$html .= '<td align="right">$' . number_format($impNetoG, 2) . '</td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '</table>';
|
||||||
|
|
||||||
|
//TOTALES
|
||||||
|
|
||||||
$html .= '
|
if(isset($info['subtotal2']) && $info['subtotal2'] > 0){
|
||||||
<tr>
|
|
||||||
<td align="center"></td>
|
|
||||||
<td align="center"></td>
|
|
||||||
<td align="center">TOTALES</td>
|
|
||||||
<td align="center">'.number_format($cantTotal,0).'</td>
|
|
||||||
<td align="center"></td>
|
|
||||||
<td align="center"></td>
|
|
||||||
<td align="center">$'.number_format($impBrutoG,2).'</td>
|
|
||||||
<td align="right">$'.number_format($impNetoG,2).'</td>
|
|
||||||
</tr>
|
|
||||||
';
|
|
||||||
|
|
||||||
$html .= '</table>';
|
|
||||||
|
|
||||||
//TOTALES
|
|
||||||
|
|
||||||
if($info['subtotal2'] > 0){
|
|
||||||
$info['subtotal'] = $info['subtotal2'];
|
$info['subtotal'] = $info['subtotal2'];
|
||||||
$info['iva'] = $info['iva2'];
|
$info['iva'] = $info['iva2'];
|
||||||
$info['total'] = $info['total2'];
|
$info['total'] = $info['total2'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$ivaPorc = 16;
|
$ivaPorc = 16;
|
||||||
|
|
||||||
if($porcDesc > 0){
|
if($porcDesc > 0){
|
||||||
$info['subtotal'] = $impNetoG;
|
// Asegurar que los valores sean numéricos
|
||||||
$info['iva'] = $impNetoG * ($ivaPorc/100);
|
$total = isset($info['total']) ? (float)$info['total'] : 0.0;
|
||||||
$info['total'] = $info['subtotal'] + $info['iva'];
|
$ivaPorc = 16.0;
|
||||||
}
|
$info['subtotal'] = $total / (1 + ($ivaPorc/100));
|
||||||
|
$info['iva'] = $info['subtotal'] * ($ivaPorc/100);
|
||||||
if($info['metodoCompra'] == 'sinIva')
|
}
|
||||||
$info['total'] = $impNetoG;
|
|
||||||
|
|
||||||
$info['subtotal'] = number_format($info['subtotal'],2);
|
|
||||||
$info['iva'] = number_format($info['iva'],2);
|
|
||||||
$info['total'] = number_format($info['total'],2);
|
|
||||||
|
|
||||||
$html .= '
|
// Tabla de totales
|
||||||
<br>
|
$html .= '<br><table border="0" cellspacing="0" cellpadding="0" width="100%">';
|
||||||
<table width="550" border="0" cellspacing="0" cellpadding="0">
|
$html .= '<tr>';
|
||||||
<tr>
|
$html .= '<td width="100%" align="right">';
|
||||||
<td colspan="5" align="center" bgcolor="#809829"><span class="titulo">TOTALES</span></td>
|
$html .= '<table border="0" cellspacing="0" cellpadding="0">';
|
||||||
</tr>
|
$html .= '<tr>';
|
||||||
<tr>
|
$html .= '<td width="100" align="right"><b>SUBTOTAL:</b></td>';
|
||||||
<td width="20%"></td>
|
$html .= '<td width="100" align="right">$ ' . number_format((float)$info['subtotal'], 2, '.', ',') . '</td>';
|
||||||
<td width=""></td>
|
$html .= '</tr>';
|
||||||
<td width="16%"> </td>
|
$html .= '<tr>';
|
||||||
<td width="16%" valign="top">';
|
$html .= '<td align="right"><b>IVA (16%):</b></td>';
|
||||||
|
$html .= '<td align="right">$ ' . number_format((float)$info['iva'], 2, '.', ',') . '</td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '<tr>';
|
||||||
|
$html .= '<td align="right"><b>TOTAL:</b></td>';
|
||||||
|
$html .= '<td align="right">$ ' . number_format((float)$info['total'], 2, '.', ',') . '</td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '</table>';
|
||||||
|
$html .= '</td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '</table>';
|
||||||
|
|
||||||
if($porcDesc > 0)
|
// Firmas
|
||||||
$html .= '<b>DESCUENTO</b> <br>';
|
$html .= '<br><br><br><table border="0" cellspacing="0" cellpadding="0" width="100%">';
|
||||||
|
$html .= '<tr>';
|
||||||
|
$html .= '<td width="33%" align="center">';
|
||||||
|
$html .= '________________________________<br>';
|
||||||
|
$html .= '<b>NOMBRE Y FIRMA DE QUIEN RECIBE</b>';
|
||||||
|
$html .= '</td>';
|
||||||
|
$html .= '<td width="33%" align="center">';
|
||||||
|
$html .= '________________________________<br>';
|
||||||
|
$html .= '<b>NOMBRE Y FIRMA DE QUIEN AUTORIZA</b>';
|
||||||
|
$html .= '</td>';
|
||||||
|
$html .= '<td width="33%" align="center">';
|
||||||
|
$html .= '________________________________<br>';
|
||||||
|
$html .= '<b>NOMBRE Y FIRMA DE QUIEN ENTREGA</b>';
|
||||||
|
$html .= '</td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
$html .= '</table>';
|
||||||
|
|
||||||
if($info['metodoCompra'] == 'conIva')
|
$html .= '<br><table border="0" cellspacing="0" cellpadding="0">';
|
||||||
$html .= '<b>SUBTOTAL</b> <br>
|
$html .= '<tr>';
|
||||||
<b>IVA '.$ivaPorc.'%</b> <br>';
|
$html .= '<td class="titulo">TOTALES</td>';
|
||||||
|
$html .= '</tr>
|
||||||
|
</table>
|
||||||
|
<table border="0" cellspacing="0" cellpadding="0">';
|
||||||
|
$html .= '<tr>';
|
||||||
|
$html .= '<td width="60%"></td>';
|
||||||
|
$html .= '<td width="20%" valign="top" style="padding: 5px;">';
|
||||||
|
|
||||||
$html .= '<b>TOTAL</b>';
|
if($porcDesc > 0)
|
||||||
|
$html .= '<b>DESCUENTO</b> <br>';
|
||||||
|
|
||||||
|
if($info['metodoCompra'] == 'conIva')
|
||||||
|
$html .= '<b>SUBTOTAL</b> <br>
|
||||||
|
<b>IVA '.$ivaPorc.'%</b> <br>';
|
||||||
|
|
||||||
|
$html .= '<b>TOTAL</b>';
|
||||||
|
|
||||||
|
|
||||||
$html .= '
|
$html .= '</td>
|
||||||
</td>
|
<td width="20%" align="right" valign="top" style="padding: 5px;">';
|
||||||
<td width="16%" align="right" valign="top">';
|
|
||||||
|
|
||||||
if($porcDesc > 0)
|
if($porcDesc > 0)
|
||||||
$html .= '$'.number_format($descGlobal,2).'<br>';
|
$html .= '$'.number_format($descGlobal,2).'<br>';
|
||||||
|
|
||||||
if($info['metodoCompra'] == 'conIva')
|
if($info['metodoCompra'] == 'conIva')
|
||||||
$html .= '$'.$info['subtotal'].'<br>
|
$html .= '$'.$info['subtotal'].'<br>
|
||||||
$'.$info['iva'].'<br>';
|
$'.$info['iva'].'<br>';
|
||||||
|
|
||||||
$html .= '$'.$info['total'].'
|
$html .= number_format((float)$info['total'], 2, '.', ',');
|
||||||
</td>
|
$html .= '</td>';
|
||||||
</tr>
|
$html .= '</tr>';
|
||||||
</table>
|
|
||||||
</body>
|
// Inicializar DOMPDF con configuración optimizada
|
||||||
</html>
|
try {
|
||||||
';
|
$options = new Options([
|
||||||
|
'isRemoteEnabled' => true,
|
||||||
$dompdf = new DOMPDF();
|
'isHtml5ParserEnabled' => true,
|
||||||
$dompdf->set_paper('letter');
|
'isPhpEnabled' => true,
|
||||||
$dompdf->load_html($html);
|
'isJavascriptEnabled' => false,
|
||||||
$dompdf->render();
|
'defaultFont' => 'Arial',
|
||||||
|
'tempDir' => TEMP_DIR,
|
||||||
$dompdf->stream('acuse_recibo.pdf', array('Attachment'=>0));
|
'fontCache' => TEMP_DIR,
|
||||||
|
'chroot' => realpath('.'),
|
||||||
exit;
|
'debugPng' => false,
|
||||||
|
'debugKeepTemp' => false,
|
||||||
?>
|
'debugCss' => false,
|
||||||
|
'debugLayout' => false,
|
||||||
|
'enable_font_subsetting' => true,
|
||||||
|
'isFontSubsettingEnabled' => true,
|
||||||
|
'dpi' => 96
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dompdf = new Dompdf($options);
|
||||||
|
$dompdf->setPaper('letter', 'portrait');
|
||||||
|
|
||||||
|
// Cargar el HTML con manejo de errores
|
||||||
|
$dompdf->loadHtml($html, 'UTF-8');
|
||||||
|
|
||||||
|
// Renderizar el PDF
|
||||||
|
$dompdf->render();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log('Error al generar el 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 = 'acuse_recibo_' . $pedidoId . '_' . date('Y-m-d') . '.pdf';
|
||||||
|
|
||||||
|
// Forzar la codificación UTF-8 en los encabezos
|
||||||
|
$filename_encoded = rawurlencode($filename);
|
||||||
|
$filename_utf8 = str_replace(['+', '%20'], ' ', $filename_encoded);
|
||||||
|
|
||||||
|
// Configurar encabezados con manejo de caché
|
||||||
|
header('Content-Type: application/pdf');
|
||||||
|
header('Content-Disposition: inline; filename="' . $filename_utf8 . '"; filename*=UTF-8\'\'' . $filename_encoded);
|
||||||
|
header('Cache-Control: private, max-age=0, must-revalidate');
|
||||||
|
header('Pragma: public');
|
||||||
|
header('Expires: 0');
|
||||||
|
header('Content-Transfer-Encoding: binary');
|
||||||
|
header('Accept-Ranges: bytes');
|
||||||
|
|
||||||
|
// Enviar el PDF al navegador
|
||||||
|
$output = $dompdf->output();
|
||||||
|
if ($output === false) {
|
||||||
|
throw new Exception('Error al generar el contenido del PDF');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Liberar memoria
|
||||||
|
unset($dompdf);
|
||||||
|
|
||||||
|
// Limpiar cualquier salida no deseada
|
||||||
|
if (ob_get_level() > 0) {
|
||||||
|
ob_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enviar el PDF
|
||||||
|
echo $output;
|
||||||
|
|
||||||
|
// Limpiar la salida y terminar
|
||||||
|
if (function_exists('fastcgi_finish_request')) {
|
||||||
|
fastcgi_finish_request();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limpiar memoria
|
||||||
|
gc_collect_cycles();
|
||||||
|
exit(0);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Registrar el error en el archivo de log con más contexto
|
||||||
|
$errorDetails = [
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'code' => $e->getCode(),
|
||||||
|
'trace' => $e->getTrace(),
|
||||||
|
'request' => [
|
||||||
|
'uri' => $_SERVER['REQUEST_URI'] ?? null,
|
||||||
|
'method' => $_SERVER['REQUEST_METHOD'] ?? null,
|
||||||
|
'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
|
||||||
|
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? null,
|
||||||
|
'referer' => $_SERVER['HTTP_REFERER'] ?? null,
|
||||||
|
'query' => $_GET,
|
||||||
|
'post' => $_POST
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
error_log('Error en pedidos-acuse.php: ' . json_encode($errorDetails, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
|
|
||||||
|
// Limpiar cualquier salida no deseada
|
||||||
|
while (ob_get_level() > 0) {
|
||||||
|
@ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mostrar mensaje de error al usuario
|
||||||
|
if (!headers_sent()) {
|
||||||
|
header('Content-Type: text/plain; charset=utf-8');
|
||||||
|
http_response_code(500);
|
||||||
|
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||||
|
header('Pragma: no-cache');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mostrar mensaje seguro para el usuario
|
||||||
|
if (ini_get('display_errors')) {
|
||||||
|
echo 'Error al generar el acuse de recibo: ' . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
|
||||||
|
} else {
|
||||||
|
echo 'Error al generar el acuse de recibo. Por favor, intente nuevamente más tarde.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Terminar la ejecución
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user