From b390ef63182afdd55fa89076327d1e6fa6d14aa0 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 12 Feb 2026 04:46:17 +0000 Subject: [PATCH] Autosave: 20260212-044617 --- db/migrations/061_add_sku_to_products.sql | 1 + get_product_details.php | 3 + registro_salida.php | 271 +++++++++++----------- sku_failures.log | 1 + 4 files changed, 142 insertions(+), 134 deletions(-) create mode 100644 db/migrations/061_add_sku_to_products.sql create mode 100644 sku_failures.log diff --git a/db/migrations/061_add_sku_to_products.sql b/db/migrations/061_add_sku_to_products.sql new file mode 100644 index 0000000..b3e53ba --- /dev/null +++ b/db/migrations/061_add_sku_to_products.sql @@ -0,0 +1 @@ +ALTER TABLE products ADD COLUMN sku VARCHAR(100) NULL UNIQUE; diff --git a/get_product_details.php b/get_product_details.php index d88ee32..8b3ce92 100644 --- a/get_product_details.php +++ b/get_product_details.php @@ -18,6 +18,9 @@ if (isset($_GET['codigo_barras'])) { $product = $stmt->fetch(PDO::FETCH_ASSOC); if (!$product) { $response['message'] = 'Producto no encontrado con el SKU/código de barras proporcionado.'; + // Log the failed SKU attempt to a file + $log_message = date('[Y-m-d H:i:s]') . " Intento fallido de búsqueda con SKU: " . $sku . PHP_EOL; + file_put_contents('sku_failures.log', $log_message, FILE_APPEND); } } catch (PDOException $e) { // Don't expose detailed SQL errors to the client diff --git a/registro_salida.php b/registro_salida.php index 04e8692..83ff44c 100644 --- a/registro_salida.php +++ b/registro_salida.php @@ -6,14 +6,14 @@ require_once 'db/config.php'; $message = ''; $error = ''; -// Lógica para manejar el envío del formulario (tanto normal como AJAX) -if ($_SERVER["REQUEST_METHOD"] == "POST") { +// Esta sección ahora solo se usará para las respuestas AJAX del escáner +if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { $product_id = filter_input(INPUT_POST, 'product_id', FILTER_VALIDATE_INT); $sede_id = filter_input(INPUT_POST, 'sede_id', FILTER_VALIDATE_INT); - $quantity = filter_input(INPUT_POST, 'quantity', FILTER_VALIDATE_INT); $movement_date = filter_input(INPUT_POST, 'movement_date'); + $quantity = 1; // Siempre es 1 al escanear - if ($product_id && $sede_id && $quantity && $movement_date) { + if ($product_id && $sede_id && $movement_date) { try { $pdo = db(); $pdo->beginTransaction(); @@ -25,7 +25,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($existing_stock) { $new_quantity = $existing_stock['quantity'] - $quantity; if ($new_quantity < 0) { - $error = "No hay suficiente stock para registrar la salida. Stock actual: " . $existing_stock['quantity']; + $error = "No hay stock para registrar la salida. Stock actual: " . $existing_stock['quantity']; $pdo->rollBack(); } else { $update_stmt = $pdo->prepare("UPDATE stock_sedes SET quantity = :quantity WHERE id = :id"); @@ -60,33 +60,27 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { $error = "Error al actualizar el inventario: " . $e->getMessage(); } } else { - $error = "Por favor, complete todos los campos del formulario, incluyendo la fecha y la sede."; + $error = "Faltan datos para registrar la salida (producto, sede o fecha)."; } - // Si es una petición AJAX, devolvemos JSON y terminamos la ejecución - if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { - header('Content-Type: application/json'); - if ($error) { - echo json_encode(['success' => false, 'message' => $error]); - } else { - echo json_encode(['success' => true, 'message' => $message]); - } - exit; + // Devolvemos JSON y terminamos la ejecución + header('Content-Type: application/json'); + if ($error) { + echo json_encode(['success' => false, 'message' => $error]); + } else { + echo json_encode(['success' => true, 'message' => $message]); } + exit; } -// Obtener productos y sedes para los dropdowns -$products = []; +// Obtener sedes para el dropdown $sedes = []; try { $pdo = db(); - $products_stmt = $pdo->query("SELECT id, nombre FROM products ORDER BY nombre ASC"); - $products = $products_stmt->fetchAll(PDO::FETCH_ASSOC); - $sedes_stmt = $pdo->query("SELECT id, nombre FROM sedes ORDER BY nombre ASC"); $sedes = $sedes_stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { - $error = "Error al cargar datos: " . $e->getMessage(); + $error_page_load = "Error al cargar datos: " . $e->getMessage(); } ?> @@ -97,23 +91,18 @@ try {
- - - - +
- Registro de Salida de Producto + Escanear Código de Barras
-
+
@@ -129,49 +118,42 @@ try {

- - - + +
-
- - -
- -
+ + +
+
+
+ Productos Registrados +
+
+
+ + + + + + + + + + + +
ProductoSKUEstado
+
+
+
+
+ - - - - - + \ No newline at end of file diff --git a/sku_failures.log b/sku_failures.log new file mode 100644 index 0000000..577af49 --- /dev/null +++ b/sku_failures.log @@ -0,0 +1 @@ +[2026-02-11 23:38:51] Intento fallido de búsqueda con SKU: 4