diff --git a/assets/uploads/vouchers/697b6e0b8d69a-WhatsApp Image 2026-01-29 at 9.03.33 AM.jpeg b/assets/uploads/vouchers/697b6e0b8d69a-WhatsApp Image 2026-01-29 at 9.03.33 AM.jpeg deleted file mode 100644 index e7f21e2..0000000 Binary files a/assets/uploads/vouchers/697b6e0b8d69a-WhatsApp Image 2026-01-29 at 9.03.33 AM.jpeg and /dev/null differ diff --git a/assets/uploads/vouchers/697baab7da5ed-WhatsApp Image 2026-01-29 at 1.42.33 PM.jpeg b/assets/uploads/vouchers/697baab7da5ed-WhatsApp Image 2026-01-29 at 1.42.33 PM.jpeg deleted file mode 100644 index 698570f..0000000 Binary files a/assets/uploads/vouchers/697baab7da5ed-WhatsApp Image 2026-01-29 at 1.42.33 PM.jpeg and /dev/null differ diff --git a/assets/uploads/vouchers/697bae1a4d683-WhatsApp Image 2026-01-29 at 1.55.55 PM (1).jpeg b/assets/uploads/vouchers/697bae1a4d683-WhatsApp Image 2026-01-29 at 1.55.55 PM (1).jpeg deleted file mode 100644 index 65ffb10..0000000 Binary files a/assets/uploads/vouchers/697bae1a4d683-WhatsApp Image 2026-01-29 at 1.55.55 PM (1).jpeg and /dev/null differ diff --git a/assets/uploads/vouchers/697bc571df400-WhatsApp Image 2026-01-29 at 3.24.52 PM.jpeg b/assets/uploads/vouchers/697bc571df400-WhatsApp Image 2026-01-29 at 3.24.52 PM.jpeg deleted file mode 100644 index 79a3e71..0000000 Binary files a/assets/uploads/vouchers/697bc571df400-WhatsApp Image 2026-01-29 at 3.24.52 PM.jpeg and /dev/null differ diff --git a/assets/uploads/vouchers/698dfc4316d0a-601.png b/assets/uploads/vouchers/698dfc4316d0a-601.png new file mode 100644 index 0000000..941cca6 Binary files /dev/null and b/assets/uploads/vouchers/698dfc4316d0a-601.png differ diff --git a/assets/uploads/vouchers/698dfc878fad9-664.png b/assets/uploads/vouchers/698dfc878fad9-664.png new file mode 100644 index 0000000..263599f Binary files /dev/null and b/assets/uploads/vouchers/698dfc878fad9-664.png differ diff --git a/assets/uploads/vouchers/698dfcb979453-551.png b/assets/uploads/vouchers/698dfcb979453-551.png new file mode 100644 index 0000000..f82e752 Binary files /dev/null and b/assets/uploads/vouchers/698dfcb979453-551.png differ diff --git a/assets/uploads/vouchers/698dfce4d632d-270.png b/assets/uploads/vouchers/698dfce4d632d-270.png new file mode 100644 index 0000000..64db66d Binary files /dev/null and b/assets/uploads/vouchers/698dfce4d632d-270.png differ diff --git a/db/migrations/061_add_sku_to_products.sql b/db/migrations/061_add_sku_to_products.sql index b3e53ba..d50330f 100644 --- a/db/migrations/061_add_sku_to_products.sql +++ b/db/migrations/061_add_sku_to_products.sql @@ -1 +1 @@ -ALTER TABLE products ADD COLUMN sku VARCHAR(100) NULL UNIQUE; +-- ALTER TABLE products ADD COLUMN sku VARCHAR(100) NULL UNIQUE; diff --git a/generar_etiquetas.php b/generar_etiquetas.php index 260c84d..c023ef0 100644 --- a/generar_etiquetas.php +++ b/generar_etiquetas.php @@ -2,6 +2,7 @@ $pageTitle = "Generador de Etiquetas"; include 'layout_header.php'; include 'db/config.php'; +require_once 'includes/barcode_generator.php'; // Added this line // Fetch products for the dropdown $products = []; @@ -13,13 +14,32 @@ try { $_SESSION['error_message'] = "Error al cargar los productos: " . $e->getMessage(); } -$generated_codes = []; // Handle form submission +$generated_codes = []; // Initialize array to hold codes for display if ($_SERVER['REQUEST_METHOD'] === 'POST') { $producto_id = $_POST['producto_id'] ?? null; $cantidad = isset($_POST['cantidad']) ? (int)$_POST['cantidad'] : 0; if ($producto_id && $cantidad > 0 && $cantidad <= 1000) { + // Find product name to generate initials + $product_name = ''; + foreach ($products as $p) { + if ($p['id'] == $producto_id) { + $product_name = $p['nombre']; + break; + } + } + + $initials = ''; + if (!empty($product_name)) { + $words = preg_split('/\s+/', trim($product_name)); + foreach ($words as $w) { + if (isset($w[0])) { + $initials .= strtoupper($w[0]); + } + } + } + $db = db(); try { $db->beginTransaction(); @@ -28,8 +48,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $stmt = $db->prepare("INSERT INTO unidades_inventario (codigo_unico, producto_id) VALUES (?, ?)"); for ($i = 0; $i < $cantidad; $i++) { - // Generate a more robust unique code - $unique_code = 'FL-' . $producto_id . '-' . strtoupper(uniqid()); + // Generate a unique code with product initials + $unique_part = strtoupper(uniqid()); + $unique_code = ($initials ? $initials . '-' : '') . $producto_id . '-' . $unique_part; $stmt->execute([$unique_code, $producto_id]); $generated_codes[] = $unique_code; @@ -46,6 +67,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_SESSION['error_message'] = 'Por favor, seleccione un producto y especifique una cantidad válida (entre 1 y 1000).'; } } + ?>
@@ -53,6 +75,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Generar Nuevas Etiquetas de Inventario

