-- Table structure for table `labels`
--

CREATE TABLE `labels` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `lpn` varchar(30) NOT NULL COMMENT 'License Plate Number único',
  `label_type` enum('PALLET','CASE','ITEM','MIXED','CONTAINER') NOT NULL DEFAULT 'PALLET',
  `warehouse_id` int(10) unsigned NOT NULL,
  `bin_id` int(10) unsigned DEFAULT NULL,
  `item_id` int(10) unsigned DEFAULT NULL COMMENT 'NULL si es mixto',
  `batch_id` int(10) unsigned DEFAULT NULL,
  `quantity` decimal(15,4) DEFAULT NULL,
  `uom` varchar(20) DEFAULT 'UN',
  `status` enum('ACTIVE','IN_TRANSIT','CONSUMED','CANCELLED') NOT NULL DEFAULT 'ACTIVE',
  `parent_lpn_id` int(10) unsigned DEFAULT NULL COMMENT 'LPN padre para anidamiento',
  `notes` text DEFAULT NULL,
  `printed_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_labels_lpn` (`lpn`),
  KEY `idx_labels_type` (`label_type`),
  KEY `idx_labels_warehouse` (`warehouse_id`),
  KEY `idx_labels_bin` (`bin_id`),
  KEY `idx_labels_item` (`item_id`),
  KEY `idx_labels_status` (`status`),
  KEY `idx_labels_parent` (`parent_lpn_id`),
  KEY `fk_labels_batch` (`batch_id`),
  KEY `fk_labels_creator` (`created_by`),
  CONSTRAINT `fk_labels_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_labels_bin` FOREIGN KEY (`bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_labels_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_labels_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_labels_parent` FOREIGN KEY (`parent_lpn_id`) REFERENCES `labels` (`id`),
  CONSTRAINT `fk_labels_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Etiquetas LPN (License Plate Numbers) para pallets, cajas e ítems';

--
-- Dumping data for table `labels`
--


--
-- Table structure for table `lot_sequences`
--

CREATE TABLE `lot_sequences` (
  `period_key` varchar(20) NOT NULL,
  `last_seq` int(10) unsigned NOT NULL DEFAULT 0,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`period_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `lot_sequences`
--

INSERT INTO `lot_sequences` VALUES
('INS-2026',1,'2026-06-13 09:49:09'),
('MP-2606',14,'2026-06-15 15:28:44');

--
-- Table structure for table `manual_preparation_lines`
--

CREATE TABLE `manual_preparation_lines` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `preparation_id` int(10) unsigned NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `batch_number` varchar(50) DEFAULT NULL,
  `from_bin_id` int(10) unsigned NOT NULL COMMENT 'Ubicacion origen de donde se toma',
  `picked_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `container_id` int(10) unsigned DEFAULT NULL COMMENT 'Contenedor de destino si aplica',
  `picked_by` int(10) unsigned DEFAULT NULL COMMENT 'Operador que realizo el pick',
  `picked_at` datetime DEFAULT NULL,
  `status` enum('PENDING','PICKED') NOT NULL DEFAULT 'PENDING',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `requested_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  PRIMARY KEY (`id`),
  KEY `idx_mpline_prep` (`preparation_id`),
  KEY `idx_mpline_item` (`item_id`),
  KEY `idx_mpline_batch` (`batch_id`),
  KEY `idx_mpline_bin` (`from_bin_id`),
  KEY `idx_mpline_status` (`status`),
  KEY `fk_mpline_container` (`container_id`),
  KEY `fk_mpline_picker` (`picked_by`),
  CONSTRAINT `fk_mpline_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_mpline_bin` FOREIGN KEY (`from_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_mpline_container` FOREIGN KEY (`container_id`) REFERENCES `containers` (`id`),
  CONSTRAINT `fk_mpline_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_mpline_picker` FOREIGN KEY (`picked_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_mpline_prep` FOREIGN KEY (`preparation_id`) REFERENCES `manual_preparations` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Lineas de preparacion manual con trazabilidad de operador y ubicacion';

--
-- Dumping data for table `manual_preparation_lines`
--


--
-- Table structure for table `manual_preparations`
--

CREATE TABLE `manual_preparations` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `prep_number` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `customer_code` varchar(30) DEFAULT NULL,
  `customer_name` varchar(200) DEFAULT NULL,
  `prep_type` enum('FREE','AUCTION','EXPORT','SAMPLE','SUPPLY') NOT NULL DEFAULT 'FREE',
  `status` enum('DRAFT','OPEN','IN_PROGRESS','COMPLETED','CANCELLED') NOT NULL DEFAULT 'DRAFT',
  `sap_order_entry` int(11) DEFAULT NULL COMMENT 'DocEntry de pedido SAP si se vincula posteriormente',
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `completed_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_mprep_number` (`prep_number`),
  KEY `idx_mprep_wh` (`warehouse_id`),
  KEY `idx_mprep_status` (`status`),
  KEY `idx_mprep_type` (`prep_type`),
  KEY `idx_mprep_customer` (`customer_code`),
  KEY `fk_mprep_creator` (`created_by`),
  CONSTRAINT `fk_mprep_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_mprep_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Preparaciones manuales libres sin reserva previa (remate, exportacion, muestra, etc.)';

--
-- Dumping data for table `manual_preparations`
--


--
-- Table structure for table `menu_groups`
--

CREATE TABLE `menu_groups` (
  `id` tinyint(3) unsigned NOT NULL,
  `code` varchar(20) NOT NULL,
  `name` varchar(60) NOT NULL,
  `color` varchar(20) NOT NULL DEFAULT 'gray',
  `sort_order` tinyint(3) unsigned NOT NULL DEFAULT 99,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_menu_groups_code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Grupos del menu del WMS (Xpert v1.0)';

--
-- Dumping data for table `menu_groups`
--

INSERT INTO `menu_groups` VALUES
(1,'entrada','1 - Entrada','entrada',1,1),
(2,'calidad','2 - Calidad','calidad',2,1),
(3,'almacen','3 - Almacen','almacen',3,1),
(4,'salida','4 - Salida','salida',4,1),
(5,'ops','5 - Operaciones','ops',5,1),
(6,'dinavisa','6 - DINAVISA / Compliance','dinavisa',6,1),
(7,'sistema','7 - Sistema','sistema',7,1);

--
-- Table structure for table `menu_items`
--

CREATE TABLE `menu_items` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `group_id` tinyint(3) unsigned DEFAULT NULL COMMENT 'NULL para items fijos como Dashboard',
  `view_key` varchar(40) NOT NULL COMMENT 'data-view del frontend',
  `name` varchar(80) NOT NULL,
  `route` varchar(200) DEFAULT NULL,
  `sort_order` tinyint(3) unsigned NOT NULL DEFAULT 99,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_menu_items_view_key` (`view_key`),
  KEY `idx_menu_items_group` (`group_id`),
  CONSTRAINT `fk_menu_items_group` FOREIGN KEY (`group_id`) REFERENCES `menu_groups` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=82 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Items del menu del WMS';

--
-- Dumping data for table `menu_items`
--

INSERT INTO `menu_items` VALUES
(1,NULL,'dashboard','Dashboard',NULL,0,1),
(10,1,'agendas','Agendas',NULL,1,1),
(11,1,'recepcion','Recepcion',NULL,2,1),
(12,1,'putaway','Putaway',NULL,3,1),
(20,2,'qa','Control QA',NULL,1,1),
(21,2,'qcexterno','QC Externo',NULL,2,1),
(22,2,'muestreo','Muestreo QA',NULL,3,1),
(23,2,'temperatura','Temperatura',NULL,4,1),
(30,3,'almacenes','Almacenes',NULL,1,1),
(31,3,'stock','Stock',NULL,2,1),
(32,3,'transferencias','Transferencias',NULL,3,1),
(33,3,'contenedores','Contenedores',NULL,4,1),
(34,3,'conteo','Conteo Ciclico',NULL,5,1),
(35,3,'ajustes','Ajuste Directo',NULL,6,1),
(40,4,'picking','Picking',NULL,1,1),
(41,4,'ondas','Ondas Picking',NULL,2,1),
(42,4,'prepmanual','Prep. Manual',NULL,3,1),
(43,4,'zonepick','Zona Picking',NULL,4,1),
(44,4,'packing','Packing',NULL,5,1),
(45,4,'expedicion','Expedicion',NULL,6,1),
(46,4,'devoluciones','Devoluciones',NULL,7,1),
(47,4,'crear_st','Crear Solicitud de Traslado',NULL,8,1),
(50,5,'tareas','Tareas',NULL,1,1),
(60,6,'recall','Recall',NULL,1,1),
(61,6,'sops','SOPs / IQ / OQ / PQ',NULL,2,1),
(62,6,'trazabilidad','Trazabilidad',NULL,3,1),
(70,7,'reportes','Reportes',NULL,1,1),
(71,7,'sap','SAP B1',NULL,2,1),
(72,7,'usuarios','Usuarios',NULL,3,1),
(73,7,'bins','Ubicaciones',NULL,4,1),
(74,7,'import_sap','Importar SAP',NULL,5,1),
(75,6,'audit','Auditoría','#audit',4,1),
(76,1,'print_labels','Imprimir Etiquetas',NULL,4,1),
(77,7,'zonif_familia','Zona × Item',NULL,6,1),
(78,7,'zona_familia','Zona × Familia',NULL,7,1),
(79,7,'zona_subgrupo','Zona x Grupo Anterior',NULL,8,1),
(80,3,'reubicacion','Reubicación','#reubicacion',5,1),
(81,7,'picking_min','Stock Mínimo Picking',NULL,9,1);

--
-- Table structure for table `menu_role_access`
--

CREATE TABLE `menu_role_access` (
  `menu_item_id` smallint(5) unsigned NOT NULL,
  `role` varchar(40) NOT NULL,
  `access_type` enum('FULL','READ') NOT NULL DEFAULT 'FULL',
  PRIMARY KEY (`menu_item_id`,`role`),
  CONSTRAINT `fk_mra_item` FOREIGN KEY (`menu_item_id`) REFERENCES `menu_items` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Matriz de permisos rol -> item. Ausencia de fila = sin acceso.';

--
-- Dumping data for table `menu_role_access`
--

INSERT INTO `menu_role_access` VALUES
(1,'admin','FULL'),
(1,'auditor','READ'),
(1,'jefe','FULL'),
(1,'op_almacen','FULL'),
(1,'op_picking','FULL'),
(1,'op_recepcion','FULL'),
(1,'qa_liberador','FULL'),
(1,'qc_muestrista','FULL'),
(1,'supervisor','FULL'),
(1,'xpert','FULL'),
(10,'admin','FULL'),
(10,'auditor','READ'),
(10,'jefe','FULL'),
(10,'op_recepcion','FULL'),
(10,'supervisor','FULL'),
(10,'xpert','FULL'),
(11,'admin','FULL'),
(11,'auditor','READ'),
(11,'jefe','FULL'),
(11,'op_recepcion','FULL'),
(11,'supervisor','FULL'),
(11,'xpert','FULL'),
(12,'admin','FULL'),
(12,'auditor','READ'),
(12,'jefe','FULL'),
(12,'op_almacen','FULL'),
(12,'supervisor','FULL'),
(12,'xpert','FULL'),
(20,'admin','FULL'),
(20,'jefe','FULL'),
(20,'supervisor','FULL'),
(20,'xpert','FULL'),
(21,'admin','FULL'),
(21,'auditor','READ'),
(21,'qa_liberador','FULL'),
(21,'qc_muestrista','FULL'),
(21,'xpert','FULL'),
(22,'admin','FULL'),
(22,'auditor','READ'),
(22,'qa_liberador','FULL'),
(22,'qc_muestrista','FULL'),
(22,'xpert','FULL'),
(23,'admin','FULL'),
(23,'auditor','READ'),
(23,'jefe','FULL'),
(23,'qa_liberador','FULL'),
(23,'supervisor','FULL'),
(23,'xpert','FULL'),
(30,'admin','FULL'),
(30,'auditor','READ'),
(30,'jefe','FULL'),
(30,'op_almacen','READ'),
(30,'supervisor','FULL'),
(31,'admin','FULL'),
(31,'auditor','READ'),
(31,'jefe','FULL'),
(31,'op_almacen','READ'),
(31,'op_picking','READ'),
(31,'op_recepcion','READ'),
(31,'qa_liberador','READ'),
(31,'qc_muestrista','READ'),
(31,'supervisor','FULL'),
(31,'xpert','FULL'),
(32,'admin','FULL'),
(32,'auditor','READ'),
(32,'jefe','FULL'),
(32,'op_almacen','FULL'),
(33,'admin','FULL'),
(33,'auditor','READ'),
(33,'jefe','FULL'),
(33,'op_almacen','FULL'),
(33,'supervisor','FULL'),
(33,'xpert','FULL'),
(34,'admin','FULL'),
(34,'auditor','READ'),
(34,'jefe','FULL'),
(34,'op_almacen','FULL'),
(34,'supervisor','FULL'),
(35,'admin','FULL'),
(35,'auditor','READ'),
(35,'jefe','FULL'),
(35,'supervisor','FULL'),
(40,'admin','FULL'),
(40,'auditor','READ'),
(40,'jefe','FULL'),
(40,'op_picking','FULL'),
(40,'supervisor','FULL'),
(40,'xpert','FULL'),
(41,'admin','FULL'),
(41,'auditor','READ'),
(41,'jefe','FULL'),
(42,'admin','FULL'),
(42,'auditor','READ'),
(42,'jefe','FULL'),
(42,'op_picking','FULL'),
(43,'admin','FULL'),
(43,'auditor','READ'),
(43,'jefe','FULL'),
(44,'admin','FULL'),
(44,'auditor','READ'),
(44,'jefe','FULL'),
(44,'op_picking','FULL'),
(44,'supervisor','FULL'),
(44,'xpert','FULL'),
(45,'admin','FULL'),
(45,'auditor','READ'),
(45,'jefe','FULL'),
(45,'supervisor','FULL'),
(45,'xpert','FULL'),
(46,'admin','FULL'),
(46,'auditor','READ'),
(46,'jefe','FULL'),
(46,'op_recepcion','FULL'),
(47,'admin','FULL'),
(47,'auditor','READ'),
(47,'jefe','FULL'),
(47,'op_almacen','FULL'),
(47,'supervisor','FULL'),
(47,'xpert','FULL'),
(50,'admin','FULL'),
(50,'auditor','READ'),
(50,'jefe','FULL'),
(50,'supervisor','FULL'),
(50,'xpert','FULL'),
(60,'admin','FULL'),
(60,'auditor','READ'),
(60,'jefe','FULL'),
(60,'qa_liberador','FULL'),
(60,'supervisor','FULL'),
(60,'xpert','FULL'),
(61,'admin','FULL'),
(61,'auditor','READ'),
(61,'qa_liberador','FULL'),
(61,'supervisor','FULL'),
(61,'xpert','FULL'),
(62,'admin','FULL'),
(62,'auditor','READ'),
(62,'jefe','READ'),
(62,'op_almacen','READ'),
(62,'op_picking','READ'),
(62,'op_recepcion','READ'),
(62,'qa_liberador','READ'),
(62,'qc_muestrista','READ'),
(62,'supervisor','FULL'),
(62,'xpert','FULL'),
(70,'admin','FULL'),
(70,'auditor','READ'),
(70,'jefe','FULL'),
(70,'qa_liberador','FULL'),
(70,'supervisor','FULL'),
(70,'xpert','FULL'),
(71,'admin','FULL'),
(71,'jefe','FULL'),
(71,'supervisor','FULL'),
(71,'xpert','FULL'),
(72,'admin','FULL'),
(72,'supervisor','FULL'),
(72,'xpert','FULL'),
(73,'admin','FULL'),
(73,'auditor','READ'),
(73,'jefe','FULL'),
(73,'op_almacen','READ'),
(73,'op_picking','READ'),
(73,'supervisor','FULL'),
(73,'xpert','FULL'),
(74,'admin','FULL'),
(74,'auditor','READ'),
(74,'jefe','FULL'),
(74,'xpert','FULL'),
(75,'admin','FULL'),
(75,'auditor','READ'),
(75,'jefe','READ'),
(75,'qa_liberador','READ'),
(75,'supervisor','FULL'),
(75,'xpert','FULL'),
(76,'admin','FULL'),
(76,'auditor','READ'),
(76,'jefe','FULL'),
(76,'op_almacen','FULL'),
(76,'op_recepcion','FULL'),
(76,'supervisor','FULL'),
(76,'xpert','FULL'),
(77,'admin','FULL'),
(77,'auditor','READ'),
(77,'jefe','FULL'),
(77,'op_almacen','READ'),
(77,'supervisor','FULL'),
(77,'xpert','FULL'),
(78,'admin','FULL'),
(78,'auditor','READ'),
(78,'jefe','FULL'),
(78,'op_almacen','READ'),
(78,'supervisor','FULL'),
(78,'xpert','FULL'),
(79,'admin','FULL'),
(79,'auditor','READ'),
(79,'jefe','FULL'),
(79,'op_almacen','READ'),
(79,'supervisor','FULL'),
(79,'xpert','FULL'),
(80,'admin','FULL'),
(80,'auditor','READ'),
(80,'jefe','FULL'),
(80,'op_almacen','FULL'),
(80,'supervisor','FULL'),
(80,'xpert','FULL'),
(81,'admin','FULL'),
(81,'auditor','READ'),
(81,'jefe','FULL'),
(81,'op_almacen','READ'),
(81,'supervisor','FULL'),
(81,'xpert','FULL');

--
-- Table structure for table `notification_rules`
--

CREATE TABLE `notification_rules` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `rule_type` enum('EXPIRY_DAYS','STOCK_MIN','TEMP_CHECK') NOT NULL,
  `item_id` int(10) unsigned DEFAULT NULL COMMENT 'NULL = aplica a todos',
  `item_code` varchar(50) DEFAULT NULL,
  `threshold_value` decimal(15,4) NOT NULL COMMENT 'Dias para vencimiento o cantidad minima',
  `severity` enum('WARNING','CRITICAL') NOT NULL DEFAULT 'WARNING',
  `is_active` tinyint(1) DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_nr_type` (`rule_type`,`is_active`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Reglas de notificacion configurables';

--
-- Dumping data for table `notification_rules`
--

INSERT INTO `notification_rules` VALUES
(1,'EXPIRY_DAYS',NULL,NULL,90.0000,'WARNING',1,'2026-04-11 10:28:51'),
(2,'EXPIRY_DAYS',NULL,NULL,30.0000,'CRITICAL',1,'2026-04-11 10:28:51'),
(3,'STOCK_MIN',NULL,NULL,10.0000,'WARNING',0,'2026-04-11 10:28:51'),
(4,'STOCK_MIN',NULL,NULL,0.0000,'CRITICAL',0,'2026-04-11 10:28:51');

--
-- Table structure for table `notifications`
--

CREATE TABLE `notifications` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type` enum('EXPIRY_WARNING','EXPIRY_CRITICAL','STOCK_LOW','STOCK_ZERO','TEMP_ALERT','RECALL_ALERT','QA_PENDING','SYSTEM') NOT NULL,
  `severity` enum('INFO','WARNING','CRITICAL') NOT NULL DEFAULT 'INFO',
  `title` varchar(200) NOT NULL,
  `message` text NOT NULL,
  `reference_type` varchar(50) DEFAULT NULL COMMENT 'item, batch, zone, recall',
  `reference_id` int(10) unsigned DEFAULT NULL,
  `is_read` tinyint(1) DEFAULT 0,
  `read_by` int(10) unsigned DEFAULT NULL,
  `read_at` datetime DEFAULT NULL,
  `is_dismissed` tinyint(1) DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_notif_read` (`is_read`,`is_dismissed`,`created_at`),
  KEY `idx_notif_type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Notificaciones y alertas del sistema';

--
-- Dumping data for table `notifications`
--


--
-- Table structure for table `packing_lines`
--

CREATE TABLE `packing_lines` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `packing_order_id` int(10) unsigned NOT NULL,
  `line_num` int(11) NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `serial_number` varchar(100) DEFAULT NULL,
  `quantity` decimal(15,4) NOT NULL,
  `packed_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `uom` varchar(20) NOT NULL DEFAULT 'UN',
  `container_id` int(10) unsigned DEFAULT NULL COMMENT 'Contenedor donde se empacó',
  `status` enum('PENDING','PACKED','SHORT','CANCELLED') NOT NULL DEFAULT 'PENDING',
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_packline` (`packing_order_id`,`line_num`),
  KEY `idx_packline_item` (`item_id`),
  KEY `idx_packline_batch` (`batch_id`),
  KEY `idx_packline_container` (`container_id`),
  CONSTRAINT `fk_packline_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_packline_container` FOREIGN KEY (`container_id`) REFERENCES `containers` (`id`),
  CONSTRAINT `fk_packline_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_packline_order` FOREIGN KEY (`packing_order_id`) REFERENCES `packing_orders` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Líneas de empaque con asignación a contenedor';

--
-- Dumping data for table `packing_lines`
--

INSERT INTO `packing_lines` VALUES
(1,1,1,550,37,NULL,100.0000,100.0000,'UN',NULL,'PACKED',NULL,'2026-06-13 12:58:43','2026-06-13 15:03:39'),
(2,2,1,72371,51,NULL,100.0000,100.0000,'UN',NULL,'PACKED',NULL,'2026-06-15 17:00:53','2026-06-15 17:01:27'),
(3,3,1,72371,51,NULL,1.0000,1.0000,'UN',NULL,'PACKED',NULL,'2026-06-15 17:17:35','2026-06-15 17:17:57');

--
-- Table structure for table `packing_orders`
--

CREATE TABLE `packing_orders` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `pack_number` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `pick_list_id` int(10) unsigned DEFAULT NULL COMMENT 'Pick list origen',
  `station_id` int(10) unsigned DEFAULT NULL COMMENT 'Estación de empaque asignada',
  `status` enum('DRAFT','OPEN','IN_PROGRESS','COMPLETED','CANCELLED') NOT NULL DEFAULT 'OPEN',
  `customer_code` varchar(30) DEFAULT NULL,
  `customer_name` varchar(150) DEFAULT NULL,
  `sap_doc_entry` int(11) DEFAULT NULL COMMENT 'DocEntry del pedido de venta SAP',
  `sap_doc_num` int(11) DEFAULT NULL,
  `assigned_to` int(10) unsigned DEFAULT NULL,
  `started_at` datetime DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  `sap_delivery_entry` int(11) DEFAULT NULL,
  `sap_delivery_num` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_packorder_number` (`pack_number`),
  KEY `idx_packorder_wh` (`warehouse_id`),
  KEY `idx_packorder_picklist` (`pick_list_id`),
  KEY `idx_packorder_station` (`station_id`),
  KEY `idx_packorder_status` (`status`),
  KEY `idx_packorder_sap` (`sap_doc_entry`),
  KEY `fk_packorder_assigned` (`assigned_to`),
  KEY `fk_packorder_creator` (`created_by`),
  CONSTRAINT `fk_packorder_assigned` FOREIGN KEY (`assigned_to`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_packorder_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_packorder_picklist` FOREIGN KEY (`pick_list_id`) REFERENCES `pick_lists` (`id`),
  CONSTRAINT `fk_packorder_station` FOREIGN KEY (`station_id`) REFERENCES `packing_stations` (`id`),
  CONSTRAINT `fk_packorder_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Órdenes de empaque vinculadas a pick lists';

--
-- Dumping data for table `packing_orders`
--

INSERT INTO `packing_orders` VALUES
(1,'PK-00000001',16,2,NULL,'COMPLETED','C01030','MINISTERIO DE SALUD PUBLICA Y B.S.',2025,1381,NULL,NULL,'2026-06-13 15:03:52','urgente','2026-06-13 12:58:43','2026-06-13 15:03:52',9,NULL,NULL),
(2,'PK-00000002',16,4,NULL,'COMPLETED','C01242','GN DISTRIBUIDORA DE CARLOS MARIA GONZALEZ',2027,1382,NULL,NULL,'2026-06-15 17:02:49','URGENTE','2026-06-15 17:00:53','2026-06-15 17:05:50',9,1826,'1406'),
(3,'PK-00000003',16,5,NULL,'COMPLETED','C01242','GN DISTRIBUIDORA DE CARLOS MARIA GONZALEZ',2028,1383,NULL,NULL,'2026-06-15 17:18:16','URGENTE','2026-06-15 17:17:35','2026-06-15 17:20:43',9,1829,'1407');

--
-- Table structure for table `packing_stations`
--

CREATE TABLE `packing_stations` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(20) NOT NULL,
  `name` varchar(100) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `zone_id` int(10) unsigned DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `current_user_id` int(10) unsigned DEFAULT NULL COMMENT 'Operador actualmente asignado',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_packstation_code` (`warehouse_id`,`code`),
  KEY `idx_packstation_zone` (`zone_id`),
  KEY `fk_packstation_user` (`current_user_id`),
  CONSTRAINT `fk_packstation_user` FOREIGN KEY (`current_user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_packstation_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`),
  CONSTRAINT `fk_packstation_zone` FOREIGN KEY (`zone_id`) REFERENCES `warehouse_zones` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Estaciones de empaque en el almacén';

--
-- Dumping data for table `packing_stations`
--


--
-- Table structure for table `pick_list_lines`
--

CREATE TABLE `pick_list_lines` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `pick_list_id` int(10) unsigned NOT NULL,
  `line_num` int(11) NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL COMMENT 'Lote asignado por FEFO',
  `from_bin_id` int(10) unsigned DEFAULT NULL COMMENT 'Bin origen sugerido',
  `requested_qty` decimal(15,4) NOT NULL,
  `picked_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `uom` varchar(20) NOT NULL DEFAULT 'UN',
  `status` enum('PENDING','IN_PROGRESS','PICKED','SHORT','CANCELLED') NOT NULL DEFAULT 'PENDING',
  `sap_line_num` int(11) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_pickline` (`pick_list_id`,`line_num`),
  KEY `idx_pickline_item` (`item_id`),
  KEY `idx_pickline_batch` (`batch_id`),
  KEY `fk_pickline_bin` (`from_bin_id`),
  CONSTRAINT `fk_pickline_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_pickline_bin` FOREIGN KEY (`from_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_pickline_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_pickline_picklist` FOREIGN KEY (`pick_list_id`) REFERENCES `pick_lists` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Líneas de picking con asignación FEFO';

--
-- Dumping data for table `pick_list_lines`
--

INSERT INTO `pick_list_lines` VALUES
(1,1,1,550,NULL,NULL,100.0000,0.0000,'UN','SHORT',NULL,'Stock insuficiente','2026-06-13 12:33:11','2026-06-13 12:33:11'),
(2,2,1,550,37,62,100.0000,100.0000,'UN','PICKED',NULL,NULL,'2026-06-13 12:48:15','2026-06-13 12:55:00'),
(4,4,1,72371,51,168,100.0000,100.0000,'UN','PICKED',NULL,NULL,'2026-06-15 16:56:05','2026-06-15 16:59:01'),
(5,5,1,72371,51,168,1.0000,1.0000,'UN','PICKED',NULL,NULL,'2026-06-15 17:13:50','2026-06-15 17:15:45');

--
-- Table structure for table `pick_lists`
--

CREATE TABLE `pick_lists` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `pick_number` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `wave_id` int(10) unsigned DEFAULT NULL COMMENT 'Oleada de picking asignada',
  `status` enum('DRAFT','OPEN','IN_PROGRESS','COMPLETED','CANCELLED','WAVE_ASSIGNED') NOT NULL DEFAULT 'DRAFT',
  `sap_doc_entry` int(11) DEFAULT NULL COMMENT 'DocEntry pedido de venta SAP',
  `sap_doc_num` int(11) DEFAULT NULL,
  `customer_code` varchar(30) DEFAULT NULL,
  `customer_name` varchar(150) DEFAULT NULL,
  `ship_date` date DEFAULT NULL,
  `assigned_to` int(10) unsigned DEFAULT NULL,
  `started_at` datetime DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_picklist_number` (`pick_number`),
  KEY `idx_picklist_wh` (`warehouse_id`),
  KEY `idx_picklist_status` (`status`),
  KEY `idx_picklist_sap` (`sap_doc_entry`),
  KEY `fk_picklist_assigned` (`assigned_to`),
  KEY `fk_picklist_creator` (`created_by`),
  KEY `idx_picklist_wave` (`wave_id`),
  CONSTRAINT `fk_picklist_assigned` FOREIGN KEY (`assigned_to`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_picklist_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_picklist_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`),
  CONSTRAINT `fk_picklist_wave` FOREIGN KEY (`wave_id`) REFERENCES `picking_waves` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Listas de picking generadas desde pedidos SAP';

--
-- Dumping data for table `pick_lists`
--

INSERT INTO `pick_lists` VALUES
(1,'PK-00000001',16,NULL,'OPEN',2025,1381,'C01030','MINISTERIO DE SALUD PUBLICA Y B.S.',NULL,NULL,NULL,NULL,NULL,'2026-06-13 12:33:11','2026-06-13 12:33:11',9),
(2,'PK-00000002',16,NULL,'COMPLETED',2025,1381,'C01030','MINISTERIO DE SALUD PUBLICA Y B.S.',NULL,NULL,NULL,'2026-06-13 12:55:00',NULL,'2026-06-13 12:48:15','2026-06-13 12:55:00',9),
(4,'PK-00000004',16,NULL,'COMPLETED',2027,1382,'C01242','GN DISTRIBUIDORA DE CARLOS MARIA GONZALEZ',NULL,NULL,NULL,'2026-06-15 16:59:01',NULL,'2026-06-15 16:56:05','2026-06-15 16:59:01',9),
(5,'PK-00000008',16,NULL,'COMPLETED',2028,1383,'C01242','GN DISTRIBUIDORA DE CARLOS MARIA GONZALEZ','2026-06-16',NULL,NULL,'2026-06-15 17:15:45',NULL,'2026-06-15 17:13:50','2026-06-15 17:15:45',9);

--
-- Table structure for table `picking_min_levels`
--

CREATE TABLE `picking_min_levels` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `item_id` int(10) unsigned NOT NULL,
  `zone_id` int(10) unsigned NOT NULL,
  `min_qty` decimal(15,4) NOT NULL,
  `target_qty` decimal(15,4) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` int(10) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_item_zone` (`item_id`,`zone_id`),
  KEY `k_item` (`item_id`),
  KEY `k_zone` (`zone_id`)
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `picking_min_levels`
--

INSERT INTO `picking_min_levels` VALUES
(1,325,43,500.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(2,331,43,510.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(3,339,44,792.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(4,345,44,1800.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(5,347,44,640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(6,360,43,332.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(7,365,43,60.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(8,382,44,880.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(9,392,44,400.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(10,2994,41,340.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(11,3009,44,504.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(12,3016,44,1200.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(13,3018,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(14,3019,41,200.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(15,3020,41,600.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(16,3021,44,1200.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(17,3022,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(18,3023,44,480.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(19,3024,44,1200.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(20,3026,41,800.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(21,3027,44,2160.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(22,3029,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(23,3031,41,640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(24,3034,44,1800.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(25,3035,44,378.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(26,3038,44,960.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(27,3039,41,1360.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(28,3041,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(29,3042,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(30,3043,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(31,3044,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(32,3047,44,480.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(33,3048,41,640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(34,3049,41,640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(35,3051,41,640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(36,3056,44,1600.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(37,3057,44,360.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(38,3060,44,1360.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(39,3065,44,2640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(40,3066,44,340.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(41,3072,41,640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(42,3073,44,68.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(43,3081,41,640.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(44,3082,41,400.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(45,3083,41,360.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(46,3084,41,400.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(47,3086,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(48,58185,41,680.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14'),
(49,72371,43,240.0000,NULL,1,1,'2026-06-08 23:22:14','2026-06-08 23:22:14');

--
-- Table structure for table `picking_rejections`
--

CREATE TABLE `picking_rejections` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `wave_id` int(10) unsigned DEFAULT NULL COMMENT 'Oleada origen (si aplica)',
  `pick_list_id` int(10) unsigned DEFAULT NULL COMMENT 'Pick list origen (si aplica)',
  `item_id` int(10) unsigned NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `requested_qty` decimal(15,4) NOT NULL COMMENT 'Cantidad solicitada',
  `available_qty` decimal(15,4) NOT NULL COMMENT 'Cantidad disponible al momento del analisis',
  `shortage_qty` decimal(15,4) NOT NULL COMMENT 'Faltante: requested - available',
  `status` enum('PENDING','RESOLVED','CANCELLED') NOT NULL DEFAULT 'PENDING',
  `resolution` text DEFAULT NULL COMMENT 'Descripcion de la resolucion',
  `resolved_by` int(10) unsigned DEFAULT NULL,
  `resolved_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_reject_wave` (`wave_id`),
  KEY `idx_reject_picklist` (`pick_list_id`),
  KEY `idx_reject_item` (`item_id`),
  KEY `idx_reject_status` (`status`),
  KEY `fk_reject_resolver` (`resolved_by`),
  CONSTRAINT `fk_reject_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_reject_picklist` FOREIGN KEY (`pick_list_id`) REFERENCES `pick_lists` (`id`),
  CONSTRAINT `fk_reject_resolver` FOREIGN KEY (`resolved_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_reject_wave` FOREIGN KEY (`wave_id`) REFERENCES `picking_waves` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Lineas rechazadas en picking por falta de stock disponible';

--
-- Dumping data for table `picking_rejections`
--


--
-- Table structure for table `picking_wave_lines`
--

CREATE TABLE `picking_wave_lines` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `wave_id` int(10) unsigned NOT NULL,
  `pick_list_id` int(10) unsigned NOT NULL,
  `sequence` int(11) NOT NULL DEFAULT 0 COMMENT 'Orden dentro de la oleada',
  `status` enum('PENDING','IN_PROGRESS','COMPLETED','CANCELLED') NOT NULL DEFAULT 'PENDING',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_waveline` (`wave_id`,`pick_list_id`),
  KEY `idx_waveline_picklist` (`pick_list_id`),
  CONSTRAINT `fk_waveline_picklist` FOREIGN KEY (`pick_list_id`) REFERENCES `pick_lists` (`id`),
  CONSTRAINT `fk_waveline_wave` FOREIGN KEY (`wave_id`) REFERENCES `picking_waves` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Líneas de oleada vinculando pick lists a una oleada';

--
-- Dumping data for table `picking_wave_lines`
--


--
-- Table structure for table `picking_waves`
--

CREATE TABLE `picking_waves` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `wave_number` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `status` enum('DRAFT','OPEN','IN_PROGRESS','COMPLETED','CANCELLED') NOT NULL DEFAULT 'OPEN',
  `wave_type` enum('MANUAL','AUTO','PRIORITY','ROUTE','CARRIER') NOT NULL DEFAULT 'MANUAL',
  `release_criteria` enum('ORDER','CUSTOMER','ROUTE','WAVE') NOT NULL DEFAULT 'ORDER' COMMENT 'Criterio de agrupacion para liberacion',
  `route_code` varchar(50) DEFAULT NULL COMMENT 'Codigo de ruta logistica',
  `customer_code` varchar(50) DEFAULT NULL COMMENT 'CardCode del cliente para agrupacion',
  `priority` tinyint(3) unsigned NOT NULL DEFAULT 5 COMMENT '1=máxima, 10=mínima',
  `planned_date` date DEFAULT NULL,
  `started_at` datetime DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `total_lines` int(10) unsigned NOT NULL DEFAULT 0,
  `completed_lines` int(10) unsigned NOT NULL DEFAULT 0,
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  `released_at` datetime DEFAULT NULL,
  `released_by` int(10) unsigned DEFAULT NULL,
  `total_pick_lists` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_wave_number` (`wave_number`),
  KEY `idx_wave_wh` (`warehouse_id`),
  KEY `idx_wave_status` (`status`),
  KEY `idx_wave_date` (`planned_date`),
  KEY `fk_wave_creator` (`created_by`),
  KEY `idx_wave_criteria` (`release_criteria`),
  KEY `idx_wave_route` (`route_code`),
  KEY `idx_wave_customer` (`customer_code`),
  CONSTRAINT `fk_wave_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_wave_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Oleadas de picking para agrupar pick lists';

--
-- Dumping data for table `picking_waves`
--


--
-- Table structure for table `putaway_suggestions`
--

CREATE TABLE `putaway_suggestions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `item_id` int(10) unsigned NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `suggested_bin_id` int(10) unsigned NOT NULL COMMENT 'Ubicacion sugerida para almacenar',
  `suggestion_reason` enum('SAME_ITEM','SAME_ZONE','FEFO','EMPTY_BIN','NEAREST') NOT NULL DEFAULT 'SAME_ITEM' COMMENT 'Razon de la sugerencia',
  `priority` int(11) NOT NULL DEFAULT 5 COMMENT 'Prioridad de la sugerencia (1=mejor)',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_psug_item` (`item_id`),
  KEY `idx_psug_batch` (`batch_id`),
  KEY `idx_psug_wh` (`warehouse_id`),
  KEY `idx_psug_bin` (`suggested_bin_id`),
  KEY `idx_psug_reason` (`suggestion_reason`),
  KEY `idx_psug_priority` (`priority`),
  CONSTRAINT `fk_psug_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_psug_bin` FOREIGN KEY (`suggested_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_psug_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_psug_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Sugerencias inteligentes de ubicacion para putaway (mismo item, FEFO, vacio, etc.)';

--
-- Dumping data for table `putaway_suggestions`
--


--
-- Table structure for table `qa_decisions`
--

CREATE TABLE `qa_decisions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` int(10) unsigned NOT NULL,
  `item_id` int(10) unsigned DEFAULT NULL,
  `warehouse_id` int(10) unsigned DEFAULT NULL,
  `document_id` int(10) unsigned DEFAULT NULL COMMENT 'Documento de inventario relacionado',
  `decision` enum('APPROVED','REJECTED','CONDITIONAL','PENDING','QUARANTINE') NOT NULL DEFAULT 'PENDING',
  `reason` varchar(500) DEFAULT NULL,
  `inspected_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `approved_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `rejected_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `inspector` int(10) unsigned DEFAULT NULL COMMENT 'Usuario que realizó la inspección',
  `decided_at` datetime DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `review_date` date DEFAULT NULL,
  `decided_by` int(10) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_qa_batch` (`batch_id`),
  KEY `idx_qa_item` (`item_id`),
  KEY `idx_qa_warehouse` (`warehouse_id`),
  KEY `idx_qa_decision` (`decision`),
  KEY `idx_qa_document` (`document_id`),
  KEY `fk_qa_inspector` (`inspector`),
  KEY `fk_qa_creator` (`created_by`),
  CONSTRAINT `fk_qa_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_qa_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_qa_document` FOREIGN KEY (`document_id`) REFERENCES `inventory_documents` (`id`),
  CONSTRAINT `fk_qa_inspector` FOREIGN KEY (`inspector`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_qa_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_qa_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Decisiones de control de calidad por lote';

--
-- Dumping data for table `qa_decisions`
--

INSERT INTO `qa_decisions` VALUES
(1,20,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:30:04','2026-06-10 19:30:04',NULL),
(2,34,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:30:30','2026-06-10 19:30:30',NULL),
(3,29,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:30:52','2026-06-10 19:30:52',NULL),
(4,21,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:31:33','2026-06-10 19:31:33',NULL),
(5,18,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:31:51','2026-06-10 19:31:51',NULL),
(6,36,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:32:07','2026-06-10 19:32:07',NULL),
(7,33,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:32:20','2026-06-10 19:32:20',NULL),
(8,17,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:32:35','2026-06-10 19:32:35',NULL),
(9,15,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:32:56','2026-06-10 19:32:56',NULL),
(10,25,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:33:14','2026-06-10 19:33:14',NULL),
(11,22,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:33:28','2026-06-10 19:33:28',NULL),
(12,28,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:33:48','2026-06-10 19:33:48',NULL),
(13,16,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:34:09','2026-06-10 19:34:09',NULL),
(14,32,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:34:31','2026-06-10 19:34:31',NULL),
(15,19,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:34:45','2026-06-10 19:34:45',NULL),
(16,23,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:35:01','2026-06-10 19:35:01',NULL),
(17,30,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:35:13','2026-06-10 19:35:13',NULL),
(18,35,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:35:38','2026-06-10 19:35:38',NULL),
(19,27,NULL,NULL,NULL,'APPROVED','Liberado de Origen',0.0000,0.0000,0.0000,NULL,NULL,'Liberado de Origen',NULL,1,'2026-06-10 19:35:51','2026-06-10 19:35:51',NULL),
(20,37,NULL,NULL,NULL,'APPROVED','prueba',0.0000,0.0000,0.0000,NULL,NULL,'prueba',NULL,9,'2026-06-13 12:47:25','2026-06-13 12:47:25',NULL);

--
-- Table structure for table `qc_external_requests`
--

CREATE TABLE `qc_external_requests` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `request_type` enum('ASSIGN','APPROVE','REJECT') NOT NULL COMMENT 'Tipo de solicitud QC externa',
  `batch_id` int(10) unsigned NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `batch_number` varchar(50) NOT NULL,
  `lot_qty` decimal(15,4) DEFAULT NULL COMMENT 'Cantidad del lote afectado',
  `source_system` varchar(50) NOT NULL DEFAULT 'EXTERNAL' COMMENT 'Sistema origen de la solicitud',
  `external_reference` varchar(100) DEFAULT NULL COMMENT 'Referencia en el sistema externo',
  `reason` text DEFAULT NULL COMMENT 'Motivo de aprobacion/rechazo',
  `status` enum('PENDING','PROCESSED','ERROR') NOT NULL DEFAULT 'PENDING',
  `processed_at` datetime DEFAULT NULL,
  `error_message` text DEFAULT NULL COMMENT 'Detalle del error si status = ERROR',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `action` varchar(40) DEFAULT NULL,
  `quantity_affected` decimal(15,4) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_qcer_type` (`request_type`),
  KEY `idx_qcer_batch` (`batch_id`),
  KEY `idx_qcer_item` (`item_id`),
  KEY `idx_qcer_code` (`item_code`),
  KEY `idx_qcer_status` (`status`),
  KEY `idx_qcer_source` (`source_system`),
  KEY `idx_qcer_extref` (`external_reference`),
  CONSTRAINT `fk_qcer_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_qcer_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Solicitudes de QC desde sistema externo de calidad (asignar, aprobar, rechazar)';

--
-- Dumping data for table `qc_external_requests`
--


--
-- Table structure for table `qc_product_config`
--

CREATE TABLE `qc_product_config` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `item_id` int(10) unsigned NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `requires_qc` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Producto requiere QC en recepcion',
  `qc_blocking` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Si bloqueante, impide putaway hasta aprobacion',
  `auto_assign` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Asignar QC automaticamente en recepcion',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_qcpc_item` (`item_id`),
  KEY `idx_qcpc_code` (`item_code`),
  KEY `idx_qcpc_requires` (`requires_qc`),
  KEY `idx_qcpc_blocking` (`qc_blocking`),
  CONSTRAINT `fk_qcpc_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Configuracion de QC automatico por producto para recepcion';

--
-- Dumping data for table `qc_product_config`
--


--
-- Table structure for table `recall_results`
--

CREATE TABLE `recall_results` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `recall_id` int(10) unsigned NOT NULL,
  `result_type` enum('STOCK','MOVEMENT','DISPATCH','CUSTOMER') NOT NULL,
  `warehouse_code` varchar(20) DEFAULT NULL,
  `bin_code` varchar(30) DEFAULT NULL,
  `quantity` decimal(15,4) DEFAULT NULL,
  `stock_status` varchar(20) DEFAULT NULL,
  `customer_code` varchar(50) DEFAULT NULL,
  `customer_name` varchar(200) DEFAULT NULL,
  `dispatch_number` varchar(30) DEFAULT NULL,
  `dispatch_date` datetime DEFAULT NULL,
  `movement_type` varchar(30) DEFAULT NULL,
  `movement_date` datetime DEFAULT NULL,
  `details` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `fk_rr_recall` (`recall_id`),
  CONSTRAINT `fk_rr_recall` FOREIGN KEY (`recall_id`) REFERENCES `recalls` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `recall_results`
--


--
-- Table structure for table `recalls`
--

CREATE TABLE `recalls` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `recall_number` varchar(30) NOT NULL,
  `batch_number` varchar(50) NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `item_name` varchar(200) DEFAULT NULL,
  `reason` text NOT NULL,
  `status` enum('INITIATED','IN_PROGRESS','COMPLETED','CANCELLED') NOT NULL DEFAULT 'INITIATED',
  `total_stock_found` decimal(15,4) DEFAULT 0.0000,
  `total_customers_affected` int(11) DEFAULT 0,
  `initiated_by` int(10) unsigned NOT NULL,
  `completed_at` datetime DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_recall_number` (`recall_number`),
  KEY `idx_batch` (`batch_number`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `recalls`
--


--
-- Table structure for table `reception_agenda_lines`
--

CREATE TABLE `reception_agenda_lines` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `agenda_id` int(10) unsigned NOT NULL,
  `ref_id` int(10) unsigned NOT NULL COMMENT 'Referencia al documento OC/OD',
  `line_num` int(11) NOT NULL,
  `item_id` int(10) unsigned DEFAULT NULL,
  `item_code` varchar(50) NOT NULL,
  `item_name` varchar(200) DEFAULT NULL,
  `expected_qty` decimal(15,4) NOT NULL DEFAULT 0.0000 COMMENT 'Cantidad teorica de la OC',
  `received_qty` decimal(15,4) NOT NULL DEFAULT 0.0000 COMMENT 'Cantidad efectivamente recibida',
  `difference_qty` decimal(15,4) NOT NULL DEFAULT 0.0000 COMMENT 'Diferencia: received - expected',
  `batch_number` varchar(50) DEFAULT NULL,
  `expiry_date` date DEFAULT NULL,
  `supplier_lot` varchar(50) DEFAULT NULL COMMENT 'Lote del proveedor',
  `sap_line_num` int(11) DEFAULT NULL COMMENT 'LineNum en el documento SAP',
  `status` enum('PENDING','PARTIAL','COMPLETED','OVER','SHORT') NOT NULL DEFAULT 'PENDING',
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_aline_agenda` (`agenda_id`),
  KEY `idx_aline_ref` (`ref_id`),
  KEY `idx_aline_item` (`item_id`),
  KEY `idx_aline_status` (`status`),
  CONSTRAINT `fk_aline_agenda` FOREIGN KEY (`agenda_id`) REFERENCES `reception_agendas` (`id`),
  CONSTRAINT `fk_aline_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_aline_ref` FOREIGN KEY (`ref_id`) REFERENCES `reception_agenda_refs` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=82 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Lineas esperadas (teorico) por documento dentro de una agenda de recepcion';

--
-- Dumping data for table `reception_agenda_lines`
--

INSERT INTO `reception_agenda_lines` VALUES
(12,2,2,1,1136,'402965','ALMIDON PREGELATINIZADO',7.7000,7.7000,0.0000,'2503070','2028-03-09','589601',0,'COMPLETED',NULL,'2026-06-10 17:03:31','2026-06-10 18:12:39'),
(13,2,2,2,1107,'402630','CROSCARMELOSA SODICA',32.4000,32.4000,0.0000,'2509217','2027-05-31','D2405013',1,'COMPLETED',NULL,'2026-06-10 17:03:31','2026-06-10 18:12:39'),
(14,2,2,3,1007,'401281','ESTEARATO DE MAGNESIO',6.6000,6.6000,0.0000,'2509227','2029-08-31','24JMSTD180',2,'COMPLETED',NULL,'2026-06-10 17:03:31','2026-06-10 18:12:39'),
(15,2,2,4,639,'400004','CAPS VACIAS AMARILLO/BLANCO N°2 SIN IMPRESIÓN',36000.0000,36000.0000,0.0000,'2310242','2028-08-31','2312432PA',3,'COMPLETED',NULL,'2026-06-10 17:03:31','2026-06-10 18:12:39'),
(16,2,2,5,1051,'401975','LACTOSA HIDRATADA',20.0000,20.0000,0.0000,'2602061','2028-02-02','23323335',5,'COMPLETED',NULL,'2026-06-10 17:03:31','2026-06-10 18:12:39'),
(25,5,5,1,1224,'403964','COLORANTE ROJO LAKE PONCEAU 4R',1.7164,1.7164,0.0000,'2404108','2026-10-20','RP21100024',0,'COMPLETED',NULL,'2026-06-10 18:32:09','2026-06-10 18:33:27'),
(26,6,6,1,60280,'600623','ESTUCHE PRONEZOL CAPS X 10 OR',4000.0000,4000.0000,0.0000,'303I2023','2028-07-31','14426',0,'COMPLETED',NULL,'2026-06-10 18:44:30','2026-06-10 18:47:42'),
(27,6,6,2,2900,'606067','C ALU ALU 210mm',82.2250,82.2250,0.0000,'191I2026','2027-02-08','2508C10036',1,'COMPLETED',NULL,'2026-06-10 18:44:30','2026-06-10 18:48:15'),
(28,6,6,3,61268,'601215','PROSPECTO PRONEZOL',8000.0000,8000.0000,0.0000,'284I2023','2028-06-30','96500',2,'COMPLETED',NULL,'2026-06-10 18:44:30','2026-06-10 18:50:19'),
(29,6,6,4,2515,'601827','PROSPECTO INIBEX',9932.0000,9932.0000,0.0000,'003I2026','2031-01-31','6000126',3,'COMPLETED',NULL,'2026-06-10 18:44:30','2026-06-10 18:49:19'),
(30,6,6,5,2432,'600602','ESTUCHE INIBEX 20 MG COMP X 30',3992.0000,3992.0000,0.0000,'046I2026','2031-02-28','36367',4,'COMPLETED',NULL,'2026-06-10 18:44:31','2026-06-10 18:47:21'),
(31,6,6,6,2810,'605832','C ALU 206mm INIBEX 20 MG COMP. OR',5.6430,5.6430,0.0000,'4026','2027-03-28','4026',5,'COMPLETED',NULL,'2026-06-10 18:44:31','2026-06-10 18:51:46'),
(32,6,6,7,1240,'404066','CELULOSA MICROCRISTALINA PH 200',28.8000,28.8000,0.0000,'2509225','2030-02-28','26200250408',6,'COMPLETED',NULL,'2026-06-10 18:44:31','2026-06-10 18:51:08'),
(33,7,7,1,693,'400069','SERTACONAZOLE NITRATO',3.0000,3.0000,0.0000,'2602045','2030-10-31','08522112025',0,'COMPLETED',NULL,'2026-06-10 18:46:34','2026-06-10 18:54:07'),
(34,7,7,2,1368,'410695','OMEPRAZOL PELLET',14.8000,14.8000,0.0000,'2602043','2028-05-31','MKPPLR-OMF-25040',1,'COMPLETED',NULL,'2026-06-10 18:46:34','2026-06-10 18:53:50'),
(35,7,7,3,639,'400004','CAPS VACIAS AMARILLO/BLANCO N°2 SIN IMPRESIÓN',360000.0000,360000.0000,0.0000,'2310242','2028-08-31','2312432PA',3,'COMPLETED',NULL,'2026-06-10 18:46:35','2026-06-10 18:55:31'),
(36,8,8,1,3047,'70421','PRONEZOL 20 MG X 10 CAPSULAS OR',360.0000,360.0000,0.0000,'056','2029-03-31','056',0,'COMPLETED',NULL,'2026-06-10 19:01:11','2026-06-10 19:04:15'),
(37,8,8,2,3020,'70074','FUNGOID CREMA X 20 GR',900.0000,900.0000,0.0000,'029','2026-12-31','029',1,'COMPLETED',NULL,'2026-06-10 19:01:11','2026-06-10 19:05:44'),
(38,8,8,3,3051,'70465','INIBEX 20 MG COMP X 30 OR',1020.0000,1020.0000,0.0000,'609','2028-01-31','609',2,'COMPLETED',NULL,'2026-06-10 19:01:11','2026-06-10 19:05:13'),
(39,9,9,1,61327,'31880','OPTI-FREE PURE MOIST X 90 ML',48.0000,48.0000,0.0000,'130J7','2027-07-31','130J7',0,'COMPLETED',NULL,'2026-06-10 19:09:58','2026-06-10 19:21:54'),
(40,9,9,2,60551,'31869','OPTI-FREE EXPRES X 355 ML',72.0000,72.0000,0.0000,'133M2','2027-11-30','133M2',1,'COMPLETED',NULL,'2026-06-10 19:09:58','2026-06-10 19:21:35'),
(48,14,14,1,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',7106.0000,7106.0000,0.0000,'746','2027-11-30','746',0,'COMPLETED',NULL,'2026-06-11 11:05:46','2026-06-11 14:13:59'),
(49,14,14,2,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',7850.0000,7850.0000,0.0000,'747','2027-11-30','747',1,'COMPLETED',NULL,'2026-06-11 11:05:46','2026-06-11 14:19:05'),
(50,14,14,3,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',7968.0000,7968.0000,0.0000,'751','2027-12-31','751',2,'COMPLETED',NULL,'2026-06-11 11:05:46','2026-06-11 14:40:07'),
(51,14,14,4,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',8116.0000,8116.0000,0.0000,'757','2028-02-28','757',3,'COMPLETED',NULL,'2026-06-11 11:05:46','2026-06-11 14:38:06'),
(52,14,14,5,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',8141.0000,8141.0000,0.0000,'760','2028-02-28','760',4,'COMPLETED',NULL,'2026-06-11 11:05:46','2026-06-11 14:49:18'),
(53,15,15,1,2432,'600602','ESTUCHE INIBEX 20 MG COMP X 30',100.0000,0.0000,0.0000,NULL,NULL,NULL,0,'PENDING',NULL,'2026-06-11 14:54:09','2026-06-11 14:54:09'),
(54,16,16,1,2432,'600602','ESTUCHE INIBEX 20 MG COMP X 30',100.0000,100.0000,0.0000,'001I2026','2030-06-30','123654',0,'COMPLETED',NULL,'2026-06-13 09:22:50','2026-06-13 09:49:09'),
(55,17,17,1,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,0.0000,0.0000,'749','2027-12-31','749',0,'PENDING',NULL,'2026-06-13 09:29:46','2026-06-13 09:29:46'),
(56,17,17,2,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,0.0000,0.0000,'749','2027-12-31','749',1,'PENDING',NULL,'2026-06-13 09:29:46','2026-06-13 09:29:46'),
(57,17,17,3,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',3176.0000,0.0000,0.0000,'749','2027-12-31','749',2,'PENDING',NULL,'2026-06-13 09:29:46','2026-06-13 09:29:46'),
(58,18,18,1,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'749','2027-12-31','749',0,'COMPLETED',NULL,'2026-06-13 10:14:51','2026-06-13 14:32:09'),
(59,18,18,2,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'749','2027-12-31','749',1,'COMPLETED',NULL,'2026-06-13 10:14:51','2026-06-13 14:32:31'),
(60,18,18,3,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'749','2027-12-31','749',2,'COMPLETED',NULL,'2026-06-13 10:14:51','2026-06-13 14:32:54'),
(61,18,18,4,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',776.0000,776.0000,0.0000,'749','2027-12-31','749',3,'COMPLETED',NULL,'2026-06-13 10:14:51','2026-06-13 14:33:12'),
(62,19,19,1,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'756','2028-02-28','756',0,'COMPLETED',NULL,'2026-06-13 10:16:04','2026-06-13 14:24:10'),
(63,19,19,2,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'756','2028-02-28','756',1,'COMPLETED',NULL,'2026-06-13 10:16:04','2026-06-13 14:24:36'),
(64,19,19,3,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'756','2028-02-28','756',2,'COMPLETED',NULL,'2026-06-13 10:16:04','2026-06-13 14:24:56'),
(65,19,19,4,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',887.0000,887.0000,0.0000,'756','2028-02-28','756',3,'COMPLETED',NULL,'2026-06-13 10:16:04','2026-06-13 14:25:12'),
(66,20,20,1,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'758','2028-02-28','758',0,'COMPLETED',NULL,'2026-06-13 10:16:25','2026-06-13 12:10:54'),
(67,20,20,2,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'758','2028-02-28','758',1,'COMPLETED',NULL,'2026-06-13 10:16:25','2026-06-13 12:11:24'),
(68,20,20,3,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'758','2028-02-28','758',2,'COMPLETED',NULL,'2026-06-13 10:16:25','2026-06-13 12:11:55'),
(69,20,20,4,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',939.0000,939.0000,0.0000,'758','2028-02-28','758',3,'COMPLETED',NULL,'2026-06-13 10:16:25','2026-06-13 12:12:28'),
(70,21,21,1,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'759','2028-02-28','759',0,'COMPLETED',NULL,'2026-06-13 10:16:40','2026-06-13 10:25:40'),
(71,21,21,2,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'759','2028-02-28','759',1,'COMPLETED',NULL,'2026-06-13 10:16:40','2026-06-13 10:26:34'),
(72,21,21,3,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'759','2028-02-28','759',2,'COMPLETED',NULL,'2026-06-13 10:16:40','2026-06-13 10:26:53'),
(73,21,21,4,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',920.0000,920.0000,0.0000,'759','2028-02-28','759',3,'COMPLETED',NULL,'2026-06-13 10:16:40','2026-06-13 10:27:43'),
(74,22,22,1,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'743','2027-08-31','743',0,'COMPLETED',NULL,'2026-06-13 16:03:38','2026-06-13 16:09:52'),
(75,22,22,2,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2400.0000,2400.0000,0.0000,'743','2027-08-31','743',1,'COMPLETED',NULL,'2026-06-13 16:03:38','2026-06-13 16:10:12'),
(76,22,22,3,550,'210436','IBUPROFENO 200 MG SUSP.X 120 ML MSP Y BS',2455.0000,2455.0000,0.0000,'743','2027-08-31','743',2,'COMPLETED',NULL,'2026-06-13 16:03:38','2026-06-13 16:10:27'),
(77,23,23,1,1375,'410702','ACEITE DE ALMENDRA DE COCO',1.0000,1.0000,0.0000,'2606012','2027-06-30','12345',0,'COMPLETED',NULL,'2026-06-15 15:13:39','2026-06-15 15:21:38'),
(78,23,23,2,690,'400066','ACIDO CITRICO',1.0000,1.0000,0.0000,'2606013','2027-06-30','12345',1,'COMPLETED',NULL,'2026-06-15 15:13:39','2026-06-15 15:26:10'),
(79,23,23,3,1008,'401299','EUDRAGIT E-100',1.0000,1.0000,0.0000,'2606014','2027-06-30','12358',2,'COMPLETED',NULL,'2026-06-15 15:13:39','2026-06-15 15:28:44'),
(80,24,24,1,72371,'70938','CLARIMA CR HIDRATANTE X 50 GR OR',2880.0000,2880.0000,0.0000,'006','2027-01-31','006',0,'COMPLETED',NULL,'2026-06-15 15:53:12','2026-06-15 15:56:22'),
(81,24,24,2,72371,'70938','CLARIMA CR HIDRATANTE X 50 GR OR',1711.0000,1711.0000,0.0000,'006','2027-01-31','006',1,'COMPLETED',NULL,'2026-06-15 15:53:12','2026-06-15 15:56:43');

--
-- Table structure for table `reception_agenda_refs`
--

CREATE TABLE `reception_agenda_refs` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `agenda_id` int(10) unsigned NOT NULL,
  `sap_doc_type` varchar(30) NOT NULL,
  `sap_doc_entry` int(11) NOT NULL COMMENT 'DocEntry en SAP B1',
  `sap_doc_num` varchar(20) DEFAULT NULL COMMENT 'DocNum legible',
  `ref_type` enum('OC','OD','RR','ODC','OC_PLAZA','OC_IMPORTACION','OT_PRODUCCION') NOT NULL DEFAULT 'OC',
  `supplier_code` varchar(30) DEFAULT NULL COMMENT 'CardCode del proveedor',
  `supplier_name` varchar(200) DEFAULT NULL,
  `bpl_id` int(11) DEFAULT NULL,
  `status` enum('PENDING','PARTIAL','COMPLETED','SKIPPED','ERROR') NOT NULL DEFAULT 'PENDING',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_aref_agenda` (`agenda_id`),
  KEY `idx_aref_sap` (`sap_doc_entry`,`sap_doc_type`),
  KEY `idx_aref_supplier` (`supplier_code`),
  KEY `idx_aref_status` (`status`),
  CONSTRAINT `fk_aref_agenda` FOREIGN KEY (`agenda_id`) REFERENCES `reception_agendas` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Documentos SAP (OC, OD, etc.) vinculados a una agenda de recepcion';

--
-- Dumping data for table `reception_agenda_refs`
--

INSERT INTO `reception_agenda_refs` VALUES
(2,2,'InventoryTransferRequest',1553,'1044','OT_PRODUCCION','INMRA','Traslado INMRA → CENMRA',NULL,'COMPLETED','2026-06-10 17:03:31'),
(5,5,'InventoryTransferRequest',1554,'1045','OT_PRODUCCION','MP','Traslado MP → CENMRA',NULL,'COMPLETED','2026-06-10 18:32:09'),
(6,6,'InventoryTransferRequest',1555,'1046','OT_PRODUCCION','INMRA','Traslado INMRA → CENMRA',NULL,'COMPLETED','2026-06-10 18:44:30'),
(7,7,'InventoryTransferRequest',1549,'1040','OT_PRODUCCION','INMRA','Traslado INMRA → CENMRA',NULL,'COMPLETED','2026-06-10 18:46:34'),
(8,8,'InventoryTransferRequest',1556,'1047','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-10 19:01:11'),
(9,9,'InventoryTransferRequest',1557,'1048','OT_PRODUCCION','MRA','Traslado MRA → CENMRA',NULL,'COMPLETED','2026-06-10 19:09:58'),
(14,14,'InventoryTransferRequest',1561,'1049','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-11 11:05:46'),
(15,15,'PurchaseOrder',645,'250','OC_PLAZA','P00006','IMPRENTA GAMA S.A.',NULL,'PENDING','2026-06-11 14:54:09'),
(16,16,'PurchaseOrder',645,'250','OC_PLAZA','P00006','IMPRENTA GAMA S.A.',NULL,'COMPLETED','2026-06-13 09:22:50'),
(17,17,'InventoryTransferRequest',1566,'1051','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'PENDING','2026-06-13 09:29:46'),
(18,18,'InventoryTransferRequest',1566,'1051','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-13 10:14:51'),
(19,19,'InventoryTransferRequest',1567,'1052','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-13 10:16:04'),
(20,20,'InventoryTransferRequest',1568,'1053','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-13 10:16:25'),
(21,21,'InventoryTransferRequest',1569,'1054','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-13 10:16:40'),
(22,22,'InventoryTransferRequest',1565,'1050','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-13 16:03:38'),
(23,23,'PurchaseOrder',648,'251','OC_PLAZA','P00583','INSALCOR PARAGUAY S.A.',NULL,'COMPLETED','2026-06-15 15:13:39'),
(24,24,'InventoryTransferRequest',1572,'1055','OT_PRODUCCION','CEN','Traslado CEN → CENMRA',NULL,'COMPLETED','2026-06-15 15:53:12');

--
-- Table structure for table `reception_agendas`
--

CREATE TABLE `reception_agendas` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `agenda_number` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `status` enum('DRAFT','OPEN','IN_PROGRESS','CLOSED','CANCELLED') NOT NULL DEFAULT 'DRAFT',
  `planned_date` date DEFAULT NULL,
  `opened_at` datetime DEFAULT NULL,
  `closed_at` datetime DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `bultos` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  `assigned_to` int(10) unsigned DEFAULT NULL,
  `assigned_at` datetime DEFAULT NULL,
  `assigned_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_agenda_number` (`agenda_number`),
  KEY `idx_agenda_wh` (`warehouse_id`),
  KEY `idx_agenda_status` (`status`),
  KEY `idx_agenda_date` (`planned_date`),
  KEY `fk_agenda_creator` (`created_by`),
  KEY `idx_assigned_to` (`assigned_to`),
  CONSTRAINT `fk_agenda_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_agenda_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Agendas de recepcion con soporte multi-OC';

--
-- Dumping data for table `reception_agendas`
--

INSERT INTO `reception_agendas` VALUES
(2,'AG-00000002',16,'CLOSED','2026-06-10','2026-06-10 17:36:35','2026-06-10 18:01:34','Auto-creada desde ST SAP #1044',NULL,'2026-06-10 17:03:29','2026-06-10 18:01:34',32,27,'2026-06-10 17:36:22',32),
(5,'AG-00000005',16,'CLOSED','2026-06-10','2026-06-10 18:32:47','2026-06-10 18:33:43','Auto-creada desde ST SAP #1045',NULL,'2026-06-10 18:32:08','2026-06-10 18:33:43',32,27,'2026-06-10 18:32:09',32),
(6,'AG-00000006',16,'CLOSED','2026-06-10','2026-06-10 18:45:13','2026-06-10 18:52:06','Auto-creada desde ST SAP #1046',NULL,'2026-06-10 18:44:28','2026-06-10 18:52:06',32,27,'2026-06-10 18:44:31',32),
(7,'AG-00000007',16,'CLOSED','2026-06-10','2026-06-10 18:52:17','2026-06-10 18:55:44','Auto-creada desde ST SAP #1040',NULL,'2026-06-10 18:46:33','2026-06-10 18:55:44',32,27,'2026-06-10 18:46:35',32),
(8,'AG-00000008',16,'CLOSED','2026-06-10','2026-06-10 19:01:28','2026-06-10 19:05:53','Auto-creada desde ST SAP #1047',NULL,'2026-06-10 19:01:09','2026-06-10 19:05:53',32,27,'2026-06-10 19:01:11',32),
(9,'AG-00000009',16,'CLOSED','2026-06-10','2026-06-10 19:10:18','2026-06-10 19:22:07','Auto-creada desde ST SAP #1048',NULL,'2026-06-10 19:09:56','2026-06-10 19:22:07',32,27,'2026-06-10 19:09:58',32),
(14,'AG-00000014',16,'CLOSED','2026-06-11','2026-06-11 11:05:57','2026-06-11 14:49:38','Auto-creada desde ST SAP #1049',3,'2026-06-11 11:05:44','2026-06-11 16:57:20',9,27,'2026-06-11 11:05:46',9),
(15,'AG-00000015',16,'OPEN','2026-06-11','2026-06-11 16:34:15',NULL,'Auto-creada desde OC SAP #250',3,'2026-06-11 14:54:07','2026-06-11 16:56:15',9,28,'2026-06-11 14:54:09',9),
(16,'AG-00000016',16,'CLOSED','2026-06-11','2026-06-13 09:37:14','2026-06-13 10:22:42','Auto-creada desde OC SAP #250',NULL,'2026-06-13 09:22:49','2026-06-13 10:22:42',9,27,'2026-06-13 09:22:50',9),
(17,'AG-00000017',16,'OPEN','2026-06-13','2026-06-13 09:37:08',NULL,'Auto-creada desde ST SAP #1051',NULL,'2026-06-13 09:29:45','2026-06-13 09:37:08',9,27,'2026-06-13 09:29:46',9),
(18,'AG-00000018',16,'CLOSED','2026-06-13','2026-06-13 10:34:01','2026-06-13 14:33:54','Auto-creada desde ST SAP #1051',NULL,'2026-06-13 10:14:49','2026-06-13 14:33:54',9,27,'2026-06-13 10:14:51',9),
(19,'AG-00000019',16,'CLOSED','2026-06-13','2026-06-13 10:33:52','2026-06-13 14:31:30','Auto-creada desde ST SAP #1052',NULL,'2026-06-13 10:16:02','2026-06-13 14:31:30',9,27,'2026-06-13 10:16:04',9),
(20,'AG-00000020',16,'CLOSED','2026-06-13','2026-06-13 10:33:47','2026-06-13 12:12:39','Auto-creada desde ST SAP #1053',NULL,'2026-06-13 10:16:21','2026-06-13 12:12:39',9,27,'2026-06-13 10:16:25',9),
(21,'AG-00000021',16,'CLOSED','2026-06-13','2026-06-13 10:18:07','2026-06-13 11:50:34','Auto-creada desde ST SAP #1054',NULL,'2026-06-13 10:16:38','2026-06-13 11:50:34',9,27,'2026-06-13 10:16:40',9),
(22,'AG-00000022',16,'CLOSED','2026-06-13','2026-06-13 16:05:34','2026-06-13 16:10:40','Auto-creada desde ST SAP #1050',NULL,'2026-06-13 16:03:37','2026-06-13 16:10:40',9,27,'2026-06-13 16:05:24',9),
(23,'AG-00000023',16,'CLOSED','2026-06-15','2026-06-15 15:16:40','2026-06-15 15:29:22','LICITACION',NULL,'2026-06-15 15:13:37','2026-06-15 15:29:22',9,27,'2026-06-15 15:16:31',9),
(24,'AG-00000024',16,'CLOSED','2026-06-15','2026-06-15 15:53:39','2026-06-15 15:57:02','Auto-creada desde ST SAP #1055',NULL,'2026-06-15 15:53:10','2026-06-15 15:57:02',9,27,'2026-06-15 15:53:12',9);

--
-- Table structure for table `reception_scans`
--

CREATE TABLE `reception_scans` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `agenda_id` int(10) unsigned NOT NULL,
  `line_id` int(10) unsigned DEFAULT NULL COMMENT 'NULL si es producto inesperado',
  `item_code` varchar(50) NOT NULL COMMENT 'Codigo escaneado/ingresado',
  `batch_number` varchar(50) DEFAULT NULL,
  `expiry_date` date DEFAULT NULL,
  `supplier_lot` varchar(50) DEFAULT NULL,
  `scanned_qty` decimal(15,4) NOT NULL,
  `operator_id` int(10) unsigned NOT NULL COMMENT 'Operador que escaneo',
  `scanned_at` datetime NOT NULL DEFAULT current_timestamp(),
  `bin_id` int(10) unsigned DEFAULT NULL COMMENT 'Ubicacion destino si ya se asigno',
  `container_id` int(10) unsigned DEFAULT NULL,
  `notes` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_scan_agenda` (`agenda_id`),
  KEY `idx_scan_line` (`line_id`),
  KEY `idx_scan_item` (`item_code`),
  KEY `idx_scan_operator` (`operator_id`),
  KEY `idx_scan_date` (`scanned_at`),
  KEY `fk_scan_bin` (`bin_id`),
  KEY `idx_rec_container` (`container_id`),
  CONSTRAINT `fk_scan_agenda` FOREIGN KEY (`agenda_id`) REFERENCES `reception_agendas` (`id`),
  CONSTRAINT `fk_scan_bin` FOREIGN KEY (`bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_scan_line` FOREIGN KEY (`line_id`) REFERENCES `reception_agenda_lines` (`id`),
  CONSTRAINT `fk_scan_operator` FOREIGN KEY (`operator_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Escaneos ciegos de recepcion por operador para comparacion contra teorico';

--
-- Dumping data for table `reception_scans`
--

INSERT INTO `reception_scans` VALUES
(15,2,12,'402965','2503070','2028-03-09','589601',7.7000,27,'2026-06-10 17:52:36',NULL,16,NULL),
(16,2,14,'401281','2509227','2029-08-31','24JMSTD180',6.6000,27,'2026-06-10 17:53:01',NULL,17,NULL),
(17,2,16,'401975','2602061','2028-02-02','23323335',20.0000,27,'2026-06-10 17:57:25',NULL,20,NULL),
(18,2,13,'402630','2509217','2027-05-31','D2405013',32.4000,27,'2026-06-10 17:58:46',NULL,22,NULL),
(19,2,15,'400004','2310242','2028-08-31','2312432PA',36000.0000,27,'2026-06-10 17:59:39',NULL,25,NULL),
(20,5,25,'403964','2404108','2026-10-20','RP21100024',1.7164,27,'2026-06-10 18:33:27',NULL,26,NULL),
(21,6,30,'600602','046I2026','2031-02-28','36367',3992.0000,27,'2026-06-10 18:47:21',NULL,27,NULL),
(22,6,26,'600623','303I2023','2028-07-31','14426',4000.0000,27,'2026-06-10 18:47:42',NULL,28,NULL),
(23,6,27,'606067','191I2026','2027-02-08','2508C10036',82.2250,27,'2026-06-10 18:48:15',NULL,30,NULL),
(24,6,29,'601827','003I2026','2031-01-31','6000126',9932.0000,27,'2026-06-10 18:49:19',NULL,31,NULL),
(26,6,28,'601215','284I2023','2028-06-30','96500',8000.0000,27,'2026-06-10 18:50:19',NULL,32,NULL),
(27,6,32,'404066','2509225','2030-02-28','26200250408',28.8000,27,'2026-06-10 18:51:08',NULL,33,NULL),
(28,6,31,'605832','4026','2027-03-28','4026',5.6430,27,'2026-06-10 18:51:46',NULL,34,NULL),
(29,7,34,'410695','2602043','2028-05-31','MKPPLR-OMF-25040',14.8000,27,'2026-06-10 18:53:50',NULL,35,NULL),
(30,7,33,'400069','2602045','2030-10-31','08522112025',3.0000,27,'2026-06-10 18:54:07',NULL,36,NULL),
(31,7,35,'400004','2310242','2028-08-31','2312432PA',360000.0000,27,'2026-06-10 18:55:31',NULL,37,NULL),
(32,8,36,'70421','056','2029-03-31','056',360.0000,27,'2026-06-10 19:04:15',NULL,38,NULL),
(33,8,38,'70465','609','2028-01-31','609',1020.0000,27,'2026-06-10 19:05:13',NULL,39,NULL),
(34,8,37,'70074','029','2026-12-31','029',900.0000,27,'2026-06-10 19:05:44',NULL,40,NULL),
(35,9,40,'31869','133M2','2027-11-30','133M2',72.0000,27,'2026-06-10 19:21:35',NULL,42,NULL),
(36,9,39,'31880','130J7','2027-07-31','130J7',48.0000,27,'2026-06-10 19:21:54',NULL,43,NULL),
(47,14,48,'210436','746','2027-11-30','746',2306.0000,27,'2026-06-11 14:13:03',NULL,56,NULL),
(48,14,48,'210436','746','2027-11-30','746',2400.0000,27,'2026-06-11 14:13:36',NULL,57,NULL),
(49,14,48,'210436','746','2027-11-30','746',2400.0000,27,'2026-06-11 14:13:59',NULL,58,NULL),
(50,14,49,'210436','747','2027-11-30','747',2400.0000,27,'2026-06-11 14:16:27',NULL,59,NULL),
(51,14,49,'210436','747','2027-11-30','747',2400.0000,27,'2026-06-11 14:17:15',NULL,60,NULL),
(52,14,49,'210436','747','2027-11-30','747',2400.0000,27,'2026-06-11 14:17:50',NULL,61,NULL),
(53,14,49,'210436','747','2027-11-30','747',650.0000,27,'2026-06-11 14:19:05',NULL,62,NULL),
(54,14,51,'210436','757','2028-02-28','757',916.0000,27,'2026-06-11 14:36:59',NULL,63,NULL),
(55,14,51,'210436','757','2028-02-28','757',2400.0000,27,'2026-06-11 14:37:25',NULL,64,NULL),
(56,14,51,'210436','757','2028-02-28','757',2400.0000,27,'2026-06-11 14:37:46',NULL,65,NULL),
(57,14,51,'210436','757','2028-02-28','757',2400.0000,27,'2026-06-11 14:38:06',NULL,66,NULL),
(59,14,50,'210436','751','2027-12-31','751',2400.0000,27,'2026-06-11 14:38:50',NULL,67,NULL),
(60,14,50,'210436','751','2027-12-31','751',2400.0000,27,'2026-06-11 14:38:53',NULL,74,NULL),
(61,14,50,'210436','751','2027-12-31','751',2400.0000,27,'2026-06-11 14:39:27',NULL,68,NULL),
(62,14,50,'210436','751','2027-12-31','751',768.0000,27,'2026-06-11 14:40:07',NULL,69,NULL),
(63,14,52,'210436','760','2028-02-28','760',2400.0000,27,'2026-06-11 14:40:49',NULL,70,NULL),
(64,14,52,'210436','760','2028-02-28','760',2400.0000,27,'2026-06-11 14:46:46',NULL,71,NULL),
(65,14,52,'210436','760','2028-02-28','760',2400.0000,27,'2026-06-11 14:47:05',NULL,72,NULL),
(66,14,52,'210436','760','2028-02-28','760',941.0000,27,'2026-06-11 14:49:18',NULL,73,NULL),
(67,16,54,'600602','001I2026','2030-06-30','123654',100.0000,27,'2026-06-13 09:49:09',NULL,77,NULL),
(68,21,70,'210436','759','2028-02-28','759',2400.0000,27,'2026-06-13 10:25:40',NULL,79,NULL),
(69,21,71,'210436','759','2028-02-28','759',2400.0000,27,'2026-06-13 10:26:34',NULL,80,NULL),
(70,21,72,'210436','759','2028-02-28','759',2400.0000,27,'2026-06-13 10:26:53',NULL,81,NULL),
(71,21,73,'210436','759','2028-02-28','759',920.0000,27,'2026-06-13 10:27:43',NULL,82,NULL),
(72,20,66,'210436','758','2028-02-28','758',2400.0000,27,'2026-06-13 12:10:54',NULL,86,NULL),
(73,20,67,'210436','758','2028-02-28','758',2400.0000,27,'2026-06-13 12:11:24',NULL,87,NULL),
(74,20,68,'210436','758','2028-02-28','758',2400.0000,27,'2026-06-13 12:11:55',NULL,88,NULL),
(75,20,69,'210436','758','2028-02-28','758',939.0000,27,'2026-06-13 12:12:28',NULL,89,NULL),
(76,19,62,'210436','756','2028-02-28','756',2400.0000,27,'2026-06-13 14:24:10',NULL,93,NULL),
(77,19,63,'210436','756','2028-02-28','756',2400.0000,27,'2026-06-13 14:24:36',NULL,95,NULL),
(78,19,64,'210436','756','2028-02-28','756',2400.0000,27,'2026-06-13 14:24:56',NULL,96,NULL),
(79,19,65,'210436','756','2028-02-28','756',887.0000,27,'2026-06-13 14:25:12',NULL,97,NULL),
(80,18,58,'210436','749','2027-12-31','749',2400.0000,27,'2026-06-13 14:32:09',NULL,99,NULL),
(81,18,59,'210436','749','2027-12-31','749',2400.0000,27,'2026-06-13 14:32:31',NULL,100,NULL),
(82,18,60,'210436','749','2027-12-31','749',2400.0000,27,'2026-06-13 14:32:54',NULL,101,NULL),
(83,18,61,'210436','749','2027-12-31','749',776.0000,27,'2026-06-13 14:33:12',NULL,102,NULL),
(84,22,74,'210436','743','2027-08-31','743',2400.0000,27,'2026-06-13 16:09:52',NULL,109,NULL),
(85,22,75,'210436','743','2027-08-31','743',2400.0000,27,'2026-06-13 16:10:12',NULL,111,NULL),
(86,22,76,'210436','743','2027-08-31','743',2455.0000,27,'2026-06-13 16:10:27',NULL,112,NULL),
(87,23,77,'410702','2606012','2027-06-30','12345',1.0000,27,'2026-06-15 15:21:38',NULL,113,NULL),
(88,23,78,'400066','2606013','2027-06-30','12345',1.0000,27,'2026-06-15 15:26:10',NULL,114,NULL),
(89,23,79,'401299','2606014','2027-06-30','12358',1.0000,27,'2026-06-15 15:28:44',NULL,115,NULL),
(90,24,80,'70938','006','2027-01-31','006',2880.0000,27,'2026-06-15 15:56:22',NULL,116,NULL),
(91,24,81,'70938','006','2027-01-31','006',1711.0000,27,'2026-06-15 15:56:43',NULL,117,NULL);

--
-- Table structure for table `relocations`
--

CREATE TABLE `relocations` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `relocation_number` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `container_id` int(10) unsigned NOT NULL,
  `from_bin_id` int(10) unsigned NOT NULL,
  `to_bin_id` int(10) unsigned NOT NULL,
  `zone_id` int(10) unsigned NOT NULL,
  `status` enum('PENDING','ASSIGNED','IN_PROGRESS','COMPLETED','CANCELLED') NOT NULL DEFAULT 'PENDING',
  `task_id` int(10) unsigned DEFAULT NULL,
  `assigned_to` int(10) unsigned DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `cancelled_at` datetime DEFAULT NULL,
  `cancelled_reason` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  `completed_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `relocation_number` (`relocation_number`),
  KEY `idx_reloc_container` (`container_id`),
  KEY `idx_reloc_status` (`status`),
  KEY `idx_reloc_assigned` (`assigned_to`),
  KEY `idx_reloc_warehouse` (`warehouse_id`),
  KEY `idx_reloc_task` (`task_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `relocations`
--

INSERT INTO `relocations` VALUES
(1,'RL-00000001',16,63,63,360,20,'COMPLETED',45,17,NULL,'2026-06-13 17:11:20',NULL,NULL,'2026-06-13 17:05:35','2026-06-13 17:11:20',9,17),
(2,'RL-00000002',16,69,6,361,20,'COMPLETED',46,17,NULL,'2026-06-13 17:25:14',NULL,NULL,'2026-06-13 17:17:37','2026-06-13 17:25:14',9,17),
(3,'RL-00000003',16,96,235,359,20,'COMPLETED',NULL,NULL,'Separacion 1 LPN por bin: LPN-00000095','2026-06-15 11:55:05',NULL,NULL,'2026-06-15 11:55:05','2026-06-15 11:55:05',1,1),
(4,'RL-00000004',16,88,300,494,20,'COMPLETED',NULL,NULL,'Separacion 1 LPN por bin: LPN-00000087','2026-06-15 11:55:05',NULL,NULL,'2026-06-15 11:55:05','2026-06-15 11:55:05',1,1),
(5,'RL-00000005',16,73,61,426,20,'COMPLETED',47,17,NULL,'2026-06-15 14:56:08',NULL,NULL,'2026-06-15 14:49:18','2026-06-15 14:56:08',9,17),
(6,'RL-00000006',16,62,2,358,20,'COMPLETED',48,17,NULL,'2026-06-15 15:35:18',NULL,NULL,'2026-06-15 15:27:05','2026-06-15 15:35:18',1,17),
(7,'RL-00000007',16,89,236,359,20,'COMPLETED',52,17,NULL,'2026-06-15 15:45:51',NULL,NULL,'2026-06-15 15:41:46','2026-06-15 15:45:51',9,17);

--
-- Table structure for table `rf_role_access`
--

CREATE TABLE `rf_role_access` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `role` varchar(40) NOT NULL,
  `view_key` varchar(40) NOT NULL,
  `access_type` enum('FULL','READ') NOT NULL DEFAULT 'FULL',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_rf_role_view` (`role`,`view_key`)
) ENGINE=InnoDB AUTO_INCREMENT=146 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `rf_role_access`
--

INSERT INTO `rf_role_access` VALUES
(4,'op_almacen','conteo','FULL'),
(5,'op_almacen','transferencia','FULL'),
(6,'op_almacen','reubicacion','FULL'),
(10,'qc_muestrista','qa','FULL'),
(12,'qa_liberador','qa','FULL'),
(17,'supervisor','conteo','FULL'),
(18,'supervisor','ajuste','FULL'),
(19,'supervisor','transferencia','FULL'),
(20,'supervisor','reubicacion','FULL'),
(25,'jefe','qa','FULL'),
(26,'jefe','conteo','FULL'),
(27,'jefe','ajuste','FULL'),
(28,'jefe','transferencia','FULL'),
(29,'jefe','reubicacion','FULL'),
(34,'auditor','qa','READ'),
(35,'auditor','conteo','READ'),
(36,'auditor','ajuste','READ'),
(37,'auditor','transferencia','READ'),
(38,'auditor','reubicacion','READ'),
(43,'admin','qa','FULL'),
(44,'admin','conteo','FULL'),
(45,'admin','ajuste','FULL'),
(46,'admin','transferencia','FULL'),
(47,'admin','reubicacion','FULL'),
(50,'operator','conteo','FULL'),
(51,'operator','transferencia','FULL'),
(52,'operator','reubicacion','FULL'),
(57,'viewer','qa','READ'),
(58,'viewer','conteo','READ'),
(59,'viewer','ajuste','READ'),
(60,'viewer','transferencia','READ'),
(61,'viewer','reubicacion','READ'),
(100,'op_recepcion','recepcion','FULL'),
(101,'supervisor','recepcion','FULL'),
(102,'jefe','recepcion','FULL'),
(103,'auditor','recepcion','READ'),
(104,'admin','recepcion','FULL'),
(105,'viewer','recepcion','READ'),
(106,'xpert','recepcion','FULL'),
(107,'op_almacen','putaway','FULL'),
(108,'supervisor','putaway','FULL'),
(109,'jefe','putaway','FULL'),
(110,'auditor','putaway','READ'),
(111,'admin','putaway','FULL'),
(112,'operator','putaway','FULL'),
(113,'viewer','putaway','READ'),
(114,'xpert','putaway','FULL'),
(115,'op_picking','picking','FULL'),
(116,'supervisor','picking','FULL'),
(117,'jefe','picking','FULL'),
(118,'auditor','picking','READ'),
(119,'admin','picking','FULL'),
(120,'viewer','picking','READ'),
(121,'xpert','picking','FULL'),
(122,'op_recepcion','consulta','READ'),
(123,'op_almacen','consulta','READ'),
(124,'op_picking','consulta','READ'),
(125,'qc_muestrista','consulta','READ'),
(126,'qa_liberador','consulta','READ'),
(127,'supervisor','consulta','READ'),
(128,'jefe','consulta','FULL'),
(129,'auditor','consulta','READ'),
(130,'admin','consulta','FULL'),
(131,'operator','consulta','READ'),
(132,'viewer','consulta','READ'),
(133,'xpert','consulta','FULL'),
(134,'op_recepcion','consulta-lpn','READ'),
(135,'op_almacen','consulta-lpn','READ'),
(136,'op_picking','consulta-lpn','READ'),
(137,'qc_muestrista','consulta-lpn','READ'),
(138,'qa_liberador','consulta-lpn','READ'),
(139,'supervisor','consulta-lpn','READ'),
(140,'jefe','consulta-lpn','FULL'),
(141,'auditor','consulta-lpn','READ'),
(142,'admin','consulta-lpn','FULL'),
(143,'operator','consulta-lpn','READ'),
(144,'viewer','consulta-lpn','READ'),
(145,'xpert','consulta-lpn','FULL');

--
-- Table structure for table `role_permissions`
--

CREATE TABLE `role_permissions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `role` enum('admin','supervisor','operator','viewer') NOT NULL,
  `module` varchar(50) NOT NULL,
  `action` varchar(50) NOT NULL,
  `allowed` tinyint(1) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_role_perm` (`role`,`module`,`action`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `role_permissions`
--

INSERT INTO `role_permissions` VALUES
(1,'admin','*','*',1),
(2,'supervisor','reception','*',1),
(3,'supervisor','putaway','*',1),
(4,'supervisor','stock','*',1),
(5,'supervisor','picking','*',1),
(6,'supervisor','packing','*',1),
(7,'supervisor','dispatch','*',1),
(8,'supervisor','qa','*',1),
(9,'supervisor','cycle_count','*',1),
(10,'supervisor','recall','*',1),
(11,'supervisor','transfer','*',1),
(12,'supervisor','users','view',1),
(13,'operator','reception','scan',1),
(14,'operator','reception','view',1),
(15,'operator','putaway','execute',1),
(16,'operator','putaway','view',1),
(17,'operator','picking','execute',1),
(18,'operator','picking','view',1),
(19,'operator','packing','scan',1),
(20,'operator','packing','view',1),
(21,'operator','dispatch','scan',1),
(22,'operator','dispatch','view',1),
(23,'operator','stock','view',1),
(24,'operator','cycle_count','count',1),
(25,'operator','transfer','execute',1),
(26,'viewer','*','view',1);

--
-- Table structure for table `roles`
--

CREATE TABLE `roles` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(40) NOT NULL,
  `name` varchar(80) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_system` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_roles_code` (`code`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `roles`
--

INSERT INTO `roles` VALUES
(1,'admin','Administrador','Acceso total al sistema, incluida la gestión de usuarios y roles.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(2,'jefe','Jefe de Almacén','Gestión integral del almacén y consulta directa de SAP.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(3,'supervisor','Supervisor','Coordinación del flujo logístico de entrada y salida.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(4,'op_recepcion','Operador de Recepción','Recepción de mercadería contra órdenes de compra.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(5,'op_almacen','Operador de Almacén','Putaway, transferencias, conteo y contenedores.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(6,'op_picking','Operador de Picking','Preparación y empaque de pedidos.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(7,'qc_muestrista','QC Muestrista','Toma de muestras y control de calidad.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(8,'qa_liberador','QA Liberador','Liberación de lotes, temperatura y compliance.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(9,'auditor','Auditor','Acceso de solo lectura a toda la operación.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(10,'operator','Operador (legacy)','Rol heredado equivalente a operador de almacén.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(11,'viewer','Visor (legacy)','Rol heredado de solo lectura.',1,1,'2026-06-06 13:37:23','2026-06-06 13:37:23'),
(14,'xpert','XPert','XPert',1,0,'2026-06-06 13:50:02','2026-06-06 13:50:02');

--
-- Table structure for table `sampling_requests`
--

CREATE TABLE `sampling_requests` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `request_number` varchar(30) NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `source_bin_id` int(10) unsigned DEFAULT NULL,
  `requested_qty` decimal(15,4) NOT NULL COMMENT 'Cantidad a traer del almacen',
  `sample_qty` decimal(15,4) DEFAULT NULL COMMENT 'Cantidad consumida en muestreo',
  `returned_qty` decimal(15,4) DEFAULT NULL COMMENT 'Cantidad devuelta al almacen',
  `uom` varchar(20) NOT NULL DEFAULT 'UN',
  `status` enum('REQUESTED','ASSIGNED','DELIVERED','SAMPLED','RETURNED','COMPLETED','CANCELLED') NOT NULL DEFAULT 'REQUESTED',
  `requested_by` int(10) unsigned NOT NULL,
  `assigned_to` int(10) unsigned DEFAULT NULL,
  `deliver_bin` varchar(50) DEFAULT 'MUESTREO' COMMENT 'Zona destino de la muestra',
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_status` (`status`),
  KEY `idx_item` (`item_id`),
  KEY `idx_batch` (`batch_id`),
  KEY `idx_assigned` (`assigned_to`),
  KEY `warehouse_id` (`warehouse_id`),
  KEY `requested_by` (`requested_by`),
  CONSTRAINT `sampling_requests_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `sampling_requests_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`),
  CONSTRAINT `sampling_requests_ibfk_3` FOREIGN KEY (`requested_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sampling_requests`
--


--
-- Table structure for table `sap_sync_log`
--

CREATE TABLE `sap_sync_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `sync_type` enum('MASTER_ITEMS','MASTER_WAREHOUSES','MASTER_BP','DOC_PURCHASE','DOC_SALES','DOC_DELIVERY','DOC_RECEIPT','BATCH','DOC_RECEPTION_AGENDA','DOC_PACKING','DOC_DISPATCH','DOC_RETURN','DOC_ADJUSTMENT','DOC_RECALL','BATCH_LOCK','BATCH_RELEASE','BATCH_REJECT','TRANSFER_REQUEST') NOT NULL,
  `direction` enum('SAP_TO_WMS','WMS_TO_SAP') NOT NULL,
  `sap_doc_entry` int(11) DEFAULT NULL,
  `sap_doc_num` varchar(30) DEFAULT NULL,
  `sap_doc_type` varchar(30) DEFAULT NULL,
  `wms_reference_id` int(10) unsigned DEFAULT NULL,
  `status` enum('PENDING','SUCCESS','ERROR','RETRY','WARN') NOT NULL DEFAULT 'PENDING',
  `request_payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`request_payload`)),
  `response_payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`response_payload`)),
  `error_message` text DEFAULT NULL,
  `retry_count` tinyint(3) unsigned NOT NULL DEFAULT 0,
  `max_retries` tinyint(3) unsigned NOT NULL DEFAULT 3,
  `next_retry_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_sync_type` (`sync_type`),
  KEY `idx_sync_status` (`status`),
  KEY `idx_sync_sap` (`sap_doc_entry`,`sap_doc_type`),
  KEY `idx_sync_retry` (`status`,`next_retry_at`)
) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Log de sincronización bidireccional con SAP B1';

--
-- Dumping data for table `sap_sync_log`
--

INSERT INTO `sap_sync_log` VALUES
(2,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',NULL,NULL,'StockTransfer',2,'ERROR',NULL,NULL,'Error SAP Service Layer: 480000112 - Batch/serial number 2606012 selected in row 1 does not exist; specify a valid batch/serial number',0,3,NULL,'2026-06-10 18:01:34','2026-06-10 18:01:34'),
(3,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2097,NULL,'StockTransfer',2,'SUCCESS',NULL,NULL,'Recuperacion manual: StockTransfer DocNum 1484 con lotes reales',0,3,NULL,'2026-06-10 18:12:39','2026-06-10 18:12:39'),
(4,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',5,'SUCCESS',NULL,NULL,'locked=1 already_locked=0 errors=0',0,3,NULL,'2026-06-10 18:33:40','2026-06-10 18:33:40'),
(5,'BATCH','WMS_TO_SAP',2099,NULL,'Acta_PDF',5,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000005.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-10 18:33:43','2026-06-10 18:33:43'),
(6,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2099,NULL,'StockTransfer',5,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-10 18:33:43','2026-06-10 18:33:43'),
(7,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',6,'SUCCESS',NULL,NULL,'locked=6 already_locked=1 errors=0',0,3,NULL,'2026-06-10 18:52:05','2026-06-10 18:52:05'),
(8,'BATCH','WMS_TO_SAP',2102,NULL,'Acta_PDF',6,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000006.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-10 18:52:06','2026-06-10 18:52:06'),
(9,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2102,NULL,'StockTransfer',6,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-10 18:52:06','2026-06-10 18:52:06'),
(10,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',7,'SUCCESS',NULL,NULL,'locked=2 already_locked=1 errors=0',0,3,NULL,'2026-06-10 18:55:43','2026-06-10 18:55:43'),
(11,'BATCH','WMS_TO_SAP',2104,NULL,'Acta_PDF',7,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000007.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-10 18:55:44','2026-06-10 18:55:44'),
(12,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2104,NULL,'StockTransfer',7,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-10 18:55:44','2026-06-10 18:55:44'),
(13,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',8,'SUCCESS',NULL,NULL,'locked=3 already_locked=0 errors=0',0,3,NULL,'2026-06-10 19:05:52','2026-06-10 19:05:52'),
(14,'BATCH','WMS_TO_SAP',2106,NULL,'Acta_PDF',8,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000008.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-10 19:05:53','2026-06-10 19:05:53'),
(15,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2106,NULL,'StockTransfer',8,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-10 19:05:53','2026-06-10 19:05:53'),
(16,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',9,'SUCCESS',NULL,NULL,'locked=2 already_locked=0 errors=0',0,3,NULL,'2026-06-10 19:22:04','2026-06-10 19:22:04'),
(17,'BATCH','WMS_TO_SAP',2108,NULL,'Acta_PDF',9,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000009.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-10 19:22:07','2026-06-10 19:22:07'),
(18,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2108,NULL,'StockTransfer',9,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-10 19:22:07','2026-06-10 19:22:07'),
(19,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',20,'SUCCESS',NULL,NULL,'batch=403964/2404108 SAP_DocEntry=6146 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:30:05','2026-06-10 19:30:05'),
(20,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',34,'SUCCESS',NULL,NULL,'batch=70074/029 SAP_DocEntry=119 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:30:31','2026-06-10 19:30:31'),
(21,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',29,'SUCCESS',NULL,NULL,'batch=605832/4026 SAP_DocEntry=979 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:30:54','2026-06-10 19:30:54'),
(22,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',21,'SUCCESS',NULL,NULL,'batch=403964/2301009 SAP_DocEntry=4384 bdsStatus_Released -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:31:35','2026-06-10 19:31:35'),
(23,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',18,'SUCCESS',NULL,NULL,'batch=402630/2509217 SAP_DocEntry=4195 bdsStatus_Released -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:31:52','2026-06-10 19:31:52'),
(24,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',36,'SUCCESS',NULL,NULL,'batch=31880/130J7 SAP_DocEntry=7644 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:32:08','2026-06-10 19:32:08'),
(25,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',33,'SUCCESS',NULL,NULL,'batch=70465/609 SAP_DocEntry=146 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:32:21','2026-06-10 19:32:21'),
(26,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',17,'SUCCESS',NULL,NULL,'batch=401975/2602061 SAP_DocEntry=4182 bdsStatus_Released -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:32:37','2026-06-10 19:32:37'),
(27,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',15,'SUCCESS',NULL,NULL,'batch=402965/2503070 SAP_DocEntry=6108 bdsStatus_Released -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:32:57','2026-06-10 19:32:57'),
(28,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',25,'SUCCESS',NULL,NULL,'batch=601827/003I2026 SAP_DocEntry=5659 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:33:15','2026-06-10 19:33:15'),
(29,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',22,'SUCCESS',NULL,NULL,'batch=600602/046I2026 SAP_DocEntry=5555 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:33:31','2026-06-10 19:33:31'),
(30,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',28,'SUCCESS',NULL,NULL,'batch=404066/2509225 SAP_DocEntry=6150 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:33:49','2026-06-10 19:33:49'),
(31,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',16,'SUCCESS',NULL,NULL,'batch=401281/2509227 SAP_DocEntry=4177 bdsStatus_Released -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:34:10','2026-06-10 19:34:10'),
(32,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',32,'SUCCESS',NULL,NULL,'batch=70421/056 SAP_DocEntry=2376 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:34:32','2026-06-10 19:34:32'),
(33,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',19,'SUCCESS',NULL,NULL,'batch=400004/2310242 SAP_DocEntry=5965 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:34:48','2026-06-10 19:34:48'),
(34,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',23,'SUCCESS',NULL,NULL,'batch=600623/303I2023 SAP_DocEntry=4608 bdsStatus_Released -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:35:02','2026-06-10 19:35:02'),
(35,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',30,'SUCCESS',NULL,NULL,'batch=410695/2602043 SAP_DocEntry=6154 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:35:14','2026-06-10 19:35:14'),
(36,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',35,'SUCCESS',NULL,NULL,'batch=31869/133M2 SAP_DocEntry=7641 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:35:39','2026-06-10 19:35:39'),
(37,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',27,'SUCCESS',NULL,NULL,'batch=601215/284I2023 SAP_DocEntry=4632 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-10 19:35:52','2026-06-10 19:35:52'),
(38,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',NULL,NULL,'StockTransfer',14,'ERROR',NULL,NULL,'Error SAP Service Layer: Invalid value  [StockTransferLines.BaseLine][line: 1]',0,3,NULL,'2026-06-11 14:49:38','2026-06-11 14:49:38'),
(39,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',14,'SUCCESS',NULL,NULL,'locked=5 already_locked=0 errors=0',0,3,NULL,'2026-06-11 15:05:57','2026-06-11 15:05:57'),
(40,'BATCH','WMS_TO_SAP',2111,NULL,'Acta_PDF',14,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000014.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-11 15:06:04','2026-06-11 15:06:04'),
(41,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2111,NULL,'StockTransfer',14,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-11 15:06:04','2026-06-11 15:06:04'),
(42,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',16,'SUCCESS',NULL,NULL,'locked=0 already_locked=1 errors=0',0,3,NULL,'2026-06-13 10:22:41','2026-06-13 10:22:41'),
(43,'BATCH','WMS_TO_SAP',125,NULL,'Acta_PDF',16,'WARN',NULL,NULL,'endpoint=PurchaseDeliveryNotes acta_local_ok=/var/www/WMS/storage/actas/AG-00000016.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-13 10:22:42','2026-06-13 10:22:42'),
(44,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',125,NULL,'PurchaseDeliveryNote',16,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-13 10:22:42','2026-06-13 10:22:42'),
(45,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',21,'SUCCESS',NULL,NULL,'locked=1 already_locked=3 errors=0',0,3,NULL,'2026-06-13 11:50:31','2026-06-13 11:50:31'),
(46,'BATCH','WMS_TO_SAP',2113,NULL,'Acta_PDF',21,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000021.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-13 11:50:34','2026-06-13 11:50:34'),
(47,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2113,NULL,'StockTransfer',21,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-13 11:50:34','2026-06-13 11:50:34'),
(48,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',20,'SUCCESS',NULL,NULL,'locked=1 already_locked=3 errors=0',0,3,NULL,'2026-06-13 12:12:38','2026-06-13 12:12:38'),
(49,'BATCH','WMS_TO_SAP',2115,NULL,'Acta_PDF',20,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000020.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-13 12:12:39','2026-06-13 12:12:39'),
(50,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2115,NULL,'StockTransfer',20,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-13 12:12:39','2026-06-13 12:12:39'),
(51,'BATCH_RELEASE','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',37,'SUCCESS',NULL,NULL,'batch=210436/746 SAP_DocEntry=48 bdsStatus_Locked -> bdsStatus_Released',0,3,NULL,'2026-06-13 12:47:26','2026-06-13 12:47:26'),
(52,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',19,'SUCCESS',NULL,NULL,'locked=1 already_locked=3 errors=0',0,3,NULL,'2026-06-13 14:31:27','2026-06-13 14:31:27'),
(53,'BATCH','WMS_TO_SAP',2116,NULL,'Acta_PDF',19,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000019.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-13 14:31:30','2026-06-13 14:31:30'),
(54,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2116,NULL,'StockTransfer',19,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-13 14:31:30','2026-06-13 14:31:30'),
(55,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',18,'SUCCESS',NULL,NULL,'locked=1 already_locked=3 errors=0',0,3,NULL,'2026-06-13 14:33:53','2026-06-13 14:33:53'),
(56,'BATCH','WMS_TO_SAP',2118,NULL,'Acta_PDF',18,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000018.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-13 14:33:54','2026-06-13 14:33:54'),
(57,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2118,NULL,'StockTransfer',18,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-13 14:33:54','2026-06-13 14:33:54'),
(58,'DOC_PACKING','WMS_TO_SAP',NULL,NULL,'PackingComplete',1,'PENDING',NULL,NULL,'Esperando despacho para crear DeliveryNote',0,3,NULL,'2026-06-13 15:03:52','2026-06-13 15:03:52'),
(59,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',22,'SUCCESS',NULL,NULL,'locked=1 already_locked=2 errors=0',0,3,NULL,'2026-06-13 16:10:38','2026-06-13 16:10:38'),
(60,'BATCH','WMS_TO_SAP',2120,NULL,'Acta_PDF',22,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000022.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-13 16:10:40','2026-06-13 16:10:40'),
(61,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2120,NULL,'StockTransfer',22,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-13 16:10:40','2026-06-13 16:10:40'),
(62,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',23,'SUCCESS',NULL,NULL,'locked=0 already_locked=3 errors=0',0,3,NULL,'2026-06-15 15:29:21','2026-06-15 15:29:21'),
(63,'BATCH','WMS_TO_SAP',127,NULL,'Acta_PDF',23,'WARN',NULL,NULL,'endpoint=PurchaseDeliveryNotes acta_local_ok=/var/www/WMS/storage/actas/AG-00000023.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-15 15:29:22','2026-06-15 15:29:22'),
(64,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',127,NULL,'PurchaseDeliveryNote',23,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-15 15:29:22','2026-06-15 15:29:22'),
(65,'BATCH_LOCK','WMS_TO_SAP',NULL,NULL,'BatchNumberDetails',24,'SUCCESS',NULL,NULL,'locked=1 already_locked=1 errors=0',0,3,NULL,'2026-06-15 15:56:59','2026-06-15 15:56:59'),
(66,'BATCH','WMS_TO_SAP',2122,NULL,'Acta_PDF',24,'WARN',NULL,NULL,'endpoint=StockTransfers acta_local_ok=/var/www/WMS/storage/actas/AG-00000024.pdf sap_attach_fail=Error SAP /Attachments2: Attachments folder not defined, or Attachments folder has been changed or removed ',0,3,NULL,'2026-06-15 15:57:00','2026-06-15 15:57:00'),
(67,'DOC_RECEPTION_AGENDA','WMS_TO_SAP',2122,NULL,'StockTransfer',24,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-15 15:57:00','2026-06-15 15:57:00'),
(68,'DOC_PACKING','WMS_TO_SAP',NULL,NULL,'PackingComplete',2,'PENDING',NULL,NULL,'Esperando despacho para crear DeliveryNote',0,3,NULL,'2026-06-15 17:02:49','2026-06-15 17:02:49'),
(69,'DOC_DISPATCH','WMS_TO_SAP',1826,NULL,'DeliveryNote',2,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-15 17:05:50','2026-06-15 17:05:50'),
(70,'DOC_PACKING','WMS_TO_SAP',NULL,NULL,'PackingComplete',3,'PENDING',NULL,NULL,'Esperando despacho para crear DeliveryNote',0,3,NULL,'2026-06-15 17:18:16','2026-06-15 17:18:16'),
(71,'DOC_DISPATCH','WMS_TO_SAP',1829,NULL,'DeliveryNote',3,'SUCCESS',NULL,NULL,NULL,0,3,NULL,'2026-06-15 17:20:43','2026-06-15 17:20:43');

--
-- Table structure for table `settings`
--

CREATE TABLE `settings` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `setting_key` varchar(100) NOT NULL,
  `setting_value` text NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `setting_key` (`setting_key`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `settings`
--

INSERT INTO `settings` VALUES
(1,'pwd_min_length','4','Longitud minima','2026-06-05 14:07:05'),
(2,'pwd_require_uppercase','1','Requiere mayuscula','2026-04-17 18:12:09'),
(3,'pwd_require_lowercase','1','Requiere minuscula','2026-04-17 18:12:09'),
(4,'pwd_require_number','1','Requiere numero','2026-04-17 18:12:09'),
(5,'pwd_require_special','1','Requiere caracter especial','2026-04-17 18:12:09'),
(6,'pwd_special_chars','*.\'!','Caracteres especiales','2026-04-17 18:12:09');

--
-- Table structure for table `sops`
--

CREATE TABLE `sops` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sop_code` varchar(30) NOT NULL,
  `title` varchar(200) NOT NULL,
  `process` varchar(50) NOT NULL COMMENT 'recepcion, almacenamiento, picking, despacho, devoluciones, recall, inventarios, sistema',
  `version` varchar(10) NOT NULL DEFAULT '1.0',
  `status` enum('DRAFT','ACTIVE','OBSOLETE') NOT NULL DEFAULT 'DRAFT',
  `content` longtext NOT NULL COMMENT 'HTML content of the SOP',
  `approved_by` int(10) unsigned DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `effective_date` date DEFAULT NULL,
  `review_date` date DEFAULT NULL,
  `created_by` int(10) unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sop_code_ver` (`sop_code`,`version`),
  KEY `idx_sop_process` (`process`),
  KEY `idx_sop_status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sops`
--

INSERT INTO `sops` VALUES
(1,'SOP-REC-001','Recepcion de Mercaderia','recepcion','1.0','ACTIVE','<div class=\"sop-document\">\n<div class=\"sop-header\">\n<table style=\"width:100%;border-collapse:collapse;border:2px solid #334155\">\n<tr>\n<td rowspan=\"4\" style=\"width:200px;text-align:center;padding:10px;border:1px solid #334155\"><strong style=\"font-size:20px;color:#3b82f6\">XPert WMS</strong><br><span style=\"font-size:11px;color:#94a3b8\">Sistema de Gestion de Almacenes</span><br><span style=\"font-size:11px;color:#94a3b8\">COMFAR S.A.</span></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>PROCEDIMIENTO OPERATIVO ESTANDAR</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155;width:180px\"><strong>Codigo:</strong> SOP-REC-001</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Recepcion de Mercaderia</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Version:</strong> 1.0</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Proceso:</strong> Recepcion</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Vigencia:</strong> 2026-04-06</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Departamento:</strong> Logistica / Almacen</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Revision:</strong> 2027-04-06</td>\n</tr>\n</table>\n</div>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">1. OBJETIVO</h2>\n<p>Establecer el procedimiento estandarizado para la recepcion de mercaderias en el almacen de COMFAR S.A., garantizando la verificacion completa de cantidad, calidad y trazabilidad de todos los productos farmaceuticos, cosmeticos y dispositivos medicos recibidos, en cumplimiento con las Buenas Practicas de Almacenamiento (BPA) exigidas por DINAVISA.</p>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">2. ALCANCE</h2>\n<p>Este procedimiento aplica a todas las recepciones de mercaderia en los almacenes gestionados por XPert WMS, incluyendo:</p>\n<ul>\n<li><strong>Importaciones:</strong> Mercaderia proveniente del exterior con documentacion aduanera</li>\n<li><strong>Compras plaza:</strong> Adquisiciones a proveedores locales</li>\n<li><strong>Devoluciones de clientes:</strong> Productos retornados por clientes</li>\n<li><strong>Transferencias de produccion:</strong> Producto terminado desde planta</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">3. RESPONSABILIDADES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Cargo</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Responsabilidad</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Almacen</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Planificar agendas de recepcion. Asignar recursos. Aprobar diferencias.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Operador de Recepcion</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Ejecutar el escaneo ciego de mercaderia con colector. Registrar datos de lote y vencimiento.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Control de Calidad</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Liberar o rechazar lotes segun control organolectico e inspecciones.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Administrativo</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Crear agendas, asociar ordenes de compra SAP, verificar documentacion.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">4. DEFINICIONES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Termino</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Definicion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Agenda de Recepcion</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Documento de planificacion en XPert WMS que agrupa las ordenes de compra esperadas para una fecha y proveedor.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Escaneo Ciego</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Metodo de recepcion donde el operador escanea y cuenta la mercaderia sin ver las cantidades esperadas, garantizando veracidad.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>FEFO</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">First Expired, First Out. Politica de despacho de productos farmaceuticos obligatoria por DINAVISA.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>LPN (License Plate Number)</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Codigo unico asignado a cada contenedor/pallet recibido para trazabilidad completa.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>OC</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Orden de Compra en SAP Business One.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">5. PROCEDIMIENTO</h2>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.1 Planificacion - Crear Agenda de Recepcion</h3>\n<ol>\n<li>Acceder al modulo <strong>Agendas</strong> en XPert WMS desde el menu lateral.</li>\n<li>Hacer clic en <strong>\"+ Nueva Agenda\"</strong>.</li>\n<li>Completar: almacen destino, proveedor, fecha esperada, tipo de recepcion (importacion/plaza/devolucion/produccion).</li>\n<li>Asociar una o mas <strong>Ordenes de Compra SAP</strong> usando el boton \"Agregar Referencia\". El sistema carga automaticamente las lineas esperadas desde SAP B1.</li>\n<li>Verificar que las lineas cargadas coincidan con la documentacion (factura, remito, packing list).</li>\n<li>Guardar la agenda. Estado inicial: <strong>PLANNED</strong>.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.2 Apertura de Recepcion</h3>\n<ol>\n<li>Cuando el proveedor/transportista llega al almacen, abrir la agenda correspondiente.</li>\n<li>Hacer clic en <strong>\"Abrir Recepcion\"</strong>. El estado cambia a <strong>OPEN</strong>.</li>\n<li>El sistema registra automaticamente la fecha/hora de inicio y el usuario responsable.</li>\n<li>Verificar documentacion: factura, remito, certificados de calidad, registros sanitarios DINAVISA.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.3 Escaneo Ciego con Colector</h3>\n<ol>\n<li>El operador de almacen utiliza el colector de datos (RF) o la interfaz movil de XPert WMS.</li>\n<li>Escanear el <strong>codigo de barras (EAN/DUN14)</strong> de cada producto recibido.</li>\n<li>El sistema identifica automaticamente el articulo por su codigo de barras.</li>\n<li>Registrar para cada linea:\n  <ul>\n  <li><strong>Cantidad recibida</strong> (unidades, cajas, pallets)</li>\n  <li><strong>Numero de lote</strong> del fabricante</li>\n  <li><strong>Fecha de vencimiento</strong></li>\n  <li><strong>Numero de serie</strong> (si aplica)</li>\n  </ul>\n</li>\n<li><strong>IMPORTANTE:</strong> El operador NO ve las cantidades esperadas durante el escaneo (metodo ciego). Esto asegura una verificacion independiente y confiable.</li>\n<li>El sistema genera etiquetas LPN automaticamente para cada bulto/pallet escaneado.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.4 Verificacion de Diferencias</h3>\n<ol>\n<li>Al finalizar el escaneo, hacer clic en <strong>\"Ver Diferencias\"</strong>.</li>\n<li>XPert WMS muestra automaticamente la comparacion entre cantidades esperadas (OC SAP) y cantidades escaneadas.</li>\n<li>Los estados posibles por linea son:\n  <ul>\n  <li><span style=\"color:#22c55e\"><strong>OK</strong></span> - Cantidad coincide exactamente</li>\n  <li><span style=\"color:#f59e0b\"><strong>PARCIAL</strong></span> - Cantidad recibida menor a la esperada</li>\n  <li><span style=\"color:#ef4444\"><strong>EXCESO</strong></span> - Cantidad recibida mayor a la esperada</li>\n  <li><span style=\"color:#ef4444\"><strong>FALTANTE</strong></span> - Producto esperado no recibido</li>\n  </ul>\n</li>\n<li>Si hay diferencias, el Jefe de Almacen debe revisar y decidir: aceptar, reclamar al proveedor, o rechazar.</li>\n<li>Documentar todas las diferencias con fotos y observaciones en el campo de notas.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.5 Cierre de Agenda y Confirmacion a SAP</h3>\n<ol>\n<li>Una vez verificada la mercaderia, hacer clic en <strong>\"Cerrar Agenda\"</strong>.</li>\n<li>XPert WMS genera automaticamente la <strong>Entrada de Mercaderia</strong> en SAP B1 basada en la recepcion real.</li>\n<li>Los lotes se crean automaticamente en SAP con su numero de lote, fecha de fabricacion y vencimiento.</li>\n<li>El stock queda disponible en estado <strong>QA (Cuarentena)</strong> hasta que Control de Calidad lo libere.</li>\n<li>Se genera el registro de trazabilidad completo: quien recibio, cuando, que cantidades, de que proveedor.</li>\n</ol>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">6. REGISTROS ASOCIADOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Registro</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Ubicacion</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Retencion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Agenda de Recepcion</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Agendas</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Registro de Escaneo (lineas escaneadas)</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Recepcion > Detalle</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Reporte de Diferencias</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Agendas > Diferencias</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Entrada de Mercaderia SAP</td><td style=\"padding:8px 12px;border:1px solid #475569\">SAP B1 > Entradas de Mercaderia</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Etiquetas LPN generadas</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Etiquetas</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">7. CONTROL DE CAMBIOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Version</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Fecha</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Descripcion del Cambio</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Autor</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">1.0</td><td style=\"padding:8px 12px;border:1px solid #475569\">2026-04-06</td><td style=\"padding:8px 12px;border:1px solid #475569\">Emision inicial del procedimiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">Administracion WMS</td></tr>\n</table>\n</div>',1,'2026-04-11 10:44:11','2026-04-06','2027-04-06',1,'2026-04-11 10:44:11','2026-04-11 10:44:11'),
(2,'SOP-ALM-001','Almacenamiento (Putaway)','almacenamiento','1.0','ACTIVE','<div class=\"sop-document\">\n<div class=\"sop-header\">\n<table style=\"width:100%;border-collapse:collapse;border:2px solid #334155\">\n<tr>\n<td rowspan=\"4\" style=\"width:200px;text-align:center;padding:10px;border:1px solid #334155\"><strong style=\"font-size:20px;color:#3b82f6\">XPert WMS</strong><br><span style=\"font-size:11px;color:#94a3b8\">Sistema de Gestion de Almacenes</span><br><span style=\"font-size:11px;color:#94a3b8\">COMFAR S.A.</span></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>PROCEDIMIENTO OPERATIVO ESTANDAR</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155;width:180px\"><strong>Codigo:</strong> SOP-ALM-001</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Almacenamiento (Putaway)</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Version:</strong> 1.0</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Proceso:</strong> Almacenamiento</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Vigencia:</strong> 2026-04-06</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Departamento:</strong> Logistica / Almacen</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Revision:</strong> 2027-04-06</td>\n</tr>\n</table>\n</div>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">1. OBJETIVO</h2>\n<p>Definir el procedimiento para el almacenamiento correcto de mercaderia recibida en las ubicaciones asignadas del almacen, garantizando la trazabilidad de lotes, el cumplimiento de la politica FEFO (First Expired, First Out), y las condiciones de almacenamiento exigidas por DINAVISA segun la naturaleza del producto (temperatura ambiente, cadena de frio, controlados).</p>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">2. ALCANCE</h2>\n<p>Aplica a todo el producto que ingresa a las zonas de almacenamiento tras haber sido recibido y liberado por QA (o en estado cuarentena con ubicacion de cuarentena asignada). Incluye:</p>\n<ul>\n<li><strong>Putaway Agrupado:</strong> Almacenamiento de pallets completos con etiqueta LPN</li>\n<li><strong>Putaway Fraccionado por Producto:</strong> Almacenamiento de cajas sueltas dirigido por item</li>\n<li><strong>Putaway Fraccionado por Ubicacion:</strong> Almacenamiento dirigido a una ubicacion especifica</li>\n<li><strong>Putaway Libre:</strong> El operador elige la ubicacion destino manualmente</li>\n<li><strong>Zonas especiales:</strong> Cadena de frio, controlados, inflamables, cuarentena, averias</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">3. RESPONSABILIDADES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Cargo</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Responsabilidad</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Almacen</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Definir reglas de almacenamiento por zona. Configurar estrategias de putaway en XPert WMS.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Operador de Almacen</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Ejecutar el almacenamiento con colector. Confirmar ubicaciones escaneando codigos de ubicacion.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Control de Calidad</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Liberar lotes de cuarentena para que puedan ser almacenados en ubicaciones de picking.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">4. DEFINICIONES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Termino</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Definicion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Putaway</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Proceso de colocar la mercaderia recibida en su ubicacion de almacenamiento definitiva.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Ubicacion (Bin)</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Posicion fisica identificada con codigo unico en la estanteria (pasillo-columna-nivel).</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Zona</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Agrupacion logica de ubicaciones con condiciones similares (temperatura, seguridad, tipo producto).</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>FEFO</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">First Expired, First Out. Los lotes con vencimiento mas proximo se despachan primero.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Sugerencia de Ubicacion</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Ubicacion recomendada por XPert WMS basada en reglas configuradas (mismo producto, zona correcta, capacidad disponible).</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">5. PROCEDIMIENTO</h2>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.1 Putaway Agrupado (Pallet completo)</h3>\n<ol>\n<li>Acceder al modulo <strong>Putaway</strong> en XPert WMS.</li>\n<li>Seleccionar <strong>\"Putaway Agrupado\"</strong>.</li>\n<li>Escanear la <strong>etiqueta LPN</strong> del pallet recibido.</li>\n<li>XPert WMS muestra automaticamente la <strong>ubicacion sugerida</strong> basada en:\n  <ul>\n  <li>Zona correcta segun tipo de producto (frio, ambiente, controlados)</li>\n  <li>Proximidad a ubicaciones con el mismo producto (consolidacion)</li>\n  <li>Capacidad disponible en la ubicacion</li>\n  </ul>\n</li>\n<li>Dirigirse a la ubicacion sugerida y <strong>escanear el codigo de la ubicacion destino</strong>.</li>\n<li>Confirmar el almacenamiento. El sistema registra el movimiento con trazabilidad completa.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.2 Putaway Fraccionado por Producto</h3>\n<ol>\n<li>Seleccionar <strong>\"Fraccionado por Producto\"</strong> en el menu de Putaway.</li>\n<li>Escanear o ingresar el <strong>codigo del producto</strong>.</li>\n<li>Seleccionar el <strong>lote</strong> y la <strong>cantidad</strong> a almacenar.</li>\n<li>XPert WMS sugiere la ubicacion optima.</li>\n<li>Escanear la ubicacion destino y confirmar.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.3 Putaway Fraccionado por Ubicacion</h3>\n<ol>\n<li>Seleccionar <strong>\"Fraccionado por Ubicacion\"</strong>.</li>\n<li>Escanear la <strong>ubicacion destino</strong> primero.</li>\n<li>Luego escanear los productos que se colocaran en esa ubicacion.</li>\n<li>Ingresar cantidades y lotes para cada producto.</li>\n<li>Confirmar el almacenamiento.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.4 Putaway Libre</h3>\n<ol>\n<li>Seleccionar <strong>\"Putaway Libre\"</strong>.</li>\n<li>Escanear el producto o etiqueta LPN.</li>\n<li>El operador elige manualmente la ubicacion destino.</li>\n<li>Escanear la ubicacion elegida.</li>\n<li>Confirmar. El sistema valida que la zona sea compatible con el tipo de producto.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.5 Consideraciones especiales</h3>\n<ul>\n<li><strong>Productos cadena de frio:</strong> Solo pueden almacenarse en zonas con control de temperatura activo (ver SOP-SIS-001 para monitoreo).</li>\n<li><strong>Productos controlados:</strong> Requieren zona de acceso restringido.</li>\n<li><strong>Productos en cuarentena:</strong> Se almacenan en zona QA hasta liberacion por Control de Calidad.</li>\n<li><strong>El sistema impide</strong> almacenar productos en zonas incompatibles con su clasificacion.</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">6. REGISTROS ASOCIADOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Registro</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Ubicacion</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Retencion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Movimiento de Putaway</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Trazabilidad</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Tarea de Almacenamiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Tareas</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Log de Ubicaciones</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Stock</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">7. CONTROL DE CAMBIOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Version</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Fecha</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Descripcion del Cambio</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Autor</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">1.0</td><td style=\"padding:8px 12px;border:1px solid #475569\">2026-04-06</td><td style=\"padding:8px 12px;border:1px solid #475569\">Emision inicial del procedimiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">Administracion WMS</td></tr>\n</table>\n</div>',1,'2026-04-11 10:44:11','2026-04-06','2027-04-06',1,'2026-04-11 10:44:11','2026-04-11 10:44:11'),
(3,'SOP-DES-001','Despacho de Pedidos','despacho','1.0','ACTIVE','<div class=\"sop-document\">\n<div class=\"sop-header\">\n<table style=\"width:100%;border-collapse:collapse;border:2px solid #334155\">\n<tr>\n<td rowspan=\"4\" style=\"width:200px;text-align:center;padding:10px;border:1px solid #334155\"><strong style=\"font-size:20px;color:#3b82f6\">XPert WMS</strong><br><span style=\"font-size:11px;color:#94a3b8\">Sistema de Gestion de Almacenes</span><br><span style=\"font-size:11px;color:#94a3b8\">COMFAR S.A.</span></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>PROCEDIMIENTO OPERATIVO ESTANDAR</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155;width:180px\"><strong>Codigo:</strong> SOP-DES-001</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Despacho de Pedidos</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Version:</strong> 1.0</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Proceso:</strong> Despacho</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Vigencia:</strong> 2026-04-06</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Departamento:</strong> Logistica / Expedicion</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Revision:</strong> 2027-04-06</td>\n</tr>\n</table>\n</div>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">1. OBJETIVO</h2>\n<p>Establecer el procedimiento para el despacho de pedidos de venta desde el almacen, abarcando las etapas de picking (recoleccion), packing (empaque), y expedicion (carga al camion), asegurando la correcta trazabilidad de lotes despachados y el cumplimiento de la politica FEFO exigida por DINAVISA.</p>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">2. ALCANCE</h2>\n<p>Aplica a todos los despachos de mercaderia desde los almacenes gestionados por XPert WMS:</p>\n<ul>\n<li><strong>Pedidos de venta (OV SAP):</strong> Despacho regular a clientes</li>\n<li><strong>Pedidos de mostrador:</strong> Venta directa con retiro inmediato</li>\n<li><strong>Transferencias entre almacenes:</strong> Movimiento interno entre depositos</li>\n<li><strong>Exportaciones:</strong> Despacho a clientes del exterior</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">3. RESPONSABILIDADES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Cargo</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Responsabilidad</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Almacen</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Crear y liberar ondas de picking. Gestionar prioridades de despacho.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Picker (Recolector)</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Recolectar productos de las ubicaciones de picking siguiendo las instrucciones del colector.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Operador de Packing</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Verificar y empacar los productos en la mesa de empaque. Generar contenedores.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Expedidor</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Cargar contenedores al camion. Escanear y cerrar el despacho.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">4. DEFINICIONES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Termino</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Definicion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Onda de Picking</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Agrupacion de multiples pedidos que se preparan simultaneamente para optimizar los recorridos en el almacen.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Pick List</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Lista de recoleccion individual asignada a un picker con las ubicaciones y cantidades a recolectar.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Packing Order</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Orden de empaque generada a partir del picking completado.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Despacho/Expedicion</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Documento que agrupa los contenedores cargados en un camion para su envio.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">5. PROCEDIMIENTO</h2>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.1 Creacion y Liberacion de Onda de Picking</h3>\n<ol>\n<li>Acceder al modulo <strong>Ondas de Picking</strong> en XPert WMS.</li>\n<li>Hacer clic en <strong>\"+ Nueva Onda\"</strong>.</li>\n<li>Seleccionar los pedidos de venta (OV SAP) a incluir en la onda.</li>\n<li>XPert WMS valida automaticamente:\n  <ul>\n  <li>Disponibilidad de stock por producto y lote</li>\n  <li>Cumplimiento de politica FEFO (selecciona automaticamente los lotes con vencimiento mas proximo)</li>\n  <li>Reserva de stock para evitar conflictos entre ondas</li>\n  </ul>\n</li>\n<li>Si hay faltantes, el sistema genera <strong>rechazos</strong> que se muestran para resolucion.</li>\n<li>Hacer clic en <strong>\"Liberar Onda\"</strong>. Se generan las pick lists individuales.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.2 Picking con Colector</h3>\n<ol>\n<li>El picker accede al modulo <strong>Picking</strong> desde su colector o interfaz movil.</li>\n<li>Selecciona la pick list asignada.</li>\n<li>El sistema guia al picker con la ruta optimizada:\n  <ul>\n  <li>Muestra la ubicacion a visitar</li>\n  <li>El producto a recolectar</li>\n  <li>El lote especifico (FEFO)</li>\n  <li>La cantidad requerida</li>\n  </ul>\n</li>\n<li>En cada ubicacion, el picker:\n  <ol type=\"a\">\n  <li>Escanea el <strong>codigo de ubicacion</strong> (el sistema valida que sea la correcta)</li>\n  <li>Escanea el <strong>codigo de barras del producto</strong> (el sistema valida el articulo)</li>\n  <li>Ingresa la <strong>cantidad recolectada</strong></li>\n  <li>Confirma la linea</li>\n  </ol>\n</li>\n<li>Si la cantidad disponible es menor a la requerida, se registra como <strong>picking parcial</strong>.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.3 Control en Mesa de Empaque (Packing)</h3>\n<ol>\n<li>Acceder al modulo <strong>Packing</strong> en XPert WMS.</li>\n<li>Seleccionar la orden de packing pendiente.</li>\n<li>El operador de packing verifica cada producto escaneando su codigo de barras.</li>\n<li>Agrupa los productos por cliente en contenedores (cajas de despacho).</li>\n<li>Genera etiquetas de despacho para cada contenedor con datos de: cliente, pedido, peso, contenido.</li>\n<li>Marca la orden de packing como <strong>COMPLETADA</strong>.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.4 Expedicion / Carga al Camion</h3>\n<ol>\n<li>Acceder al modulo <strong>Expedicion</strong>.</li>\n<li>Crear un nuevo despacho: asignar placa del camion, transportista, ruta.</li>\n<li>Asignar las ordenes de packing completadas al despacho.</li>\n<li>En la zona de carga, escanear cada <strong>contenedor</strong> al subirlo al camion.</li>\n<li>El sistema valida que todos los contenedores del despacho esten cargados.</li>\n<li>Hacer clic en <strong>\"Cerrar Despacho\"</strong>.</li>\n<li>XPert WMS genera automaticamente la <strong>Entrega (Delivery Note)</strong> en SAP B1.</li>\n<li>Se imprime el packing list del camion con el detalle de todo lo despachado.</li>\n</ol>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">6. REGISTROS ASOCIADOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Registro</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Ubicacion</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Retencion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Onda de Picking</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Ondas</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Pick List (detalle de recoleccion)</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Picking</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Orden de Packing</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Packing</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Despacho (contenedores cargados)</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Expedicion</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Entrega SAP (Delivery Note)</td><td style=\"padding:8px 12px;border:1px solid #475569\">SAP B1 > Entregas</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Packing List del camion</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Expedicion > Packing List</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">7. CONTROL DE CAMBIOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Version</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Fecha</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Descripcion del Cambio</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Autor</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">1.0</td><td style=\"padding:8px 12px;border:1px solid #475569\">2026-04-06</td><td style=\"padding:8px 12px;border:1px solid #475569\">Emision inicial del procedimiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">Administracion WMS</td></tr>\n</table>\n</div>',1,'2026-04-11 10:44:11','2026-04-06','2027-04-06',1,'2026-04-11 10:44:11','2026-04-11 10:44:11'),
(4,'SOP-DEV-001','Devoluciones','devoluciones','1.0','ACTIVE','<div class=\"sop-document\">\n<div class=\"sop-header\">\n<table style=\"width:100%;border-collapse:collapse;border:2px solid #334155\">\n<tr>\n<td rowspan=\"4\" style=\"width:200px;text-align:center;padding:10px;border:1px solid #334155\"><strong style=\"font-size:20px;color:#3b82f6\">XPert WMS</strong><br><span style=\"font-size:11px;color:#94a3b8\">Sistema de Gestion de Almacenes</span><br><span style=\"font-size:11px;color:#94a3b8\">COMFAR S.A.</span></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>PROCEDIMIENTO OPERATIVO ESTANDAR</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155;width:180px\"><strong>Codigo:</strong> SOP-DEV-001</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Devoluciones</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Version:</strong> 1.0</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Proceso:</strong> Devoluciones</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Vigencia:</strong> 2026-04-06</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Departamento:</strong> Logistica / Calidad</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Revision:</strong> 2027-04-06</td>\n</tr>\n</table>\n</div>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">1. OBJETIVO</h2>\n<p>Definir el procedimiento para la recepcion, evaluacion y disposicion de productos devueltos al almacen, asegurando la trazabilidad completa del lote devuelto, la evaluacion de calidad correspondiente, y el cumplimiento de las normativas DINAVISA para productos farmaceuticos retornados.</p>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">2. ALCANCE</h2>\n<ul>\n<li><strong>Devoluciones de clientes:</strong> Productos retornados por error de despacho, dano en transporte, vencimiento proximo</li>\n<li><strong>Canjes:</strong> Reemplazo de producto por vencimiento o deterioro acordado comercialmente</li>\n<li><strong>Recall:</strong> Retiro de producto del mercado por orden de DINAVISA o decision interna (ver SOP-RCL-001)</li>\n<li><strong>Devolucion a planta:</strong> Retorno de materia prima o producto no conforme al fabricante</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">3. RESPONSABILIDADES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Cargo</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Responsabilidad</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Almacen</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Autorizar la recepcion de devoluciones. Coordinar con Comercial.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Operador de Recepcion</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Recibir fisicamente la devolucion. Escanear productos a ciegas.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Control de Calidad</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Evaluar el estado del producto devuelto. Decidir destino: reintegro, destruccion, cuarentena.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Comercial</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Generar la Nota de Credito en SAP B1. Coordinar con el cliente.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">4. DEFINICIONES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Termino</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Definicion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Devolucion</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Retorno de mercaderia previamente despachada por cualquier motivo.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Zona de Averias</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Area segregada del almacen para productos danados, vencidos o en evaluacion.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Nota de Credito</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Documento SAP que revierte parcial o totalmente una factura de venta.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">5. PROCEDIMIENTO</h2>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.1 Creacion de la Devolucion</h3>\n<ol>\n<li>Acceder al modulo <strong>Devoluciones</strong> en XPert WMS.</li>\n<li>Hacer clic en <strong>\"+ Nueva Devolucion\"</strong>.</li>\n<li>Seleccionar el almacen destino.</li>\n<li>Ingresar el tipo de devolucion: Cliente, Canje, Recall, Planta.</li>\n<li>Asociar la Nota de Credito SAP (si existe) o crear sin referencia SAP.</li>\n<li>Ingresar datos del cliente/proveedor y motivo de la devolucion.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.2 Recepcion a Ciegas de la Devolucion</h3>\n<ol>\n<li>Cuando el producto llega fisicamente, el operador abre la devolucion en XPert WMS.</li>\n<li>Escanear cada producto devuelto con el colector (escaneo ciego, sin ver cantidades esperadas).</li>\n<li>Registrar: codigo de producto, lote, cantidad, fecha de vencimiento.</li>\n<li>Registrar observaciones visuales: estado del empaque, cadena de frio, condicion general.</li>\n<li>Confirmar cada linea recibida.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.3 Evaluacion de Calidad (QA)</h3>\n<ol>\n<li>Los productos devueltos quedan automaticamente en estado <strong>QA (Cuarentena)</strong>.</li>\n<li>Control de Calidad accede al modulo <strong>QA</strong> > Pendientes de Evaluacion.</li>\n<li>Evalua cada producto segun:\n  <ul>\n  <li>Integridad del empaque primario y secundario</li>\n  <li>Condiciones de almacenamiento (temperatura, humedad)</li>\n  <li>Fecha de vencimiento (vida util remanente minima segun politica)</li>\n  <li>Trazabilidad del lote</li>\n  </ul>\n</li>\n<li>Decide la disposicion:\n  <ul>\n  <li><strong>APROBADO:</strong> Reintegro a stock disponible</li>\n  <li><strong>RECHAZADO:</strong> Transferir a zona de averias para destruccion</li>\n  <li><strong>CUARENTENA:</strong> Mantener en evaluacion por mas tiempo</li>\n  </ul>\n</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.4 Almacenamiento en Zona de Averias</h3>\n<ol>\n<li>Los productos rechazados se almacenan en la <strong>zona de averias</strong> del almacen.</li>\n<li>XPert WMS mantiene el stock con estado <strong>BLOCKED</strong> para evitar despacho accidental.</li>\n<li>Se programa la destruccion o devolucion a planta segun politica de la empresa.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.5 Cierre y Confirmacion SAP</h3>\n<ol>\n<li>Al completar la devolucion, hacer clic en <strong>\"Completar Devolucion\"</strong>.</li>\n<li>XPert WMS genera la entrada de mercaderia correspondiente en SAP B1.</li>\n<li>Se actualiza el stock en SAP con los lotes y cantidades realmente recibidas.</li>\n</ol>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">6. REGISTROS ASOCIADOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Registro</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Ubicacion</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Retencion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Documento de Devolucion</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Devoluciones</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Evaluacion QA de Devolucion</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > QA</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Nota de Credito SAP</td><td style=\"padding:8px 12px;border:1px solid #475569\">SAP B1 > Notas de Credito</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">7. CONTROL DE CAMBIOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Version</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Fecha</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Descripcion del Cambio</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Autor</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">1.0</td><td style=\"padding:8px 12px;border:1px solid #475569\">2026-04-06</td><td style=\"padding:8px 12px;border:1px solid #475569\">Emision inicial del procedimiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">Administracion WMS</td></tr>\n</table>\n</div>',1,'2026-04-11 10:44:11','2026-04-06','2027-04-06',1,'2026-04-11 10:44:11','2026-04-11 10:44:11'),
(5,'SOP-RCL-001','Recall / Retiro de Producto','recall','1.0','ACTIVE','<div class=\"sop-document\">\n<div class=\"sop-header\">\n<table style=\"width:100%;border-collapse:collapse;border:2px solid #334155\">\n<tr>\n<td rowspan=\"4\" style=\"width:200px;text-align:center;padding:10px;border:1px solid #334155\"><strong style=\"font-size:20px;color:#3b82f6\">XPert WMS</strong><br><span style=\"font-size:11px;color:#94a3b8\">Sistema de Gestion de Almacenes</span><br><span style=\"font-size:11px;color:#94a3b8\">COMFAR S.A.</span></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>PROCEDIMIENTO OPERATIVO ESTANDAR</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155;width:180px\"><strong>Codigo:</strong> SOP-RCL-001</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Recall / Retiro de Producto</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Version:</strong> 1.0</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Proceso:</strong> Recall</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Vigencia:</strong> 2026-04-06</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Departamento:</strong> Calidad / Regulatorio</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Revision:</strong> 2027-04-06</td>\n</tr>\n</table>\n</div>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">1. OBJETIVO</h2>\n<p>Establecer el procedimiento para el retiro rapido y trazable de productos del mercado (recall) en cumplimiento con los requerimientos de DINAVISA, asegurando la identificacion completa de todo el stock afectado en almacen y de todos los clientes que recibieron el lote en cuestion, permitiendo una respuesta inmediata ante alertas sanitarias.</p>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">2. ALCANCE</h2>\n<ul>\n<li><strong>Recall por alerta DINAVISA:</strong> Retiro ordenado por la autoridad regulatoria</li>\n<li><strong>Recall voluntario:</strong> Retiro proactivo por hallazgo interno de no conformidad</li>\n<li><strong>Retiro por calidad:</strong> Producto que no cumple especificaciones post-comercializacion</li>\n<li><strong>Trazabilidad completa:</strong> Desde la recepcion hasta el ultimo cliente que recibio el lote</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">3. RESPONSABILIDADES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Cargo</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Responsabilidad</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Director Tecnico</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Autorizar el recall. Coordinar con DINAVISA. Firmar documentacion regulatoria.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Calidad</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Ejecutar la trazabilidad en XPert WMS. Coordinar el bloqueo de lotes.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Almacen</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Ejecutar el bloqueo fisico del stock. Segregar producto en zona de averias.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Comercial</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Notificar a los clientes afectados. Coordinar la devolucion del producto.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">4. DEFINICIONES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Termino</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Definicion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Recall</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Retiro de un producto del mercado por defecto de calidad, seguridad o incumplimiento regulatorio.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Trazabilidad</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Capacidad de rastrear un lote desde su origen hasta el destino final (forward tracing) y viceversa (backward tracing).</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Lote bloqueado</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Stock con estado BLOCKED que no puede ser despachado ni movido sin autorizacion.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">5. PROCEDIMIENTO</h2>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.1 Iniciar el Recall</h3>\n<ol>\n<li>Acceder al modulo <strong>DINAVISA - Recall</strong> en XPert WMS.</li>\n<li>Hacer clic en <strong>\"+ Nuevo Recall\"</strong>.</li>\n<li>Ingresar:\n  <ul>\n  <li>Codigo del producto afectado</li>\n  <li>Numero de lote a rastrear</li>\n  <li>Motivo del recall (alerta DINAVISA, hallazgo interno, queja de cliente, etc.)</li>\n  </ul>\n</li>\n<li>El sistema crea el recall con estado <strong>INITIATED</strong> y genera un numero de seguimiento unico.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.2 Ejecutar Trazabilidad</h3>\n<ol>\n<li>Hacer clic en <strong>\"Ejecutar Trazabilidad\"</strong> en el detalle del recall.</li>\n<li>XPert WMS ejecuta automaticamente la busqueda completa del lote en toda la base de datos:\n  <ul>\n  <li><strong>Stock actual:</strong> Todas las ubicaciones donde se encuentra el lote actualmente</li>\n  <li><strong>Movimientos historicos:</strong> Todo el historial de movimientos del lote (recepcion, almacenamiento, picks, transferencias)</li>\n  <li><strong>Despachos:</strong> Todos los despachos que incluyeron el lote</li>\n  <li><strong>Clientes afectados:</strong> Lista completa de clientes que recibieron mercaderia de ese lote</li>\n  </ul>\n</li>\n<li>El estado cambia a <strong>IN_PROGRESS</strong>.</li>\n<li>Revisar los resultados en las tablas: Stock Encontrado, Clientes Afectados, Movimientos.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.3 Bloquear el Lote</h3>\n<ol>\n<li>Una vez revisada la trazabilidad, hacer clic en <strong>\"Bloquear Lote y Completar\"</strong>.</li>\n<li>XPert WMS bloquea automaticamente TODO el stock del lote en todas las ubicaciones.</li>\n<li>El estado del lote en la tabla de batches cambia a <strong>BLOCKED</strong>.</li>\n<li>Se generan movimientos de stock tipo BLOCK con referencia al recall.</li>\n<li>El lote bloqueado no puede ser seleccionado para picking ni despacho.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.4 Notificacion y Recoleccion</h3>\n<ol>\n<li>Exportar la lista de clientes afectados desde XPert WMS (CSV desde Reportes > Recalls).</li>\n<li>El area Comercial contacta a cada cliente para coordinar la devolucion.</li>\n<li>Las devoluciones se procesan segun SOP-DEV-001.</li>\n<li>Toda la documentacion se archiva junto al recall para presentar a DINAVISA.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.5 Disposicion Final</h3>\n<ol>\n<li>El producto recolectado se almacena en la <strong>zona de averias</strong>.</li>\n<li>Control de Calidad decide la disposicion final: destruccion, reproceso, devolucion a fabricante.</li>\n<li>Se documenta la destruccion o disposicion con acta firmada.</li>\n<li>Se genera el informe final del recall para DINAVISA.</li>\n</ol>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">6. REGISTROS ASOCIADOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Registro</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Ubicacion</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Retencion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Recall (cabecera y resultados)</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > DINAVISA - Recall</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Reporte de Trazabilidad</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Recall > Detalle</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Exportacion CSV clientes afectados</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Reportes > Recalls</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Acta de destruccion</td><td style=\"padding:8px 12px;border:1px solid #475569\">Archivo fisico Calidad</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">7. CONTROL DE CAMBIOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Version</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Fecha</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Descripcion del Cambio</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Autor</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">1.0</td><td style=\"padding:8px 12px;border:1px solid #475569\">2026-04-06</td><td style=\"padding:8px 12px;border:1px solid #475569\">Emision inicial del procedimiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">Administracion WMS</td></tr>\n</table>\n</div>',1,'2026-04-11 10:44:11','2026-04-06','2027-04-06',1,'2026-04-11 10:44:11','2026-04-11 10:44:11'),
(6,'SOP-INV-001','Control de Inventarios','inventarios','1.0','ACTIVE','<div class=\"sop-document\">\n<div class=\"sop-header\">\n<table style=\"width:100%;border-collapse:collapse;border:2px solid #334155\">\n<tr>\n<td rowspan=\"4\" style=\"width:200px;text-align:center;padding:10px;border:1px solid #334155\"><strong style=\"font-size:20px;color:#3b82f6\">XPert WMS</strong><br><span style=\"font-size:11px;color:#94a3b8\">Sistema de Gestion de Almacenes</span><br><span style=\"font-size:11px;color:#94a3b8\">COMFAR S.A.</span></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>PROCEDIMIENTO OPERATIVO ESTANDAR</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155;width:180px\"><strong>Codigo:</strong> SOP-INV-001</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Control de Inventarios</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Version:</strong> 1.0</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Proceso:</strong> Inventarios</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Vigencia:</strong> 2026-04-06</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Departamento:</strong> Logistica / Control Interno</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Revision:</strong> 2027-04-06</td>\n</tr>\n</table>\n</div>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">1. OBJETIVO</h2>\n<p>Definir el procedimiento para el control periodico de inventarios en el almacen mediante conteos ciclicos, conteos oportunos y ajustes directos, garantizando la exactitud del inventario registrado en XPert WMS y SAP B1, y cumpliendo con los requisitos de DINAVISA para la trazabilidad de productos farmaceuticos.</p>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">2. ALCANCE</h2>\n<ul>\n<li><strong>Conteo Ciclico:</strong> Conteo planificado de ubicaciones seleccionadas segun criterios (rotacion ABC, zona, fecha ultimo conteo)</li>\n<li><strong>Conteo Oportuno:</strong> Conteo disparado por un evento (diferencia detectada, reclamo, auditoria)</li>\n<li><strong>Ajuste Directo:</strong> Correccion de cantidades cuando se detecta y documenta una discrepancia</li>\n<li><strong>Segundo Conteo:</strong> Reconteo obligatorio cuando el primer conteo muestra diferencias significativas</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">3. RESPONSABILIDADES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Cargo</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Responsabilidad</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Almacen</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Planificar conteos ciclicos. Aprobar ajustes de inventario. Definir criterios de seleccion.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Contador (Operador)</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Ejecutar el conteo fisico. Registrar cantidades en XPert WMS.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Supervisor</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Verificar diferencias. Ejecutar segundo conteo si es necesario. Aprobar o rechazar ajustes.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">4. DEFINICIONES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Termino</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Definicion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Conteo Ciclico</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Metodo de inventario donde se cuentan subconjuntos de ubicaciones de forma rotativa durante el ano.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Conteo Guiado</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">El sistema muestra los productos esperados y el operador confirma cantidades.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Conteo Ciego</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">El operador cuenta sin ver las cantidades del sistema (mayor confiabilidad).</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Exactitud de Inventario</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Porcentaje de ubicaciones contadas que coinciden con el registro del sistema. Objetivo: >98%.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">5. PROCEDIMIENTO</h2>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.1 Planificacion del Conteo Ciclico</h3>\n<ol>\n<li>Acceder al modulo <strong>Conteo Ciclico</strong> en XPert WMS.</li>\n<li>Hacer clic en <strong>\"+ Nuevo Conteo\"</strong>.</li>\n<li>Seleccionar el metodo de seleccion:\n  <ul>\n  <li><strong>Por Ubicaciones:</strong> Seleccionar manualmente las ubicaciones a contar</li>\n  <li><strong>Por Stock:</strong> Seleccionar registros de stock especificos (producto + ubicacion + lote)</li>\n  </ul>\n</li>\n<li>Definir parametros: almacen, zona, pasillo, tipo de conteo (guiado/ciego).</li>\n<li>El sistema genera las lineas de conteo con estado <strong>PLANNED</strong>.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.2 Ejecucion del Conteo</h3>\n<ol>\n<li>El operador abre el conteo asignado en su colector o interfaz web.</li>\n<li>Para cada linea de conteo:\n  <ol type=\"a\">\n  <li>Dirigirse a la ubicacion indicada</li>\n  <li>Escanear el codigo de ubicacion para confirmar</li>\n  <li>Contar fisicamente los productos en la ubicacion</li>\n  <li>Registrar la cantidad contada en XPert WMS</li>\n  <li>Si el conteo es ciego, no se muestra la cantidad esperada</li>\n  </ol>\n</li>\n<li>El estado de la linea cambia a <strong>COUNTED</strong>.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.3 Verificacion de Diferencias</h3>\n<ol>\n<li>XPert WMS calcula automaticamente la diferencia entre cantidad del sistema y cantidad contada.</li>\n<li>Las diferencias se clasifican en:\n  <ul>\n  <li><span style=\"color:#22c55e\"><strong>Sin diferencia:</strong></span> Cantidad coincide exactamente</li>\n  <li><span style=\"color:#f59e0b\"><strong>Diferencia menor:</strong></span> Variacion dentro del umbral configurable</li>\n  <li><span style=\"color:#ef4444\"><strong>Diferencia critica:</strong></span> Variacion que supera el umbral - requiere segundo conteo</li>\n  </ul>\n</li>\n<li>Si hay diferencia critica, se habilita el boton <strong>\"Segundo Conteo\"</strong>.</li>\n<li>Un operador diferente al primero ejecuta el segundo conteo (segregacion de funciones).</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.4 Aprobacion de Ajustes</h3>\n<ol>\n<li>El Jefe de Almacen o Supervisor revisa las diferencias verificadas.</li>\n<li>Para cada linea con diferencia, decide:\n  <ul>\n  <li><strong>Aprobar ajuste:</strong> Se ajusta el stock del sistema al conteo real</li>\n  <li><strong>Rechazar:</strong> Se mantiene el stock del sistema (requiere justificacion)</li>\n  </ul>\n</li>\n<li>Al aprobar, XPert WMS genera un movimiento de ajuste con trazabilidad completa.</li>\n<li>El ajuste se sincroniza con SAP B1 (Entrada/Salida de inventario segun sea positivo o negativo).</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.5 Ajuste Directo</h3>\n<ol>\n<li>Acceder al modulo <strong>Ajuste Directo</strong> en XPert WMS.</li>\n<li>Ingresar: almacen, ubicacion, producto, lote, cantidad actual, cantidad real, motivo.</li>\n<li>El Supervisor aprueba el ajuste.</li>\n<li>Se genera el movimiento de ajuste con documentacion del motivo.</li>\n</ol>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">6. REGISTROS ASOCIADOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Registro</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Ubicacion</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Retencion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Conteo Ciclico (cabecera y lineas)</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Conteo Ciclico</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Ajuste de Inventario</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Ajuste Directo</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Movimientos de Ajuste</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Trazabilidad</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Entrada/Salida SAP</td><td style=\"padding:8px 12px;border:1px solid #475569\">SAP B1 > Inventario</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Reporte de Exactitud de Inventario</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Reportes > Inventario</td><td style=\"padding:8px 12px;border:1px solid #475569\">5 anos</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">7. CONTROL DE CAMBIOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Version</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Fecha</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Descripcion del Cambio</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Autor</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">1.0</td><td style=\"padding:8px 12px;border:1px solid #475569\">2026-04-06</td><td style=\"padding:8px 12px;border:1px solid #475569\">Emision inicial del procedimiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">Administracion WMS</td></tr>\n</table>\n</div>',1,'2026-04-11 10:44:11','2026-04-06','2027-04-06',1,'2026-04-11 10:44:11','2026-04-11 10:44:11'),
(7,'SOP-SIS-001','Manejo del Sistema WMS','sistema','1.0','ACTIVE','<div class=\"sop-document\">\n<div class=\"sop-header\">\n<table style=\"width:100%;border-collapse:collapse;border:2px solid #334155\">\n<tr>\n<td rowspan=\"4\" style=\"width:200px;text-align:center;padding:10px;border:1px solid #334155\"><strong style=\"font-size:20px;color:#3b82f6\">XPert WMS</strong><br><span style=\"font-size:11px;color:#94a3b8\">Sistema de Gestion de Almacenes</span><br><span style=\"font-size:11px;color:#94a3b8\">COMFAR S.A.</span></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>PROCEDIMIENTO OPERATIVO ESTANDAR</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155;width:180px\"><strong>Codigo:</strong> SOP-SIS-001</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Manejo del Sistema WMS</strong></td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Version:</strong> 1.0</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Proceso:</strong> Sistema</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Vigencia:</strong> 2026-04-06</td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Departamento:</strong> TI / Administracion</td>\n<td style=\"padding:8px 12px;border:1px solid #334155\"><strong>Revision:</strong> 2027-04-06</td>\n</tr>\n</table>\n</div>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">1. OBJETIVO</h2>\n<p>Establecer los lineamientos para el uso, administracion, seguridad y mantenimiento del sistema XPert WMS, garantizando la integridad de los datos, la continuidad operativa, el control de accesos y la trazabilidad de todas las acciones realizadas en el sistema, en cumplimiento con las Buenas Practicas de Documentacion y los requerimientos de DINAVISA sobre sistemas informaticos de soporte.</p>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">2. ALCANCE</h2>\n<ul>\n<li><strong>Acceso al sistema:</strong> Autenticacion, tokens JWT, sesiones</li>\n<li><strong>Gestion de usuarios y roles:</strong> Creacion, modificacion, desactivacion de cuentas</li>\n<li><strong>Auditoria:</strong> Registro de todas las acciones criticas en el sistema</li>\n<li><strong>Backup y recuperacion:</strong> Respaldo diario de la base de datos</li>\n<li><strong>Control de cambios:</strong> Documentacion de modificaciones al sistema</li>\n<li><strong>Integracion SAP B1:</strong> Gestion de la conexion con SAP Business One via Service Layer</li>\n</ul>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">3. RESPONSABILIDADES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Cargo</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Responsabilidad</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Administrador de TI</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Administrar el servidor. Ejecutar backups. Gestionar actualizaciones del sistema.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Administrador WMS</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Crear y gestionar usuarios. Asignar roles. Configurar parametros del sistema.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Usuarios Operativos</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Utilizar el sistema segun su rol asignado. Reportar incidencias.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Jefe de Calidad</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Verificar que el sistema cumpla con las normativas DINAVISA. Auditar periodicamente.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">4. DEFINICIONES</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Termino</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Definicion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>JWT</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">JSON Web Token. Mecanismo de autenticacion utilizado por XPert WMS para validar sesiones.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Rol</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Perfil de permisos que determina las funciones accesibles para un usuario (admin, supervisor, operator, viewer).</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Service Layer</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">API REST de SAP B1 utilizada para la integracion bidireccional entre XPert WMS y SAP.</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\"><strong>Audit Trail</strong></td><td style=\"padding:8px 12px;border:1px solid #475569\">Registro cronologico de todas las operaciones realizadas en el sistema con usuario, fecha y detalle.</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">5. PROCEDIMIENTO</h2>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.1 Acceso al Sistema (Login)</h3>\n<ol>\n<li>Acceder a XPert WMS desde un navegador web: <strong>https://[direccion-servidor]/</strong></li>\n<li>Ingresar <strong>nombre de usuario</strong> y <strong>contrasena</strong>.</li>\n<li>El sistema valida las credenciales y genera un token JWT con expiracion de 8 horas.</li>\n<li>Politica de contrasenas:\n  <ul>\n  <li>Minimo 8 caracteres</li>\n  <li>Debe incluir letras y numeros</li>\n  <li>Cambio obligatorio cada 90 dias</li>\n  <li>No repetir las ultimas 3 contrasenas</li>\n  </ul>\n</li>\n<li>Tras 5 intentos fallidos, la cuenta se bloquea por 30 minutos.</li>\n<li>Toda sesion inactiva por mas de 2 horas se cierra automaticamente.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.2 Gestion de Usuarios y Roles</h3>\n<ol>\n<li>Acceder al modulo <strong>Usuarios</strong> (solo disponible para rol admin).</li>\n<li>Para crear un usuario: clic en <strong>\"+ Nuevo Usuario\"</strong>.\n  <ul>\n  <li>Nombre completo</li>\n  <li>Nombre de usuario (unico)</li>\n  <li>Contrasena temporal</li>\n  <li>Rol: admin, supervisor, operator, viewer</li>\n  <li>Almacen asignado (si aplica)</li>\n  </ul>\n</li>\n<li>Roles disponibles:\n  <ul>\n  <li><strong>admin:</strong> Acceso total al sistema, gestion de usuarios, configuraciones</li>\n  <li><strong>supervisor:</strong> Operaciones de almacen, aprobaciones, reportes</li>\n  <li><strong>operator:</strong> Operaciones basicas (escaneo, picking, putaway)</li>\n  <li><strong>viewer:</strong> Solo lectura, consultas y reportes</li>\n  </ul>\n</li>\n<li>Para desactivar un usuario: editar y cambiar estado a inactivo. NO eliminar usuarios para mantener trazabilidad.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.3 Auditoria y Trazabilidad</h3>\n<ol>\n<li>XPert WMS registra automaticamente en la base de datos:\n  <ul>\n  <li>Cada operacion de stock (recepcion, putaway, picking, ajuste, bloqueo)</li>\n  <li>El usuario que ejecuto la operacion</li>\n  <li>La fecha y hora exacta</li>\n  <li>Los datos anteriores y posteriores al cambio</li>\n  </ul>\n</li>\n<li>El modulo <strong>Trazabilidad</strong> permite consultar el historial completo de movimientos.</li>\n<li>El modulo <strong>Reportes</strong> permite exportar los registros de auditoria en formato CSV.</li>\n<li>Los registros de auditoria no pueden ser eliminados ni modificados.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.4 Backup Diario</h3>\n<ol>\n<li>El servidor ejecuta automaticamente un backup de la base de datos <strong>wms_pro</strong> cada dia a las 02:00 AM.</li>\n<li>El backup se almacena en <strong>/var/backups/wms/</strong> con formato: <code>wms_pro_YYYYMMDD_HHMMSS.sql.gz</code></li>\n<li>Se mantienen los ultimos 30 dias de backups.</li>\n<li>El Administrador de TI verifica semanalmente que los backups se esten generando correctamente.</li>\n<li>Prueba de restauracion: se ejecuta al menos una vez por trimestre para validar la integridad del backup.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.5 Control de Cambios del Sistema</h3>\n<ol>\n<li>Toda modificacion al sistema (codigo, base de datos, configuracion) debe ser documentada.</li>\n<li>El registro incluye: fecha, descripcion del cambio, responsable, justificacion.</li>\n<li>Los cambios se despliegan fuera del horario operativo cuando sea posible.</li>\n<li>Se mantiene un historial de versiones del sistema.</li>\n</ol>\n\n<h3 style=\"margin-top:16px;color:#22c55e\">5.6 Integracion con SAP B1</h3>\n<ol>\n<li>XPert WMS se conecta a SAP B1 mediante <strong>Service Layer</strong> (API REST).</li>\n<li>La conexion se autentica con credenciales configuradas en el sistema.</li>\n<li>Operaciones sincronizadas:\n  <ul>\n  <li>Ordenes de Compra (SAP -> WMS)</li>\n  <li>Pedidos de Venta (SAP -> WMS)</li>\n  <li>Entradas de Mercaderia (WMS -> SAP)</li>\n  <li>Entregas / Despachos (WMS -> SAP)</li>\n  <li>Ajustes de Inventario (WMS -> SAP)</li>\n  <li>Transferencias de Stock (WMS -> SAP)</li>\n  </ul>\n</li>\n<li>El estado de la conexion SAP se monitorea desde el menu <strong>SAP B1</strong> en XPert WMS.</li>\n</ol>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">6. REGISTROS ASOCIADOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Registro</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Ubicacion</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Retencion</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Log de accesos (login/logout)</td><td style=\"padding:8px 12px;border:1px solid #475569\">Base de datos wms_pro</td><td style=\"padding:8px 12px;border:1px solid #475569\">2 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Movimientos de stock (audit trail)</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Trazabilidad</td><td style=\"padding:8px 12px;border:1px solid #475569\">10 anos</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Registro de usuarios</td><td style=\"padding:8px 12px;border:1px solid #475569\">XPert WMS > Usuarios</td><td style=\"padding:8px 12px;border:1px solid #475569\">Permanente</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Backups de base de datos</td><td style=\"padding:8px 12px;border:1px solid #475569\">/var/backups/wms/</td><td style=\"padding:8px 12px;border:1px solid #475569\">30 dias</td></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">Log de cambios del sistema</td><td style=\"padding:8px 12px;border:1px solid #475569\">Documentacion interna TI</td><td style=\"padding:8px 12px;border:1px solid #475569\">Permanente</td></tr>\n</table>\n\n<h2 style=\"margin-top:24px;color:#3b82f6;border-bottom:2px solid #3b82f6;padding-bottom:6px\">7. CONTROL DE CAMBIOS</h2>\n<table style=\"width:100%;border-collapse:collapse;margin:12px 0\">\n<tr style=\"background:#1e293b\"><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Version</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Fecha</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Descripcion del Cambio</th><th style=\"padding:8px 12px;border:1px solid #475569;text-align:left\">Autor</th></tr>\n<tr><td style=\"padding:8px 12px;border:1px solid #475569\">1.0</td><td style=\"padding:8px 12px;border:1px solid #475569\">2026-04-06</td><td style=\"padding:8px 12px;border:1px solid #475569\">Emision inicial del procedimiento</td><td style=\"padding:8px 12px;border:1px solid #475569\">Administracion WMS</td></tr>\n</table>\n</div>',1,'2026-04-11 10:44:11','2026-04-06','2027-04-06',1,'2026-04-11 10:44:11','2026-04-11 10:44:11'),
(8,'PROT-IQ-001','Protocolo de Calificacion de Instalacion (IQ) - XPert WMS','validacion','1.0','ACTIVE','<style>\n  .proto-container { font-family: \"Segoe UI\", Arial, sans-serif; max-width: 1100px; margin: 0 auto; color: #1a1a2e; line-height: 1.6; }\n  .proto-header-table { width: 100%; border-collapse: collapse; margin-bottom: 30px; border: 2px solid #003366; }\n  .proto-header-table td { border: 1px solid #003366; padding: 8px 12px; font-size: 13px; }\n  .proto-header-table .label { background: #003366; color: #fff; font-weight: 600; width: 160px; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }\n  .proto-header-table .value { background: #f8f9fa; font-weight: 500; }\n  .proto-header-table .company-cell { text-align: center; background: #003366; color: #fff; font-size: 18px; font-weight: 700; padding: 15px; letter-spacing: 1px; }\n  .proto-header-table .doc-title { text-align: center; background: #e8edf2; font-size: 15px; font-weight: 700; color: #003366; padding: 12px; }\n  .proto-section { margin: 25px 0; }\n  .proto-section h2 { color: #003366; font-size: 16px; border-bottom: 2px solid #003366; padding-bottom: 6px; margin-bottom: 15px; text-transform: uppercase; letter-spacing: 0.5px; }\n  .proto-section h3 { color: #1a1a2e; font-size: 14px; margin: 15px 0 10px 0; }\n  .proto-section p, .proto-section li { font-size: 13px; color: #333; }\n  .proto-section ul { margin: 8px 0; padding-left: 25px; }\n  .proto-section ul li { margin-bottom: 4px; }\n  .iq-table { width: 100%; border-collapse: collapse; margin: 15px 0; font-size: 12px; }\n  .iq-table thead th { background: #003366; color: #fff; padding: 10px 8px; text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }\n  .iq-table tbody td { border: 1px solid #dee2e6; padding: 8px; vertical-align: top; }\n  .iq-table tbody tr:nth-child(even) { background: #f8f9fa; }\n  .iq-table tbody tr:hover { background: #e8edf2; }\n  .iq-table .col-num { width: 60px; text-align: center; font-weight: 700; color: #003366; }\n  .iq-table .col-result { width: 90px; text-align: center; }\n  .pass { color: #0a7c42; font-weight: 700; font-size: 16px; }\n  .fail { color: #c0392b; font-weight: 700; }\n  .criteria-box { background: #f0f7f0; border-left: 4px solid #0a7c42; padding: 12px 15px; margin: 15px 0; border-radius: 0 4px 4px 0; }\n  .criteria-box p { margin: 4px 0; font-size: 13px; }\n  .criteria-box strong { color: #003366; }\n  .signature-table { width: 100%; border-collapse: collapse; margin: 30px 0; }\n  .signature-table td { border: 1px solid #003366; padding: 12px; height: 60px; vertical-align: bottom; font-size: 12px; }\n  .signature-table .sig-label { background: #f8f9fa; font-weight: 600; color: #003366; width: 160px; vertical-align: middle; text-align: center; }\n  .signature-table .sig-line { border-bottom: 1px solid #999; width: 200px; display: inline-block; margin-bottom: 2px; }\n  .conclusion-box { background: #e8f5e9; border: 2px solid #0a7c42; padding: 20px; border-radius: 6px; margin: 25px 0; }\n  .conclusion-box h3 { color: #0a7c42; margin-top: 0; }\n  .watermark { text-align: center; color: #ccc; font-size: 10px; margin-top: 40px; border-top: 1px solid #eee; padding-top: 10px; }\n  .ref-box { background: #fff3e0; border-left: 4px solid #e65100; padding: 12px 15px; margin: 15px 0; border-radius: 0 4px 4px 0; }\n  @media print { .proto-container { font-size: 11px; } .iq-table { page-break-inside: avoid; } .signature-table { page-break-inside: avoid; } }\n</style>\n\n<div class=\"proto-container\">\n\n  <table class=\"proto-header-table\">\n    <tr><td colspan=\"6\" class=\"company-cell\">COMFAR PARAGUAY S.A.</td></tr>\n    <tr><td colspan=\"6\" class=\"doc-title\">PROTOCOLO DE CALIFICACI&Oacute;N DE INSTALACI&Oacute;N (IQ)<br>Sistema XPert WMS</td></tr>\n    <tr>\n      <td class=\"label\">C&oacute;digo</td><td class=\"value\">PROT-IQ-001</td>\n      <td class=\"label\">Versi&oacute;n</td><td class=\"value\">1.0</td>\n      <td class=\"label\">Fecha</td><td class=\"value\">2026-04-06</td>\n    </tr>\n    <tr>\n      <td class=\"label\">Sistema</td><td class=\"value\">XPert WMS v1.0</td>\n      <td class=\"label\">Servidor</td><td class=\"value\">200.10.10.150</td>\n      <td class=\"label\">Base de Datos</td><td class=\"value\">MariaDB - wms_pro</td>\n    </tr>\n    <tr>\n      <td class=\"label\">Elaborado por</td><td class=\"value\">Departamento de TI</td>\n      <td class=\"label\">&Aacute;rea</td><td class=\"value\">Aseguramiento de Calidad</td>\n      <td class=\"label\">Clasificaci&oacute;n</td><td class=\"value\">Confidencial</td>\n    </tr>\n  </table>\n\n  <div class=\"proto-section\">\n    <h2>1. Objetivo</h2>\n    <p>Verificar y documentar que el sistema <strong>XPert WMS v1.0</strong> ha sido instalado correctamente seg&uacute;n las especificaciones de dise&ntilde;o aprobadas, y que todos los componentes de hardware, software, infraestructura y configuraci&oacute;n cumplen con los requisitos establecidos para su operaci&oacute;n en el entorno de distribuci&oacute;n farmac&eacute;utica de <strong>COMFAR Paraguay S.A.</strong>, conforme a las normativas de la <strong>Direcci&oacute;n Nacional de Vigilancia Sanitaria (DINAVISA)</strong>.</p>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>2. Alcance</h2>\n    <p>Este protocolo aplica a la calificaci&oacute;n de instalaci&oacute;n de los siguientes componentes del sistema XPert WMS:</p>\n    <ul>\n      <li><strong>Servidor de aplicaci&oacute;n:</strong> Linux Ubuntu, IP 200.10.10.150</li>\n      <li><strong>Base de datos:</strong> MariaDB, esquema wms_pro con 55 tablas</li>\n      <li><strong>Servidor web:</strong> Apache con PHP 8.3, HTTPS puerto 8443</li>\n      <li><strong>Aplicaci&oacute;n WMS:</strong> Frontend Desktop (26 m&oacute;dulos) y Mobile RF (10 m&oacute;dulos)</li>\n      <li><strong>Integraci&oacute;n:</strong> SAP Business One Service Layer (200.10.10.151:50000)</li>\n      <li><strong>Perif&eacute;ricos:</strong> Impresoras Zebra ZPL, scanners de c&oacute;digo de barras</li>\n      <li><strong>Seguridad:</strong> Certificado SSL, control de acceso SSH, autenticaci&oacute;n JWT</li>\n    </ul>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>3. Referencias Normativas</h2>\n    <div class=\"ref-box\">\n      <p><strong>DINAVISA</strong> &mdash; Resoluciones vigentes sobre Buenas Pr&aacute;cticas de Almacenamiento y Distribuci&oacute;n (BPAD)</p>\n      <p><strong>OMS</strong> &mdash; Anexo 5: Buenas Pr&aacute;cticas de Distribuci&oacute;n de Productos Farmac&eacute;uticos (TRS 957)</p>\n      <p><strong>ISPE GAMP 5</strong> &mdash; Gu&iacute;a de Buenas Pr&aacute;cticas para Sistemas Computarizados en entornos GxP</p>\n      <p><strong>21 CFR Part 11</strong> &mdash; Registros Electr&oacute;nicos y Firmas Electr&oacute;nicas (referencia)</p>\n      <p><strong>ISO/IEC 27001</strong> &mdash; Sistema de Gesti&oacute;n de Seguridad de la Informaci&oacute;n (referencia)</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>4. Criterios de Aceptaci&oacute;n</h2>\n    <div class=\"criteria-box\">\n      <p><strong>Criterio General:</strong> Todas las verificaciones de instalaci&oacute;n deben obtener resultado <span class=\"pass\">CONFORME</span> para que la calificaci&oacute;n IQ sea aprobada.</p>\n      <p><strong>Desviaciones:</strong> Cualquier resultado NO CONFORME debe ser documentado como desviaci&oacute;n, evaluado su impacto y resuelto antes de proceder a la Calificaci&oacute;n Operacional (OQ).</p>\n      <p><strong>Evidencia:</strong> Cada verificaci&oacute;n debe estar respaldada por capturas de pantalla, logs del sistema o documentaci&oacute;n t&eacute;cnica equivalente.</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>5. Verificaciones de Instalaci&oacute;n</h2>\n\n    <h3>5.1 Infraestructura de Servidor y Base de Datos</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Verificaci&oacute;n</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th><th>Observaciones</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">IQ-001</td><td>Servidor Linux instalado y operativo</td><td>Sistema operativo Ubuntu 22.04/24.04 LTS funcionando correctamente</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>Servidor 200.10.10.150 &mdash; Ubuntu LTS operativo, uptime verificado</td></tr>\n        <tr><td class=\"col-num\">IQ-002</td><td>Base de datos MariaDB configurada</td><td>Esquema wms_pro creado con 55 tablas, charset utf8mb4_unicode_ci</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>MariaDB con esquema wms_pro, charset utf8mb4, collation utf8mb4_unicode_ci</td></tr>\n        <tr><td class=\"col-num\">IQ-003</td><td>PHP 8.3 instalado y configurado</td><td>PHP-CLI y mod_php funcionales, extensiones requeridas activas</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>PHP 8.3.6 con extensiones: pdo_mysql, curl, json, mbstring, openssl</td></tr>\n        <tr><td class=\"col-num\">IQ-004</td><td>Apache configurado con HTTPS</td><td>Servidor web Apache escuchando en puerto 8443 con SSL habilitado</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>Apache2 con mod_ssl, puerto 8443, certificado Let&rsquo;s Encrypt</td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.2 Aplicaci&oacute;n y M&oacute;dulos</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Verificaci&oacute;n</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th><th>Observaciones</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">IQ-005</td><td>Aplicaci&oacute;n WMS desplegada</td><td>168 rutas API activas y respondiendo correctamente</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>Desplegada en /var/www/WMS &mdash; 168 endpoints API verificados</td></tr>\n        <tr><td class=\"col-num\">IQ-006</td><td>Frontend Desktop accesible</td><td>P&aacute;gina de login funcional con acceso a 26 m&oacute;dulos operativos</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>index.html &mdash; Login funcional, dashboard con 26 m&oacute;dulos cargando</td></tr>\n        <tr><td class=\"col-num\">IQ-007</td><td>Frontend Mobile RF accesible</td><td>10 m&oacute;dulos RF operativos con soporte de scanner integrado</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>rf.html &mdash; 10 m&oacute;dulos RF con scanner de c&oacute;digo de barras integrado</td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.3 Integraci&oacute;n SAP Business One</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Verificaci&oacute;n</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th><th>Observaciones</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">IQ-008</td><td>Integraci&oacute;n SAP Service Layer</td><td>Login exitoso al Service Layer, base COMFAR_CAPA accesible</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>Service Layer 200.10.10.151:50000, sesi&oacute;n autenticada a COMFAR_CAPA</td></tr>\n        <tr><td class=\"col-num\">IQ-009</td><td>11 tipos de documentos SAP configurados</td><td>Lectura y escritura de: OC, OV, EM, EN, NC, TR, ST, OP, FC, E+, S-</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>PurchaseOrders, Orders, PurchaseDeliveryNotes, DeliveryNotes, CreditNotes, StockTransfers, StockTransferRequests, ProductionOrders, Invoices, InventoryGenEntries, InventoryGenExits</td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.4 Seguridad y Respaldos</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Verificaci&oacute;n</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th><th>Observaciones</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">IQ-010</td><td>Backup automatizado configurado</td><td>Cron job ejecut&aacute;ndose diariamente a las 2:00 AM, retenci&oacute;n de 30 d&iacute;as</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>Crontab configurado, backups en /var/www/WMS/backups, retenci&oacute;n 30 d&iacute;as</td></tr>\n        <tr><td class=\"col-num\">IQ-011</td><td>Control de acceso al servidor</td><td>Acceso SSH exclusivamente con llave RSA, sudo protegido con contrase&ntilde;a</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>SSH con autenticaci&oacute;n por llave RSA, &uacute;nico usuario autorizado: comfar</td></tr>\n        <tr><td class=\"col-num\">IQ-014</td><td>Certificado SSL v&aacute;lido</td><td>Certificado Let&rsquo;s Encrypt vigente con renovaci&oacute;n autom&aacute;tica</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>Dominio comfar-middleware.duckdns.org, certificado auto-renovable via certbot</td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.5 Perif&eacute;ricos y Dispositivos</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Verificaci&oacute;n</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th><th>Observaciones</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">IQ-012</td><td>Impresoras de etiquetas configuradas</td><td>Soporte de impresi&oacute;n ZPL/Zebra via protocolo TCP puerto 9100</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>M&oacute;dulo de impresi&oacute;n ZPL configurable, conexi&oacute;n TCP/9100 a impresoras Zebra</td></tr>\n        <tr><td class=\"col-num\">IQ-013</td><td>Scanner de c&oacute;digo de barras integrado</td><td>Soporte de lectura por c&aacute;mara, dispositivo RF y USB/Bluetooth</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td><td>Librer&iacute;a html5-qrcode integrada, compatible con c&aacute;mara, RF y dispositivos USB/BT</td></tr>\n      </tbody>\n    </table>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>6. Resumen de Resultados</h2>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th>Categor&iacute;a</th><th style=\"text-align:center\">Total Verificaciones</th><th style=\"text-align:center\">Conformes</th><th style=\"text-align:center\">No Conformes</th><th style=\"text-align:center\">% Cumplimiento</th></tr>\n      </thead>\n      <tbody>\n        <tr><td>Infraestructura</td><td style=\"text-align:center\">4</td><td style=\"text-align:center\"><span class=\"pass\">4</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Aplicaci&oacute;n y M&oacute;dulos</td><td style=\"text-align:center\">3</td><td style=\"text-align:center\"><span class=\"pass\">3</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Integraci&oacute;n SAP</td><td style=\"text-align:center\">2</td><td style=\"text-align:center\"><span class=\"pass\">2</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Seguridad y Respaldos</td><td style=\"text-align:center\">3</td><td style=\"text-align:center\"><span class=\"pass\">3</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Perif&eacute;ricos</td><td style=\"text-align:center\">2</td><td style=\"text-align:center\"><span class=\"pass\">2</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr style=\"background:#e8f5e9;font-weight:700\"><td>TOTAL</td><td style=\"text-align:center\">14</td><td style=\"text-align:center\"><span class=\"pass\">14</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n      </tbody>\n    </table>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>7. Desviaciones</h2>\n    <p>No se registraron desviaciones durante la ejecuci&oacute;n de la Calificaci&oacute;n de Instalaci&oacute;n. Todas las verificaciones resultaron <strong>CONFORMES</strong>.</p>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>8. Conclusi&oacute;n</h2>\n    <div class=\"conclusion-box\">\n      <h3>CALIFICACI&Oacute;N DE INSTALACI&Oacute;N &mdash; APROBADA</h3>\n      <p>El sistema <strong>XPert WMS v1.0</strong> ha sido instalado y configurado correctamente seg&uacute;n las especificaciones de dise&ntilde;o aprobadas. Todos los componentes de infraestructura, software, integraci&oacute;n, seguridad y perif&eacute;ricos cumplen con los criterios de aceptaci&oacute;n establecidos.</p>\n      <p>Se recomienda proceder con la ejecuci&oacute;n del <strong>Protocolo de Calificaci&oacute;n Operacional (OQ) &mdash; PROT-OQ-001</strong>.</p>\n      <p><strong>Total de verificaciones:</strong> 14 | <strong>Conformes:</strong> 14 | <strong>No conformes:</strong> 0 | <strong>Cumplimiento:</strong> 100%</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>9. Firmas de Aprobaci&oacute;n</h2>\n    <table class=\"signature-table\">\n      <tr>\n        <td class=\"sig-label\">Ejecutado por</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n        <td class=\"sig-label\">Revisado por</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n      </tr>\n      <tr>\n        <td class=\"sig-label\">Aprobado por<br>(Aseg. Calidad)</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n        <td class=\"sig-label\">Aprobado por<br>(Dir. T&eacute;cnica)</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n      </tr>\n    </table>\n  </div>\n\n  <div class=\"watermark\">\n    COMFAR Paraguay S.A. &mdash; Documento Confidencial &mdash; PROT-IQ-001 v1.0 &mdash; P&aacute;gina 1 de 1<br>\n    Impreso el: ____/____/________ &mdash; Las copias impresas son consideradas NO CONTROLADAS\n  </div>\n\n</div>',1,'2026-04-06 00:00:00','2026-04-06','2027-04-06',1,'2026-04-11 18:25:10','2026-04-11 18:25:10'),
(9,'PROT-OQ-001','Protocolo de Calificacion Operacional (OQ) - XPert WMS','validacion','1.0','ACTIVE','<style>\n  .proto-container { font-family: \"Segoe UI\", Arial, sans-serif; max-width: 1100px; margin: 0 auto; color: #1a1a2e; line-height: 1.6; }\n  .proto-header-table { width: 100%; border-collapse: collapse; margin-bottom: 30px; border: 2px solid #003366; }\n  .proto-header-table td { border: 1px solid #003366; padding: 8px 12px; font-size: 13px; }\n  .proto-header-table .label { background: #003366; color: #fff; font-weight: 600; width: 160px; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }\n  .proto-header-table .value { background: #f8f9fa; font-weight: 500; }\n  .proto-header-table .company-cell { text-align: center; background: #003366; color: #fff; font-size: 18px; font-weight: 700; padding: 15px; letter-spacing: 1px; }\n  .proto-header-table .doc-title { text-align: center; background: #e8edf2; font-size: 15px; font-weight: 700; color: #003366; padding: 12px; }\n  .proto-section { margin: 25px 0; }\n  .proto-section h2 { color: #003366; font-size: 16px; border-bottom: 2px solid #003366; padding-bottom: 6px; margin-bottom: 15px; text-transform: uppercase; letter-spacing: 0.5px; }\n  .proto-section h3 { color: #1a1a2e; font-size: 14px; margin: 15px 0 10px 0; }\n  .proto-section p, .proto-section li { font-size: 13px; color: #333; }\n  .proto-section ul { margin: 8px 0; padding-left: 25px; }\n  .proto-section ul li { margin-bottom: 4px; }\n  .iq-table { width: 100%; border-collapse: collapse; margin: 15px 0; font-size: 12px; }\n  .iq-table thead th { background: #003366; color: #fff; padding: 10px 8px; text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }\n  .iq-table tbody td { border: 1px solid #dee2e6; padding: 8px; vertical-align: top; }\n  .iq-table tbody tr:nth-child(even) { background: #f8f9fa; }\n  .iq-table tbody tr:hover { background: #e8edf2; }\n  .iq-table .col-num { width: 60px; text-align: center; font-weight: 700; color: #003366; }\n  .iq-table .col-result { width: 90px; text-align: center; }\n  .pass { color: #0a7c42; font-weight: 700; font-size: 16px; }\n  .criteria-box { background: #f0f7f0; border-left: 4px solid #0a7c42; padding: 12px 15px; margin: 15px 0; border-radius: 0 4px 4px 0; }\n  .criteria-box p { margin: 4px 0; font-size: 13px; }\n  .criteria-box strong { color: #003366; }\n  .signature-table { width: 100%; border-collapse: collapse; margin: 30px 0; }\n  .signature-table td { border: 1px solid #003366; padding: 12px; height: 60px; vertical-align: bottom; font-size: 12px; }\n  .signature-table .sig-label { background: #f8f9fa; font-weight: 600; color: #003366; width: 160px; vertical-align: middle; text-align: center; }\n  .signature-table .sig-line { border-bottom: 1px solid #999; width: 200px; display: inline-block; margin-bottom: 2px; }\n  .conclusion-box { background: #e8f5e9; border: 2px solid #0a7c42; padding: 20px; border-radius: 6px; margin: 25px 0; }\n  .conclusion-box h3 { color: #0a7c42; margin-top: 0; }\n  .watermark { text-align: center; color: #ccc; font-size: 10px; margin-top: 40px; border-top: 1px solid #eee; padding-top: 10px; }\n  .ref-box { background: #fff3e0; border-left: 4px solid #e65100; padding: 12px 15px; margin: 15px 0; border-radius: 0 4px 4px 0; }\n  @media print { .proto-container { font-size: 11px; } .iq-table { page-break-inside: avoid; } .signature-table { page-break-inside: avoid; } }\n</style>\n\n<div class=\"proto-container\">\n\n  <table class=\"proto-header-table\">\n    <tr><td colspan=\"6\" class=\"company-cell\">COMFAR PARAGUAY S.A.</td></tr>\n    <tr><td colspan=\"6\" class=\"doc-title\">PROTOCOLO DE CALIFICACI&Oacute;N OPERACIONAL (OQ)<br>Sistema XPert WMS</td></tr>\n    <tr>\n      <td class=\"label\">C&oacute;digo</td><td class=\"value\">PROT-OQ-001</td>\n      <td class=\"label\">Versi&oacute;n</td><td class=\"value\">1.0</td>\n      <td class=\"label\">Fecha</td><td class=\"value\">2026-04-06</td>\n    </tr>\n    <tr>\n      <td class=\"label\">Sistema</td><td class=\"value\">XPert WMS v1.0</td>\n      <td class=\"label\">Prerrequisito</td><td class=\"value\">PROT-IQ-001 Aprobado</td>\n      <td class=\"label\">Base de Datos</td><td class=\"value\">MariaDB - wms_pro</td>\n    </tr>\n    <tr>\n      <td class=\"label\">Elaborado por</td><td class=\"value\">Departamento de TI</td>\n      <td class=\"label\">&Aacute;rea</td><td class=\"value\">Aseguramiento de Calidad</td>\n      <td class=\"label\">Clasificaci&oacute;n</td><td class=\"value\">Confidencial</td>\n    </tr>\n  </table>\n\n  <div class=\"proto-section\">\n    <h2>1. Objetivo</h2>\n    <p>Verificar y documentar que todas las funcionalidades del sistema <strong>XPert WMS v1.0</strong> operan correctamente seg&uacute;n las especificaciones funcionales aprobadas, incluyendo controles de acceso, trazabilidad de lotes, procesos de almac&eacute;n (recepci&oacute;n, almacenamiento, picking, despacho), integraci&oacute;n con SAP Business One, controles de calidad, y funciones de cumplimiento regulatorio requeridas por <strong>DINAVISA</strong>.</p>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>2. Alcance</h2>\n    <p>Este protocolo cubre la verificaci&oacute;n operacional de las siguientes &aacute;reas funcionales:</p>\n    <ul>\n      <li><strong>Seguridad y Control de Acceso:</strong> Autenticaci&oacute;n JWT, roles, permisos, segregaci&oacute;n de funciones</li>\n      <li><strong>Trazabilidad:</strong> Control de lotes, ubicaciones, historial de movimientos</li>\n      <li><strong>Recepci&oacute;n (Inbound):</strong> Importaci&oacute;n OC SAP, recepci&oacute;n a ciegas, gesti&oacute;n de diferencias, confirmaci&oacute;n SAP</li>\n      <li><strong>Control de Calidad:</strong> Cuarentena, aprobaci&oacute;n/rechazo, interfaz QC externa</li>\n      <li><strong>Despacho (Outbound):</strong> Picking FEFO, ondas, mesa de empaque, expedici&oacute;n</li>\n      <li><strong>Operaciones:</strong> Devoluciones, transferencias, conteo c&iacute;clico, ajustes</li>\n      <li><strong>Cumplimiento:</strong> Control de vencimientos, FEFO/FIFO, stock negativo, audit trail, recall</li>\n      <li><strong>Soporte:</strong> Control de temperatura, impresi&oacute;n de etiquetas, reportes, notificaciones</li>\n    </ul>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>3. Referencias Normativas</h2>\n    <div class=\"ref-box\">\n      <p><strong>DINAVISA</strong> &mdash; Resoluciones vigentes sobre Buenas Pr&aacute;cticas de Almacenamiento y Distribuci&oacute;n (BPAD)</p>\n      <p><strong>OMS</strong> &mdash; Anexo 5: Buenas Pr&aacute;cticas de Distribuci&oacute;n de Productos Farmac&eacute;uticos (TRS 957)</p>\n      <p><strong>ISPE GAMP 5</strong> &mdash; Gu&iacute;a de Buenas Pr&aacute;cticas para Sistemas Computarizados en entornos GxP</p>\n      <p><strong>PROT-IQ-001</strong> &mdash; Protocolo de Calificaci&oacute;n de Instalaci&oacute;n (prerrequisito aprobado)</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>4. Criterios de Aceptaci&oacute;n</h2>\n    <div class=\"criteria-box\">\n      <p><strong>Criterio General:</strong> Todas las verificaciones operacionales deben obtener resultado <span class=\"pass\">CONFORME</span> para que la calificaci&oacute;n OQ sea aprobada.</p>\n      <p><strong>Desviaciones:</strong> Cualquier resultado NO CONFORME debe ser documentado como desviaci&oacute;n, evaluado su impacto y resuelto antes de proceder a la Calificaci&oacute;n de Desempe&ntilde;o (PQ).</p>\n      <p><strong>M&eacute;todo de prueba:</strong> Cada funci&oacute;n ser&aacute; verificada mediante ejecuci&oacute;n directa en el sistema con datos de prueba, verificando entrada, procesamiento y resultado esperado.</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>5. Verificaciones Operacionales</h2>\n\n    <h3>5.1 Seguridad y Control de Acceso</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-001</td><td>Control de accesos</td><td>Iniciar sesi&oacute;n con usuario y contrase&ntilde;a v&aacute;lidos</td><td>JWT token generado correctamente, sesi&oacute;n activa</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-002</td><td>Roles y permisos</td><td>Verificar perfiles: Admin, Supervisor, Operario, Viewer</td><td>Cada rol tiene permisos diferenciados seg&uacute;n matriz</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-003</td><td>Segregaci&oacute;n de funciones</td><td>Operario intenta aprobar control de calidad</td><td>Sistema rechaza la acci&oacute;n, restricci&oacute;n activa</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.2 Trazabilidad</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-004</td><td>Trazabilidad de lote</td><td>Registrar lote durante recepci&oacute;n de mercader&iacute;a</td><td>Lote trazable en tabla stock_movements con fecha y usuario</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-005</td><td>Tracking de ubicaci&oacute;n</td><td>Ejecutar putaway a bin espec&iacute;fico</td><td>Stock vinculado correctamente al bin de destino</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-006</td><td>Historial de movimientos</td><td>Mover stock entre bins diferentes</td><td>Movimiento registrado con origen, destino, cantidad y timestamp</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.3 Recepci&oacute;n (Inbound)</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-007</td><td>Recepci&oacute;n OC SAP</td><td>Importar Orden de Compra desde SAP Business One</td><td>Agenda de recepci&oacute;n creada con l&iacute;neas de OC correctas</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-008</td><td>Recepci&oacute;n a ciegas</td><td>Escanear productos sin visualizar cantidades te&oacute;ricas</td><td>Sistema compara conteo real vs. esperado al finalizar</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-009</td><td>Gesti&oacute;n de diferencias</td><td>Recibir cantidad diferente a la esperada</td><td>Diferencias (sobrante/faltante) detectadas y visibles en reporte</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-010</td><td>Confirmaci&oacute;n SAP</td><td>Cerrar agenda de recepci&oacute;n completada</td><td>PurchaseDeliveryNotes creada autom&aacute;ticamente en SAP</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.4 Control de Calidad</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-011</td><td>Control de calidad QA</td><td>Producto ingresa en estado cuarentena</td><td>Stock bloqueado, no disponible para picking</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-012</td><td>Aprobar/Rechazar QC</td><td>Ejecutar workflow de aprobaci&oacute;n y rechazo de QC</td><td>Estado del producto cambia correctamente seg&uacute;n decisi&oacute;n</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-013</td><td>QC interfaz externa</td><td>Invocar API assign, approve y reject de QC</td><td>Batch actualizado correctamente via API externa</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.5 Despacho (Outbound)</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-014</td><td>Picking FEFO</td><td>Crear pick list para productos con m&uacute;ltiples lotes</td><td>Lote m&aacute;s pr&oacute;ximo a vencer asignado primero</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-015</td><td>Ondas de picking</td><td>Liberar onda con criterios de selecci&oacute;n</td><td>Stock reservado, tareas de picking creadas correctamente</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-016</td><td>Mesa de empaque</td><td>Escanear y verificar productos en mesa de empaque</td><td>100% de productos controlados y verificados</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-017</td><td>Expedici&oacute;n</td><td>Cerrar cami&oacute;n y confirmar despacho</td><td>DeliveryNotes creada autom&aacute;ticamente en SAP</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.6 Operaciones Especiales</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-018</td><td>Devoluciones</td><td>Recibir devoluci&oacute;n de cliente</td><td>CreditNotes creada autom&aacute;ticamente en SAP</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-019</td><td>Transferencias</td><td>Generar etiqueta de tr&aacute;nsito y transferir stock</td><td>Stock movido correctamente, StockTransfer creado en SAP</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-020</td><td>Conteo c&iacute;clico</td><td>Ejecutar conteo y aprobar resultado</td><td>Ajuste de inventario aplicado correctamente</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-021</td><td>Ajuste directo</td><td>Registrar consumo/producci&oacute;n</td><td>InventoryGenEntries/InventoryGenExits creados en SAP</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.7 Cumplimiento Regulatorio</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-022</td><td>Control de vencimientos</td><td>Verificar alertas para productos pr&oacute;ximos a vencer</td><td>Alertas generadas a 90 y 30 d&iacute;as antes del vencimiento</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-023</td><td>Control FEFO/FIFO</td><td>Verificar que picking respeta orden de vencimiento</td><td>Lote con vencimiento m&aacute;s pr&oacute;ximo asignado correctamente</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-024</td><td>Stock negativo</td><td>Intentar extraer m&aacute;s stock del disponible</td><td>Sistema muestra error &quot;Stock insuficiente&quot;, operaci&oacute;n rechazada</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-025</td><td>Audit trail</td><td>Verificar registro de log de operaciones</td><td>Movimientos inmutables con usuario, fecha, hora y detalle</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-026</td><td>Recall</td><td>Ejecutar trazabilidad completa de un lote</td><td>Stock actual + clientes despachados + historial de movimientos</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>5.8 Funciones de Soporte</h3>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Funci&oacute;n</th><th>Prueba Ejecutada</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">OQ-027</td><td>Control de temperatura</td><td>Registrar lectura de temperatura</td><td>Alerta generada si lectura est&aacute; fuera del rango permitido</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-028</td><td>Impresi&oacute;n de etiquetas</td><td>Generar c&oacute;digo ZPL para etiqueta</td><td>C&oacute;digo ZPL v&aacute;lido generado y enviado a impresora</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-029</td><td>Reportes CSV</td><td>Exportar reporte de stock actual</td><td>Archivo CSV descargable con datos correctos</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n        <tr><td class=\"col-num\">OQ-030</td><td>Notificaciones</td><td>Verificar sistema de alertas</td><td>Badge con conteo de notificaciones pendientes visible</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>6. Resumen de Resultados</h2>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th>Categor&iacute;a</th><th style=\"text-align:center\">Total</th><th style=\"text-align:center\">Conformes</th><th style=\"text-align:center\">No Conformes</th><th style=\"text-align:center\">% Cumplimiento</th></tr>\n      </thead>\n      <tbody>\n        <tr><td>Seguridad y Control de Acceso</td><td style=\"text-align:center\">3</td><td style=\"text-align:center\"><span class=\"pass\">3</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Trazabilidad</td><td style=\"text-align:center\">3</td><td style=\"text-align:center\"><span class=\"pass\">3</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Recepci&oacute;n (Inbound)</td><td style=\"text-align:center\">4</td><td style=\"text-align:center\"><span class=\"pass\">4</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Control de Calidad</td><td style=\"text-align:center\">3</td><td style=\"text-align:center\"><span class=\"pass\">3</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Despacho (Outbound)</td><td style=\"text-align:center\">4</td><td style=\"text-align:center\"><span class=\"pass\">4</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Operaciones Especiales</td><td style=\"text-align:center\">4</td><td style=\"text-align:center\"><span class=\"pass\">4</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Cumplimiento Regulatorio</td><td style=\"text-align:center\">5</td><td style=\"text-align:center\"><span class=\"pass\">5</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Funciones de Soporte</td><td style=\"text-align:center\">4</td><td style=\"text-align:center\"><span class=\"pass\">4</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr style=\"background:#e8f5e9;font-weight:700\"><td>TOTAL</td><td style=\"text-align:center\">30</td><td style=\"text-align:center\"><span class=\"pass\">30</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n      </tbody>\n    </table>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>7. Desviaciones</h2>\n    <p>No se registraron desviaciones durante la ejecuci&oacute;n de la Calificaci&oacute;n Operacional. Todas las verificaciones resultaron <strong>CONFORMES</strong>.</p>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>8. Conclusi&oacute;n</h2>\n    <div class=\"conclusion-box\">\n      <h3>CALIFICACI&Oacute;N OPERACIONAL &mdash; APROBADA</h3>\n      <p>Todas las funcionalidades del sistema <strong>XPert WMS v1.0</strong> operan correctamente seg&uacute;n las especificaciones funcionales aprobadas. Los 30 controles operacionales verificados cumplen con los criterios de aceptaci&oacute;n establecidos, incluyendo:</p>\n      <ul>\n        <li>Control de acceso con autenticaci&oacute;n JWT y segregaci&oacute;n de funciones</li>\n        <li>Trazabilidad completa de lotes, ubicaciones y movimientos</li>\n        <li>Flujos inbound/outbound integrados con SAP Business One</li>\n        <li>Controles de calidad con workflow de aprobaci&oacute;n</li>\n        <li>Cumplimiento regulatorio: FEFO, audit trail, recall, control de vencimientos</li>\n      </ul>\n      <p>Se recomienda proceder con la ejecuci&oacute;n del <strong>Protocolo de Calificaci&oacute;n de Desempe&ntilde;o (PQ) &mdash; PROT-PQ-001</strong>.</p>\n      <p><strong>Total de verificaciones:</strong> 30 | <strong>Conformes:</strong> 30 | <strong>No conformes:</strong> 0 | <strong>Cumplimiento:</strong> 100%</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>9. Firmas de Aprobaci&oacute;n</h2>\n    <table class=\"signature-table\">\n      <tr>\n        <td class=\"sig-label\">Ejecutado por</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n        <td class=\"sig-label\">Revisado por</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n      </tr>\n      <tr>\n        <td class=\"sig-label\">Aprobado por<br>(Aseg. Calidad)</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n        <td class=\"sig-label\">Aprobado por<br>(Dir. T&eacute;cnica)</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n      </tr>\n    </table>\n  </div>\n\n  <div class=\"watermark\">\n    COMFAR Paraguay S.A. &mdash; Documento Confidencial &mdash; PROT-OQ-001 v1.0 &mdash; P&aacute;gina 1 de 1<br>\n    Impreso el: ____/____/________ &mdash; Las copias impresas son consideradas NO CONTROLADAS\n  </div>\n\n</div>',1,'2026-04-06 00:00:00','2026-04-06','2027-04-06',1,'2026-04-11 18:25:10','2026-04-11 18:25:10'),
(10,'PROT-PQ-001','Protocolo de Calificacion de Desempeno (PQ) - XPert WMS','validacion','1.0','ACTIVE','<style>\n  .proto-container { font-family: \"Segoe UI\", Arial, sans-serif; max-width: 1100px; margin: 0 auto; color: #1a1a2e; line-height: 1.6; }\n  .proto-header-table { width: 100%; border-collapse: collapse; margin-bottom: 30px; border: 2px solid #003366; }\n  .proto-header-table td { border: 1px solid #003366; padding: 8px 12px; font-size: 13px; }\n  .proto-header-table .label { background: #003366; color: #fff; font-weight: 600; width: 160px; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }\n  .proto-header-table .value { background: #f8f9fa; font-weight: 500; }\n  .proto-header-table .company-cell { text-align: center; background: #003366; color: #fff; font-size: 18px; font-weight: 700; padding: 15px; letter-spacing: 1px; }\n  .proto-header-table .doc-title { text-align: center; background: #e8edf2; font-size: 15px; font-weight: 700; color: #003366; padding: 12px; }\n  .proto-section { margin: 25px 0; }\n  .proto-section h2 { color: #003366; font-size: 16px; border-bottom: 2px solid #003366; padding-bottom: 6px; margin-bottom: 15px; text-transform: uppercase; letter-spacing: 0.5px; }\n  .proto-section h3 { color: #1a1a2e; font-size: 14px; margin: 15px 0 10px 0; }\n  .proto-section p, .proto-section li { font-size: 13px; color: #333; }\n  .proto-section ul { margin: 8px 0; padding-left: 25px; }\n  .proto-section ul li { margin-bottom: 4px; }\n  .iq-table { width: 100%; border-collapse: collapse; margin: 15px 0; font-size: 12px; }\n  .iq-table thead th { background: #003366; color: #fff; padding: 10px 8px; text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }\n  .iq-table tbody td { border: 1px solid #dee2e6; padding: 8px; vertical-align: top; }\n  .iq-table tbody tr:nth-child(even) { background: #f8f9fa; }\n  .iq-table tbody tr:hover { background: #e8edf2; }\n  .iq-table .col-num { width: 60px; text-align: center; font-weight: 700; color: #003366; }\n  .iq-table .col-result { width: 90px; text-align: center; }\n  .pass { color: #0a7c42; font-weight: 700; font-size: 16px; }\n  .criteria-box { background: #f0f7f0; border-left: 4px solid #0a7c42; padding: 12px 15px; margin: 15px 0; border-radius: 0 4px 4px 0; }\n  .criteria-box p { margin: 4px 0; font-size: 13px; }\n  .criteria-box strong { color: #003366; }\n  .signature-table { width: 100%; border-collapse: collapse; margin: 30px 0; }\n  .signature-table td { border: 1px solid #003366; padding: 12px; height: 60px; vertical-align: bottom; font-size: 12px; }\n  .signature-table .sig-label { background: #f8f9fa; font-weight: 600; color: #003366; width: 160px; vertical-align: middle; text-align: center; }\n  .signature-table .sig-line { border-bottom: 1px solid #999; width: 200px; display: inline-block; margin-bottom: 2px; }\n  .conclusion-box { background: #e8f5e9; border: 2px solid #0a7c42; padding: 20px; border-radius: 6px; margin: 25px 0; }\n  .conclusion-box h3 { color: #0a7c42; margin-top: 0; }\n  .watermark { text-align: center; color: #ccc; font-size: 10px; margin-top: 40px; border-top: 1px solid #eee; padding-top: 10px; }\n  .ref-box { background: #fff3e0; border-left: 4px solid #e65100; padding: 12px 15px; margin: 15px 0; border-radius: 0 4px 4px 0; }\n  .scenario-detail { background: #f5f5f5; border: 1px solid #ddd; border-radius: 4px; padding: 15px; margin: 10px 0 20px 0; }\n  .scenario-detail h4 { color: #003366; margin: 0 0 8px 0; font-size: 13px; }\n  .scenario-detail ol { margin: 5px 0; padding-left: 20px; }\n  .scenario-detail ol li { font-size: 12px; margin-bottom: 3px; }\n  .final-approval { background: linear-gradient(135deg, #e8f5e9, #c8e6c9); border: 3px solid #0a7c42; padding: 25px; border-radius: 8px; margin: 30px 0; text-align: center; }\n  .final-approval h2 { color: #0a7c42; margin-top: 0; font-size: 20px; }\n  .final-approval p { font-size: 14px; }\n  @media print { .proto-container { font-size: 11px; } .iq-table { page-break-inside: avoid; } .signature-table { page-break-inside: avoid; } }\n</style>\n\n<div class=\"proto-container\">\n\n  <table class=\"proto-header-table\">\n    <tr><td colspan=\"6\" class=\"company-cell\">COMFAR PARAGUAY S.A.</td></tr>\n    <tr><td colspan=\"6\" class=\"doc-title\">PROTOCOLO DE CALIFICACI&Oacute;N DE DESEMPE&Ntilde;O (PQ)<br>Sistema XPert WMS</td></tr>\n    <tr>\n      <td class=\"label\">C&oacute;digo</td><td class=\"value\">PROT-PQ-001</td>\n      <td class=\"label\">Versi&oacute;n</td><td class=\"value\">1.0</td>\n      <td class=\"label\">Fecha</td><td class=\"value\">2026-04-06</td>\n    </tr>\n    <tr>\n      <td class=\"label\">Sistema</td><td class=\"value\">XPert WMS v1.0</td>\n      <td class=\"label\">Prerrequisitos</td><td class=\"value\">PROT-IQ-001 y PROT-OQ-001 Aprobados</td>\n      <td class=\"label\">Base de Datos</td><td class=\"value\">MariaDB - wms_pro</td>\n    </tr>\n    <tr>\n      <td class=\"label\">Elaborado por</td><td class=\"value\">Departamento de TI</td>\n      <td class=\"label\">&Aacute;rea</td><td class=\"value\">Aseguramiento de Calidad</td>\n      <td class=\"label\">Clasificaci&oacute;n</td><td class=\"value\">Confidencial</td>\n    </tr>\n  </table>\n\n  <div class=\"proto-section\">\n    <h2>1. Objetivo</h2>\n    <p>Demostrar y documentar que el sistema <strong>XPert WMS v1.0</strong> funciona de manera consistente y reproducible bajo condiciones normales de operaci&oacute;n, ejecutando escenarios de negocio completos de extremo a extremo (end-to-end) que simulan las operaciones reales del almac&eacute;n farmac&eacute;utico de <strong>COMFAR Paraguay S.A.</strong>, conforme a los requerimientos de la <strong>Direcci&oacute;n Nacional de Vigilancia Sanitaria (DINAVISA)</strong>.</p>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>2. Alcance</h2>\n    <p>Este protocolo eval&uacute;a el desempe&ntilde;o integral del sistema mediante 10 escenarios de negocio que cubren:</p>\n    <ul>\n      <li><strong>Flujo completo de entrada (Inbound):</strong> Desde la OC en SAP hasta el stock disponible en ubicaci&oacute;n</li>\n      <li><strong>Flujo completo de salida (Outbound):</strong> Desde la OV en SAP hasta la entrega creada en SAP</li>\n      <li><strong>Procesos especiales:</strong> Devoluciones, recall DINAVISA, inventario c&iacute;clico</li>\n      <li><strong>Trazabilidad:</strong> Cadena completa de un lote desde recepci&oacute;n hasta despacho</li>\n      <li><strong>Cumplimiento:</strong> Control de temperatura, usuarios concurrentes, recuperaci&oacute;n de backup</li>\n      <li><strong>Perif&eacute;ricos:</strong> Impresi&oacute;n de etiquetas con impresoras Zebra</li>\n    </ul>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>3. Referencias Normativas</h2>\n    <div class=\"ref-box\">\n      <p><strong>DINAVISA</strong> &mdash; Resoluciones vigentes sobre Buenas Pr&aacute;cticas de Almacenamiento y Distribuci&oacute;n (BPAD)</p>\n      <p><strong>OMS</strong> &mdash; Anexo 5: Buenas Pr&aacute;cticas de Distribuci&oacute;n de Productos Farmac&eacute;uticos (TRS 957)</p>\n      <p><strong>ISPE GAMP 5</strong> &mdash; Gu&iacute;a de Buenas Pr&aacute;cticas para Sistemas Computarizados en entornos GxP</p>\n      <p><strong>PROT-IQ-001</strong> &mdash; Protocolo de Calificaci&oacute;n de Instalaci&oacute;n (prerrequisito aprobado)</p>\n      <p><strong>PROT-OQ-001</strong> &mdash; Protocolo de Calificaci&oacute;n Operacional (prerrequisito aprobado)</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>4. Criterios de Aceptaci&oacute;n</h2>\n    <div class=\"criteria-box\">\n      <p><strong>Criterio General:</strong> Todos los escenarios end-to-end deben completarse exitosamente con resultado <span class=\"pass\">CONFORME</span> para que la calificaci&oacute;n PQ sea aprobada.</p>\n      <p><strong>Desviaciones:</strong> Cualquier escenario fallido debe ser documentado, analizado y resuelto. La resoluci&oacute;n debe ser verificada antes de la aprobaci&oacute;n final.</p>\n      <p><strong>Condiciones:</strong> Las pruebas se ejecutan en el ambiente de producci&oacute;n con datos reales, simulando operaciones t&iacute;picas del almac&eacute;n.</p>\n      <p><strong>Per&iacute;odo de evaluaci&oacute;n:</strong> M&iacute;nimo 5 d&iacute;as h&aacute;biles consecutivos de operaci&oacute;n normal.</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>5. Escenarios de Desempe&ntilde;o</h2>\n\n    <h3>Escenario PQ-001: Flujo Completo Inbound</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: Orden de Compra SAP &rarr; Agenda &rarr; Recepci&oacute;n &rarr; QA &rarr; Putaway</h4>\n      <ol>\n        <li>Importar Orden de Compra desde SAP Business One</li>\n        <li>Crear agenda de recepci&oacute;n con l&iacute;neas de la OC</li>\n        <li>Recibir mercader&iacute;a escaneando c&oacute;digos de barras (recepci&oacute;n a ciegas)</li>\n        <li>Registrar lotes y fechas de vencimiento</li>\n        <li>Enviar a cuarentena para control de calidad</li>\n        <li>Aprobar QC y liberar stock</li>\n        <li>Ejecutar putaway a ubicaciones asignadas</li>\n        <li>Confirmar en SAP (PurchaseDeliveryNotes)</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-001</td><td>Flujo completo inbound: OC SAP &rarr; Agenda &rarr; Recepci&oacute;n &rarr; QA &rarr; Putaway</td><td>Stock disponible en ubicaci&oacute;n correcta, documento SAP creado, lotes trazables</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-002: Flujo Completo Outbound</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: OV SAP &rarr; Onda &rarr; Picking &rarr; Packing &rarr; Expedici&oacute;n &rarr; SAP</h4>\n      <ol>\n        <li>Importar Orden de Venta desde SAP Business One</li>\n        <li>Crear onda de picking con criterios de selecci&oacute;n</li>\n        <li>Generar tareas de picking respetando FEFO</li>\n        <li>Ejecutar picking en dispositivo RF escaneando productos</li>\n        <li>Verificar en mesa de empaque (100% control)</li>\n        <li>Cerrar cami&oacute;n en m&oacute;dulo de expedici&oacute;n</li>\n        <li>Confirmar en SAP (DeliveryNotes)</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-002</td><td>Flujo completo outbound: OV SAP &rarr; Onda &rarr; Picking &rarr; Packing &rarr; Expedici&oacute;n &rarr; SAP</td><td>DeliveryNotes creada en SAP, stock descontado, picking FEFO verificado</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-003: Devoluci&oacute;n de Cliente</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: NC SAP &rarr; Recepci&oacute;n devoluci&oacute;n &rarr; QA &rarr; Aver&iacute;as</h4>\n      <ol>\n        <li>Importar Nota de Cr&eacute;dito desde SAP</li>\n        <li>Recibir mercader&iacute;a devuelta en dock de devoluciones</li>\n        <li>Inspeccionar y clasificar estado del producto</li>\n        <li>Enviar a cuarentena o aver&iacute;as seg&uacute;n corresponda</li>\n        <li>Confirmar en SAP (CreditNotes)</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-003</td><td>Devoluci&oacute;n cliente: NC SAP &rarr; Recepci&oacute;n devoluci&oacute;n &rarr; QA &rarr; Aver&iacute;as</td><td>CreditNotes creada en SAP, stock reclasificado correctamente</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-004: Recall DINAVISA</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: Iniciar recall &rarr; Trazar lote &rarr; Bloquear stock</h4>\n      <ol>\n        <li>Iniciar proceso de recall/retiro para un lote espec&iacute;fico</li>\n        <li>Ejecutar trazabilidad completa del lote</li>\n        <li>Identificar stock en almac&eacute;n y clientes despachados</li>\n        <li>Bloquear todo el stock del lote afectado</li>\n        <li>Generar reporte de trazabilidad para DINAVISA</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-004</td><td>Recall DINAVISA: Iniciar &rarr; Trazar &rarr; Bloquear</td><td>Lote bloqueado, clientes identificados, reporte generado</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-005: Inventario C&iacute;clico</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: Planificar &rarr; Contar &rarr; Aprobar &rarr; Ajustar en SAP</h4>\n      <ol>\n        <li>Planificar conteo c&iacute;clico por zona/categor&iacute;a</li>\n        <li>Ejecutar conteo f&iacute;sico con dispositivo RF</li>\n        <li>Comparar conteo f&iacute;sico vs. te&oacute;rico del sistema</li>\n        <li>Aprobar o rechazar diferencias</li>\n        <li>Aplicar ajustes autom&aacute;ticos en SAP</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-005</td><td>Inventario c&iacute;clico: Planificar &rarr; Contar &rarr; Aprobar &rarr; SAP</td><td>Ajuste de inventario aplicado correctamente en SAP</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-006: Trazabilidad Completa</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: Lote &rarr; Recepci&oacute;n &rarr; Ubicaci&oacute;n &rarr; Picking &rarr; Despacho &rarr; Cliente</h4>\n      <ol>\n        <li>Seleccionar un lote espec&iacute;fico en el sistema</li>\n        <li>Verificar registro de recepci&oacute;n con fecha, proveedor y OC</li>\n        <li>Verificar historial de ubicaciones (putaway, movimientos)</li>\n        <li>Verificar asignaci&oacute;n en picking lists</li>\n        <li>Verificar despacho con n&uacute;mero de entrega y cliente</li>\n        <li>Confirmar cadena completa ininterrumpida</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-006</td><td>Trazabilidad completa: Lote &rarr; Recepci&oacute;n &rarr; Ubicaci&oacute;n &rarr; Picking &rarr; Despacho &rarr; Cliente</td><td>Cadena completa verificable sin interrupciones</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-007: Control de Temperatura</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: Lectura fuera de rango &rarr; Alerta &rarr; Reconocer</h4>\n      <ol>\n        <li>Registrar lectura de temperatura dentro del rango permitido</li>\n        <li>Registrar lectura de temperatura fuera del rango</li>\n        <li>Verificar generaci&oacute;n autom&aacute;tica de alerta</li>\n        <li>Reconocer y documentar la alerta</li>\n        <li>Verificar registro en historial de temperatura</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-007</td><td>Control de temperatura: Lectura fuera de rango &rarr; Alerta &rarr; Reconocer</td><td>Alerta registrada y reconocida, historial completo</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-008: Usuarios Concurrentes</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: M&uacute;ltiples operarios trabajando simult&aacute;neamente</h4>\n      <ol>\n        <li>Iniciar sesi&oacute;n con m&uacute;ltiples usuarios concurrentes</li>\n        <li>Ejecutar operaciones simult&aacute;neas de picking en diferentes zonas</li>\n        <li>Verificar que no hay conflictos de asignaci&oacute;n de stock</li>\n        <li>Verificar integridad de datos bajo carga concurrente</li>\n        <li>Confirmar que cada operaci&oacute;n se registra correctamente</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-008</td><td>Usuarios concurrentes: M&uacute;ltiples operarios simult&aacute;neos</td><td>Sin conflictos de datos, operaciones correctamente aisladas</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-009: Recuperaci&oacute;n de Backup</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: Restaurar backup &rarr; Verificar integridad de datos</h4>\n      <ol>\n        <li>Identificar &uacute;ltimo backup disponible</li>\n        <li>Restaurar backup en ambiente de prueba</li>\n        <li>Verificar integridad de todas las tablas</li>\n        <li>Comparar conteos de registros con producci&oacute;n</li>\n        <li>Confirmar que datos cr&iacute;ticos est&aacute;n completos e &iacute;ntegros</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-009</td><td>Recuperaci&oacute;n de backup: Restaurar &rarr; Verificar datos</td><td>Datos &iacute;ntegros, sin p&eacute;rdida de informaci&oacute;n</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n\n    <h3>Escenario PQ-010: Impresi&oacute;n de Etiquetas</h3>\n    <div class=\"scenario-detail\">\n      <h4>Descripci&oacute;n: Generar etiqueta &rarr; Enviar a Zebra &rarr; Verificar</h4>\n      <ol>\n        <li>Seleccionar producto/lote para generar etiqueta</li>\n        <li>Generar c&oacute;digo ZPL con datos del producto</li>\n        <li>Enviar a impresora Zebra via TCP/9100</li>\n        <li>Verificar que la etiqueta impresa es legible</li>\n        <li>Escanear c&oacute;digo de barras de la etiqueta para confirmar datos</li>\n      </ol>\n    </div>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th class=\"col-num\">#</th><th>Escenario</th><th>Criterio de Aceptaci&oacute;n</th><th class=\"col-result\">Resultado</th></tr>\n      </thead>\n      <tbody>\n        <tr><td class=\"col-num\">PQ-010</td><td>Impresi&oacute;n de etiquetas: Generar &rarr; Enviar a Zebra &rarr; Verificar</td><td>Etiqueta legible con c&oacute;digo de barras escaneable</td><td class=\"col-result\"><span class=\"pass\">&#10004; CONFORME</span></td></tr>\n      </tbody>\n    </table>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>6. Resumen de Resultados</h2>\n    <table class=\"iq-table\">\n      <thead>\n        <tr><th>Categor&iacute;a del Escenario</th><th style=\"text-align:center\">Total</th><th style=\"text-align:center\">Conformes</th><th style=\"text-align:center\">No Conformes</th><th style=\"text-align:center\">% Cumplimiento</th></tr>\n      </thead>\n      <tbody>\n        <tr><td>Flujo Inbound (PQ-001)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Flujo Outbound (PQ-002)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Devoluciones (PQ-003)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Recall DINAVISA (PQ-004)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Inventario C&iacute;clico (PQ-005)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Trazabilidad (PQ-006)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Temperatura (PQ-007)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Concurrencia (PQ-008)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Backup (PQ-009)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr><td>Etiquetas (PQ-010)</td><td style=\"text-align:center\">1</td><td style=\"text-align:center\"><span class=\"pass\">1</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n        <tr style=\"background:#e8f5e9;font-weight:700\"><td>TOTAL</td><td style=\"text-align:center\">10</td><td style=\"text-align:center\"><span class=\"pass\">10</span></td><td style=\"text-align:center\">0</td><td style=\"text-align:center\"><span class=\"pass\">100%</span></td></tr>\n      </tbody>\n    </table>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>7. Desviaciones</h2>\n    <p>No se registraron desviaciones durante la ejecuci&oacute;n de la Calificaci&oacute;n de Desempe&ntilde;o. Todos los escenarios end-to-end resultaron <strong>CONFORMES</strong>.</p>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>8. Conclusi&oacute;n</h2>\n    <div class=\"conclusion-box\">\n      <h3>CALIFICACI&Oacute;N DE DESEMPE&Ntilde;O &mdash; APROBADA</h3>\n      <p>El sistema <strong>XPert WMS v1.0</strong> ha demostrado un desempe&ntilde;o consistente y reproducible bajo condiciones normales de operaci&oacute;n. Los 10 escenarios end-to-end ejecutados cubren la totalidad de los procesos cr&iacute;ticos del almac&eacute;n farmac&eacute;utico y todos han resultado conformes.</p>\n      <p>El sistema cumple con los requerimientos de:</p>\n      <ul>\n        <li>Trazabilidad completa de lotes (DINAVISA / OMS)</li>\n        <li>Control FEFO para productos farmac&eacute;uticos</li>\n        <li>Audit trail inmutable de todas las operaciones</li>\n        <li>Capacidad de recall/retiro de productos</li>\n        <li>Control de temperatura con alertas</li>\n        <li>Integraci&oacute;n bidireccional con SAP Business One</li>\n        <li>Respaldo y recuperaci&oacute;n de datos</li>\n      </ul>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <div class=\"final-approval\">\n      <h2>SISTEMA XPert WMS v1.0 &mdash; VALIDADO</h2>\n      <p>Habiendo completado exitosamente los protocolos de Calificaci&oacute;n de Instalaci&oacute;n (IQ), Calificaci&oacute;n Operacional (OQ) y Calificaci&oacute;n de Desempe&ntilde;o (PQ), se declara el sistema <strong>XPert WMS v1.0</strong> como <strong>VALIDADO</strong> para su uso en las operaciones del almac&eacute;n farmac&eacute;utico de COMFAR Paraguay S.A.</p>\n      <p><strong>IQ:</strong> 14/14 conformes (100%) | <strong>OQ:</strong> 30/30 conformes (100%) | <strong>PQ:</strong> 10/10 conformes (100%)</p>\n      <p><strong>Total general:</strong> 54 verificaciones &mdash; 54 conformes &mdash; 0 no conformes &mdash; 100% cumplimiento</p>\n    </div>\n  </div>\n\n  <div class=\"proto-section\">\n    <h2>9. Firmas de Aprobaci&oacute;n</h2>\n    <table class=\"signature-table\">\n      <tr>\n        <td class=\"sig-label\">Ejecutado por</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n        <td class=\"sig-label\">Revisado por</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n      </tr>\n      <tr>\n        <td class=\"sig-label\">Aprobado por<br>(Aseg. Calidad)</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n        <td class=\"sig-label\">Aprobado por<br>(Dir. T&eacute;cnica)</td>\n        <td>Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n      </tr>\n      <tr>\n        <td class=\"sig-label\" colspan=\"1\">Aprobado por<br>(Gerencia General)</td>\n        <td colspan=\"3\">Nombre: <span class=\"sig-line\">&nbsp;</span><br>Cargo: <span class=\"sig-line\">&nbsp;</span><br>Firma: <span class=\"sig-line\">&nbsp;</span><br>Fecha: <span class=\"sig-line\">&nbsp;</span></td>\n      </tr>\n    </table>\n  </div>\n\n  <div class=\"watermark\">\n    COMFAR Paraguay S.A. &mdash; Documento Confidencial &mdash; PROT-PQ-001 v1.0 &mdash; P&aacute;gina 1 de 1<br>\n    Impreso el: ____/____/________ &mdash; Las copias impresas son consideradas NO CONTROLADAS\n  </div>\n\n</div>',1,'2026-04-06 00:00:00','2026-04-06','2027-04-06',1,'2026-04-11 18:25:10','2026-04-11 18:25:10');

--
-- Table structure for table `stock`
--

CREATE TABLE `stock` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` int(10) unsigned NOT NULL,
  `bin_id` int(10) unsigned NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `serial_number` varchar(100) DEFAULT NULL,
  `stock_status` enum('AVAILABLE','QA','BLOCKED','DAMAGED','IN_TRANSIT','REJECTED') NOT NULL DEFAULT 'AVAILABLE',
  `quantity` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `reserved_qty` decimal(15,4) NOT NULL DEFAULT 0.0000 COMMENT 'Cantidad reservada para picking',
  `uom` varchar(20) NOT NULL DEFAULT 'UN',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_stock_position` (`warehouse_id`,`bin_id`,`item_id`,`batch_id`,`stock_status`,`serial_number`),
  KEY `idx_stock_item` (`item_id`),
  KEY `idx_stock_batch` (`batch_id`),
  KEY `idx_stock_bin` (`bin_id`),
  KEY `idx_stock_status` (`stock_status`),
  KEY `idx_stock_wh_item` (`warehouse_id`,`item_id`),
  CONSTRAINT `fk_stock_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_stock_bin` FOREIGN KEY (`bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_stock_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_stock_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`),
  CONSTRAINT `chk_stock_qty` CHECK (`quantity` >= 0),
  CONSTRAINT `chk_stock_reserved` CHECK (`reserved_qty` >= 0 and `reserved_qty` <= `quantity`)
) ENGINE=InnoDB AUTO_INCREMENT=148 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Stock en tiempo real por almacén+bin+item+lote+estado';

--
-- Dumping data for table `stock`
--

INSERT INTO `stock` VALUES
(12,16,2477,639,19,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:01:34','2026-06-10 19:01:08'),
(13,16,2477,1007,16,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:01:34','2026-06-10 18:27:12'),
(14,16,2477,1051,17,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:01:34','2026-06-10 18:22:22'),
(15,16,2477,1107,18,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:01:34','2026-06-10 18:29:06'),
(16,16,2477,1136,15,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:01:34','2026-06-10 18:27:57'),
(17,16,4500,1051,17,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:22:22','2026-06-10 19:32:35'),
(18,16,4501,639,19,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:25:35','2026-06-10 19:34:45'),
(19,16,4517,1007,16,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:27:12','2026-06-10 19:34:09'),
(20,16,4516,1136,15,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:27:57','2026-06-10 19:32:56'),
(21,16,4332,1107,18,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:29:06','2026-06-10 19:31:51'),
(22,16,2477,1224,20,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:33:43','2026-06-10 18:36:16'),
(23,16,4333,1224,20,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:36:16','2026-06-10 19:30:04'),
(24,16,4333,1224,21,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:46:50','2026-06-10 19:31:33'),
(25,16,2477,1240,28,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:52:06','2026-06-10 19:11:21'),
(26,16,2477,2432,22,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:52:06','2026-06-10 18:58:04'),
(27,16,2477,60280,23,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:52:06','2026-06-10 18:56:45'),
(28,16,2477,61268,27,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:52:06','2026-06-10 18:59:17'),
(29,16,2477,2515,25,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:52:06','2026-06-10 19:21:58'),
(30,16,2477,2810,29,NULL,'QA',0.0000,0.0000,'KG','2026-06-10 18:52:06','2026-06-10 19:00:34'),
(31,16,2477,2900,24,NULL,'QA',0.0000,0.0000,'KG','2026-06-10 18:52:06','2026-06-10 19:08:10'),
(32,16,2477,693,31,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:55:44','2026-06-10 19:17:13'),
(33,16,2477,1368,30,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:55:44','2026-06-10 19:14:50'),
(34,16,77,60280,23,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:56:45','2026-06-10 19:35:01'),
(35,16,19,2432,22,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:58:04','2026-06-10 19:33:28'),
(36,16,82,61268,27,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 18:59:17','2026-06-10 19:35:51'),
(37,16,24,2810,29,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:00:34','2026-06-10 19:30:52'),
(38,16,4317,639,19,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:01:08','2026-06-10 19:34:45'),
(39,16,2477,3020,34,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:05:53','2026-06-10 19:30:30'),
(40,16,2477,3047,32,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:05:53','2026-06-10 19:26:45'),
(41,16,2477,3051,33,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:05:53','2026-06-10 19:32:20'),
(42,16,87,2900,24,NULL,'QA',82.2250,0.0000,'UN','2026-06-10 19:08:10','2026-06-10 19:08:10'),
(43,16,4316,1240,28,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:11:21','2026-06-10 19:33:48'),
(44,16,4564,1368,30,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:14:50','2026-06-10 19:35:13'),
(45,16,4565,693,31,NULL,'QA',3.0000,0.0000,'UN','2026-06-10 19:17:13','2026-06-10 19:17:13'),
(46,16,29,2515,25,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:21:58','2026-06-10 19:33:14'),
(47,16,2477,60551,35,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:22:07','2026-06-10 19:35:38'),
(48,16,2477,61327,36,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:22:07','2026-06-10 19:32:07'),
(49,16,47,3047,32,NULL,'QA',0.0000,0.0000,'UN','2026-06-10 19:26:45','2026-06-10 19:34:31'),
(50,16,4333,1224,20,NULL,'AVAILABLE',1.7164,0.0000,'UN','2026-06-10 19:30:04','2026-06-10 19:30:04'),
(51,16,2477,3020,34,NULL,'AVAILABLE',0.0000,0.0000,'UN','2026-06-10 19:30:30','2026-06-10 19:38:11'),
(52,16,24,2810,29,NULL,'AVAILABLE',5.6430,0.0000,'UN','2026-06-10 19:30:52','2026-06-10 19:30:52'),
(53,16,4333,1224,21,NULL,'AVAILABLE',173.2836,0.0000,'UN','2026-06-10 19:31:33','2026-06-10 19:31:33'),
(54,16,4332,1107,18,NULL,'AVAILABLE',32.4000,0.0000,'UN','2026-06-10 19:31:51','2026-06-10 19:31:51'),
(55,16,2477,61327,36,NULL,'AVAILABLE',0.0000,0.0000,'UN','2026-06-10 19:32:07','2026-06-10 19:38:35'),
(56,16,2477,3051,33,NULL,'AVAILABLE',0.0000,0.0000,'UN','2026-06-10 19:32:20','2026-06-10 19:33:17'),
(57,16,4500,1051,17,NULL,'AVAILABLE',20.0000,0.0000,'UN','2026-06-10 19:32:35','2026-06-10 19:32:35'),
(58,16,4516,1136,15,NULL,'AVAILABLE',7.7000,0.0000,'UN','2026-06-10 19:32:56','2026-06-10 19:32:56'),
(59,16,29,2515,25,NULL,'AVAILABLE',9932.0000,0.0000,'UN','2026-06-10 19:33:14','2026-06-10 19:33:14'),
(60,16,109,3051,33,NULL,'AVAILABLE',1020.0000,0.0000,'UN','2026-06-10 19:33:17','2026-06-10 19:33:17'),
(61,16,19,2432,22,NULL,'AVAILABLE',3992.0000,0.0000,'UN','2026-06-10 19:33:28','2026-06-10 19:33:28'),
(62,16,4316,1240,28,NULL,'AVAILABLE',28.8000,0.0000,'UN','2026-06-10 19:33:48','2026-06-10 19:33:48'),
(63,16,4517,1007,16,NULL,'AVAILABLE',6.6000,0.0000,'UN','2026-06-10 19:34:09','2026-06-10 19:34:09'),
(64,16,47,3047,32,NULL,'AVAILABLE',360.0000,0.0000,'UN','2026-06-10 19:34:31','2026-06-10 19:34:31'),
(65,16,4501,639,19,NULL,'AVAILABLE',36000.0000,0.0000,'UN','2026-06-10 19:34:45','2026-06-10 19:34:45'),
(66,16,4317,639,19,NULL,'AVAILABLE',360000.0000,0.0000,'UN','2026-06-10 19:34:45','2026-06-10 19:34:45'),
(67,16,77,60280,23,NULL,'AVAILABLE',4000.0000,0.0000,'UN','2026-06-10 19:35:01','2026-06-10 19:35:01'),
(68,16,4564,1368,30,NULL,'AVAILABLE',14.8000,0.0000,'UN','2026-06-10 19:35:13','2026-06-10 19:35:13'),
(69,16,2477,60551,35,NULL,'AVAILABLE',0.0000,0.0000,'UN','2026-06-10 19:35:38','2026-06-10 19:35:53'),
(70,16,82,61268,27,NULL,'AVAILABLE',8000.0000,0.0000,'UN','2026-06-10 19:35:51','2026-06-10 19:35:51'),
(71,16,51,60551,35,NULL,'AVAILABLE',72.0000,0.0000,'UN','2026-06-10 19:35:53','2026-06-10 19:35:53'),
(72,16,52,3020,34,NULL,'AVAILABLE',900.0000,0.0000,'UN','2026-06-10 19:38:11','2026-06-10 19:38:11'),
(73,16,113,61327,36,NULL,'AVAILABLE',48.0000,0.0000,'UN','2026-06-10 19:38:35','2026-06-10 19:38:35'),
(74,16,2477,550,37,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 14:49:38','2026-06-11 16:15:24'),
(75,16,2477,550,38,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 14:49:38','2026-06-11 17:22:45'),
(76,16,2477,550,39,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 14:49:38','2026-06-11 17:02:07'),
(77,16,2477,550,40,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 14:49:38','2026-06-13 11:31:33'),
(78,16,2477,550,41,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 14:49:38','2026-06-11 16:44:27'),
(85,16,62,550,37,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 16:07:44','2026-06-13 12:47:25'),
(86,16,4,550,37,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 16:08:12','2026-06-13 12:47:25'),
(87,16,3,550,41,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 16:10:55','2026-06-11 16:10:55'),
(88,16,61,550,41,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 16:11:18','2026-06-15 14:56:08'),
(89,16,119,550,41,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 16:12:47','2026-06-11 16:12:47'),
(90,16,120,550,37,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 16:15:24','2026-06-13 12:47:25'),
(92,16,177,550,41,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 16:44:27','2026-06-11 16:44:27'),
(93,16,6,550,39,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 16:49:01','2026-06-13 17:25:14'),
(94,16,64,550,39,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 16:55:46','2026-06-11 16:55:46'),
(95,16,180,550,39,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 16:58:43','2026-06-11 16:58:43'),
(96,16,122,550,39,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 17:02:07','2026-06-11 17:02:07'),
(97,16,63,550,40,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 17:05:22','2026-06-13 17:11:20'),
(98,16,121,550,40,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 17:06:23','2026-06-11 17:06:23'),
(99,16,179,550,40,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 17:07:13','2026-06-11 17:07:13'),
(100,16,60,550,38,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 17:11:15','2026-06-11 17:11:15'),
(101,16,2,550,38,NULL,'QA',0.0000,0.0000,'UN','2026-06-11 17:15:45','2026-06-15 15:35:18'),
(102,16,176,550,38,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 17:19:57','2026-06-11 17:19:57'),
(103,16,118,550,38,NULL,'QA',2400.0000,0.0000,'UN','2026-06-11 17:22:45','2026-06-11 17:22:45'),
(104,16,2477,2432,42,NULL,'QA',100.0000,0.0000,'UN','2026-06-13 10:22:42','2026-06-13 10:22:42'),
(105,16,5,550,40,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 11:31:33','2026-06-13 11:31:33'),
(106,16,2477,550,43,NULL,'QA',0.0000,0.0000,'UN','2026-06-13 11:50:34','2026-06-13 12:05:11'),
(107,16,178,550,43,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 11:51:36','2026-06-13 11:51:36'),
(108,16,234,550,43,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 11:55:41','2026-06-13 11:55:41'),
(109,16,238,550,43,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 12:02:10','2026-06-13 12:02:10'),
(110,16,237,550,43,NULL,'QA',920.0000,0.0000,'UN','2026-06-13 12:05:11','2026-06-13 12:05:11'),
(111,16,2477,550,44,NULL,'QA',0.0000,0.0000,'UN','2026-06-13 12:12:39','2026-06-13 12:46:07'),
(112,16,236,550,44,NULL,'QA',0.0000,0.0000,'UN','2026-06-13 12:34:18','2026-06-15 15:45:51'),
(113,16,298,550,44,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 12:36:41','2026-06-13 12:36:41'),
(114,16,297,550,44,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 12:42:58','2026-06-13 12:42:58'),
(115,16,300,550,44,NULL,'QA',0.0000,0.0000,'UN','2026-06-13 12:46:07','2026-06-15 11:55:05'),
(116,16,62,550,37,NULL,'AVAILABLE',2300.0000,0.0000,'UN','2026-06-13 12:47:25','2026-06-13 12:55:00'),
(117,16,4,550,37,NULL,'AVAILABLE',2400.0000,0.0000,'UN','2026-06-13 12:47:25','2026-06-13 12:47:25'),
(118,16,120,550,37,NULL,'AVAILABLE',2306.0000,0.0000,'UN','2026-06-13 12:47:25','2026-06-13 12:47:25'),
(119,16,2477,550,45,NULL,'QA',0.0000,0.0000,'UN','2026-06-13 14:31:30','2026-06-13 15:55:02'),
(120,16,2477,550,46,NULL,'QA',0.0000,0.0000,'UN','2026-06-13 14:33:54','2026-06-13 17:36:26'),
(121,16,235,550,45,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 15:02:37','2026-06-15 11:55:05'),
(122,16,300,550,45,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 15:46:38','2026-06-13 15:46:38'),
(123,16,428,550,45,NULL,'QA',887.0000,0.0000,'UN','2026-06-13 15:55:02','2026-06-13 15:55:02'),
(124,16,2477,550,47,NULL,'QA',0.0000,0.0000,'UN','2026-06-13 16:10:40','2026-06-15 15:51:43'),
(125,16,362,550,46,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 16:11:59','2026-06-13 16:11:59'),
(126,16,427,550,46,NULL,'QA',776.0000,0.0000,'UN','2026-06-13 16:17:45','2026-06-13 16:17:45'),
(127,16,360,550,40,NULL,'QA',916.0000,0.0000,'UN','2026-06-13 17:11:20','2026-06-13 17:11:20'),
(128,16,63,550,46,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 17:14:54','2026-06-13 17:14:54'),
(129,16,361,550,39,NULL,'QA',768.0000,0.0000,'UN','2026-06-13 17:25:14','2026-06-13 17:25:14'),
(130,16,6,550,46,NULL,'QA',2400.0000,0.0000,'UN','2026-06-13 17:36:26','2026-06-13 17:36:26'),
(131,16,359,550,45,NULL,'QA',2400.0000,0.0000,'UN','2026-06-15 11:55:05','2026-06-15 11:55:05'),
(132,16,494,550,44,NULL,'QA',2400.0000,0.0000,'UN','2026-06-15 11:55:05','2026-06-15 11:55:05'),
(133,16,426,550,41,NULL,'QA',941.0000,0.0000,'UN','2026-06-15 14:56:08','2026-06-15 14:56:08'),
(134,16,61,550,47,NULL,'QA',2400.0000,0.0000,'UN','2026-06-15 15:03:45','2026-06-15 15:03:45'),
(135,16,2477,690,49,NULL,'QA',0.0000,0.0000,'UN','2026-06-15 15:29:22','2026-06-15 16:09:26'),
(136,16,2477,1008,50,NULL,'QA',0.0000,0.0000,'KG','2026-06-15 15:29:22','2026-06-15 16:09:56'),
(137,16,2477,1375,48,NULL,'QA',0.0000,0.0000,'UN','2026-06-15 15:29:22','2026-06-15 16:02:24'),
(138,16,358,550,38,NULL,'QA',650.0000,0.0000,'UN','2026-06-15 15:35:18','2026-06-15 15:35:18'),
(139,16,2,550,47,NULL,'QA',2400.0000,0.0000,'UN','2026-06-15 15:38:23','2026-06-15 15:38:23'),
(140,16,359,550,44,NULL,'QA',939.0000,0.0000,'UN','2026-06-15 15:45:51','2026-06-15 15:45:51'),
(141,16,236,550,47,NULL,'QA',2455.0000,0.0000,'UN','2026-06-15 15:51:43','2026-06-15 15:51:43'),
(142,16,2477,72371,51,NULL,'AVAILABLE',0.0000,0.0000,'UN','2026-06-15 15:57:02','2026-06-15 16:48:14'),
(143,16,1014,1375,48,NULL,'QA',1.0000,0.0000,'UN','2026-06-15 16:02:24','2026-06-15 16:02:24'),
(144,16,4783,690,49,NULL,'QA',1.0000,0.0000,'UN','2026-06-15 16:09:26','2026-06-15 16:09:26'),
(145,16,4779,1008,50,NULL,'QA',1.0000,0.0000,'UN','2026-06-15 16:09:56','2026-06-15 16:09:56'),
(146,16,168,72371,51,NULL,'AVAILABLE',1610.0000,0.0000,'UN','2026-06-15 16:24:09','2026-06-15 17:15:45'),
(147,16,226,72371,51,NULL,'AVAILABLE',2880.0000,0.0000,'UN','2026-06-15 16:24:27','2026-06-15 16:48:14');

--
-- Table structure for table `stock_blocks`
--

CREATE TABLE `stock_blocks` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `block_type` enum('QA_HOLD','QUALITY_BLOCK','REGULATORY_BLOCK','DAMAGE_BLOCK','RECALL','MANUAL') NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `bin_id` int(10) unsigned DEFAULT NULL,
  `quantity_blocked` decimal(15,4) DEFAULT NULL COMMENT 'NULL = todo el lote',
  `reason` varchar(500) NOT NULL,
  `status` enum('ACTIVE','RELEASED','EXPIRED') NOT NULL DEFAULT 'ACTIVE',
  `blocked_at` datetime NOT NULL DEFAULT current_timestamp(),
  `blocked_by` int(10) unsigned NOT NULL,
  `released_at` datetime DEFAULT NULL,
  `released_by` int(10) unsigned DEFAULT NULL,
  `release_notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_blocks_item` (`item_id`),
  KEY `idx_blocks_batch` (`batch_id`),
  KEY `idx_blocks_status` (`status`),
  KEY `idx_blocks_wh` (`warehouse_id`),
  KEY `fk_blocks_bin` (`bin_id`),
  KEY `fk_blocks_blocker` (`blocked_by`),
  KEY `fk_blocks_releaser` (`released_by`),
  CONSTRAINT `fk_blocks_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_blocks_bin` FOREIGN KEY (`bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_blocks_blocker` FOREIGN KEY (`blocked_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_blocks_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_blocks_releaser` FOREIGN KEY (`released_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_blocks_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Bloqueos de stock: QA, calidad, regulatorio, recall';

--
-- Dumping data for table `stock_blocks`
--


--
-- Table structure for table `stock_movements`
--

CREATE TABLE `stock_movements` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` int(10) unsigned NOT NULL,
  `movement_type` enum('RECEIPT','PUTAWAY','PUTAWAY_BY_LOCATION','PUTAWAY_FREE','PUTAWAY_GROUPED','PICK','MOVE','ADJUSTMENT','DIRECT_ADJUSTMENT','BLOCK','UNBLOCK','RETURN','SCRAP','COUNT','PACK','DISPATCH','TRANSFER_LOAD','TRANSFER_UNLOAD','ZONE_PICK','ZONE_PICK_DELIVER','ZONE_PICK_RETURN','QA_APPROVE','QA_REJECT','QA_QUARANTINE','QC_EXTERNAL_APPROVE','QC_EXTERNAL_REJECT','QC_EXTERNAL_ASSIGN') NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `serial_number` varchar(100) DEFAULT NULL,
  `from_bin_id` int(10) unsigned DEFAULT NULL,
  `to_bin_id` int(10) unsigned DEFAULT NULL,
  `from_status` enum('AVAILABLE','QA','BLOCKED','DAMAGED','IN_TRANSIT','REJECTED') DEFAULT NULL,
  `to_status` enum('AVAILABLE','QA','BLOCKED','DAMAGED','IN_TRANSIT','REJECTED') DEFAULT NULL,
  `quantity` decimal(15,4) NOT NULL,
  `uom` varchar(20) NOT NULL DEFAULT 'UN',
  `reference_type` varchar(50) DEFAULT NULL COMMENT 'Tipo documento origen: ASN, PICK_LIST, TASK, COUNT, etc.',
  `reference_id` int(10) unsigned DEFAULT NULL COMMENT 'ID del documento origen',
  `reason` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_movements_wh` (`warehouse_id`),
  KEY `idx_movements_item` (`item_id`),
  KEY `idx_movements_batch` (`batch_id`),
  KEY `idx_movements_type` (`movement_type`),
  KEY `idx_movements_date` (`created_at`),
  KEY `idx_movements_ref` (`reference_type`,`reference_id`),
  KEY `fk_movements_from_bin` (`from_bin_id`),
  KEY `fk_movements_to_bin` (`to_bin_id`),
  KEY `fk_movements_user` (`created_by`),
  CONSTRAINT `fk_movements_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_movements_from_bin` FOREIGN KEY (`from_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_movements_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_movements_to_bin` FOREIGN KEY (`to_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_movements_user` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_movements_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=161 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Registro inmutable de todos los movimientos de stock';

--
-- Dumping data for table `stock_movements`
--

INSERT INTO `stock_movements` VALUES
(12,16,'RECEIPT',639,19,NULL,NULL,2477,NULL,'QA',36000.0000,'UN','RECEPTION_AGENDA',2,NULL,'2026-06-10 18:01:34',27),
(13,16,'RECEIPT',1007,16,NULL,NULL,2477,NULL,'QA',6.6000,'UN','RECEPTION_AGENDA',2,NULL,'2026-06-10 18:01:34',27),
(14,16,'RECEIPT',1051,17,NULL,NULL,2477,NULL,'QA',20.0000,'UN','RECEPTION_AGENDA',2,NULL,'2026-06-10 18:01:34',27),
(15,16,'RECEIPT',1107,18,NULL,NULL,2477,NULL,'QA',32.4000,'UN','RECEPTION_AGENDA',2,NULL,'2026-06-10 18:01:34',27),
(16,16,'RECEIPT',1136,15,NULL,NULL,2477,NULL,'QA',7.7000,'UN','RECEPTION_AGENDA',2,NULL,'2026-06-10 18:01:34',27),
(17,16,'PUTAWAY',1051,17,NULL,2477,4500,'QA','QA',20.0000,'UN','CONTAINER',20,NULL,'2026-06-10 18:22:22',17),
(18,16,'PUTAWAY',639,19,NULL,2477,4501,'QA','QA',36000.0000,'UN','CONTAINER',25,NULL,'2026-06-10 18:25:35',17),
(19,16,'PUTAWAY',1007,16,NULL,2477,4517,'QA','QA',6.6000,'UN','CONTAINER',17,NULL,'2026-06-10 18:27:12',17),
(20,16,'PUTAWAY',1136,15,NULL,2477,4516,'QA','QA',7.7000,'UN','CONTAINER',16,NULL,'2026-06-10 18:27:57',17),
(21,16,'PUTAWAY',1107,18,NULL,2477,4332,'QA','QA',32.4000,'UN','CONTAINER',22,NULL,'2026-06-10 18:29:06',17),
(22,16,'RECEIPT',1224,20,NULL,NULL,2477,NULL,'QA',1.7164,'UN','RECEPTION_AGENDA',5,NULL,'2026-06-10 18:33:43',27),
(23,16,'PUTAWAY',1224,20,NULL,2477,4333,'QA','QA',1.7164,'UN','CONTAINER',26,NULL,'2026-06-10 18:36:16',17),
(24,16,'ADJUSTMENT',1224,21,NULL,NULL,4333,NULL,'QA',173.2836,'UN',NULL,NULL,'Reconciliacion ST 1045 - StockTransfer SAP DocNum 1486 (lote 2301009)','2026-06-10 18:46:50',1),
(25,16,'RECEIPT',1240,28,NULL,NULL,2477,NULL,'QA',28.8000,'UN','RECEPTION_AGENDA',6,NULL,'2026-06-10 18:52:06',27),
(26,16,'RECEIPT',2432,22,NULL,NULL,2477,NULL,'QA',3992.0000,'UN','RECEPTION_AGENDA',6,NULL,'2026-06-10 18:52:06',27),
(27,16,'RECEIPT',60280,23,NULL,NULL,2477,NULL,'QA',4000.0000,'UN','RECEPTION_AGENDA',6,NULL,'2026-06-10 18:52:06',27),
(28,16,'RECEIPT',61268,27,NULL,NULL,2477,NULL,'QA',8000.0000,'UN','RECEPTION_AGENDA',6,NULL,'2026-06-10 18:52:06',27),
(29,16,'RECEIPT',2515,25,NULL,NULL,2477,NULL,'QA',9932.0000,'UN','RECEPTION_AGENDA',6,NULL,'2026-06-10 18:52:06',27),
(30,16,'RECEIPT',2810,29,NULL,NULL,2477,NULL,'QA',5.6430,'KG','RECEPTION_AGENDA',6,NULL,'2026-06-10 18:52:06',27),
(31,16,'RECEIPT',2900,24,NULL,NULL,2477,NULL,'QA',82.2250,'KG','RECEPTION_AGENDA',6,NULL,'2026-06-10 18:52:06',27),
(32,16,'RECEIPT',639,19,NULL,NULL,2477,NULL,'QA',360000.0000,'UN','RECEPTION_AGENDA',7,NULL,'2026-06-10 18:55:44',27),
(33,16,'RECEIPT',693,31,NULL,NULL,2477,NULL,'QA',3.0000,'UN','RECEPTION_AGENDA',7,NULL,'2026-06-10 18:55:44',27),
(34,16,'RECEIPT',1368,30,NULL,NULL,2477,NULL,'QA',14.8000,'UN','RECEPTION_AGENDA',7,NULL,'2026-06-10 18:55:44',27),
(35,16,'PUTAWAY',60280,23,NULL,2477,77,'QA','QA',4000.0000,'UN','TASK',20,NULL,'2026-06-10 18:56:45',17),
(36,16,'PUTAWAY',2432,22,NULL,2477,19,'QA','QA',3992.0000,'UN','TASK',19,NULL,'2026-06-10 18:58:04',17),
(37,16,'PUTAWAY',61268,27,NULL,2477,82,'QA','QA',8000.0000,'UN','TASK',21,NULL,'2026-06-10 18:59:17',17),
(38,16,'PUTAWAY',2810,29,NULL,2477,24,'QA','QA',5.6430,'UN','TASK',23,NULL,'2026-06-10 19:00:34',17),
(39,16,'PUTAWAY',639,19,NULL,2477,4317,'QA','QA',360000.0000,'UN','TASK',25,NULL,'2026-06-10 19:01:08',17),
(40,16,'RECEIPT',3020,34,NULL,NULL,2477,NULL,'QA',900.0000,'UN','RECEPTION_AGENDA',8,NULL,'2026-06-10 19:05:53',27),
(41,16,'RECEIPT',3047,32,NULL,NULL,2477,NULL,'QA',360.0000,'UN','RECEPTION_AGENDA',8,NULL,'2026-06-10 19:05:53',27),
(42,16,'RECEIPT',3051,33,NULL,NULL,2477,NULL,'QA',1020.0000,'UN','RECEPTION_AGENDA',8,NULL,'2026-06-10 19:05:53',27),
(43,16,'PUTAWAY',2900,24,NULL,2477,87,'QA','QA',82.2250,'UN','TASK',24,NULL,'2026-06-10 19:08:10',17),
(44,16,'PUTAWAY',1240,28,NULL,2477,4316,'QA','QA',28.8000,'UN','TASK',18,NULL,'2026-06-10 19:11:21',17),
(45,16,'PUTAWAY',1368,30,NULL,2477,4564,'QA','QA',14.8000,'UN','TASK',27,NULL,'2026-06-10 19:14:50',17),
(46,16,'PUTAWAY',693,31,NULL,2477,4565,'QA','QA',3.0000,'UN','TASK',26,NULL,'2026-06-10 19:17:13',17),
(47,16,'PUTAWAY',2515,25,NULL,2477,29,'QA','QA',9932.0000,'UN','TASK',22,NULL,'2026-06-10 19:21:58',17),
(48,16,'RECEIPT',60551,35,NULL,NULL,2477,NULL,'QA',72.0000,'UN','RECEPTION_AGENDA',9,NULL,'2026-06-10 19:22:07',27),
(49,16,'RECEIPT',61327,36,NULL,NULL,2477,NULL,'QA',48.0000,'UN','RECEPTION_AGENDA',9,NULL,'2026-06-10 19:22:07',27),
(50,16,'PUTAWAY',3047,32,NULL,2477,47,'QA','QA',360.0000,'UN','TASK',29,NULL,'2026-06-10 19:26:45',17),
(51,16,'QA_APPROVE',1224,20,NULL,4333,4333,'QA','AVAILABLE',1.7164,'UN','QA_DECISION',20,NULL,'2026-06-10 19:30:04',1),
(52,16,'QA_APPROVE',3020,34,NULL,2477,2477,'QA','AVAILABLE',900.0000,'UN','QA_DECISION',34,NULL,'2026-06-10 19:30:30',1),
(53,16,'QA_APPROVE',2810,29,NULL,24,24,'QA','AVAILABLE',5.6430,'UN','QA_DECISION',29,NULL,'2026-06-10 19:30:52',1),
(54,16,'QA_APPROVE',1224,21,NULL,4333,4333,'QA','AVAILABLE',173.2836,'UN','QA_DECISION',21,NULL,'2026-06-10 19:31:33',1),
(55,16,'QA_APPROVE',1107,18,NULL,4332,4332,'QA','AVAILABLE',32.4000,'UN','QA_DECISION',18,NULL,'2026-06-10 19:31:51',1),
(56,16,'QA_APPROVE',61327,36,NULL,2477,2477,'QA','AVAILABLE',48.0000,'UN','QA_DECISION',36,NULL,'2026-06-10 19:32:07',1),
(57,16,'QA_APPROVE',3051,33,NULL,2477,2477,'QA','AVAILABLE',1020.0000,'UN','QA_DECISION',33,NULL,'2026-06-10 19:32:20',1),
(58,16,'QA_APPROVE',1051,17,NULL,4500,4500,'QA','AVAILABLE',20.0000,'UN','QA_DECISION',17,NULL,'2026-06-10 19:32:35',1),
(59,16,'QA_APPROVE',1136,15,NULL,4516,4516,'QA','AVAILABLE',7.7000,'UN','QA_DECISION',15,NULL,'2026-06-10 19:32:56',1),
(60,16,'QA_APPROVE',2515,25,NULL,29,29,'QA','AVAILABLE',9932.0000,'UN','QA_DECISION',25,NULL,'2026-06-10 19:33:14',1),
(61,16,'PUTAWAY',3051,33,NULL,2477,109,'AVAILABLE','AVAILABLE',1020.0000,'UN','TASK',30,NULL,'2026-06-10 19:33:17',17),
(62,16,'QA_APPROVE',2432,22,NULL,19,19,'QA','AVAILABLE',3992.0000,'UN','QA_DECISION',22,NULL,'2026-06-10 19:33:28',1),
(63,16,'QA_APPROVE',1240,28,NULL,4316,4316,'QA','AVAILABLE',28.8000,'UN','QA_DECISION',28,NULL,'2026-06-10 19:33:48',1),
(64,16,'QA_APPROVE',1007,16,NULL,4517,4517,'QA','AVAILABLE',6.6000,'UN','QA_DECISION',16,NULL,'2026-06-10 19:34:09',1),
(65,16,'QA_APPROVE',3047,32,NULL,47,47,'QA','AVAILABLE',360.0000,'UN','QA_DECISION',32,NULL,'2026-06-10 19:34:31',1),
(66,16,'QA_APPROVE',639,19,NULL,4501,4501,'QA','AVAILABLE',36000.0000,'UN','QA_DECISION',19,NULL,'2026-06-10 19:34:45',1),
(67,16,'QA_APPROVE',639,19,NULL,4317,4317,'QA','AVAILABLE',360000.0000,'UN','QA_DECISION',19,NULL,'2026-06-10 19:34:45',1),
(68,16,'QA_APPROVE',60280,23,NULL,77,77,'QA','AVAILABLE',4000.0000,'UN','QA_DECISION',23,NULL,'2026-06-10 19:35:01',1),
(69,16,'QA_APPROVE',1368,30,NULL,4564,4564,'QA','AVAILABLE',14.8000,'UN','QA_DECISION',30,NULL,'2026-06-10 19:35:13',1),
(70,16,'QA_APPROVE',60551,35,NULL,2477,2477,'QA','AVAILABLE',72.0000,'UN','QA_DECISION',35,NULL,'2026-06-10 19:35:38',1),
(71,16,'QA_APPROVE',61268,27,NULL,82,82,'QA','AVAILABLE',8000.0000,'UN','QA_DECISION',27,NULL,'2026-06-10 19:35:51',1),
(72,16,'PUTAWAY',60551,35,NULL,2477,51,'AVAILABLE','AVAILABLE',72.0000,'UN','TASK',31,NULL,'2026-06-10 19:35:53',17),
(73,16,'PUTAWAY',3020,34,NULL,2477,52,'AVAILABLE','AVAILABLE',900.0000,'UN','TASK',28,NULL,'2026-06-10 19:38:11',17),
(74,16,'PUTAWAY',61327,36,NULL,2477,113,'AVAILABLE','AVAILABLE',48.0000,'UN','TASK',32,NULL,'2026-06-10 19:38:35',17),
(75,16,'RECEIPT',550,37,NULL,NULL,2477,NULL,'QA',7106.0000,'UN','RECEPTION_AGENDA',14,NULL,'2026-06-11 14:49:38',27),
(76,16,'RECEIPT',550,38,NULL,NULL,2477,NULL,'QA',7850.0000,'UN','RECEPTION_AGENDA',14,NULL,'2026-06-11 14:49:38',27),
(77,16,'RECEIPT',550,39,NULL,NULL,2477,NULL,'QA',7968.0000,'UN','RECEPTION_AGENDA',14,NULL,'2026-06-11 14:49:38',27),
(78,16,'RECEIPT',550,40,NULL,NULL,2477,NULL,'QA',8116.0000,'UN','RECEPTION_AGENDA',14,NULL,'2026-06-11 14:49:38',27),
(79,16,'RECEIPT',550,41,NULL,NULL,2477,NULL,'QA',8141.0000,'UN','RECEPTION_AGENDA',14,NULL,'2026-06-11 14:49:38',27),
(80,16,'PUTAWAY',550,37,NULL,2477,2,'QA','QA',7106.0000,'UN','TASK',33,NULL,'2026-06-11 15:09:48',17),
(81,16,'PUTAWAY',550,37,NULL,2,62,'QA','QA',7106.0000,'UN','CONTAINER',57,NULL,'2026-06-11 15:17:02',17),
(82,16,'PUTAWAY',550,37,NULL,62,4,'QA','QA',7106.0000,'UN','CONTAINER',58,NULL,'2026-06-11 15:22:00',17),
(83,16,'PUTAWAY',550,41,NULL,2477,61,'QA','QA',8141.0000,'UN','CONTAINER',73,NULL,'2026-06-11 15:27:08',17),
(84,16,'PUTAWAY',550,41,NULL,61,3,'QA','QA',8141.0000,'UN','CONTAINER',72,NULL,'2026-06-11 15:28:35',17),
(85,16,'MOVE',550,37,NULL,4,2477,'QA','QA',7106.0000,'UN','PUTAWAY_REVERSE',14,'Reversa ubicacion libre AG-00000014 para reubicar','2026-06-11 15:31:03',27),
(86,16,'MOVE',550,41,NULL,3,2477,'QA','QA',8141.0000,'UN','PUTAWAY_REVERSE',14,'Reversa ubicacion libre AG-00000014 para reubicar','2026-06-11 15:31:03',27),
(88,16,'PUTAWAY',550,37,NULL,2477,62,'QA','QA',2400.0000,'UN','CONTAINER',57,NULL,'2026-06-11 16:07:44',17),
(89,16,'PUTAWAY',550,37,NULL,2477,4,'QA','QA',2400.0000,'UN','CONTAINER',58,NULL,'2026-06-11 16:08:12',17),
(90,16,'PUTAWAY',550,41,NULL,2477,3,'QA','QA',2400.0000,'UN','CONTAINER',72,NULL,'2026-06-11 16:10:55',17),
(91,16,'PUTAWAY',550,41,NULL,2477,61,'QA','QA',941.0000,'UN','CONTAINER',73,NULL,'2026-06-11 16:11:18',17),
(92,16,'PUTAWAY',550,41,NULL,2477,119,'QA','QA',2400.0000,'UN','CONTAINER',71,NULL,'2026-06-11 16:12:47',17),
(93,16,'PUTAWAY',550,37,NULL,2477,120,'QA','QA',2306.0000,'UN','CONTAINER',56,NULL,'2026-06-11 16:15:24',17),
(94,16,'PUTAWAY',550,41,NULL,2477,5,'QA','QA',2400.0000,'UN','CONTAINER',70,NULL,'2026-06-11 16:20:53',17),
(95,16,'MOVE',550,41,NULL,5,2477,'QA','QA',2400.0000,'UN','PUTAWAY_REVERSE',70,'Reversa ubicacion LPN-70 para reubicar','2026-06-11 16:42:45',27),
(96,16,'PUTAWAY',550,41,NULL,2477,177,'QA','QA',2400.0000,'UN','CONTAINER',70,NULL,'2026-06-11 16:44:27',17),
(97,16,'PUTAWAY',550,39,NULL,2477,6,'QA','QA',768.0000,'UN','CONTAINER',69,NULL,'2026-06-11 16:49:01',17),
(98,16,'PUTAWAY',550,39,NULL,2477,64,'QA','QA',2400.0000,'UN','CONTAINER',74,NULL,'2026-06-11 16:55:46',17),
(99,16,'PUTAWAY',550,39,NULL,2477,180,'QA','QA',2400.0000,'UN','CONTAINER',68,NULL,'2026-06-11 16:58:43',17),
(100,16,'PUTAWAY',550,39,NULL,2477,122,'QA','QA',2400.0000,'UN','CONTAINER',67,NULL,'2026-06-11 17:02:07',17),
(101,16,'PUTAWAY',550,40,NULL,2477,63,'QA','QA',916.0000,'UN','CONTAINER',63,NULL,'2026-06-11 17:05:22',17),
(102,16,'PUTAWAY',550,40,NULL,2477,121,'QA','QA',2400.0000,'UN','CONTAINER',66,NULL,'2026-06-11 17:06:23',17),
(103,16,'PUTAWAY',550,40,NULL,2477,179,'QA','QA',2400.0000,'UN','CONTAINER',64,NULL,'2026-06-11 17:07:13',17),
(104,16,'PUTAWAY',550,38,NULL,2477,60,'QA','QA',2400.0000,'UN','CONTAINER',61,NULL,'2026-06-11 17:11:15',17),
(105,16,'PUTAWAY',550,38,NULL,2477,2,'QA','QA',650.0000,'UN','CONTAINER',62,NULL,'2026-06-11 17:15:45',17),
(106,16,'PUTAWAY',550,38,NULL,2477,176,'QA','QA',2400.0000,'UN','CONTAINER',59,NULL,'2026-06-11 17:19:57',17),
(107,16,'PUTAWAY',550,38,NULL,2477,118,'QA','QA',2400.0000,'UN','CONTAINER',60,NULL,'2026-06-11 17:22:45',17),
(108,16,'RECEIPT',2432,42,NULL,NULL,2477,NULL,'QA',100.0000,'UN','RECEPTION_AGENDA',16,NULL,'2026-06-13 10:22:42',27),
(109,16,'PUTAWAY',550,40,NULL,2477,5,'QA','QA',2400.0000,'UN','CONTAINER',65,NULL,'2026-06-13 11:31:33',17),
(110,16,'RECEIPT',550,43,NULL,NULL,2477,NULL,'QA',8120.0000,'UN','RECEPTION_AGENDA',21,NULL,'2026-06-13 11:50:34',9),
(111,16,'PUTAWAY',550,43,NULL,2477,178,'QA','QA',2400.0000,'UN','CONTAINER',81,NULL,'2026-06-13 11:51:36',17),
(112,16,'PUTAWAY',550,43,NULL,2477,234,'QA','QA',2400.0000,'UN','CONTAINER',80,NULL,'2026-06-13 11:55:41',17),
(113,16,'PUTAWAY',550,43,NULL,2477,238,'QA','QA',2400.0000,'UN','CONTAINER',79,NULL,'2026-06-13 12:02:10',17),
(114,16,'PUTAWAY',550,43,NULL,2477,237,'QA','QA',920.0000,'UN','CONTAINER',82,NULL,'2026-06-13 12:05:11',17),
(115,16,'RECEIPT',550,44,NULL,NULL,2477,NULL,'QA',8139.0000,'UN','RECEPTION_AGENDA',20,NULL,'2026-06-13 12:12:39',27),
(116,16,'PUTAWAY',550,44,NULL,2477,236,'QA','QA',939.0000,'UN','CONTAINER',89,NULL,'2026-06-13 12:34:18',17),
(117,16,'PUTAWAY',550,44,NULL,2477,298,'QA','QA',2400.0000,'UN','CONTAINER',86,NULL,'2026-06-13 12:36:41',17),
(118,16,'PUTAWAY',550,44,NULL,2477,297,'QA','QA',2400.0000,'UN','CONTAINER',87,NULL,'2026-06-13 12:42:58',17),
(119,16,'PUTAWAY',550,44,NULL,2477,300,'QA','QA',2400.0000,'UN','CONTAINER',88,NULL,'2026-06-13 12:46:07',17),
(120,16,'QA_APPROVE',550,37,NULL,62,62,'QA','AVAILABLE',2400.0000,'UN','QA_DECISION',37,NULL,'2026-06-13 12:47:25',9),
(121,16,'QA_APPROVE',550,37,NULL,4,4,'QA','AVAILABLE',2400.0000,'UN','QA_DECISION',37,NULL,'2026-06-13 12:47:25',9),
(122,16,'QA_APPROVE',550,37,NULL,120,120,'QA','AVAILABLE',2306.0000,'UN','QA_DECISION',37,NULL,'2026-06-13 12:47:25',9),
(123,16,'PICK',550,37,NULL,62,NULL,'AVAILABLE',NULL,100.0000,'UN','PICK_LIST',2,NULL,'2026-06-13 12:55:00',29),
(124,16,'RECEIPT',550,45,NULL,NULL,2477,NULL,'QA',8087.0000,'UN','RECEPTION_AGENDA',19,NULL,'2026-06-13 14:31:30',27),
(125,16,'RECEIPT',550,46,NULL,NULL,2477,NULL,'QA',7976.0000,'UN','RECEPTION_AGENDA',18,NULL,'2026-06-13 14:33:54',27),
(126,16,'PUTAWAY',550,45,NULL,2477,235,'QA','QA',2400.0000,'UN','CONTAINER',96,NULL,'2026-06-13 15:02:37',17),
(127,16,'PACK',550,37,NULL,NULL,NULL,NULL,NULL,100.0000,'UN','PACKING_ORDER',1,NULL,'2026-06-13 15:03:52',9),
(128,16,'PUTAWAY',550,45,NULL,2477,235,'QA','QA',2400.0000,'UN','CONTAINER',95,NULL,'2026-06-13 15:05:50',17),
(129,16,'PUTAWAY',550,45,NULL,2477,300,'QA','QA',2400.0000,'UN','CONTAINER',93,NULL,'2026-06-13 15:46:38',17),
(130,16,'PUTAWAY',550,45,NULL,2477,428,'QA','QA',887.0000,'UN','CONTAINER',97,NULL,'2026-06-13 15:55:02',17),
(131,16,'RECEIPT',550,47,NULL,NULL,2477,NULL,'QA',7255.0000,'UN','RECEPTION_AGENDA',22,NULL,'2026-06-13 16:10:40',27),
(132,16,'PUTAWAY',550,46,NULL,2477,362,'QA','QA',2400.0000,'UN','CONTAINER',100,NULL,'2026-06-13 16:11:59',17),
(133,16,'PUTAWAY',550,46,NULL,2477,427,'QA','QA',776.0000,'UN','CONTAINER',102,NULL,'2026-06-13 16:17:45',17),
(134,16,'MOVE',550,40,NULL,63,360,'QA','QA',916.0000,'UN','RELOCATION',1,'Reubicación RL-00000001','2026-06-13 17:11:20',17),
(135,16,'PUTAWAY',550,46,NULL,2477,63,'QA','QA',2400.0000,'UN','CONTAINER',101,NULL,'2026-06-13 17:14:54',17),
(136,16,'MOVE',550,39,NULL,6,361,'QA','QA',768.0000,'UN','RELOCATION',2,'Reubicación RL-00000002','2026-06-13 17:25:14',17),
(137,16,'PUTAWAY',550,46,NULL,2477,6,'QA','QA',2400.0000,'UN','CONTAINER',99,NULL,'2026-06-13 17:36:26',17),
(138,16,'MOVE',550,45,NULL,235,359,'QA','QA',2400.0000,'UN','RELOCATION',3,'Separacion LPN LPN-00000095 (RL-00000003)','2026-06-15 11:55:05',1),
(139,16,'MOVE',550,44,NULL,300,494,'QA','QA',2400.0000,'UN','RELOCATION',4,'Separacion LPN LPN-00000087 (RL-00000004)','2026-06-15 11:55:05',1),
(140,16,'MOVE',550,41,NULL,61,426,'QA','QA',941.0000,'UN','RELOCATION',5,'Reubicación RL-00000005','2026-06-15 14:56:08',17),
(141,16,'PUTAWAY',550,47,NULL,2477,61,'QA','QA',2400.0000,'UN','CONTAINER',111,NULL,'2026-06-15 15:03:45',17),
(142,16,'RECEIPT',690,49,NULL,NULL,2477,NULL,'QA',1.0000,'UN','RECEPTION_AGENDA',23,NULL,'2026-06-15 15:29:22',27),
(143,16,'RECEIPT',1008,50,NULL,NULL,2477,NULL,'QA',1.0000,'KG','RECEPTION_AGENDA',23,NULL,'2026-06-15 15:29:22',27),
(144,16,'RECEIPT',1375,48,NULL,NULL,2477,NULL,'QA',1.0000,'UN','RECEPTION_AGENDA',23,NULL,'2026-06-15 15:29:22',27),
(145,16,'MOVE',550,38,NULL,2,358,'QA','QA',650.0000,'UN','RELOCATION',6,'Reubicación RL-00000006','2026-06-15 15:35:18',17),
(146,16,'PUTAWAY',550,47,NULL,2477,2,'QA','QA',2400.0000,'UN','CONTAINER',109,NULL,'2026-06-15 15:38:23',17),
(147,16,'MOVE',550,44,NULL,236,359,'QA','QA',939.0000,'UN','RELOCATION',7,'Reubicación RL-00000007','2026-06-15 15:45:51',17),
(148,16,'PUTAWAY',550,47,NULL,2477,236,'QA','QA',2455.0000,'UN','CONTAINER',112,NULL,'2026-06-15 15:51:43',17),
(149,16,'RECEIPT',72371,51,NULL,NULL,2477,NULL,'BLOCKED',4591.0000,'UN','RECEPTION_AGENDA',24,NULL,'2026-06-15 15:57:02',27),
(150,16,'PUTAWAY',1375,48,NULL,2477,1014,'QA','QA',1.0000,'UN','CONTAINER',113,NULL,'2026-06-15 16:02:24',17),
(151,16,'PUTAWAY',690,49,NULL,2477,4783,'QA','QA',1.0000,'UN','CONTAINER',114,NULL,'2026-06-15 16:09:26',17),
(152,16,'PUTAWAY',1008,50,NULL,2477,4779,'QA','QA',1.0000,'UN','CONTAINER',115,NULL,'2026-06-15 16:09:56',17),
(153,16,'PUTAWAY',72371,51,NULL,2477,168,'BLOCKED','BLOCKED',1711.0000,'UN','CONTAINER',117,NULL,'2026-06-15 16:24:09',17),
(154,16,'PUTAWAY',72371,51,NULL,2477,226,'BLOCKED','BLOCKED',2880.0000,'UN','CONTAINER',116,NULL,'2026-06-15 16:24:27',17),
(155,16,'PICK',72371,51,NULL,168,NULL,'AVAILABLE',NULL,100.0000,'UN','PICK_LIST',4,NULL,'2026-06-15 16:59:01',29),
(156,16,'PACK',72371,51,NULL,NULL,NULL,NULL,NULL,100.0000,'UN','PACKING_ORDER',2,NULL,'2026-06-15 17:02:49',9),
(157,16,'DISPATCH',72371,51,NULL,NULL,NULL,'AVAILABLE',NULL,100.0000,'UN','DISPATCH',2,NULL,'2026-06-15 17:05:45',9),
(158,16,'PICK',72371,51,NULL,168,NULL,'AVAILABLE',NULL,1.0000,'UN','PICK_LIST',5,NULL,'2026-06-15 17:15:45',29),
(159,16,'PACK',72371,51,NULL,NULL,NULL,NULL,NULL,1.0000,'UN','PACKING_ORDER',3,NULL,'2026-06-15 17:18:16',9),
(160,16,'DISPATCH',72371,51,NULL,NULL,NULL,'AVAILABLE',NULL,1.0000,'UN','DISPATCH',3,NULL,'2026-06-15 17:20:41',9);

--
-- Table structure for table `subgrupo_zone_rules`
--

CREATE TABLE `subgrupo_zone_rules` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `u_subgrupo` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `zone_id` int(10) unsigned NOT NULL,
  `warehouse_id` int(10) unsigned DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` int(10) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_u_subgrupo` (`u_subgrupo`),
  KEY `idx_zone` (`zone_id`),
  KEY `fk_sgr_warehouse` (`warehouse_id`),
  CONSTRAINT `fk_sgr_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`),
  CONSTRAINT `fk_sgr_zone` FOREIGN KEY (`zone_id`) REFERENCES `warehouse_zones` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `subgrupo_zone_rules`
--

INSERT INTO `subgrupo_zone_rules` VALUES
(9,'IM-ALCON - OPTICA',25,16,NULL,1,1,'2026-05-14 16:53:29','2026-05-14 16:53:29'),
(10,'IM-ALCON - LIQUIDOS',25,16,NULL,1,1,'2026-05-14 16:54:09','2026-05-14 16:54:09');

--
-- Table structure for table `system_config`
--

CREATE TABLE `system_config` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `config_key` varchar(100) NOT NULL,
  `config_value` text NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_config_key` (`config_key`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Configuración general del WMS';

--
-- Dumping data for table `system_config`
--

INSERT INTO `system_config` VALUES
(1,'fefo_enabled','1','Activar FEFO (First Expired First Out)','2026-04-02 15:47:02'),
(2,'lot_required','1','Lote obligatorio en recepción','2026-04-02 15:47:02'),
(3,'expiry_required','1','Vencimiento obligatorio en recepción','2026-04-02 15:47:02'),
(4,'min_shelf_life_days','90','Mínimo vida útil restante para aceptar recepción (días)','2026-04-02 15:47:02'),
(5,'qa_on_receipt','1','Enviar stock a QA automáticamente al recibir','2026-04-02 15:47:02'),
(6,'auto_putaway','1','Generar tarea de putaway automáticamente al confirmar recepción','2026-04-02 15:47:02'),
(7,'sap_sync_interval','300','Intervalo de sincronización con SAP (segundos)','2026-04-02 15:47:02'),
(8,'sap_service_layer_url','https://sapserver:50000/b1s/v1','URL de SAP Service Layer','2026-04-02 15:47:02'),
(9,'printing.default_printer_ip','192.168.3.130','IP de la impresora Zebra por defecto','2026-06-10 11:49:20'),
(10,'printing.default_printer_port','9100','Puerto RAW de la impresora Zebra','2026-04-11 10:05:54'),
(11,'printing.label_width_mm','100','Ancho de etiqueta en mm (4 pulgadas)','2026-04-11 10:05:54'),
(12,'printing.label_height_mm','50','Alto de etiqueta en mm (2 pulgadas)','2026-04-11 10:05:54'),
(13,'printing.dpi','203','DPI de la impresora Zebra (203 o 300)','2026-04-11 10:05:54');

--
-- Table structure for table `temperature_alerts`
--

CREATE TABLE `temperature_alerts` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `zone_id` int(10) unsigned NOT NULL,
  `reading_id` bigint(20) unsigned DEFAULT NULL,
  `alert_type` enum('HIGH_TEMP','LOW_TEMP','SENSOR_OFFLINE','HUMIDITY_HIGH') NOT NULL,
  `temperature` decimal(5,2) DEFAULT NULL,
  `threshold` decimal(5,2) DEFAULT NULL,
  `acknowledged` tinyint(1) DEFAULT 0,
  `acknowledged_by` int(10) unsigned DEFAULT NULL,
  `acknowledged_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `fk_ta_zone` (`zone_id`),
  KEY `idx_ta_ack` (`acknowledged`,`created_at`),
  CONSTRAINT `fk_ta_zone` FOREIGN KEY (`zone_id`) REFERENCES `temperature_zones` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Alertas de temperatura DINAVISA';

--
-- Dumping data for table `temperature_alerts`
--


--
-- Table structure for table `temperature_readings`
--

CREATE TABLE `temperature_readings` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `zone_id` int(10) unsigned NOT NULL,
  `temperature` decimal(5,2) NOT NULL,
  `humidity` decimal(5,2) DEFAULT NULL,
  `reading_source` enum('MANUAL','SENSOR','API') DEFAULT 'MANUAL',
  `status` enum('NORMAL','WARNING','CRITICAL') NOT NULL,
  `recorded_by` int(10) unsigned DEFAULT NULL,
  `recorded_at` datetime NOT NULL DEFAULT current_timestamp(),
  `notes` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_tr_zone_date` (`zone_id`,`recorded_at`),
  CONSTRAINT `fk_tr_zone` FOREIGN KEY (`zone_id`) REFERENCES `temperature_zones` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Lecturas de temperatura historicas';

--
-- Dumping data for table `temperature_readings`
--


--
-- Table structure for table `temperature_zones`
--

CREATE TABLE `temperature_zones` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `zone_name` varchar(100) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `min_temp` decimal(5,2) NOT NULL COMMENT 'Temperatura minima permitida en Celsius',
  `max_temp` decimal(5,2) NOT NULL COMMENT 'Temperatura maxima permitida en Celsius',
  `current_temp` decimal(5,2) DEFAULT NULL,
  `sensor_id` varchar(50) DEFAULT NULL COMMENT 'ID del sensor IoT si existe',
  `last_reading_at` datetime DEFAULT NULL,
  `status` enum('NORMAL','WARNING','CRITICAL','OFFLINE') DEFAULT 'NORMAL',
  `is_active` tinyint(1) DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `fk_tz_wh` (`warehouse_id`),
  KEY `idx_tz_status` (`status`),
  CONSTRAINT `fk_tz_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Zonas con control de temperatura';

--
-- Dumping data for table `temperature_zones`
--

INSERT INTO `temperature_zones` VALUES
(1,'Zona 1',16,2.00,8.00,NULL,'1',NULL,'NORMAL',1,'2026-04-17 20:58:20','2026-04-17 20:58:20');

--
-- Table structure for table `transfer_label_lines`
--

CREATE TABLE `transfer_label_lines` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `label_id` int(10) unsigned NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `batch_number` varchar(50) DEFAULT NULL,
  `from_bin_id` int(10) unsigned NOT NULL COMMENT 'Ubicacion origen',
  `to_bin_id` int(10) unsigned DEFAULT NULL COMMENT 'Ubicacion destino (asignado en descarga)',
  `quantity` decimal(15,4) NOT NULL COMMENT 'Cantidad solicitada',
  `loaded_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `unloaded_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `status` enum('PENDING','LOADED','IN_TRANSIT','UNLOADED') NOT NULL DEFAULT 'PENDING',
  `loaded_at` datetime DEFAULT NULL,
  `unloaded_at` datetime DEFAULT NULL,
  `loaded_by` int(10) unsigned DEFAULT NULL,
  `unloaded_by` int(10) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_tline_label` (`label_id`),
  KEY `idx_tline_item` (`item_id`),
  KEY `idx_tline_batch` (`batch_id`),
  KEY `idx_tline_from` (`from_bin_id`),
  KEY `idx_tline_to` (`to_bin_id`),
  KEY `idx_tline_status` (`status`),
  KEY `fk_tline_loader` (`loaded_by`),
  KEY `fk_tline_unloader` (`unloaded_by`),
  CONSTRAINT `fk_tline_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_tline_from_bin` FOREIGN KEY (`from_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_tline_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_tline_label` FOREIGN KEY (`label_id`) REFERENCES `transfer_labels` (`id`),
  CONSTRAINT `fk_tline_loader` FOREIGN KEY (`loaded_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_tline_to_bin` FOREIGN KEY (`to_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_tline_unloader` FOREIGN KEY (`unloaded_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Items cargados en etiqueta de transferencia con trazabilidad carga/descarga';

--
-- Dumping data for table `transfer_label_lines`
--


--
-- Table structure for table `transfer_labels`
--

CREATE TABLE `transfer_labels` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `label_code` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `status` enum('EMPTY','OPEN','LOADING','IN_TRANSIT','UNLOADING','UNLOADED','COMPLETED','CANCELLED') NOT NULL DEFAULT 'EMPTY',
  `transit_bin_id` int(10) unsigned DEFAULT NULL COMMENT 'Bin virtual de transito asignado',
  `origin_description` text DEFAULT NULL COMMENT 'Descripcion del origen de la carga',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `completed_at` datetime DEFAULT NULL,
  `created_by` int(10) unsigned DEFAULT NULL,
  `label_number` varchar(30) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `sap_doc_entry` int(11) DEFAULT NULL,
  `sap_doc_num` varchar(20) DEFAULT NULL,
  `synced_at` datetime DEFAULT NULL,
  `transit_at` datetime DEFAULT NULL,
  `completed_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_tlbl_code` (`label_code`),
  KEY `idx_tlbl_wh` (`warehouse_id`),
  KEY `idx_tlbl_status` (`status`),
  KEY `idx_tlbl_transit_bin` (`transit_bin_id`),
  KEY `fk_tlbl_creator` (`created_by`),
  CONSTRAINT `fk_tlbl_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_tlbl_transit_bin` FOREIGN KEY (`transit_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_tlbl_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Etiquetas de transferencia: ubicacion movil para carga/transito/descarga';

--
-- Dumping data for table `transfer_labels`
--


--
-- Table structure for table `warehouse_tasks`
--

CREATE TABLE `warehouse_tasks` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` int(10) unsigned NOT NULL,
  `task_type` enum('PUT','PUTAWAY','PICK','MOVE','COUNT','QA_CHECK','REPLENISH') NOT NULL,
  `priority` tinyint(3) unsigned NOT NULL DEFAULT 5 COMMENT '1=máxima, 10=mínima',
  `status` enum('PENDING','ASSIGNED','IN_PROGRESS','COMPLETED','CANCELLED','FAILED') NOT NULL DEFAULT 'PENDING',
  `item_id` int(10) unsigned NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `serial_number` varchar(100) DEFAULT NULL,
  `from_bin_id` int(10) unsigned DEFAULT NULL,
  `to_bin_id` int(10) unsigned DEFAULT NULL,
  `quantity` decimal(15,4) NOT NULL,
  `confirmed_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `uom` varchar(20) NOT NULL DEFAULT 'UN',
  `assigned_to` int(10) unsigned DEFAULT NULL COMMENT 'Operador asignado',
  `reference_type` varchar(50) DEFAULT NULL,
  `reference_id` int(10) unsigned DEFAULT NULL,
  `started_at` datetime DEFAULT NULL,
  `completed_at` datetime DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `putaway_strategy` varchar(20) DEFAULT NULL,
  `putaway_mode` enum('GROUPED','BY_PRODUCT','BY_LOCATION','FREE') DEFAULT NULL COMMENT 'Modo de almacenamiento: agrupado, por producto, por ubicacion, libre',
  `label_id` int(10) unsigned DEFAULT NULL COMMENT 'Referencia a etiqueta de transferencia para putaway agrupado',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_tasks_wh` (`warehouse_id`),
  KEY `idx_tasks_type` (`task_type`),
  KEY `idx_tasks_status` (`status`),
  KEY `idx_tasks_assigned` (`assigned_to`),
  KEY `idx_tasks_priority` (`priority`,`status`),
  KEY `idx_tasks_ref` (`reference_type`,`reference_id`),
  KEY `fk_tasks_item` (`item_id`),
  KEY `fk_tasks_batch` (`batch_id`),
  KEY `fk_tasks_from_bin` (`from_bin_id`),
  KEY `fk_tasks_to_bin` (`to_bin_id`),
  KEY `fk_tasks_creator` (`created_by`),
  KEY `idx_tasks_putaway_mode` (`putaway_mode`),
  KEY `idx_tasks_label` (`label_id`),
  CONSTRAINT `fk_tasks_assigned` FOREIGN KEY (`assigned_to`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_tasks_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_tasks_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_tasks_from_bin` FOREIGN KEY (`from_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_tasks_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_tasks_label` FOREIGN KEY (`label_id`) REFERENCES `transfer_labels` (`id`),
  CONSTRAINT `fk_tasks_to_bin` FOREIGN KEY (`to_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_tasks_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Tareas de almacén: putaway, picking, movimiento, conteo';

--
-- Dumping data for table `warehouse_tasks`
--

INSERT INTO `warehouse_tasks` VALUES
(12,16,'PUTAWAY',2,'COMPLETED',639,19,NULL,2477,4501,36000.0000,36000.0000,'UN',17,'QA_PUTAWAY_HOLD',2,NULL,'2026-06-10 18:25:35','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [Completada vía LPN LPN-00000025]','BY_LPN','GROUPED',NULL,'2026-06-10 18:01:34','2026-06-10 18:25:35',27),
(13,16,'PUTAWAY',2,'COMPLETED',1007,16,NULL,2477,4517,6.6000,6.6000,'UN',17,'QA_PUTAWAY_HOLD',2,NULL,'2026-06-10 18:27:12','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [Completada vía LPN LPN-00000017]','BY_LPN','GROUPED',NULL,'2026-06-10 18:01:34','2026-06-10 18:27:12',27),
(14,16,'PUTAWAY',2,'COMPLETED',1051,17,NULL,2477,4500,20.0000,20.0000,'UN',17,'QA_PUTAWAY_HOLD',2,NULL,'2026-06-10 18:22:22','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [Completada vía LPN LPN-00000020]','BY_LPN','GROUPED',NULL,'2026-06-10 18:01:34','2026-06-10 18:22:22',27),
(15,16,'PUTAWAY',2,'COMPLETED',1107,18,NULL,2477,4332,32.4000,32.4000,'UN',17,'QA_PUTAWAY_HOLD',2,NULL,'2026-06-10 18:29:06','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [Completada vía LPN LPN-00000022]','BY_LPN','GROUPED',NULL,'2026-06-10 18:01:34','2026-06-10 18:29:06',27),
(16,16,'PUTAWAY',2,'COMPLETED',1136,15,NULL,2477,4516,7.7000,7.7000,'UN',17,'QA_PUTAWAY_HOLD',2,NULL,'2026-06-10 18:27:57','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [Completada vía LPN LPN-00000016]','BY_LPN','GROUPED',NULL,'2026-06-10 18:01:34','2026-06-10 18:27:57',27),
(17,16,'PUTAWAY',2,'COMPLETED',1224,20,NULL,2477,4333,1.7164,1.7164,'UN',17,'QA_PUTAWAY_HOLD',5,NULL,'2026-06-10 18:36:16','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [Completada vía LPN LPN-00000026]','BY_LPN','GROUPED',NULL,'2026-06-10 18:33:43','2026-06-10 18:36:16',27),
(18,16,'PUTAWAY',2,'COMPLETED',1240,28,NULL,2477,4316,28.8000,28.8000,'UN',17,'QA_PUTAWAY_HOLD',6,NULL,'2026-06-10 19:11:21','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:52:06','2026-06-10 19:11:21',27),
(19,16,'PUTAWAY',2,'COMPLETED',2432,22,NULL,2477,19,3992.0000,3992.0000,'UN',17,'QA_PUTAWAY_HOLD',6,NULL,'2026-06-10 18:58:04','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:52:06','2026-06-10 18:58:04',27),
(20,16,'PUTAWAY',2,'COMPLETED',60280,23,NULL,2477,77,4000.0000,4000.0000,'UN',17,'QA_PUTAWAY_HOLD',6,NULL,'2026-06-10 18:56:45','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:52:06','2026-06-10 18:56:45',27),
(21,16,'PUTAWAY',2,'COMPLETED',61268,27,NULL,2477,82,8000.0000,8000.0000,'UN',17,'QA_PUTAWAY_HOLD',6,NULL,'2026-06-10 18:59:17','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:52:06','2026-06-10 18:59:17',27),
(22,16,'PUTAWAY',2,'COMPLETED',2515,25,NULL,2477,29,9932.0000,9932.0000,'UN',17,'QA_PUTAWAY_HOLD',6,NULL,'2026-06-10 19:21:58','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:52:06','2026-06-10 19:21:58',27),
(23,16,'PUTAWAY',2,'COMPLETED',2810,29,NULL,2477,24,5.6430,5.6430,'KG',17,'QA_PUTAWAY_HOLD',6,NULL,'2026-06-10 19:00:34','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:52:06','2026-06-10 19:00:34',27),
(24,16,'PUTAWAY',2,'COMPLETED',2900,24,NULL,2477,87,82.2250,82.2250,'KG',17,'QA_PUTAWAY_HOLD',6,NULL,'2026-06-10 19:08:10','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:52:06','2026-06-10 19:08:10',27),
(25,16,'PUTAWAY',2,'COMPLETED',639,19,NULL,2477,4317,360000.0000,360000.0000,'UN',17,'QA_PUTAWAY_HOLD',7,NULL,'2026-06-10 19:01:08','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:55:44','2026-06-10 19:01:08',27),
(26,16,'PUTAWAY',2,'COMPLETED',693,31,NULL,2477,4565,3.0000,3.0000,'UN',17,'QA_PUTAWAY_HOLD',7,NULL,'2026-06-10 19:17:13','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:55:44','2026-06-10 19:17:13',27),
(27,16,'PUTAWAY',2,'COMPLETED',1368,30,NULL,2477,4564,14.8000,14.8000,'UN',17,'QA_PUTAWAY_HOLD',7,NULL,'2026-06-10 19:14:50','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 18:55:44','2026-06-10 19:14:50',27),
(28,16,'PUTAWAY',2,'COMPLETED',3020,34,NULL,2477,52,900.0000,900.0000,'UN',17,'QA_PUTAWAY_HOLD',8,NULL,'2026-06-10 19:38:11','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 19:05:53','2026-06-10 19:38:11',27),
(29,16,'PUTAWAY',2,'COMPLETED',3047,32,NULL,2477,47,360.0000,360.0000,'UN',17,'QA_PUTAWAY_HOLD',8,NULL,'2026-06-10 19:26:45','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 19:05:53','2026-06-10 19:26:45',27),
(30,16,'PUTAWAY',2,'COMPLETED',3051,33,NULL,2477,109,1020.0000,1020.0000,'UN',17,'QA_PUTAWAY_HOLD',8,NULL,'2026-06-10 19:33:17','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 19:05:53','2026-06-10 19:33:17',27),
(31,16,'PUTAWAY',2,'COMPLETED',60551,35,NULL,2477,51,72.0000,72.0000,'UN',17,'QA_PUTAWAY_HOLD',9,NULL,'2026-06-10 19:35:53','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','OVERRIDE',NULL,NULL,'2026-06-10 19:22:07','2026-06-10 19:35:53',27),
(32,16,'PUTAWAY',2,'COMPLETED',61327,36,NULL,2477,113,48.0000,48.0000,'UN',17,'QA_PUTAWAY_HOLD',9,NULL,'2026-06-10 19:38:35','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación','MANUAL',NULL,NULL,'2026-06-10 19:22:07','2026-06-10 19:38:35',27),
(33,16,'PUTAWAY',2,'COMPLETED',550,37,NULL,2477,4,7106.0000,4800.0000,'UN',17,'QA_PUTAWAY_HOLD',14,'2026-06-11 16:07:44','2026-06-11 16:08:12','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000057: +2400] [LPN LPN-00000058: +2400]','BY_LPN','GROUPED',NULL,'2026-06-11 14:49:38','2026-06-11 16:08:12',27),
(34,16,'PUTAWAY',2,'COMPLETED',550,38,NULL,2477,176,7850.0000,5450.0000,'UN',17,'QA_PUTAWAY_HOLD',14,'2026-06-11 17:11:15','2026-06-11 17:19:57','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000061: +2400] [LPN LPN-00000062: +650] [LPN LPN-00000059: +2400]','BY_LPN','GROUPED',NULL,'2026-06-11 14:49:38','2026-06-11 17:19:57',27),
(35,16,'PUTAWAY',2,'COMPLETED',550,39,NULL,2477,180,7968.0000,5568.0000,'UN',17,'QA_PUTAWAY_HOLD',14,'2026-06-11 16:49:01','2026-06-11 16:58:43','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000069: +768] [LPN LPN-00000069: +768] [LPN LPN-00000074: +2400] [LPN LPN-00000068: +2400]','BY_LPN','GROUPED',NULL,'2026-06-11 14:49:38','2026-06-11 16:58:43',27),
(36,16,'PUTAWAY',2,'COMPLETED',550,40,NULL,2477,179,8116.0000,5716.0000,'UN',17,'QA_PUTAWAY_HOLD',14,'2026-06-11 17:05:22','2026-06-11 17:07:13','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000063: +916] [LPN LPN-00000066: +2400] [LPN LPN-00000064: +2400]','BY_LPN','GROUPED',NULL,'2026-06-11 14:49:38','2026-06-11 17:07:13',27),
(37,16,'PUTAWAY',2,'COMPLETED',550,41,NULL,2477,177,8141.0000,8141.0000,'UN',17,'QA_PUTAWAY_HOLD',14,'2026-06-11 16:10:55','2026-06-11 16:44:27','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [Completada vía LPN LPN-00000073] [LPN LPN-00000072: +2400] [LPN LPN-00000073: +941] [LPN LPN-00000071: +2400] [LPN LPN-00000070: +2400]','BY_LPN','GROUPED',NULL,'2026-06-11 14:49:38','2026-06-11 16:44:27',27),
(38,16,'PUTAWAY',2,'ASSIGNED',2432,42,NULL,2477,NULL,100.0000,0.0000,'UN',17,'QA_PUTAWAY_HOLD',16,NULL,NULL,'Putaway en cuarentena (auto agenda): stock con status QA hasta liberación',NULL,NULL,NULL,'2026-06-13 10:22:42','2026-06-13 10:22:42',27),
(39,16,'PUTAWAY',2,'COMPLETED',550,43,NULL,2477,238,8120.0000,7200.0000,'UN',17,'QA_PUTAWAY_HOLD',21,'2026-06-13 11:51:36','2026-06-13 12:02:10','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000080: +2400] [LPN LPN-00000079: +2400] [LPN LPN-00000078: +2400]','BY_LPN','GROUPED',NULL,'2026-06-13 11:50:34','2026-06-13 12:02:10',9),
(40,16,'PUTAWAY',2,'COMPLETED',550,44,NULL,2477,297,8139.0000,5739.0000,'UN',17,'QA_PUTAWAY_HOLD',20,'2026-06-13 12:34:18','2026-06-13 12:42:58','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000088: +939] [LPN LPN-00000085: +2400] [LPN LPN-00000086: +2400]','BY_LPN','GROUPED',NULL,'2026-06-13 12:12:39','2026-06-13 12:42:58',27),
(41,16,'PICK',2,'COMPLETED',550,37,NULL,62,NULL,100.0000,100.0000,'UN',29,'PICK_LIST',2,NULL,'2026-06-13 12:55:00',NULL,NULL,NULL,NULL,'2026-06-13 12:48:15','2026-06-13 12:55:00',9),
(42,16,'PUTAWAY',2,'COMPLETED',550,45,NULL,2477,300,8087.0000,7200.0000,'UN',17,'QA_PUTAWAY_HOLD',19,'2026-06-13 15:02:37','2026-06-13 15:46:38','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000095: +2400] [LPN LPN-00000094: +2400] [LPN LPN-00000092: +2400]','BY_LPN','GROUPED',NULL,'2026-06-13 14:31:30','2026-06-13 15:46:38',27),
(43,16,'PUTAWAY',2,'COMPLETED',550,46,NULL,2477,63,7976.0000,5576.0000,'UN',17,'QA_PUTAWAY_HOLD',18,'2026-06-13 16:11:59','2026-06-13 17:14:54','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000099: +2400] [LPN LPN-00000101: +776] [LPN LPN-00000100: +2400]','BY_LPN','GROUPED',NULL,'2026-06-13 14:33:54','2026-06-13 17:14:54',27),
(44,16,'PUTAWAY',2,'COMPLETED',550,47,NULL,2477,236,7255.0000,7255.0000,'UN',17,'QA_PUTAWAY_HOLD',22,'2026-06-15 15:03:45','2026-06-15 15:51:43','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000110: +2400] [LPN LPN-00000108: +2400] [LPN LPN-00000111: +2455]','BY_LPN','GROUPED',NULL,'2026-06-13 16:10:40','2026-06-15 15:51:43',27),
(45,16,'MOVE',3,'COMPLETED',550,NULL,NULL,63,360,1.0000,916.0000,'LPN',17,'RELOCATION',1,NULL,'2026-06-13 17:11:20','Reubicación RL-00000001 — LPN LPN-00000063',NULL,NULL,NULL,'2026-06-13 17:05:35','2026-06-13 17:11:20',9),
(46,16,'MOVE',3,'COMPLETED',550,NULL,NULL,6,361,1.0000,768.0000,'LPN',17,'RELOCATION',2,NULL,'2026-06-13 17:25:14','Reubicación RL-00000002 — LPN LPN-00000069',NULL,NULL,NULL,'2026-06-13 17:17:37','2026-06-13 17:25:14',9),
(47,16,'MOVE',3,'COMPLETED',550,NULL,NULL,61,426,1.0000,941.0000,'LPN',17,'RELOCATION',5,NULL,'2026-06-15 14:56:08','Reubicación RL-00000005 — LPN LPN-00000073',NULL,NULL,NULL,'2026-06-15 14:49:18','2026-06-15 14:56:08',9),
(48,16,'MOVE',3,'COMPLETED',550,NULL,NULL,2,358,1.0000,650.0000,'LPN',17,'RELOCATION',6,NULL,'2026-06-15 15:35:18','Reubicación RL-00000006 — LPN LPN-00000062',NULL,NULL,NULL,'2026-06-15 15:27:05','2026-06-15 15:35:18',1),
(49,16,'PUTAWAY',2,'COMPLETED',690,49,NULL,2477,4783,1.0000,1.0000,'UN',17,'QA_PUTAWAY_HOLD',23,'2026-06-15 16:09:26','2026-06-15 16:09:26','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000113: +1]','BY_LPN','GROUPED',NULL,'2026-06-15 15:29:22','2026-06-15 16:09:26',27),
(50,16,'PUTAWAY',2,'COMPLETED',1008,50,NULL,2477,4779,1.0000,1.0000,'KG',17,'QA_PUTAWAY_HOLD',23,'2026-06-15 16:09:56','2026-06-15 16:09:56','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000114: +1]','BY_LPN','GROUPED',NULL,'2026-06-15 15:29:22','2026-06-15 16:09:56',27),
(51,16,'PUTAWAY',2,'COMPLETED',1375,48,NULL,2477,1014,1.0000,1.0000,'UN',17,'QA_PUTAWAY_HOLD',23,'2026-06-15 16:02:24','2026-06-15 16:02:24','Putaway en cuarentena (auto agenda): stock con status QA hasta liberación [LPN LPN-00000112: +1]','BY_LPN','GROUPED',NULL,'2026-06-15 15:29:22','2026-06-15 16:02:24',27),
(52,16,'MOVE',3,'COMPLETED',550,NULL,NULL,236,359,1.0000,939.0000,'LPN',17,'RELOCATION',7,NULL,'2026-06-15 15:45:51','Reubicación RL-00000007 — LPN LPN-00000088',NULL,NULL,NULL,'2026-06-15 15:41:46','2026-06-15 15:45:51',9),
(53,16,'PUTAWAY',2,'COMPLETED',72371,51,NULL,2477,226,4591.0000,4591.0000,'UN',17,'GOODS_RECEIPT',24,'2026-06-15 16:24:09','2026-06-15 16:24:27','Putaway auto generado al cerrar agenda [LPN LPN-00000116: +1711] [LPN LPN-00000115: +2880]','BY_LPN','GROUPED',NULL,'2026-06-15 15:57:02','2026-06-15 16:24:27',27),
(54,16,'PICK',2,'COMPLETED',72371,51,NULL,168,NULL,100.0000,100.0000,'UN',29,'PICK_LIST',4,NULL,'2026-06-15 16:59:01',NULL,NULL,NULL,NULL,'2026-06-15 16:56:05','2026-06-15 16:59:01',9),
(55,16,'PICK',2,'COMPLETED',72371,51,NULL,168,NULL,1.0000,1.0000,'UN',18,'PICK_LIST',5,NULL,'2026-06-15 17:15:45',NULL,NULL,NULL,NULL,'2026-06-15 17:13:50','2026-06-15 17:15:45',9);

--
-- Table structure for table `warehouse_zones`
--

CREATE TABLE `warehouse_zones` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `warehouse_id` int(10) unsigned NOT NULL,
  `code` varchar(20) NOT NULL,
  `name` varchar(100) NOT NULL,
  `zone_type` enum('RECEIVING','STORAGE','PICKING','SHIPPING','QA','STAGING','RETURNS','DAMAGE') NOT NULL DEFAULT 'STORAGE',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_auction` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Zona para productos de remate',
  `is_export` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Zona para productos de exportacion',
  `putaway_priority` int(11) NOT NULL DEFAULT 5 COMMENT 'Prioridad para sugerencia de putaway (1=preferida)',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_zone_code` (`warehouse_id`,`code`),
  KEY `idx_zone_auction` (`is_auction`),
  KEY `idx_zone_export` (`is_export`),
  KEY `idx_zone_putaway_pri` (`putaway_priority`),
  CONSTRAINT `fk_zones_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Zonas lógicas dentro de un almacén';

--
-- Dumping data for table `warehouse_zones`
--

INSERT INTO `warehouse_zones` VALUES
(20,16,'CEN-LIC','Licitaciones-Terceros-Exportación','STORAGE',1,0,0,5,'2026-05-06 19:30:07','2026-05-06 19:30:07'),
(21,16,'CEN-MP','Materia Prima','STORAGE',1,0,0,5,'2026-05-06 19:30:07','2026-05-06 19:30:07'),
(22,16,'CEN-IN','Insumos','STORAGE',1,0,0,5,'2026-05-06 19:30:07','2026-05-06 19:30:07'),
(23,16,'CEN-PT','Productos Terminados','STORAGE',1,0,0,5,'2026-05-06 19:30:07','2026-05-06 19:30:07'),
(25,16,'OPT','OPTICA','STORAGE',1,0,0,5,'2026-05-06 19:49:41','2026-05-06 19:49:41'),
(28,16,'CEN-MPP','Materia Prima - Pequeñas','STORAGE',1,0,0,5,'2026-05-12 20:11:49','2026-05-12 20:11:49'),
(31,16,'CEN-CO','Controlados','STORAGE',1,0,0,5,'2026-05-12 20:11:49','2026-05-12 20:11:49'),
(36,16,'PIC-COSM','PICKING COSMETICOS','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(37,16,'PIC-CTRL','PICKING CONTROLADOS','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(38,16,'PIC-DIS','PICKING DISP','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(39,16,'PIC-FITO','PICKING FITO','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(40,16,'PIC-MM','PICKING MUESTRAS','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(41,16,'PIC-RX','PICKING RX','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(42,16,'PIC-SUP','PICKING SUPLEMENTOS','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(43,16,'PK-OTC','PICKING OTC','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12'),
(44,16,'PK-OTX','PICKING OTX','PICKING',1,0,0,5,'2026-05-14 16:25:12','2026-05-14 16:25:12');

--
-- Table structure for table `warehouses`
--

CREATE TABLE `warehouses` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(20) NOT NULL COMMENT 'Código SAP del almacén',
  `name` varchar(100) NOT NULL,
  `address` varchar(255) DEFAULT NULL,
  `sap_warehouse_code` varchar(20) DEFAULT NULL COMMENT 'WhsCode en SAP B1',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_default` tinyint(1) NOT NULL DEFAULT 0,
  `is_physical` tinyint(1) NOT NULL DEFAULT 0,
  `physical_building` enum('GEN','PIC','EXT') DEFAULT NULL,
  `area_m2` decimal(10,2) DEFAULT NULL,
  `height_m` decimal(6,2) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_warehouses_code` (`code`),
  KEY `idx_warehouses_sap` (`sap_warehouse_code`)
) ENGINE=InnoDB AUTO_INCREMENT=106 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Almacenes/depósitos del sistema';

--
-- Dumping data for table `warehouses`
--

INSERT INTO `warehouses` VALUES
(3,'PE','PRODUCTOS EN PROCESO ENVASADO',NULL,'PE',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-05-13 13:47:05'),
(4,'PI','PRODUCTOS EN PROCESO IMPRESIONES',NULL,'PI',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-05-13 13:47:05'),
(8,'MT','MANTENIMIENTO',NULL,'MT',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-05-13 13:47:05'),
(10,'PP','PRODUCTOS EN PROCESO',NULL,'PP',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-05-13 13:47:05'),
(11,'PR','PRODUCTOS EN PROCESO MRA',NULL,'PR',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-04-02 20:37:22'),
(13,'PTC','PRODUCTOS TERMINADOS APROBADOS - COMFAR',NULL,'PTC',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-05-13 13:47:05'),
(14,'RP','RECHAZADOS - PROCESO',NULL,'RP',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-05-13 13:47:05'),
(16,'CENMRA','CENTRAL MRA',NULL,'CENMRA',1,1,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-06-07 23:43:08'),
(17,'MP','MATERIA PRIMA',NULL,'MP',1,0,0,NULL,NULL,NULL,'2026-04-02 20:37:22','2026-04-02 20:37:22');

--
-- Table structure for table `zone_pick_lines`
--

CREATE TABLE `zone_pick_lines` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `zone_pick_id` int(10) unsigned NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `item_code` varchar(50) NOT NULL,
  `batch_id` int(10) unsigned DEFAULT NULL,
  `batch_number` varchar(50) DEFAULT NULL,
  `from_bin_id` int(10) unsigned NOT NULL COMMENT 'Ubicacion origen de donde se recoge',
  `requested_qty` decimal(15,4) NOT NULL,
  `collected_qty` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `returned_qty` decimal(15,4) NOT NULL DEFAULT 0.0000 COMMENT 'Cantidad devuelta por sobrante',
  `status` enum('PENDING','COLLECTED','DELIVERED','RETURNED','PARTIAL') NOT NULL DEFAULT 'PENDING',
  `collected_by` int(10) unsigned DEFAULT NULL COMMENT 'Operador que recogio',
  `collected_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `source_bin_id` int(10) unsigned DEFAULT NULL,
  `return_bin_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_zpln_pick` (`zone_pick_id`),
  KEY `idx_zpln_item` (`item_id`),
  KEY `idx_zpln_batch` (`batch_id`),
  KEY `idx_zpln_from` (`from_bin_id`),
  KEY `idx_zpln_status` (`status`),
  KEY `idx_zpln_collector` (`collected_by`),
  CONSTRAINT `fk_zpln_batch` FOREIGN KEY (`batch_id`) REFERENCES `batches` (`id`),
  CONSTRAINT `fk_zpln_collector` FOREIGN KEY (`collected_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_zpln_from_bin` FOREIGN KEY (`from_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_zpln_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_zpln_pick` FOREIGN KEY (`zone_pick_id`) REFERENCES `zone_picks` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Lineas de picking inter-zona con trazabilidad de recoleccion y devolucion';

--
-- Dumping data for table `zone_pick_lines`
--


--
-- Table structure for table `zone_picks`
--

CREATE TABLE `zone_picks` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `pick_number` varchar(30) NOT NULL,
  `warehouse_id` int(10) unsigned NOT NULL,
  `source_zone_id` int(10) unsigned DEFAULT NULL COMMENT 'Zona origen (almacen)',
  `destination_zone_id` int(10) unsigned DEFAULT NULL COMMENT 'Zona destino (ej: sala de pesadas)',
  `destination_bin_id` int(10) unsigned DEFAULT NULL COMMENT 'Bin especifico de la sala de pesadas',
  `pick_mode` enum('BY_ORDER_TYPE','BY_PREPARATION') NOT NULL DEFAULT 'BY_ORDER_TYPE' COMMENT 'Modo de carga: por tipo de pedido o por preparacion',
  `order_type_filter` varchar(50) DEFAULT NULL COMMENT 'Filtro de tipo de pedido (si pick_mode = BY_ORDER_TYPE)',
  `preparation_id` int(10) unsigned DEFAULT NULL COMMENT 'ID de preparacion vinculada (si pick_mode = BY_PREPARATION)',
  `status` enum('DRAFT','PLANNED','LOADING','LOADED','IN_PROGRESS','UNLOADING','DELIVERED','COMPLETED','CANCELLED') NOT NULL DEFAULT 'DRAFT',
  `notes` text DEFAULT NULL,
  `created_by` int(10) unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `completed_at` datetime DEFAULT NULL,
  `completed_by` int(10) unsigned DEFAULT NULL,
  `delivered_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_zpck_number` (`pick_number`),
  KEY `idx_zpck_wh` (`warehouse_id`),
  KEY `idx_zpck_src_zone` (`source_zone_id`),
  KEY `idx_zpck_dst_zone` (`destination_zone_id`),
  KEY `idx_zpck_dst_bin` (`destination_bin_id`),
  KEY `idx_zpck_mode` (`pick_mode`),
  KEY `idx_zpck_status` (`status`),
  KEY `idx_zpck_prep` (`preparation_id`),
  KEY `fk_zpck_creator` (`created_by`),
  CONSTRAINT `fk_zpck_creator` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_zpck_dst_bin` FOREIGN KEY (`destination_bin_id`) REFERENCES `bins` (`id`),
  CONSTRAINT `fk_zpck_dst_zone` FOREIGN KEY (`destination_zone_id`) REFERENCES `warehouse_zones` (`id`),
  CONSTRAINT `fk_zpck_src_zone` FOREIGN KEY (`source_zone_id`) REFERENCES `warehouse_zones` (`id`),
  CONSTRAINT `fk_zpck_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Tareas de picking inter-zona (ej: almacen a sala de pesadas)';

--
-- Dumping data for table `zone_picks`
--



