--
-- Host: localhost    Database: italvettools_bdcrm
-- ------------------------------------------------------


--
-- Table structure for table `audit_logs`
--

CREATE TABLE `audit_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `action` varchar(100) NOT NULL,
  `entity_type` varchar(100) NOT NULL,
  `entity_id` int(11) DEFAULT NULL,
  `old_values` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`old_values`)),
  `new_values` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`new_values`)),
  `ip_address` varchar(45) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_audit_logs_entity` (`entity_type`,`entity_id`),
  KEY `idx_audit_logs_user_id` (`user_id`),
  KEY `idx_audit_logs_created_at` (`created_at`),
  CONSTRAINT `audit_logs_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `audit_logs`
--


--
-- Table structure for table `backups`
--

CREATE TABLE `backups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `file_name` varchar(300) NOT NULL,
  `file_path` varchar(500) NOT NULL,
  `type` enum('completo','parcial') NOT NULL DEFAULT 'completo',
  `size_bytes` bigint(20) DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `backups_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `backups`
--

INSERT INTO `backups` VALUES
(1,'backup_20260624_092138.sql','/home/italvettools/back.italvettools.com/storage/backups/backup_20260624_092138.sql','completo',33103,1,'2026-06-24 15:21:40');

--
-- Table structure for table `configurations`
--

CREATE TABLE `configurations` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `key` varchar(100) NOT NULL,
  `value` text DEFAULT NULL,
  `description` varchar(300) DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `key` (`key`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `configurations`
--

INSERT INTO `configurations` VALUES
(1,'smtp_host','smtp.test.qa',NULL,1,'2026-06-18 04:01:20'),
(2,'smtp_port','2525',NULL,1,'2026-06-18 04:01:21'),
(3,'google_vision_key','qa-123',NULL,1,'2026-06-18 04:01:22'),
(4,'nueva_key','val',NULL,1,'2026-06-18 04:01:26');

--
-- Table structure for table `event_users`
--

CREATE TABLE `event_users` (
  `event_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  PRIMARY KEY (`event_id`,`user_id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `event_users_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE,
  CONSTRAINT `event_users_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `event_users`
--

INSERT INTO `event_users` VALUES
(6,2),
(7,4);

--
-- Table structure for table `events`
--

CREATE TABLE `events` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `description` text DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `location` varchar(300) DEFAULT NULL,
  `status` enum('active','inactive') NOT NULL DEFAULT 'active',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `events`
--

INSERT INTO `events` VALUES
(1,'Feria QA Editada','Actualizado','2026-08-15','2026-08-20','Lima','active','2026-06-16 05:52:24','2026-06-16 05:52:33'),
(2,'Congreso QA',NULL,NULL,NULL,'Arequipa','active','2026-06-16 05:52:25','2026-06-16 05:52:25'),
(3,'Feria QA',NULL,NULL,NULL,NULL,'active','2026-06-17 02:59:38','2026-06-17 02:59:38'),
(4,'Test',NULL,NULL,NULL,NULL,'active','2026-06-17 03:01:14','2026-06-17 03:01:14'),
(6,'Evento Gestor',NULL,NULL,NULL,NULL,'active','2026-06-18 04:15:25','2026-06-18 04:15:25'),
(7,'APROHPERU 2026','Feria principal','2026-08-15','2026-08-20','Lima','active','2026-06-18 05:04:53','2026-06-18 05:04:53');

--
-- Table structure for table `lead_products`
--

CREATE TABLE `lead_products` (
  `lead_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`lead_id`,`product_id`),
  KEY `product_id` (`product_id`),
  CONSTRAINT `lead_products_ibfk_1` FOREIGN KEY (`lead_id`) REFERENCES `leads` (`id`) ON DELETE CASCADE,
  CONSTRAINT `lead_products_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `lead_products`
--


--
-- Table structure for table `lead_status_history`
--

CREATE TABLE `lead_status_history` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lead_id` int(11) NOT NULL,
  `previous_status` varchar(30) DEFAULT NULL,
  `new_status` varchar(30) NOT NULL,
  `loss_reason_id` int(11) DEFAULT NULL,
  `notes` varchar(500) DEFAULT NULL,
  `changed_by` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `lead_id` (`lead_id`),
  KEY `loss_reason_id` (`loss_reason_id`),
  KEY `changed_by` (`changed_by`),
  CONSTRAINT `lead_status_history_ibfk_1` FOREIGN KEY (`lead_id`) REFERENCES `leads` (`id`) ON DELETE CASCADE,
  CONSTRAINT `lead_status_history_ibfk_2` FOREIGN KEY (`loss_reason_id`) REFERENCES `loss_reasons` (`id`) ON DELETE SET NULL,
  CONSTRAINT `lead_status_history_ibfk_3` FOREIGN KEY (`changed_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `lead_status_history`
--

INSERT INTO `lead_status_history` VALUES
(1,1,'nuevo','contactado',NULL,'Primer contacto',1,'2026-06-17 02:59:56'),
(2,1,'contactado','calificado',NULL,NULL,1,'2026-06-17 02:59:58'),
(3,1,'calificado','ganado',NULL,'Cerrado!',1,'2026-06-17 03:00:00'),
(4,2,'nuevo','propuesta',NULL,NULL,1,'2026-06-17 03:00:02'),
(5,2,'propuesta','negociacion',NULL,NULL,1,'2026-06-17 03:00:04'),
(6,4,'nuevo','contactado',NULL,NULL,1,'2026-06-17 03:01:20'),
(9,23,'nuevo','contactado',NULL,NULL,4,'2026-06-23 04:37:21');

--
-- Table structure for table `lead_technical_profiles`
--

CREATE TABLE `lead_technical_profiles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lead_id` int(11) NOT NULL,
  `animal_type` varchar(100) DEFAULT NULL,
  `herd_size` varchar(100) DEFAULT NULL,
  `current_supplier` varchar(200) DEFAULT NULL,
  `interest_area` varchar(200) DEFAULT NULL,
  `additional_data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`additional_data`)),
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `lead_id` (`lead_id`),
  CONSTRAINT `lead_technical_profiles_ibfk_1` FOREIGN KEY (`lead_id`) REFERENCES `leads` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `lead_technical_profiles`
