Autosave: 20260521-172923

This commit is contained in:
Flatlogic Bot 2026-05-21 17:29:24 +00:00
parent 29814f9aa8
commit b4284d6ec3
2 changed files with 140 additions and 13 deletions

View File

@ -14,27 +14,30 @@ if (empty($codes)) {
$display_name = count($product_names) > 0 ? "etiquetas_multiples" : str_replace(' ', '_', $single_product_name);
$filename = $display_name . "_" . date("Y-m-d") . ".xls";
// Funciones para generar el formato binario BIFF5 (Excel 97-2003)
// Funciones para generar el formato binario BIFF5 (Excel 5.0 / 95 / 97-2003 compatible)
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
// 0x0809 = BOF, 0x0008 = Length, 0x0500 = Version (BIFF5), 0x0010 = Worksheet
echo pack("ssssss", 0x0809, 0x0008, 0x0500, 0x0010, 0x0, 0x0);
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
// 0x000A = EOF, 0x0000 = Length
echo pack("ss", 0x000A, 0x0000);
}
function xlsWriteLabel($Row, $Col, $Value) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
// 0x0204 = LABEL, Length = 8 + string length
echo pack("ssssss", 0x0204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
}
// Añadir registro de Codepage para que Excel reconozca el juego de caracteres Windows-1252
function xlsCodepage() {
echo pack("sss", 0x0042, 0x0002, 0x04E4); // 1252 (Windows Latin 1)
function xlsDimensions($maxRow, $maxCol) {
// 0x0200 = DIMENSIONS, 0x000A = Length
echo pack("ssssss", 0x0200, 0x000A, 0, $maxRow, 0, $maxCol);
}
// Configurar cabeceras para descarga de archivo binario XLS (Excel 97-2003)
// Configurar cabeceras para descarga de archivo binario XLS
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
@ -43,9 +46,11 @@ header('Content-Transfer-Encoding: binary');
// Iniciar el archivo Excel
xlsBOF();
xlsCodepage();
// Escribir cabeceras de columnas
// Definir dimensiones (filas, columnas)
xlsDimensions(count($codes) + 1, 3);
// Escribir cabeceras de columnas (usando Windows-1252 para compatibilidad)
xlsWriteLabel(0, 0, mb_convert_encoding("Nombre del producto", 'Windows-1252', 'UTF-8'));
xlsWriteLabel(0, 1, mb_convert_encoding("Codigo unico", 'Windows-1252', 'UTF-8'));
xlsWriteLabel(0, 2, mb_convert_encoding("Codigo de barra (usar fuente)", 'Windows-1252', 'UTF-8'));
@ -54,8 +59,6 @@ xlsWriteLabel(0, 2, mb_convert_encoding("Codigo de barra (usar fuente)", 'Window
$row = 1;
foreach ($codes as $index => $code) {
$p_name = isset($product_names[$index]) ? $product_names[$index] : $single_product_name;
// Convertir a Windows-1252 para compatibilidad con el formato BIFF antiguo
$p_name_encoded = mb_convert_encoding($p_name, 'Windows-1252', 'UTF-8');
xlsWriteLabel($row, 0, $p_name_encoded);
@ -66,4 +69,4 @@ foreach ($codes as $index => $code) {
// Finalizar el archivo Excel
xlsEOF();
exit;
exit;

124
test_etiquetas.php Normal file
View File

@ -0,0 +1,124 @@
<?php
// test_etiquetas.php - Página de prueba para impresión de etiquetas 3x3
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Prueba de Etiquetas 3x3</title>
<style>
/* Estilos para pantalla */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.no-print {
margin-bottom: 20px;
padding: 15px 25px;
background: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.no-print:hover {
background: #0056b3;
}
/* Contenedor de etiquetas */
.etiquetas-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 0; /* Sin espacio entre etiquetas */
width: 100mm; /* Ancho total del papel */
height: 75mm; /* Alto total del papel */
background: white;
padding: 0;
border: 1px solid #ccc;
box-sizing: border-box;
}
.etiqueta {
border: 0.1mm solid #eee;
padding: 1mm;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 25mm; /* 75mm / 3 = 25mm */
width: 33.33mm; /* 100mm / 3 = 33.33mm */
box-sizing: border-box;
overflow: hidden;
}
.producto-nombre {
font-size: 8px;
font-weight: bold;
margin-bottom: 1mm;
text-transform: uppercase;
line-height: 1;
}
.barcode-placeholder {
font-family: 'Courier New', Courier, monospace;
font-size: 12px;
letter-spacing: 1px;
border-top: 1px solid black;
padding-top: 1mm;
}
/* Estilos específicos para IMPRESIÓN */
@media print {
body {
background: none;
padding: 0;
margin: 0;
}
.no-print {
display: none;
}
.etiquetas-container {
border: none;
padding: 0;
margin: 0;
width: 100mm;
height: 75mm;
}
.etiqueta {
border: none;
}
@page {
margin: 0;
size: 100mm 75mm;
}
}
</style>
</head>
<body>
<button class="no-print" onclick="window.print()">Imprimir Etiquetas de Prueba</button>
<div class="etiquetas-container">
<?php for ($i = 1; $i <= 9; $i++): ?>
<div class="etiqueta">
<div class="producto-nombre">Producto Ejemplo #<?php echo $i; ?></div>
<div class="barcode-placeholder">123456789</div>
<div style="font-size: 8px; margin-top: 1mm;">SKU-TEST-00<?php echo $i; ?></div>
</div>
<?php endfor; ?>
</div>
<div class="no-print" style="margin-top: 20px; color: #666; max-width: 400px; text-align: center;">
<p><strong>Nota:</strong> Al imprimir, asegúrate de seleccionar tu impresora <strong>REDPOS</strong> y en "Más ajustes" verifica que los márgenes estén en <strong>"Ninguno"</strong>.</p>
</div>
</body>
</html>