+ ' . $_SESSION['success_message'] . '
'; + unset($_SESSION['success_message']); // Clear the message + } + if (isset($_SESSION['error_message'])) { + echo '
' . $_SESSION['error_message'] . '
'; + unset($_SESSION['error_message']); // Clear the message + } + ?>
@@ -78,20 +111,42 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- +
-
-

Códigos Generados

+
+

Códigos Generados

+ + + + + +
-

Guarda estos códigos para imprimirlos y pegarlos en tus paquetes.

- - +

Estos son los códigos generados. Puedes escanearlos con una app en tu teléfono para probar que funcionan.

+
+ +
+
+ getBarcode($code); + } catch (Exception $e) { + echo '
Error al generar código de barras.
'; + } + ?> +
+ +
+ +
- + \ No newline at end of file diff --git a/imprimir_etiquetas.php b/imprimir_etiquetas.php index 4719eb8..b66f11c 100644 --- a/imprimir_etiquetas.php +++ b/imprimir_etiquetas.php @@ -1,90 +1,105 @@ prepare("SELECT id, nombre, sku FROM products WHERE id IN ($placeholders)"); -foreach ($product_ids as $k => $id) { - $stmt->bindValue(($k + 1), $id, PDO::PARAM_INT); -} -$stmt->execute(); -$products = $stmt->fetchAll(PDO::FETCH_ASSOC); - +$generator = new BarcodeGenerator(); ?> - Imprimir Etiquetas de Códigos de Barras + Imprimir Etiquetas + - +
+
+

Vista Previa de Impresión

+

Ajusta el tamaño y la escala en el diálogo de impresión de tu navegador si es necesario.

+ +
-
- -
-
- - Barcode for product SKU <?php echo htmlspecialchars($product['sku']); ?> - -

Sin SKU

- + +
+ +
+
+ getBarcode($code, 2, 50); + } catch (Exception $e) { + echo '
Error
'; + } + ?> +
+
+ +
+
+ +
+ +
+ No se han proporcionado códigos. Por favor, vuelve al generador para crear nuevas etiquetas.
- +
- + \ No newline at end of file diff --git a/includes/barcode_generator.php b/includes/barcode_generator.php new file mode 100644 index 0000000..156c486 --- /dev/null +++ b/includes/barcode_generator.php @@ -0,0 +1,98 @@ +barcode_codes = $this->getCode128Map(); + } + + public function getBarcode($code, $widthFactor = 2, $height = 50, $foregroundColor = 'black') + { + $barcodeData = $this->getBarcodeData($code); + + $bars = ''; + $x = 0; + + // Generate SVG bars + foreach (str_split($barcodeData['bars']) as $bar) { + $width = $widthFactor * (int)$bar; + if ($x % 2 == 0) { // 0, 2, 4... are black bars + $bars .= ''; + } + $x += $width; + } + + $svg = ''; + $svg .= $bars; + $svg .= ''; + + return $svg; + } + + private function getBarcodeData($code) + { + // For simplicity, we'll stick to Code Set B + $codeSet = 'B'; + $data = ''; + $sum = 104; // Start code B + $mult = 1; + + foreach (str_split($code) as $char) { + $value = $this->getCharValue($codeSet, $char); + if ($value === null) { + // Fallback for unsupported characters, or switch sets (more complex) + // For now, we'll just skip them to avoid errors + continue; + } + $data .= str_pad($value, 2, '0', STR_PAD_LEFT); + $sum += ($value * $mult); + $mult++; + } + + $checksum = $sum % 103; + $data .= str_pad($checksum, 2, '0', STR_PAD_LEFT); + + // Start, data, checksum, stop + $full_code = '104' . $data . '106'; + $bars = ''; + for ($i = 0; $i < strlen($full_code); $i += 2) { + $index = (int)substr($full_code, $i, 2); + $bars .= $this->barcode_codes['bars'][$index]; + } + + return ['bars' => $bars, 'code' => $full_code]; + } + + private function getCharValue($set, $char) + { + if (isset($this->barcode_codes[$set][$char])) { + return $this->barcode_codes[$set][$char]; + } + return null; // Character not in set + } + + private function getCode128Map() + { + return [ + 'B' => [ + ' ' => 0, '!' => 1, '"' => 2, '#' => 3, '$' => 4, '%' => 5, '&' => 6, '\'' => 7, + '(' => 8, ')' => 9, '*' => 10, '+' => 11, ',' => 12, '-' => 13, '.' => 14, '/' => 15, + '0' => 16, '1' => 17, '2' => 18, '3' => 19, '4' => 20, '5' => 21, '6' => 22, '7' => 23, + '8' => 24, '9' => 25, ':' => 26, ';' => 27, '<' => 28, '=' => 29, '>' => 30, '?' => 31, + '@' => 32, 'A' => 33, 'B' => 34, 'C' => 35, 'D' => 36, 'E' => 37, 'F' => 38, 'G' => 39, + 'H' => 40, 'I' => 41, 'J' => 42, 'K' => 43, 'L' => 44, 'M' => 45, 'N' => 46, 'O' => 47, + 'P' => 48, 'Q' => 49, 'R' => 50, 'S' => 51, 'T' => 52, 'U' => 53, 'V' => 54, 'W' => 55, + 'X' => 56, 'Y' => 57, 'Z' => 58, '[' => 59, '\\' => 60, ']' => 61, '^' => 62, '_' => 63 + ], + 'bars' => [ + '212222', '222122', '222221', '121223', '121322', '131222', '122213', '122312', '132212', '221213', '221312', '231212', '112232', '122132', '122231', '113222', '123122', '123221', '223211', '221132', '221231', '213212', '223112', '312131', '311222', '321122', '321221', '312212', '322112', '322211', '212123', '212321', '232121', '111323', '131123', '131321', '112313', '132113', '132311', '211313', '231113', '231311', '112133', '112331', '132131', '113123', '113321', '133121', '313121', '211331', '231131', '213113', '213311', '213131', '311123', '311321', '331121', '312113', '312311', '332111', '314111', '221411', '413111', '111224', '111421', '121124', '121421', '141122', '141221', '112214', '112412', '122114', '122411', '142112', '142211', '241211', '221114', '411122', '411221', '421121', '421211', '212141', '214121', '412121', '111143', '111341', '131141', '114113', '114311', '411113', '411311', '113141', '114131', '311141', '411131', '211412', '211214', '211232', '2331112' + ] + ]; + } +} +?> \ No newline at end of file