--

INSERT INTO `lead_technical_profiles` VALUES
(2,23,'Prueba','100','Prueba','Prueba',NULL,'2026-06-23 03:43:40','2026-06-23 04:44:20');

--
-- Table structure for table `leads`
--

CREATE TABLE `leads` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `event_id` int(11) NOT NULL,
  `first_name` varchar(150) NOT NULL,
  `last_name` varchar(150) NOT NULL,
  `email` varchar(200) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `company` varchar(200) DEFAULT NULL,
  `position` varchar(200) DEFAULT NULL,
  `city` varchar(150) DEFAULT NULL,
  `region` varchar(150) DEFAULT NULL,
  `client_type` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`client_type`)),
  `industry` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`industry`)),
  `classification` varchar(20) DEFAULT NULL,
  `observations` text DEFAULT NULL,
  `source` enum('manual','scan','voice') NOT NULL DEFAULT 'manual',
  `status` enum('nuevo','contactado','calificado','propuesta','negociacion','ganado','perdido') NOT NULL DEFAULT 'nuevo',
  `loss_reason_id` int(11) DEFAULT NULL,
  `is_duplicate` tinyint(1) NOT NULL DEFAULT 0,
  `duplicate_of` int(11) DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `loss_reason_id` (`loss_reason_id`),
  KEY `duplicate_of` (`duplicate_of`),
  KEY `updated_by` (`updated_by`),
  KEY `idx_leads_event_id` (`event_id`),
  KEY `idx_leads_status` (`status`),
  KEY `idx_leads_created_by` (`created_by`),
  KEY `idx_leads_email` (`email`),
  KEY `idx_leads_phone` (`phone`),
  CONSTRAINT `leads_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE,
  CONSTRAINT `leads_ibfk_2` FOREIGN KEY (`loss_reason_id`) REFERENCES `loss_reasons` (`id`) ON DELETE SET NULL,
  CONSTRAINT `leads_ibfk_3` FOREIGN KEY (`duplicate_of`) REFERENCES `leads` (`id`) ON DELETE SET NULL,
  CONSTRAINT `leads_ibfk_4` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `leads_ibfk_5` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `leads`
--

INSERT INTO `leads` VALUES
(1,3,'Carlos Editado','Gomez','carlos@test.com','5550001','AgroMex 2.0','Gerente',NULL,NULL,NULL,NULL,NULL,NULL,'manual','ganado',NULL,0,NULL,1,1,'2026-06-17 02:59:42','2026-06-17 03:00:00'),
(2,3,'Maria','Lopez','maria@test.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','negociacion',NULL,0,NULL,1,1,'2026-06-17 02:59:44','2026-06-17 03:00:04'),
(3,3,'Copia','Gomez','carlos@test.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,1,1,1,NULL,'2026-06-17 02:59:45','2026-06-17 02:59:45'),
(4,4,'T','L',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','contactado',NULL,0,NULL,1,1,'2026-06-17 03:01:18','2026-06-17 03:01:20'),
(10,7,'Sin nombre','Por voz',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:36:54','2026-06-18 05:36:54'),
(11,7,'Sin nombre','Por voz',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:37:33','2026-06-18 05:37:33'),
(12,7,'Sin nombre','Por voz',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:42:30','2026-06-18 05:42:30'),
(13,7,'Brad','Delacruz',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:46:27','2026-06-18 05:46:27'),
(14,7,'Hola','Esto',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:48:26','2026-06-18 05:48:26'),
(15,7,'Brian','Por voz',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:48:45','2026-06-18 05:48:45'),
(16,7,'Carlos','De',NULL,NULL,'Agromex',NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:50:45','2026-06-18 05:50:45'),
(17,7,'Sin nombre','Por voz',NULL,'55 50 2320',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:51:05','2026-06-18 05:51:05'),
(18,7,'Brian','Trabaja',NULL,NULL,'Agromex Mi Teléfono Es Nueve Veinte Uno Tres Cuatro Cuatro Tres Ocho',NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 05:53:16','2026-06-18 05:53:16'),
(19,7,'Brian','Trabajo',NULL,'940 123 4056','Cruz',NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 06:00:36','2026-06-18 06:00:36'),
(20,7,'Brian','Trabajador',NULL,'920 123456','Cruz',NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-18 06:02:12','2026-06-18 06:02:12'),
(22,7,'Brian','De',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'manual','nuevo',NULL,0,NULL,4,NULL,'2026-06-19 20:10:08','2026-06-19 20:10:08'),
(23,7,'Bryan','De la cruz','bdelacruz654@gmail.com','+51947394676','Agromex','Gerente','chincha','Ica','[\"Distribuidor\"]','[\"Nutrici\\u00f3n Animal\"]','caliente','sssssss','manual','contactado',NULL,1,NULL,4,4,'2026-06-23 03:43:40','2026-06-23 04:37:21');

--
-- Table structure for table `loss_reasons`
--

CREATE TABLE `loss_reasons` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(150) NOT NULL,
  `description` text DEFAULT NULL,
  `status` enum('active','inactive') NOT NULL DEFAULT 'active',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `loss_reasons`
--

INSERT INTO `loss_reasons` VALUES
(1,'Precio','El lead considero que el precio era muy alto','active','2026-06-17 03:03:47'),
(2,'Competencia','El lead eligio un competidor','active','2026-06-17 03:03:47'),
(3,'Sin interes','El lead perdio interes','active','2026-06-17 03:03:47'),
(4,'No contactable','No fue posible contactar al lead','active','2026-06-17 03:03:47'),
(5,'Presupuesto','El lead no cuenta con presupuesto','active','2026-06-17 03:03:47'),
(6,'Otro','Otro motivo no especificado','active','2026-06-17 03:03:47'),
(7,'Precio','El lead consideró que el precio era muy alto','active','2026-06-24 15:17:26'),
(8,'Competencia','El lead eligió un competidor','active','2026-06-24 15:17:26'),
(9,'Sin interés','El lead perdió interés en el producto/servicio','active','2026-06-24 15:17:26'),
(10,'No contactable','No fue posible contactar al lead','active','2026-06-24 15:17:26'),
(11,'Presupuesto','El lead no cuenta con presupuesto','active','2026-06-24 15:17:26'),
(12,'Otro','Otro motivo no especificado','active','2026-06-24 15:17:26');

--
-- Table structure for table `notes`
--

CREATE TABLE `notes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lead_id` int(11) NOT NULL,
  `type` enum('texto','audio') NOT NULL DEFAULT 'texto',
  `content` text DEFAULT NULL,
  `audio_file_path` varchar(500) DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `lead_id` (`lead_id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `notes_ibfk_1` FOREIGN KEY (`lead_id`) REFERENCES `leads` (`id`) ON DELETE CASCADE,
  CONSTRAINT `notes_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `notes`
--


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

CREATE TABLE `notifications` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `type` enum('tarea_proxima','tarea_vencida','nuevo_lead','invitacion','actividad') NOT NULL,
  `title` varchar(200) NOT NULL,
  `message` text DEFAULT NULL,
  `reference_type` varchar(100) DEFAULT NULL,
  `reference_id` int(11) DEFAULT NULL,
  `is_read` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_notifications_user` (`user_id`,`is_read`),
  CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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


--
-- Table structure for table `password_resets`
--

CREATE TABLE `password_resets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `token` varchar(255) NOT NULL,
  `expires_at` timestamp NOT NULL,
  `used` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `token` (`token`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `password_resets_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `password_resets`
--

INSERT INTO `password_resets` VALUES
(1,1,'6f0cfaa28cc61fce548e6b46e7d9829f1ea3f1940d5994c28af44bfa6efb3ead','2026-06-24 00:42:37',1,'2026-06-23 23:42:37'),
(2,1,'d51a388dec1bd9194132eea1151c387c38fdf4d2b3d78c04b4d7eaa9817dd714','2026-06-24 00:42:38',1,'2026-06-23 23:42:38'),
(3,1,'7885e3af013f75501dbd4b1f69e6f50cd7dd27e37de41ae4d1af12d5a4ecee2a','2026-06-24 00:42:39',1,'2026-06-23 23:42:39'),
(4,1,'e982ea8f42745c4c45550a82a3a38c88f2e1f7d6473e7aaf589526f5a438bef7','2026-06-24 00:46:22',1,'2026-06-23 23:46:22'),
(5,1,'c63ba429baf6de0011ab5fe54e99c044f2261cd0e317a95f34763ffbc576a3b0','2026-06-24 00:46:23',1,'2026-06-23 23:46:23'),
(6,1,'8a1e0e03295f78a7198458c54934e7484f875a65cb93f64157d4681106ef1134','2026-06-24 00:46:24',1,'2026-06-23 23:46:24');

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `description` text DEFAULT NULL,
  `category` varchar(150) DEFAULT NULL,
  `status` enum('active','inactive') NOT NULL DEFAULT 'active',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `products`
--

INSERT INTO `products` VALUES
(1,'v2','Upd','Nutricion','active','2026-06-17 03:14:40','2026-06-17 03:14:48');

--
-- Table structure for table `sessions`
--

CREATE TABLE `sessions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `token` varchar(500) NOT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` text DEFAULT NULL,
  `expires_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `token` (`token`),
  KEY `idx_sessions_user_id` (`user_id`),
  KEY `idx_sessions_expires_at` (`expires_at`),
  CONSTRAINT `sessions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `sessions`
--

INSERT INTO `sessions` VALUES
(79,4,'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjUxNzMiLCJpYXQiOjE3ODIzMTIzMzMsImV4cCI6MTc4MjMxNTkzMywic3ViIjo0LCJyb2xlIjoiY29tZXJjaWFsX21hbmFnZXIiLCJldmVudF9pZCI6bnVsbH0.rDmwnFkVSNIKF4UYXIQV4lVmu5g1IlsSXcAmQOobW6g','181.67.176.175','curl/8.19.0','2026-06-24 15:45:33','2026-06-24 14:45:33');

--
-- Table structure for table `tasks`
--

CREATE TABLE `tasks` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lead_id` int(11) NOT NULL,
  `type` enum('llamada','reunion','correo','whatsapp','seguimiento','otro') NOT NULL,
  `scheduled_date` date NOT NULL,
  `scheduled_time` time DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `assigned_to` int(11) NOT NULL,
  `status` enum('pendiente','completada','cancelada') NOT NULL DEFAULT 'pendiente',
  `completed_at` timestamp NULL DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `lead_id` (`lead_id`),
  KEY `created_by` (`created_by`),
  KEY `idx_tasks_assigned_to` (`assigned_to`),
  KEY `idx_tasks_scheduled_date` (`scheduled_date`),
  KEY `idx_tasks_status` (`status`),
  CONSTRAINT `tasks_ibfk_1` FOREIGN KEY (`lead_id`) REFERENCES `leads` (`id`) ON DELETE CASCADE,
  CONSTRAINT `tasks_ibfk_2` FOREIGN KEY (`assigned_to`) REFERENCES `users` (`id`),
  CONSTRAINT `tasks_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `tasks`
--

INSERT INTO `tasks` VALUES
(1,23,'llamada','2026-06-23','00:00:00','ssssssss',4,'pendiente',NULL,4,'2026-06-23 05:03:03','2026-06-23 05:03:03');

--
-- Table structure for table `technical_materials`
--

CREATE TABLE `technical_materials` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) NOT NULL,
  `description` text DEFAULT NULL,
  `type` enum('pdf','video') NOT NULL,
  `file_path` varchar(500) DEFAULT NULL,
  `external_url` varchar(500) DEFAULT NULL,
  `status` enum('active','inactive') NOT NULL DEFAULT 'active',
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `technical_materials_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `technical_materials`
--

INSERT INTO `technical_materials` VALUES
(1,'Guia v2','Manual','pdf',NULL,'https://e.com/g.pdf','active',1,'2026-06-17 03:41:25','2026-06-17 03:41:31');

--
-- Table structure for table `user_invitations`
--

CREATE TABLE `user_invitations` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(200) NOT NULL,
  `token` varchar(255) NOT NULL,
  `role` enum('super_admin','comercial_manager') NOT NULL,
  `invited_by` int(11) NOT NULL,
  `status` enum('pendiente','aceptada','expirada') NOT NULL DEFAULT 'pendiente',
  `expires_at` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `token` (`token`),
  KEY `invited_by` (`invited_by`),
  CONSTRAINT `user_invitations_ibfk_1` FOREIGN KEY (`invited_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `user_invitations`
--


--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(150) NOT NULL,
  `email` varchar(200) NOT NULL,
  `password` varchar(255) NOT NULL,
  `role` enum('super_admin','comercial_manager') NOT NULL DEFAULT 'comercial_manager',
  `status` enum('pending_activation','active','inactive') NOT NULL DEFAULT 'pending_activation',
  `current_event_id` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `users`
--

INSERT INTO `users` VALUES
(1,'Super Administrador','admin@italvet.com','$2y$10$XTmLzR1.cSKQp0mOFH7gLOTSsQHF2BlMYZGaWst608rjvPMGEf0NG','super_admin','active',NULL,'2026-06-16 05:28:14','2026-06-23 21:17:46'),
(2,'Gestor QA','gq@t.com','$2y$10$uZx7lHW/qeNkdrc6dnqrNOOV4Mbw0X1hscCRROgeVhD0jlXCkiQte','comercial_manager','active',6,'2026-06-16 05:56:05','2026-06-18 04:15:27'),
(3,'Bryan Angel De La Cruz Soto','bdelacruz654@gmail.com','$2y$10$rQG63gpd.9DDQ.o24wQITOQB9GJB4eBX6o3ToHYS7052IOY7ByDrW','super_admin','active',NULL,'2026-06-17 02:41:36','2026-06-17 02:41:36'),
(4,'Carlos Vendedor','vendedor@italvet.com','$2y$10$jtNOIARnXIYsYwpkC8x0iempgK62xzlxdV1U1kOmomqhJPPPCiGZi','comercial_manager','active',NULL,'2026-06-18 04:43:48','2026-06-23 05:11:23');

--
-- Table structure for table `whatsapp_templates`
--

CREATE TABLE `whatsapp_templates` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `content` text NOT NULL,
  `variables` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`variables`)),
  `status` enum('active','inactive') NOT NULL DEFAULT 'active',
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `created_by` (`created_by`),
  CONSTRAINT `whatsapp_templates_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `whatsapp_templates`
--

INSERT INTO `whatsapp_templates` VALUES
(1,'Saludo v2','Hola {nombre}!','[\"nombre\"]','active',1,'2026-06-17 04:36:04','2026-06-17 04:36:08');


