--
-- Host: 34.46.213.230    Database: grayskull
-- ------------------------------------------------------

SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;

--
-- GTID state at the beginning of the backup 
--


--
-- Table structure for table `OFR`
--

CREATE TABLE `OFR` (
  `semana` int NOT NULL,
  `fecha` date NOT NULL,
  `tipo_orden` varchar(20) NOT NULL,
  `pendientes` int DEFAULT NULL,
  `completas` int DEFAULT NULL,
  `incompletas` int DEFAULT NULL,
  `total_ordenes` int DEFAULT NULL,
  `OFR` float DEFAULT NULL,
  PRIMARY KEY (`fecha`,`tipo_orden`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `OFR_tiendas`
--

CREATE TABLE `OFR_tiendas` (
  `ano` int NOT NULL,
  `semana` int NOT NULL,
  `mes` int NOT NULL,
  `tienda` varchar(15) COLLATE utf8mb4_spanish_ci NOT NULL,
  `pedidos` int DEFAULT NULL,
  `total` int DEFAULT NULL,
  `parcial` int DEFAULT NULL,
  `preparados` int DEFAULT NULL,
  `pendientes` int DEFAULT NULL,
  `nombre_tienda` varchar(100) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `primer_dia` date DEFAULT NULL,
  `udds` int DEFAULT NULL,
  `udds_qt` int DEFAULT NULL,
  `udds_qp` int DEFAULT NULL,
  `udds_prep` int DEFAULT NULL,
  `udds_pend` int DEFAULT NULL,
  PRIMARY KEY (`ano`,`semana`,`mes`,`tienda`),
  UNIQUE KEY `OFR_tiendas_tienda_IDX` (`tienda`,`ano`,`mes`,`semana`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_spanish_ci;

--
-- Table structure for table `UFR`
--

CREATE TABLE `UFR` (
  `fecha` date NOT NULL,
  `semana` int NOT NULL,
  `expedidas` int DEFAULT NULL,
  `canceladas` int DEFAULT NULL,
  `pendientes` int DEFAULT NULL,
  `tipo_producto` varchar(10) NOT NULL,
  `total` int DEFAULT NULL,
  `UFR` float DEFAULT NULL,
  PRIMARY KEY (`fecha`,`tipo_producto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `alertas_reposicion_eds`
--

CREATE TABLE `alertas_reposicion_eds` (
  `fecha_recepcion_eds` datetime NOT NULL,
  `doc_entry_sap` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku_diferencia` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `udds_diferencia` int DEFAULT NULL,
  `fecha_notificacion_inventario` datetime DEFAULT NULL,
  PRIMARY KEY (`doc_entry_sap`,`sku_diferencia`,`fecha_recepcion_eds`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci COMMENT='Alertas de diferencias en reposición a EDS, entre lo informado como despachado por SAP y lo confirmado por EDS.';

--
-- Table structure for table `analytics`
--

CREATE TABLE `analytics` (
  `sitio` varchar(11) NOT NULL,
  `ano` int NOT NULL,
  `semana` int NOT NULL,
  `sesiones` int DEFAULT NULL,
  `users` int DEFAULT NULL,
  `new_users` int DEFAULT NULL,
  `ad_cost` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`sitio`,`ano`,`semana`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `analytics_diario`
--

CREATE TABLE `analytics_diario` (
  `fecha` date DEFAULT NULL,
  `sitio` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `pedidos` int DEFAULT NULL,
  `sesiones` int DEFAULT NULL,
  `addtocart` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `analytics_mes`
--

CREATE TABLE `analytics_mes` (
  `sitio` varchar(11) NOT NULL,
  `ano` int NOT NULL,
  `mes` int NOT NULL,
  `sesiones` int DEFAULT NULL,
  `users` int DEFAULT NULL,
  `new_users` int DEFAULT NULL,
  `ad_cost` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`sitio`,`ano`,`mes`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `analytics_productos`
--

CREATE TABLE `analytics_productos` (
  `sku` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sitio` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `clicks_l3m` int DEFAULT NULL,
  `ctr_l3m` decimal(10,8) DEFAULT NULL,
  `views_l3m` int DEFAULT NULL,
  PRIMARY KEY (`sitio`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `anulados_tiendas`
--

CREATE TABLE `anulados_tiendas` (
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fulfillment` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estado` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_estado` datetime DEFAULT NULL,
  `folio_nc` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `asn`
--

CREATE TABLE `asn` (
  `cli` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `estado` varchar(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha` datetime DEFAULT NULL,
  `folio_nc` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`cli`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `carta_porte_digital`
--

CREATE TABLE `carta_porte_digital` (
  `id_carta` int NOT NULL,
  `fecha_carta` datetime DEFAULT NULL,
  `patente_vehiculo` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre_chofer` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `transportista` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `id_transportista` int DEFAULT NULL,
  `estado_entrega` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cli` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `categorias_magento`
--

CREATE TABLE `categorias_magento` (
  `id` int NOT NULL,
  `nombre_categoria` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `parent_id` int NOT NULL,
  `rama` int DEFAULT NULL,
  `store_id` int DEFAULT NULL,
  `url_key` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `categorias_magento_parent_id_IDX` (`parent_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `categorias_productos_magento`
--

CREATE TABLE `categorias_productos_magento` (
  `category_id` int NOT NULL,
  `product_id` mediumint unsigned NOT NULL,
  `posicion` int DEFAULT NULL,
  PRIMARY KEY (`category_id`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `cli_operador`
--

CREATE TABLE `cli_operador` (
  `cli` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `operador` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `subestado` varchar(400) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`cli`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `clientes`
--

CREATE TABLE `clientes` (
  `rut` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `nombre` varchar(87) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `apellido` varchar(65) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `telefono` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cumpleanos` date DEFAULT NULL,
  `intereses` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `grupo` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sexo` varchar(6) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ano_nacimiento` smallint DEFAULT NULL,
  `fecha_adicion` date DEFAULT NULL,
  PRIMARY KEY (`rut`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `clientes_comportamiento`
--

CREATE TABLE `clientes_comportamiento` (
  `fecha` datetime DEFAULT NULL,
  `correo` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `accion` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `valor` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `etiqueta` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `clientes_correos`
--

CREATE TABLE `clientes_correos` (
  `rut` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `correo` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`rut`,`correo`),
  KEY `CORREO_INDEX` (`correo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `comentarios_pedidos_rt`
--

CREATE TABLE `comentarios_pedidos_rt` (
  `fecha_comentario` date NOT NULL,
  `cli` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `comentario` varchar(200) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`cli`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `comunas_region`
--

CREATE TABLE `comunas_region` (
  `cod_comuna` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre_comuna` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `cod_region` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre_region` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `grupo` varchar(5) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `orden_region` int DEFAULT NULL,
  `oms_cod_comuna` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `oms_cod_region` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`nombre_comuna`),
  KEY `idx_comuna` (`nombre_comuna`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `confirmaciones_de_compra`
--

CREATE TABLE `confirmaciones_de_compra` (
  `fecha_compra` date DEFAULT NULL,
  `fecha_compromiso` date DEFAULT NULL,
  `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `pedido` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sku` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `producto` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `unidades` int DEFAULT NULL,
  `precio_unitario` decimal(10,0) DEFAULT NULL,
  `descuento` decimal(10,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `cortes`
--

CREATE TABLE `cortes` (
  `fecha_corte` date DEFAULT NULL,
  `canal` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `orden` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` int DEFAULT NULL,
  `tipo` varchar(7) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comentario` varchar(60) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `deshabilitado` int DEFAULT NULL,
  `fecha_deshabilitado` timestamp NULL DEFAULT NULL,
  `doc_entry_sap` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`orden`,`sku`),
  KEY `idx_cli` (`orden`),
  KEY `idx_sku` (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `cortes_productos`
--

CREATE TABLE `cortes_productos` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_corte` date NOT NULL,
  `republicado` int DEFAULT NULL,
  PRIMARY KEY (`sku`,`fecha_corte`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `datos_magento_para_cortes`
--

CREATE TABLE `datos_magento_para_cortes` (
  `pedido` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_compra` datetime DEFAULT NULL,
  `operador_pago` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `metodo_pago` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `json_pago` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci,
  `sku` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `udds` int DEFAULT NULL,
  `producto` varchar(99) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `precio_unit` int DEFAULT NULL,
  `valor_despacho` int DEFAULT NULL,
  `total_compra` int DEFAULT NULL,
  `nombre_cliente` varchar(150) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `email_cliente` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `rut_cliente` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `compromiso_entrega` date DEFAULT NULL,
  PRIMARY KEY (`pedido`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `despachos`
--

CREATE TABLE `despachos` (
  `cli` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `operador` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estado` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_estado` datetime NOT NULL,
  `subestado` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`cli`,`fecha_estado`),
  KEY `idx_despachos` (`cli`,`fecha_estado`),
  KEY `idx_fecha_estado` (`fecha_estado`),
  KEY `idx_cli` (`cli`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `despachos_tiendas`
--

CREATE TABLE `despachos_tiendas` (
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `operador` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estado` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_estado` datetime NOT NULL,
  `subestado` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`,`fecha_estado`),
  KEY `despachos_tiendas_pedido_IDX` (`pedido`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `direcciones_magento`
--

CREATE TABLE `direcciones_magento` (
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_compra` date NOT NULL,
  `compromiso_picking` date DEFAULT NULL,
  `compromiso_carga` date DEFAULT NULL,
  `compromiso_entrega` date NOT NULL,
  `direccion` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_picking` date DEFAULT NULL,
  `nombre_cliente` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_estado` date DEFAULT NULL,
  `comuna` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `metodo_envio` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `zona` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `status_orden` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `id_pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_disp_retiro` date DEFAULT NULL,
  `punto_retiro` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`),
  KEY `idx_pedido` (`pedido`),
  KEY `idx_comuna` (`zona`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `direcciones_magento_OLD`
--

CREATE TABLE `direcciones_magento_OLD` (
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `direccion` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre_cliente` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comuna` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`),
  KEY `idx_pedido` (`pedido`),
  KEY `idx_comuna` (`comuna`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `docs_abiertos_sap`
--

CREATE TABLE `docs_abiertos_sap` (
  `documento` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tienda` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `docnum` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `folionum` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_contable` date DEFAULT NULL,
  `fecha_vencimiento` date DEFAULT NULL,
  `rut_cliente` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cliente` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `total_dcto` int DEFAULT NULL,
  `pagado` int DEFAULT NULL,
  `saldo` int DEFAULT NULL,
  `tipo_doc_base` varchar(5) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `folio_doc_base` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `pedido` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comentario` varchar(200) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nota` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `rut` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `email` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`docnum`,`documento`),
  KEY `docs_abiertos_sap_pedido_IDX` (`pedido`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `eds_pedidos_expedidos`
--

CREATE TABLE `eds_pedidos_expedidos` (
  `fecha_expedicion` datetime NOT NULL,
  `pedido` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `udds_expedidas` int DEFAULT NULL,
  `fecha_notificacion_sap` datetime DEFAULT NULL,
  `datos_notif_2` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_notificacion_sap_2` datetime DEFAULT NULL,
  PRIMARY KEY (`pedido`,`sku`,`fecha_expedicion`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `entregados_multivende`
--

CREATE TABLE `entregados_multivende` (
  `pedido_mkp` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_notificado` datetime NOT NULL,
  PRIMARY KEY (`pedido_mkp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `estilo_info_cat`
--

CREATE TABLE `estilo_info_cat` (
  `estilo` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sin_info` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sin_foto` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `catalogable` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`estilo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `estilo_sitio`
--

CREATE TABLE `estilo_sitio` (
  `estilo` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sitio` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`estilo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `fechas_eventos`
--

CREATE TABLE `fechas_eventos` (
  `fecha` date DEFAULT NULL,
  `evento` varchar(100) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tipo_dia` varchar(25) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `dia` varchar(20) COLLATE utf8mb3_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `feriados`
--

CREATE TABLE `feriados` (
  `dia` date NOT NULL,
  `feriado` int NOT NULL,
  PRIMARY KEY (`dia`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `flapp_incidencias`
--

CREATE TABLE `flapp_incidencias` (
  `fecha_incidencia` datetime NOT NULL,
  `pedido` varchar(11) COLLATE utf8mb4_spanish_ci NOT NULL,
  `tipo_correo_origen` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `courier` varchar(30) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `origen_stock` varchar(8) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `estado_envio` varchar(30) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `id_envio_flapp` varchar(30) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `ticket_creado` tinyint DEFAULT NULL,
  `ticket` int DEFAULT NULL,
  `nota_creada` tinyint DEFAULT NULL,
  PRIMARY KEY (`fecha_incidencia`,`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_spanish_ci;

--
-- Table structure for table `flapp_mapeo_categorias`
--

CREATE TABLE `flapp_mapeo_categorias` (
  `departamento` varchar(40) COLLATE utf8mb3_spanish_ci NOT NULL,
  `categoria` varchar(40) COLLATE utf8mb3_spanish_ci NOT NULL,
  `subcategoria` varchar(40) COLLATE utf8mb3_spanish_ci NOT NULL,
  `flapp_product_size` varchar(3) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`departamento`,`categoria`,`subcategoria`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `flapp_product_sizes`
--

CREATE TABLE `flapp_product_sizes` (
  `flapp_product_size` varchar(3) COLLATE utf8mb3_spanish_ci NOT NULL,
  `height` int DEFAULT NULL,
  `depth` int DEFAULT NULL,
  `length` int DEFAULT NULL,
  `weight` int DEFAULT NULL,
  PRIMARY KEY (`flapp_product_size`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `flapp_productos_creados`
--

CREATE TABLE `flapp_productos_creados` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `flapp_product_size` varchar(3) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_creacion_flapp` datetime DEFAULT NULL,
  `nombre` varchar(100) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `imagen` text COLLATE utf8mb3_spanish_ci,
  PRIMARY KEY (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `ids_pedidos_multivende`
--

CREATE TABLE `ids_pedidos_multivende` (
  `id` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `numero_venta` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `origin` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `id_despacho` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sold_at` datetime NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `kommi_estados`
--

CREATE TABLE `kommi_estados` (
  `estado` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `descripcion` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `kommi_pedidos`
--

CREATE TABLE `kommi_pedidos` (
  `fecha_lectura` datetime NOT NULL,
  `pedido` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `estado` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_confirmacion` datetime DEFAULT NULL,
  PRIMARY KEY (`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `kpis_flapp`
--

CREATE TABLE `kpis_flapp` (
  `ano` int DEFAULT NULL,
  `semana` int DEFAULT NULL,
  `fecha` date DEFAULT NULL,
  `metodo_envio` varchar(30) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `lugar_retiro` varchar(10) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tienda` varchar(100) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tipo_producto` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `a_tiempo` int DEFAULT NULL,
  `atrasado` int DEFAULT NULL,
  `pendiente` int DEFAULT NULL,
  `no_entregado_atrasado` int DEFAULT NULL,
  `p_a_tiempo` int DEFAULT NULL,
  `p_pendiente` int DEFAULT NULL,
  `p_atrasado` int DEFAULT NULL,
  `p_no_pickeado_atrasado` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `leadtimes`
--

CREATE TABLE `leadtimes` (
  `comuna` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `region` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `codigo_comuna` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `metodo_envio` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `pedidos_l4w` int DEFAULT NULL,
  `universo_entrega` int DEFAULT NULL,
  `entregados` int DEFAULT NULL,
  `leadtime` int NOT NULL,
  PRIMARY KEY (`comuna`,`metodo_envio`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_ajuste_stock`
--

CREATE TABLE `log_ajuste_stock` (
  `fecha` datetime NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `qty` int DEFAULT NULL,
  `is_in_stock` int DEFAULT NULL,
  KEY `idx_sku` (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_entregados`
--

CREATE TABLE `log_entregados` (
  `fecha_notificacion` datetime NOT NULL,
  `pedido` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `id_pedido` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `status` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comentario` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  PRIMARY KEY (`fecha_notificacion`,`pedido`,`id_pedido`),
  KEY `log_entregados_id_pedido_IDX` (`id_pedido`) USING BTREE,
  KEY `log_entregados_pedido_IDX` (`pedido`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_entregados_oms`
--

CREATE TABLE `log_entregados_oms` (
  `fecha_notificacion` datetime NOT NULL,
  `pedido` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `order_id_oms` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fulfillment_id_oms` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`fecha_notificacion`,`pedido`),
  KEY `log_entregados_oms_pedido_IDX` (`pedido`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_entregados_oms_errores`
--

CREATE TABLE `log_entregados_oms_errores` (
  `fecha_registro` datetime NOT NULL,
  `pedido` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `error` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  PRIMARY KEY (`fecha_registro`,`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_fix_sku_magento`
--

CREATE TABLE `log_fix_sku_magento` (
  `fecha_log` datetime NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `product_id` int NOT NULL,
  `fixed` int DEFAULT NULL,
  `fecha_fix` datetime DEFAULT NULL,
  `fixed_2` int DEFAULT NULL,
  `fecha_fix_2` datetime DEFAULT NULL,
  PRIMARY KEY (`fecha_log`,`sku`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_gama_alta`
--

CREATE TABLE `log_gama_alta` (
  `fecha_log` datetime NOT NULL,
  `pedido` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `precio_base` int DEFAULT NULL,
  PRIMARY KEY (`pedido`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_pedido_funcionario`
--

CREATE TABLE `log_pedido_funcionario` (
  `fecha_log` datetime NOT NULL,
  `pedido` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `rut` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `grand_total` int DEFAULT NULL,
  `dcto_total` int DEFAULT NULL,
  `respuesta_certificado` varchar(50) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `status_certificado` smallint DEFAULT NULL,
  KEY `log_pedido_funcionario_pedido_IDX` (`pedido`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_recepcion_eds_sap`
--

CREATE TABLE `log_recepcion_eds_sap` (
  `fecha_recepcion_eds` datetime NOT NULL,
  `folio_num` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `detalle_notificado` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `fecha_notificacion_sap` datetime NOT NULL,
  `response_sap` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `mensaje_sap` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  PRIMARY KEY (`folio_num`,`fecha_recepcion_eds`,`fecha_notificacion_sap`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci COMMENT='Log de recepción de reposición de stock confirmada por EDS, y su notificación hacia SAP.';

--
-- Table structure for table `log_rt_beetrack`
--

CREATE TABLE `log_rt_beetrack` (
  `tie` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_carga_beetrack` datetime DEFAULT NULL,
  `route_id` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`tie`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `log_shipment`
--

CREATE TABLE `log_shipment` (
  `fecha` datetime NOT NULL,
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `order_id` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `json_items` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  PRIMARY KEY (`fecha`,`pedido`,`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `maestra_magento`
--

CREATE TABLE `maestra_magento` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `entity_id` mediumint unsigned NOT NULL,
  `tipo` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `qty_source_general` smallint DEFAULT NULL,
  `stock` smallint DEFAULT NULL,
  `is_in_stock` tinyint DEFAULT NULL,
  `estado` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre` varchar(106) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `url` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sitio` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `marca` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `imagen` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `peso` smallint DEFAULT NULL,
  `gama_alta` int DEFAULT NULL,
  `color` varchar(20) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `genero` varchar(20) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `stock_oms` smallint DEFAULT NULL,
  `stock_oms_tiendas` smallint DEFAULT NULL,
  `fecha_catalogacion` date DEFAULT NULL,
  PRIMARY KEY (`sku`,`entity_id`),
  KEY `idx_sku` (`sku`),
  KEY `idx_entity_id` (`entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `maestra_magento_link`
--

CREATE TABLE `maestra_magento_link` (
  `sku_configurable` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku_simple` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`sku_configurable`,`sku_simple`),
  KEY `maestra_magento_link_sku_simple_IDX` (`sku_simple`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `maestra_sap`
--

CREATE TABLE `maestra_sap` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `nombre` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `new_categoria_antigua` varchar(19) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria_antigua` varchar(19) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(31) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `temporada` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `talla` varchar(5) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `marca` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `genero` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estilo` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estilo_sin_0` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `desestilo` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `color` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `deporte` varchar(18) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `codebars` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `configurable` varchar(18) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_ingreso` date DEFAULT NULL,
  `ciclo_vida` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `modelo` varchar(30) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`sku`),
  KEY `idx_sku` (`sku`),
  KEY `idx_configurable` (`configurable`),
  KEY `idx_catold` (`categoria_antigua`),
  KEY `idx_cat` (`categoria`),
  KEY `idx_subcat` (`subcategoria`),
  KEY `idx_codebars` (`codebars`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `maestra_sap_configurables`
--

CREATE TABLE `maestra_sap_configurables` (
  `sku_configurable` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `categoria_antigua` varchar(19) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(31) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `temporada` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `marca` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `genero` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estilo` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estilo_sin_0` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `desestilo` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `color` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `deporte` varchar(18) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_ingreso` date DEFAULT NULL,
  `ciclo_vida` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `modelo` varchar(30) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`sku_configurable`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `magento_sitios`
--

CREATE TABLE `magento_sitios` (
  `year` int NOT NULL,
  `semana` int NOT NULL,
  `sitio` varchar(12) NOT NULL,
  `cuentas_nuevas` int DEFAULT NULL,
  PRIMARY KEY (`sitio`,`semana`,`year`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `magento_sitios_mes`
--

CREATE TABLE `magento_sitios_mes` (
  `year` int DEFAULT NULL,
  `mes` int DEFAULT NULL,
  `sitio` varchar(12) DEFAULT NULL,
  `cuentas_nuevas` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `notas_credito_sap`
--

CREATE TABLE `notas_credito_sap` (
  `fecha_nc` date DEFAULT NULL,
  `folio_nc` varchar(8) COLLATE utf8mb3_spanish_ci NOT NULL,
  `borrador_nc` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sku` varchar(20) COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades_nc` tinyint DEFAULT NULL,
  `pedido_magento` varchar(19) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `almacen` varchar(8) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `norma_reparto` varchar(8) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`folio_nc`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `oms_cancelados`
--

CREATE TABLE `oms_cancelados` (
  `id_pedido` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_estado` datetime NOT NULL,
  `estado_oms` varchar(17) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` smallint NOT NULL,
  `fulfillment` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id_pedido`,`fecha_estado`,`estado_oms`,`sku`,`unidades`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `oms_entregados`
--

CREATE TABLE `oms_entregados` (
  `id_pedido` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `estado_oms` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_estado` datetime NOT NULL,
  `origen_stock` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fulfillment` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id_pedido`,`fecha_estado`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `oms_forzar_novedades`
--

CREATE TABLE `oms_forzar_novedades` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_registro` datetime NOT NULL,
  PRIMARY KEY (`sku`,`fecha_registro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `oms_incidencias`
--

CREATE TABLE `oms_incidencias` (
  `fecha_incidencia` datetime NOT NULL,
  `id_pedido` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` smallint DEFAULT NULL,
  `id_oms` varchar(24) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comentario` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `tipo_incidencia` varchar(24) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fulfillment` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`fecha_incidencia`,`id_pedido`,`sku`),
  KEY `oms_incidencias_id_pedido_IDX` (`id_pedido`,`sku`,`fecha_incidencia`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `oms_preparados`
--

CREATE TABLE `oms_preparados` (
  `id_pedido` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `estado_oms` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `pin_retiro` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_estado` datetime NOT NULL,
  `sku` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades_solicitadas` smallint DEFAULT NULL,
  `unidades_preparadas` smallint DEFAULT NULL,
  `id_oms` varchar(24) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fulfillment` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id_pedido`,`estado_oms`,`fecha_estado`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `oms_quiebres_a_sap`
--

CREATE TABLE `oms_quiebres_a_sap` (
  `tipo_notificacion` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `cli` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `doc_entry_sap` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_notificacion` datetime NOT NULL,
  `data` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  PRIMARY KEY (`tipo_notificacion`,`cli`,`doc_entry_sap`,`fecha_notificacion`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `ordenes_por_cliente`
--

CREATE TABLE `ordenes_por_cliente` (
  `orden_id` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `rut` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tienda_id` smallint DEFAULT NULL,
  `fecha_orden` date DEFAULT NULL,
  `sku` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `precio_producto` int DEFAULT NULL,
  `cantidad_producto` smallint DEFAULT NULL,
  PRIMARY KEY (`orden_id`,`sku`),
  KEY `idx_rut` (`rut`),
  KEY `idx_fecha_orden` (`fecha_orden`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `otd`
--

CREATE TABLE `otd` (
  `ano` int NOT NULL,
  `semana` int NOT NULL,
  `fecha` date NOT NULL,
  `metodo_envio` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `operador` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `metodo_envio_magento` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `a_tiempo` int DEFAULT NULL,
  `pendiente` int DEFAULT NULL,
  `atrasado` int DEFAULT NULL,
  `no_entregado_atrasado` int DEFAULT NULL,
  PRIMARY KEY (`fecha`,`metodo_envio`,`operador`,`metodo_envio_magento`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `otp_tiendas`
--

CREATE TABLE `otp_tiendas` (
  `ano` int DEFAULT NULL,
  `semana` int DEFAULT NULL,
  `fecha` date DEFAULT NULL,
  `metodo_envio` varchar(30) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `lugar_retiro` varchar(10) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre` varchar(100) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tipo_producto` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `a_tiempo` int DEFAULT NULL,
  `pendiente` int DEFAULT NULL,
  `atrasado` int DEFAULT NULL,
  `no_pickeado_atrasado` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `parametros_conexiones`
--

CREATE TABLE `parametros_conexiones` (
  `parametro` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `valor` varchar(2000) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`parametro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `parametros_envio`
--

CREATE TABLE `parametros_envio` (
  `codigo_de_operador` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `dias_de_carga` varchar(20) DEFAULT NULL,
  `dias_demora_envio` int DEFAULT NULL,
  `codigo_de_comuna` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`codigo_de_operador`,`codigo_de_comuna`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `parametros_envio_oms`
--

CREATE TABLE `parametros_envio_oms` (
  `operador` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo_servicio` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `leadtime` int DEFAULT NULL,
  `codigo_comuna` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `codigo_region` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`operador`,`tipo_servicio`,`codigo_comuna`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `parametros_fechas`
--

CREATE TABLE `parametros_fechas` (
  `parametro` varchar(20) COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha` datetime DEFAULT NULL,
  PRIMARY KEY (`parametro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_cli`
--

CREATE TABLE `pedidos_cli` (
  `cli` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `pedido` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`cli`,`pedido`),
  KEY `idx_pedido` (`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_cli_mkp`
--

CREATE TABLE `pedidos_cli_mkp` (
  `cli` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `pedido_mkp` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`cli`,`pedido_mkp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_magento`
--

CREATE TABLE `pedidos_magento` (
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_compra` date NOT NULL,
  `compromiso_picking` date DEFAULT NULL,
  `compromiso_carga` date DEFAULT NULL,
  `compromiso_entrega` date NOT NULL,
  `picking` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_picking` date DEFAULT NULL,
  `estado` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_estado` date DEFAULT NULL,
  `entrega` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `metodo_envio` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `zona` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `status_orden` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `id_pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_disp_retiro` date DEFAULT NULL,
  `punto_retiro` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `origen_stock` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fulfillment` varchar(15) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`),
  KEY `idx_pedido` (`pedido`),
  KEY `idx_comuna` (`zona`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_magento_bultos`
--

CREATE TABLE `pedidos_magento_bultos` (
  `id_bulto` int NOT NULL AUTO_INCREMENT,
  `cli` varchar(32) NOT NULL,
  `bulto` varchar(50) NOT NULL,
  `qty` int NOT NULL,
  `codigo_barra` varchar(50) NOT NULL,
  `sku` varchar(50) NOT NULL,
  `num_magento` varchar(30) NOT NULL,
  PRIMARY KEY (`id_bulto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Table structure for table `pedidos_marketplace`
--

CREATE TABLE `pedidos_marketplace` (
  `pedido_mkp` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo_doc` varchar(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cli_cancelado` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cli` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_cli` datetime DEFAULT NULL,
  `estado_linea` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades_cli` int DEFAULT NULL,
  `unidades_cli_pendientes` int DEFAULT NULL,
  `fecha_doc_entrega` datetime DEFAULT NULL,
  `unidades_doc_entrega` int DEFAULT NULL,
  `tipo_doc_boleta` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `folio_boleta` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_boleta` datetime DEFAULT NULL,
  `unidades_boleta` int DEFAULT NULL,
  `prioridad` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_venc_entrega` date DEFAULT NULL,
  `nombre_cliente` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `rut_cliente` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `email_cliente` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comuna` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `leadtime_mercadolibre` int DEFAULT NULL,
  `direccion` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `telefono` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_cartaporte` datetime DEFAULT NULL,
  `estado_cartaporte` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido_mkp`,`cli`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_multivende`
--

CREATE TABLE `pedidos_multivende` (
  `_id` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
  `numero_venta` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `identificador_orden` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `code` bigint NOT NULL,
  `origin` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
  `total_payment` bigint NOT NULL,
  `discount` bigint NOT NULL,
  `coupon_code` varchar(200) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `discount_description` varchar(1000) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `tipo_pago` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
  `sold_at` datetime NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `numero_tarjeta` varchar(24) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `codigo_autorizador` bigint DEFAULT NULL,
  `auth_resp_cd` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `medio_pago_id` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `delivery_code` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `warehouse` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `nombre_cliente` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `email_cliente` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `cliente` char(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `rut_cliente` char(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `ciudad` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `estado` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `calle` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `numero` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `complemento_direccion` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `comuna` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `fono` char(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `nombre_cliente_despacho` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_out`
--

CREATE TABLE `pedidos_out` (
  `FECHA_ORDEN` date DEFAULT NULL,
  `FECHA_WMS` date DEFAULT NULL,
  `SEM_ENVIO_WMS` int DEFAULT NULL,
  `PRIORITY` int DEFAULT NULL,
  `CLIENTE` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ORDERKEY` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `TIE_CLIE` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `TIENDA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `CAT_ANTIGUA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `GRUPO` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `SUBCATEGORIA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `DEPORTE` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `SKU` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `COD_BARRA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `DESCR` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `CANT_ORIG` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `CANT_PEND` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `CANT_DESP` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `STATUS_ORDEN` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `STATUS_LINEA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `STATUS_DESC` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ESTADO_ORDEN` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ESTADO_LINEA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ATRIBUTO` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `OC_XDOCK` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `PRIORIDAD` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `RUTA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `FECHA_DESPACHO` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `SEM_DESPACHO` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `FECHA_EXPEDICION_PROGRAMADA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `FECHA_ENTREGA_SOLICITADA` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `FECHA_CARTAPORTE` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `FECHA_LANZADO` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ORDEN_ORIGINAL` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ORDEN_PARCIAL` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_retiro_tienda`
--

CREATE TABLE `pedidos_retiro_tienda` (
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `telefono` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `punto_retiro` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `origen_stock` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_sap`
--

CREATE TABLE `pedidos_sap` (
  `MagentoPedido` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `TipoDocto` varchar(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `CLICanceled` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `CLIDocNum` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `CLIDocDateTime` datetime DEFAULT NULL,
  `LineStatus` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ItemCode` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `CLIQuantity` int DEFAULT NULL,
  `QtyPending` int DEFAULT NULL,
  `ENTDocDateTime` datetime DEFAULT NULL,
  `ENTQuantity` int DEFAULT NULL,
  `BOLTipoDocto` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `BOLDocNum` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `BOLDocDateTime` datetime DEFAULT NULL,
  `BOLQuantity` int DEFAULT NULL,
  `Prioridad` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `TipoPago` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  KEY `pedidos_sap_CLIDocNum_IDX` (`CLIDocNum`) USING BTREE,
  KEY `pedidos_sap_MagentoPedido_IDX` (`MagentoPedido`) USING BTREE,
  KEY `pedidos_sap_ItemCode_IDX` (`ItemCode`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pedidos_sap_rp`
--

CREATE TABLE `pedidos_sap_rp` (
  `pedido_tie_nc` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `pedido` varchar(13) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo_dcto` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `boleta` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_boleta` datetime DEFAULT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `estado_linea` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `udds_boleta` int DEFAULT NULL,
  `udds_pendientes` int DEFAULT NULL,
  `NC` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tie` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_tie` datetime DEFAULT NULL,
  `udds_tie` int DEFAULT NULL,
  `estado_tie` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tr` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_tr` datetime DEFAULT NULL,
  `udds_tr` int DEFAULT NULL,
  `tr_cancelado` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido_tie_nc`,`sku`),
  KEY `pedidos_sap_rp_pedido_IDX` (`pedido`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci COMMENT='Pedidos SAP nuevo, tras integración de Magento y Retail Pro';

--
-- Table structure for table `pg_orden`
--

CREATE TABLE `pg_orden` (
  `ID` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
  `Clicks` decimal(8,3) DEFAULT NULL,
  `CTR` decimal(8,3) DEFAULT NULL,
  `Venta_L3M` decimal(8,3) DEFAULT NULL,
  `Antiguedad_SAP` decimal(8,3) DEFAULT NULL,
  `Contribución` decimal(8,3) DEFAULT NULL,
  `Stock` decimal(8,3) DEFAULT NULL,
  `Unidades` decimal(8,3) DEFAULT NULL,
  `Stock a costo` decimal(8,3) DEFAULT NULL,
  `Cobertura` decimal(8,3) DEFAULT NULL,
  `Conversion` decimal(8,3) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `pg_rotacion`
--

CREATE TABLE `pg_rotacion` (
  `id` varchar(100) DEFAULT NULL,
  `antiguedad sap` decimal(8,3) DEFAULT NULL,
  `stock` decimal(8,3) DEFAULT NULL,
  `stock a costo` decimal(8,3) DEFAULT NULL,
  `cobertura` decimal(8,3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `prod_desh_cat`
--

CREATE TABLE `prod_desh_cat` (
  `sku` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `razon` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `product_size`
--

CREATE TABLE `product_size` (
  `subcategoria` varchar(35) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo_producto` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`subcategoria`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `proyeccion_venta`
--

CREATE TABLE `proyeccion_venta` (
  `fecha` date NOT NULL,
  `tienda` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` decimal(6,2) DEFAULT NULL,
  `contribucion` decimal(11,2) DEFAULT NULL,
  `venta_neta` decimal(11,2) DEFAULT NULL,
  `new_categoria_antigua` varchar(19) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `categoria_antigua` varchar(19) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `categoria` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `subcategoria` varchar(31) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo` varchar(14) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `marca` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`fecha`,`tienda`,`new_categoria_antigua`,`categoria_antigua`,`categoria`,`subcategoria`,`tipo`,`marca`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `quiebres_eds`
--

CREATE TABLE `quiebres_eds` (
  `fecha_quiebre` datetime NOT NULL,
  `pedido` varchar(10) NOT NULL,
  `sku` varchar(20) NOT NULL,
  `udds_quiebre` int DEFAULT NULL,
  `tipo` varchar(10) DEFAULT NULL,
  `comentario` varchar(60) DEFAULT NULL,
  PRIMARY KEY (`pedido`,`sku`,`fecha_quiebre`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Table structure for table `quiebres_tiendas`
--

CREATE TABLE `quiebres_tiendas` (
  `fecha_quiebre` datetime DEFAULT NULL,
  `pedido` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo` varchar(7) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `udds_quiebre` smallint NOT NULL,
  `origen_stock` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `id_oms` varchar(24) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tipo_incidencia` varchar(24) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comentario` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  PRIMARY KEY (`pedido`,`sku`,`udds_quiebre`,`origen_stock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `reporte_metodos_envio`
--

CREATE TABLE `reporte_metodos_envio` (
  `fecha_compra` date NOT NULL,
  `metodo_envio` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `vta_neta` decimal(11,2) DEFAULT NULL,
  `cto_envio` int DEFAULT NULL,
  `unidades` smallint DEFAULT NULL,
  `pedidos` smallint DEFAULT NULL,
  `region` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `comuna` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`fecha_compra`,`metodo_envio`,`region`,`comuna`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `rutas`
--

CREATE TABLE `rutas` (
  `cod_comuna` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `cod_ruta` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `frecuencia` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`cod_comuna`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_fd`
--

CREATE TABLE `sac_fd` (
  `ticket` int NOT NULL,
  `pedido` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_solicitud` timestamp NULL DEFAULT NULL,
  `fecha_modificacion` timestamp NULL DEFAULT NULL,
  `fecha_primera_resp` timestamp NULL DEFAULT NULL,
  `fecha_cambio_estado` timestamp NULL DEFAULT NULL,
  `fecha_resolucion` timestamp NULL DEFAULT NULL,
  `fecha_cierre` timestamp NULL DEFAULT NULL,
  `responsable` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `id_responsable` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `grupo_responsable` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `id_cliente` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `rut_cliente` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estado` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `titulo` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `descripcion` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `notas` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `prioridad` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tipo_cuenta_devolucion` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `motivo_devolucion` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `marca` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `origen` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cat_wm` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`ticket`),
  KEY `idx_pedido` (`pedido`) USING BTREE,
  KEY `sac_fd_id_responsable_IDX` (`id_responsable`) USING BTREE,
  KEY `sac_fd_id_cliente_IDX` (`id_cliente`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_fd_agentes`
--

CREATE TABLE `sac_fd_agentes` (
  `id_agente` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `nombre` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `email` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `grupo` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id_agente`),
  KEY `sac_fd_agentes_grupo_IDX` (`grupo`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_fd_clientes`
--

CREATE TABLE `sac_fd_clientes` (
  `id_cliente` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `nombre` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `email` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id_cliente`),
  KEY `sac_fd_clientes_email_IDX` (`email`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_fd_diario`
--

CREATE TABLE `sac_fd_diario` (
  `fecha` date NOT NULL,
  `ticket` int NOT NULL,
  `pedido` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_solicitud` datetime DEFAULT NULL,
  `fecha_modificacion` datetime DEFAULT NULL,
  `fecha_cierre` datetime DEFAULT NULL,
  `responsable` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `grupo_responsable` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cliente` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `email_cliente` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estado` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `titulo` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `descripcion` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `notas` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `prioridad` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`fecha`,`ticket`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_mda`
--

CREATE TABLE `sac_mda` (
  `ticket` int NOT NULL,
  `pedido` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_solicitud` timestamp NULL DEFAULT NULL,
  `fecha_modificacion` timestamp NULL DEFAULT NULL,
  `fecha_cierre` timestamp NULL DEFAULT NULL,
  `responsable` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `solicitante` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tercer_nivel` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estado` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `titulo` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `descripcion` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `notas` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `urgencia` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `prioridad` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`ticket`),
  KEY `idx_pedido` (`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_mda_diario`
--

CREATE TABLE `sac_mda_diario` (
  `fecha` date NOT NULL,
  `ticket` varchar(6) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `pedido` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_solicitud` timestamp NULL DEFAULT NULL,
  `fecha_modificacion` timestamp NULL DEFAULT NULL,
  `fecha_cierre` timestamp NULL DEFAULT NULL,
  `responsable` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `solicitante` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tercer_nivel` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `estado` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `titulo` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `descripcion` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `notas` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `urgencia` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `prioridad` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  KEY `idx_fecha` (`fecha`),
  KEY `idx_ticket` (`ticket`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_mda_history`
--

CREATE TABLE `sac_mda_history` (
  `ticket` int NOT NULL,
  `estado` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tercer_nivel` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `actualizado_por` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `responsable` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `hora_actualizacion` timestamp NULL DEFAULT NULL,
  `urgencia` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `notas` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `version` int DEFAULT NULL,
  KEY `idx_ticket` (`ticket`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sac_stock_tiendas`
--

CREATE TABLE `sac_stock_tiendas` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tienda` varchar(35) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `cod_tienda` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `stock_disponible` smallint DEFAULT NULL,
  PRIMARY KEY (`sku`,`tienda`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sap_boletas`
--

CREATE TABLE `sap_boletas` (
  `pedido` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `boleta` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_boleta` datetime DEFAULT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` int DEFAULT NULL,
  `folio_boleta` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `id_url_boleta` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`,`boleta`,`folio_boleta`,`sku`),
  KEY `sap_boletas_pedido_IDX` (`pedido`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sap_ties`
--

CREATE TABLE `sap_ties` (
  `pedido` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tie` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_tie` datetime DEFAULT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` int DEFAULT NULL,
  PRIMARY KEY (`pedido`,`tie`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `scraping`
--

CREATE TABLE `scraping` (
  `fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `marca` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `precio` int DEFAULT NULL,
  `url` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tienda` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`fecha`,`sku`),
  KEY `idx_sku` (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `scraping_calzado_nb`
--

CREATE TABLE `scraping_calzado_nb` (
  `fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `modelo` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `precio` int DEFAULT NULL,
  `url` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tienda` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`fecha`,`sku`),
  KEY `idx_sku` (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `scraping_sku`
--

CREATE TABLE `scraping_sku` (
  `sku_tienda` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tienda` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku_sparta` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  PRIMARY KEY (`sku_tienda`,`tienda`),
  KEY `idx_sku` (`sku_sparta`),
  KEY `idx_sku_tienda` (`sku_tienda`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `sku_por_catalogar`
--

CREATE TABLE `sku_por_catalogar` (
  `sku` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `antiguedad` int DEFAULT NULL,
  `catalogador` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `prioridad` int DEFAULT NULL,
  `stock_inicial` int DEFAULT '0',
  PRIMARY KEY (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `skus_excluir`
--

CREATE TABLE `skus_excluir` (
  `sku` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `stock_bodegas_2000`
--

CREATE TABLE `stock_bodegas_2000` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `bodega` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock_disponible` mediumint DEFAULT NULL,
  PRIMARY KEY (`sku`,`bodega`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `stock_retail_pro`
--

CREATE TABLE `stock_retail_pro` (
  `cod_tienda` varchar(8) COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock` int DEFAULT NULL,
  `stock_transfer_order` int DEFAULT NULL,
  `stock_disponible` int DEFAULT NULL,
  PRIMARY KEY (`cod_tienda`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `stock_seguridad`
--

CREATE TABLE `stock_seguridad` (
  `categoria_antigua` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `categoria` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `subcategoria` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock_seguridad` int DEFAULT NULL,
  UNIQUE KEY `catold_cat_subcat` (`categoria_antigua`,`categoria`,`subcategoria`),
  KEY `idx_catold` (`categoria_antigua`),
  KEY `idx_cat` (`categoria`),
  KEY `idx_subcat` (`subcategoria`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `stock_seguridad_CD_sku`
--

CREATE TABLE `stock_seguridad_CD_sku` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock_seguridad` int DEFAULT NULL,
  PRIMARY KEY (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `stock_seguridad_oms_excepciones`
--

CREATE TABLE `stock_seguridad_oms_excepciones` (
  `SKU` varchar(20) COLLATE utf8mb3_spanish_ci NOT NULL,
  `SECURITY_STOCK` tinyint DEFAULT NULL,
  PRIMARY KEY (`SKU`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `stock_sources_magento`
--

CREATE TABLE `stock_sources_magento` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `source_code` varchar(22) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `quantity` int DEFAULT NULL,
  `status` smallint DEFAULT NULL,
  `cod_tienda` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `in_stock_general` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`sku`,`source_code`),
  KEY `stock_sources_magento_cod_tienda_IDX` (`cod_tienda`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `stock_wms`
--

CREATE TABLE `stock_wms` (
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock_wms` int DEFAULT NULL,
  `stock_wms_internet` int DEFAULT NULL,
  PRIMARY KEY (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `tiendas`
--

CREATE TABLE `tiendas` (
  `id` smallint NOT NULL,
  `nombre` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tipo` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `zona` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `lugar` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `direccion` varchar(55) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comuna` varchar(16) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `region` varchar(37) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `local` varchar(60) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `mapa` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `telefono` bigint DEFAULT NULL,
  `correo` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `horario` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `lat` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `long` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ruta` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `parada` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `codigo_tienda` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `habilitado_rt` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `ct_destino_beetrack` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `tienda_collect_beetrack` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `habilitado_bopis` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `nombre_bonito` varchar(40) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id`,`nombre`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `tmgm_digital`
--

CREATE TABLE `tmgm_digital` (
  `Fecha` date DEFAULT NULL,
  `Sitio` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `VB_TM` decimal(11,2) DEFAULT NULL,
  `VB_LM` decimal(11,2) DEFAULT NULL,
  `VB_LY` decimal(11,2) DEFAULT NULL,
  `P_TM` int DEFAULT NULL,
  `P_LM` int DEFAULT NULL,
  `P_LY` int DEFAULT NULL,
  `VB_PLAN` decimal(11,2) DEFAULT NULL,
  `P_PLAN` int DEFAULT NULL,
  `TP_TM` decimal(11,2) DEFAULT NULL,
  `TP_LM` decimal(11,2) DEFAULT NULL,
  `TP_LY` decimal(11,2) DEFAULT NULL,
  `TP_PLAN` decimal(11,2) DEFAULT NULL,
  `UB_TM` int DEFAULT NULL,
  `UB_LM` int DEFAULT NULL,
  `UB_LY` int DEFAULT NULL,
  `UB_PLAN` int DEFAULT NULL,
  `SE_TM` int DEFAULT NULL,
  `SE_LM` int DEFAULT NULL,
  `SE_LY` int DEFAULT NULL,
  `SE_PLAN` int DEFAULT NULL,
  `TC_TM` decimal(11,4) DEFAULT NULL,
  `TC_LM` decimal(11,4) DEFAULT NULL,
  `TC_LY` decimal(11,4) DEFAULT NULL,
  `TC_PLAN` decimal(11,4) DEFAULT NULL,
  `PSU_TM` decimal(11,4) DEFAULT NULL,
  `PSU_LM` decimal(11,4) DEFAULT NULL,
  `PSU_LY` decimal(11,4) DEFAULT NULL,
  `PSU_PLAN` decimal(11,4) DEFAULT NULL,
  `CR_TM` decimal(11,4) DEFAULT NULL,
  `CR_LM` decimal(11,4) DEFAULT NULL,
  `CR_LY` decimal(11,4) DEFAULT NULL,
  `CLINU_TM` int DEFAULT NULL,
  `CLINU_LM` int DEFAULT NULL,
  `CLINU_LY` int DEFAULT NULL,
  `RECU_TM` int DEFAULT NULL,
  `RECU_LM` int DEFAULT NULL,
  `RECU_LY` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `tr_reposicion_sap`
--

CREATE TABLE `tr_reposicion_sap` (
  `fecha_tr` datetime NOT NULL,
  `doc_entry` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `doc_num` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `folio_num` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `items` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `card_code` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `address` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `filler` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `to_whs_code` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`doc_entry`,`doc_num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci COMMENT='TRs de reposición hacia EDS creadas por SAP y notificadas a Digital';

--
-- Table structure for table `trazabilidad_4000`
--

CREATE TABLE `trazabilidad_4000` (
  `fecha` date NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock` smallint NOT NULL,
  PRIMARY KEY (`fecha`,`sku`),
  KEY `idx_sku` (`sku`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `trazabilidad_eds`
--

CREATE TABLE `trazabilidad_eds` (
  `fecha` date NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock_eds` int DEFAULT NULL,
  `qty_mg_eds` int DEFAULT NULL,
  `stock_mg_eds` int DEFAULT NULL,
  `stock_sap_eds` int DEFAULT NULL,
  PRIMARY KEY (`fecha`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `trazabilidad_precios_magento`
--

CREATE TABLE `trazabilidad_precios_magento` (
  `fecha` date NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `precio_base_sparta` int DEFAULT NULL,
  `precio_base_nb` int DEFAULT NULL,
  `oferta_sparta` int DEFAULT NULL,
  `oferta_nb` int DEFAULT NULL,
  `precio_base_spyder` int DEFAULT NULL,
  `oferta_spyder` int DEFAULT NULL,
  `precio_base_head` int DEFAULT NULL,
  `oferta_head` int DEFAULT NULL,
  `precio_base_speedo` int DEFAULT NULL,
  `oferta_speedo` int DEFAULT NULL,
  `precio_base_trek` int DEFAULT NULL,
  `oferta_trek` int DEFAULT NULL,
  PRIMARY KEY (`fecha`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `trazabilidad_producto`
--

CREATE TABLE `trazabilidad_producto` (
  `fecha` date NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock` smallint NOT NULL,
  `precio_base` int DEFAULT NULL,
  `oferta_sparta` int DEFAULT NULL,
  `oferta_nb` int DEFAULT NULL,
  `costo_unitario` decimal(9,2) DEFAULT NULL,
  PRIMARY KEY (`fecha`,`sku`),
  KEY `idx_sku` (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `trazabilidad_sap`
--

CREATE TABLE `trazabilidad_sap` (
  `fecha` date NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock` int NOT NULL,
  `precio_base` int DEFAULT NULL,
  `oferta_sparta` int DEFAULT NULL,
  `oferta_nb` int DEFAULT NULL,
  `costo_unitario` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`fecha`,`sku`),
  KEY `SKU_PRECIO_SPARTA` (`sku`,`oferta_sparta`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `trazabilidad_tiendas`
--

CREATE TABLE `trazabilidad_tiendas` (
  `fecha` date NOT NULL,
  `id_tienda` smallint NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `stock` smallint NOT NULL,
  PRIMARY KEY (`fecha`,`id_tienda`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `unidades_expedidas`
--

CREATE TABLE `unidades_expedidas` (
  `fecha` date NOT NULL,
  `año` int DEFAULT NULL,
  `semana` int DEFAULT NULL,
  `tipo_producto` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `canal` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `udds_expedidas` int DEFAULT NULL,
  `udds_solicitadas` int DEFAULT NULL,
  PRIMARY KEY (`fecha`,`canal`,`tipo_producto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `venta_magento`
--

CREATE TABLE `venta_magento` (
  `fecha` datetime NOT NULL,
  `tienda` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` smallint DEFAULT NULL,
  `precio_unitario` int DEFAULT NULL,
  `costo_unitario` decimal(9,2) DEFAULT NULL,
  `descuento` decimal(9,2) DEFAULT NULL,
  `contribucion` decimal(11,2) DEFAULT NULL,
  `venta_neta` decimal(11,2) DEFAULT NULL,
  `pedido` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `state` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `status` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `metodo_pago` varchar(39) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `metodo_pago_info` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `metodo_pago_detalle` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci,
  `cupon` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`pedido`,`sku`),
  KEY `idx_sku` (`sku`) USING BTREE,
  KEY `idx_pedido` (`pedido`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `venta_marketplace`
--

CREATE TABLE `venta_marketplace` (
  `_ID` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci NOT NULL,
  `CODE` varchar(30) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `IDENTIFICADOR_ORDEN` varchar(30) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `ORIGEN` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci NOT NULL,
  `TOTAL_PAYMENT` bigint NOT NULL,
  `ESTADO` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci NOT NULL,
  `FECHA_CREACION` datetime NOT NULL,
  `FECHA_VENTA` datetime NOT NULL,
  `TIPO_DELIVERY` varchar(50) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `NOMBRE_COURIER` varchar(50) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `NOMBRE_CLIENTE` varchar(200) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `APELLIDO_CLIENTE` varchar(200) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `COSTO_DESPACHO` bigint DEFAULT NULL,
  `PRECIO_CON_DESCUENTO` bigint DEFAULT NULL,
  `sNETO` decimal(27,6) DEFAULT NULL,
  `CONTRIBUCION` decimal(28,6) DEFAULT NULL,
  `ID_PAGO` varchar(50) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `CODIGO_BARRA` varchar(50) COLLATE utf8mb4_spanish_ci NOT NULL,
  `PRECIO` int NOT NULL,
  `CANTIDAD` smallint NOT NULL,
  `PRODUCTO` varchar(250) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `CatAntigua` varchar(30) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `Marca` varchar(30) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `Categoria` varchar(40) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `SubCategoria` varchar(40) COLLATE utf8mb4_spanish_ci DEFAULT NULL,
  `PCosto` decimal(19,6) DEFAULT NULL,
  `DIA` int DEFAULT NULL,
  `MES` int DEFAULT NULL,
  `ANIO` int DEFAULT NULL,
  PRIMARY KEY (`_ID`,`CODIGO_BARRA`),
  KEY `idx_codebar` (`CODIGO_BARRA`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_spanish_ci;

--
-- Table structure for table `venta_multivende`
--

CREATE TABLE `venta_multivende` (
  `_id` varchar(40) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(160) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `precio` int NOT NULL,
  `descuento` int NOT NULL,
  `cantidad` smallint NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `venta_retail`
--

CREATE TABLE `venta_retail` (
  `fecha` date NOT NULL,
  `id_tienda` smallint NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` smallint DEFAULT NULL,
  `venta_neta` decimal(11,2) DEFAULT NULL,
  `contribucion` decimal(11,2) DEFAULT NULL,
  PRIMARY KEY (`fecha`,`id_tienda`,`sku`),
  KEY `idx_sku` (`sku`),
  KEY `idx_tienda` (`id_tienda`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `venta_tienda`
--

CREATE TABLE `venta_tienda` (
  `ano` int DEFAULT NULL,
  `mes` int DEFAULT NULL,
  `fecha_compra` date DEFAULT NULL,
  `cupon` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `numero_de_pedido` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sitio` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `producto` varchar(150) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades` int DEFAULT NULL,
  `precio_unitario` int DEFAULT NULL,
  `descuento` int DEFAULT NULL,
  `venta_neta` int DEFAULT NULL,
  `cat_antigua` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `categoria` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `subcategoria` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `Marca` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cli` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `cod_tienda` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`numero_de_pedido`,`cli`,`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `venta_tienda_vendedores`
--

CREATE TABLE `venta_tienda_vendedores` (
  `cupon` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tienda` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `vendedor` varchar(125) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `codigo_tienda` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`cupon`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wishlist`
--

CREATE TABLE `wishlist` (
  `rut` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `tienda_id` smallint NOT NULL,
  `cod18` varchar(18) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_marcado` date NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wms_kp_orders`
--

CREATE TABLE `wms_kp_orders` (
  `fecha_creacion` datetime DEFAULT NULL,
  `fecha_edicion` datetime DEFAULT NULL,
  `fecha_preparacion` datetime DEFAULT NULL,
  `orden_sap` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `orden_wms` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `status` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `canal` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cancela_tipo` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cancela_subtipo` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `cancela_estado` varchar(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `pedido_full` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `metodo_envio_magento` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`orden_wms`),
  KEY `wms_kp_orders_orden_sap_IDX` (`orden_sap`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wms_kp_orders_details`
--

CREATE TABLE `wms_kp_orders_details` (
  `orden_wms` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades_solicitadas` int DEFAULT NULL,
  `unidades_despachadas` int DEFAULT NULL,
  `status_linea` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_edicion` datetime DEFAULT NULL,
  `fecha_preparacion` datetime DEFAULT NULL,
  `unidades_preparadas` int DEFAULT NULL,
  PRIMARY KEY (`orden_wms`,`sku`),
  KEY `wms_kp_orders_details_sku_IDX` (`sku`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wms_kp_status_codes`
--

CREATE TABLE `wms_kp_status_codes` (
  `status` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `description` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `description_tek` varchar(11) COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wms_orders`
--

CREATE TABLE `wms_orders` (
  `fecha_creacion` datetime DEFAULT NULL,
  `fecha_edicion` datetime DEFAULT NULL,
  `orden_sap` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `orden_wms` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `status` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `metodo` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `canal` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `comentario` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `compromiso_carga` datetime DEFAULT NULL,
  `fecha_cartaporte` datetime DEFAULT NULL,
  PRIMARY KEY (`orden_wms`),
  KEY `idx_orden_sap` (`orden_sap`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wms_orders_details`
--

CREATE TABLE `wms_orders_details` (
  `orden_wms` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `sku` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `unidades_solicitadas` int DEFAULT NULL,
  `unidades_expedidas` int DEFAULT NULL,
  `status` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `fecha_edicion` datetime DEFAULT NULL,
  `comentario_linea` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `udds_preparadas` int DEFAULT NULL,
  `fecha_preparacion` datetime DEFAULT NULL,
  PRIMARY KEY (`orden_wms`,`sku`),
  KEY `idx_sku` (`sku`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wms_reprogramaciones`
--

CREATE TABLE `wms_reprogramaciones` (
  `orden` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `fecha_reprogramacion` date DEFAULT NULL,
  `comentario_reprogramacion` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`orden`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `wms_status_codes`
--

CREATE TABLE `wms_status_codes` (
  `status` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `code` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `description` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Table structure for table `yotpo`
--

CREATE TABLE `yotpo` (
  `id` int unsigned NOT NULL,
  `tienda` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `titulo` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `estrellas` int unsigned NOT NULL,
  `id_producto` int unsigned DEFAULT NULL,
  `fecha` datetime DEFAULT NULL,
  `comentario` text CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci NOT NULL,
  `etiqueta` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  `etiqueta2` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_spanish_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_spanish_ci;

--
-- Dumping events for database 'grayskull'
--
/*!50106 DROP EVENT IF EXISTS `evento_guardar_estados_brightcell_con_tie_modificado` */;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `evento_guardar_estados_brightcell_con_tie_modificado` ON SCHEDULE EVERY 1 DAY STARTS '2025-08-09 04:33:30' ON COMPLETION PRESERVE ENABLE COMMENT 'Modifica pinchazos Brightcell con N° TIE empezando en 5, para que queden con 2' DO UPDATE despachos d
	JOIN (
	    SELECT 
	        d.cli AS cli_actual,
	        CONCAT('2', RIGHT(d.cli, LENGTH(d.cli) - 1)) AS cli_correcto,
	        d.fecha_estado
	    FROM despachos d
	    JOIN pedidos_cli pc 
	      ON pc.cli = CONCAT('2', RIGHT(d.cli, LENGTH(d.cli) - 1))
	    LEFT JOIN despachos d2 ON d2.cli=pc.cli AND d2.fecha_estado=d.fecha_estado 
	    WHERE d.operador = 'Brightcell'
	      AND d.cli LIKE '5%'
	      AND LENGTH(d.cli) = 8
	      AND d2.cli IS NULL /*no es un estado que ya cargamos*/
	      AND d.fecha_estado >= DATE_ADD(CURDATE(), INTERVAL - 30 DAY)
	--       AND d.cli='50428825'
	) sub 
	ON d.cli = sub.cli_actual AND d.fecha_estado = sub.fecha_estado
	SET d.cli = sub.cli_correcto
	WHERE 1=1
	AND d.cli LIKE '5%'
	AND d.fecha_estado >= DATE_ADD(CURDATE(), INTERVAL - 30 DAY)
	-- AND d.cli = '50428825' */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
/*!50106 DROP EVENT IF EXISTS `evento_llevar_registros_cruzados_a_tabla_asn` */;;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `evento_llevar_registros_cruzados_a_tabla_asn` ON SCHEDULE EVERY 1 DAY STARTS '2026-03-28 04:00:00' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO asn (cli, estado, tipo, fecha, folio_nc)
  SELECT 
    pc.cli, 
    'asn', 
    a.estado, 
    a.fecha_estado, 
    IFNULL(a.folio_nc, 'pendiente')
  FROM anulados_tiendas a
  INNER JOIN pedidos_cli pc ON pc.pedido = a.pedido
  LEFT JOIN asn a2 ON a2.cli = pc.cli
  WHERE a2.cli IS NULL */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
/*!50106 DROP EVENT IF EXISTS `e_actualizar_pedidos_entregados_CD` */;;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `e_actualizar_pedidos_entregados_CD` ON SCHEDULE EVERY 4 HOUR STARTS '2026-04-27 22:16:41' ON COMPLETION NOT PRESERVE ENABLE DO CALL sp_actualizar_pedidos_entregados_CD() */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
/*!50106 DROP EVENT IF EXISTS `e_actualizar_pedidos_entregados_Tiendas` */;;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `e_actualizar_pedidos_entregados_Tiendas` ON SCHEDULE EVERY 4 HOUR STARTS '2026-04-27 22:27:01' ON COMPLETION NOT PRESERVE ENABLE DO CALL sp_actualizar_pedidos_entregados_Tiendas() */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
/*!50106 DROP EVENT IF EXISTS `e_limpiar_pedidos_anulados_CD` */;;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `e_limpiar_pedidos_anulados_CD` ON SCHEDULE EVERY 4 HOUR STARTS '2026-04-27 22:37:56' ON COMPLETION NOT PRESERVE ENABLE DO CALL sp_limpiar_pedidos_anulados_CD() */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
/*!50106 DROP EVENT IF EXISTS `e_limpiar_pedidos_anulados_Tiendas` */;;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `e_limpiar_pedidos_anulados_Tiendas` ON SCHEDULE EVERY 4 HOUR STARTS '2026-04-28 14:35:02' ON COMPLETION NOT PRESERVE ENABLE DO CALL sp_limpiar_pedidos_anulados_Tiendas() */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
/*!50106 DROP EVENT IF EXISTS `limpiar_despachos_tiendas_con_espacio` */;;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `limpiar_despachos_tiendas_con_espacio` ON SCHEDULE EVERY 4 HOUR STARTS '2026-03-23 17:52:50' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'Limpia espacios en blanco en la columna pedido de despachos_tiendas' DO CALL sp_limpiar_despachos_tiendas() */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
/*!50106 DROP EVENT IF EXISTS `limpiar_pedidos_en_anulados_tiendas_con_espacio` */;;
DELIMITER ;;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client  = utf8mb4 */ ;;
/*!50003 SET character_set_results = utf8mb4 */ ;;
/*!50003 SET collation_connection  = utf8mb4_0900_ai_ci */ ;;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;;
/*!50003 SET sql_mode              = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone      = @@time_zone */ ;;
/*!50003 SET time_zone             = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`he-man`@`%`*/ /*!50106 EVENT `limpiar_pedidos_en_anulados_tiendas_con_espacio` ON SCHEDULE EVERY 4 HOUR STARTS '2026-03-13 19:00:47' ON COMPLETION NOT PRESERVE ENABLE DO CALL sp_limpiar_pedidos_anulados() */ ;;
/*!50003 SET time_zone             = @saved_time_zone */ ;;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;;
/*!50003 SET character_set_client  = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection  = @saved_col_connection */ ;;
DELIMITER ;

--
-- Dumping routines for database 'grayskull'
--
/*!50003 DROP FUNCTION IF EXISTS `CAP_FIRST` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` FUNCTION `CAP_FIRST`(input VARCHAR(255)) RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_spanish_ci
    DETERMINISTIC
BEGIN
	DECLARE len INT;
	DECLARE i INT;

	SET len   = CHAR_LENGTH(input);
	SET input = LOWER(input);
	SET i = 0;

	WHILE (i < len) DO
		IF (MID(input,i,1) = ' ' OR i = 0) THEN
			IF (i < len) THEN
				SET input = CONCAT(
					LEFT(input,i),
					UPPER(MID(input,i + 1,1)),
					RIGHT(input,len - i - 1)
				);
			END IF;
		END IF;
		SET i = i + 1;
	END WHILE;

	RETURN input;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `dias_habiles` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` FUNCTION `dias_habiles`(inicio DATE, fin DATE) RETURNS int
    DETERMINISTIC
BEGIN
	DECLARE DIFERENCIA INT DEFAULT 0;
	DECLARE NOHABILES INT DEFAULT 0;
	
  	SET DIFERENCIA = DATEDIFF(fin,inicio);
  	SELECT SUM(feriado) INTO NOHABILES 
	FROM feriados
	WHERE dia >= inicio
	AND dia <= fin;
  	
 	RETURN DIFERENCIA-NOHABILES;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `fecha_habil` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` FUNCTION `fecha_habil`(inicio DATETIME, periodo INT(2)) RETURNS date
    DETERMINISTIC
BEGIN
	DECLARE fin DATE DEFAULT DATE(inicio);
	DECLARE inicio_feriado INT DEFAULT 0;
	DECLARE periodo_buscado INT DEFAULT 0;
	DECLARE habiles_hasta_ahora INT DEFAULT 0;
	DECLARE i INT DEFAULT 0;

	SET inicio = DATE(inicio);
	SET fin = DATE_ADD(inicio, INTERVAL periodo DAY);
	SET i = 0;

	SELECT feriado INTO inicio_feriado
	FROM feriados WHERE dia = inicio;

	IF (inicio_feriado = 1) THEN
		SET periodo_buscado = periodo;
	ELSE
		SET periodo_buscado = periodo + 1;
	END IF;

	SELECT SUM(1-feriado) INTO habiles_hasta_ahora
	FROM feriados
	WHERE dia >= inicio
	AND dia <= fin;

	WHILE (habiles_hasta_ahora < periodo_buscado) AND (i<50) DO
		SET fin = DATE_ADD(fin, INTERVAL 1 DAY);

		SELECT SUM(1-feriado) INTO habiles_hasta_ahora
		FROM feriados
		WHERE dia >= inicio
		AND dia <= fin;

		SET i = i + 1;

	END WHILE;

	RETURN fin;
	
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `fecha_habil_previa` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` FUNCTION `fecha_habil_previa`(fin DATETIME, periodo INT(2)) RETURNS date
    DETERMINISTIC
BEGIN
	DECLARE inicio DATE DEFAULT DATE(fin);
	DECLARE fin_feriado INT DEFAULT 0;
	DECLARE periodo_buscado INT DEFAULT 0;
	DECLARE habiles_hasta_ahora INT DEFAULT 0;
	DECLARE i INT DEFAULT 0;

	SET fin = DATE(fin);
	SET inicio = DATE_ADD(fin, INTERVAL -periodo DAY);
	SET i = 0;

	SELECT feriado INTO fin_feriado
	FROM feriados WHERE dia = fin;

	IF (fin_feriado = 1) THEN
		SET periodo_buscado = periodo;
	ELSE
		SET periodo_buscado = periodo + 1;
	END IF;

	SELECT SUM(1-feriado) INTO habiles_hasta_ahora
	FROM feriados
	WHERE dia >= inicio
	AND dia <= fin;

	WHILE (habiles_hasta_ahora < periodo_buscado) AND (i<50) DO
		SET inicio = DATE_ADD(inicio, INTERVAL -1 DAY);

		SELECT SUM(1-feriado) INTO habiles_hasta_ahora
		FROM feriados
		WHERE dia >= inicio
		AND dia <= fin;

		SET i = i + 1;

	END WHILE;

	RETURN inicio;
	
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `validar_rut` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` FUNCTION `validar_rut`(RUT VARCHAR(12)) RETURNS int
BEGIN
	DECLARE strlen INT;
	DECLARE i INT;
	DECLARE j INT;
	DECLARE suma NUMERIC;
	DECLARE temprut VARCHAR(12);
	DECLARE verify_dv CHAR(2);
	DECLARE DV CHAR(1);
	SET RUT = REPLACE(REPLACE(RUT, '.', ''),'-','');
	SET DV = SUBSTR(RUT,-1,1);
	SET RUT = SUBSTR(RUT,1,LENGTH(RUT)-1);
	SET i = 1;
  	SET strlen = LENGTH(RUT);
  	SET j = 2;
  	SET suma = 0;
	IF strlen = 8 OR strlen = 7 THEN
		SET temprut = REVERSE(RUT);
		moduloonce: LOOP
		    IF i <= LENGTH(temprut) THEN
    			SET suma = suma + (CONVERT(SUBSTRING(temprut, i, 1),UNSIGNED INTEGER) * j); 
	      		SET i = i + 1;
	      		IF j = 7 THEN
		    		SET j = 2;
	    		ELSE
	    			SET j = j + 1;
    			END IF;
	      		ITERATE moduloonce;
		    END IF;
		    LEAVE moduloonce;
	  	END LOOP moduloonce;
	  	SET verify_dv = 11 - (suma % 11);
	  	IF verify_dv = 11 THEN
	  		SET verify_dv = 0;
	  	ELSEIF verify_dv = 10 THEN 
	  		SET verify_dv = 'K';
	  	END IF;
	  	IF DV = verify_dv THEN
	  		RETURN 1;
	  	ELSE 
	  		RETURN 0;
	  	END IF;
	END IF;
	RETURN 0;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_actualizar_pedidos_entregados_CD` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` PROCEDURE `sp_actualizar_pedidos_entregados_CD`()
BEGIN
    UPDATE pedidos_magento p
    INNER JOIN pedidos_cli pc ON pc.pedido = p.pedido
    INNER JOIN despachos d ON d.cli = pc.cli
    SET 
        p.estado = d.estado,
        p.fecha_estado = DATE(d.fecha_estado),
        p.fecha_disp_retiro = IF(
            p.metodo_envio = 'Retiro en tienda' AND p.fecha_disp_retiro IS NULL,
            DATE(d.fecha_estado),
            p.fecha_disp_retiro
        )
    WHERE p.origen_stock = 'CD'
      AND p.fecha_compra >= DATE_ADD(CURDATE(), INTERVAL -365 DAY)
      AND p.estado <> 'Entregado'
      AND d.estado = 'Entregado';
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_actualizar_pedidos_entregados_Tiendas` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` PROCEDURE `sp_actualizar_pedidos_entregados_Tiendas`()
BEGIN
    UPDATE pedidos_magento p
    INNER JOIN despachos_tiendas dt ON dt.pedido = p.pedido
    SET 
        p.estado = dt.estado,
        p.fecha_estado = DATE(dt.fecha_estado),
        p.fecha_disp_retiro = IF(
            p.metodo_envio = 'Retiro en tienda BOPIS' AND p.fecha_disp_retiro IS NULL,
            DATE(dt.fecha_estado),
            p.fecha_disp_retiro
        )
    WHERE p.origen_stock <> 'CD'
      AND p.fecha_compra >= DATE_ADD(CURDATE(), INTERVAL -365 DAY)
      AND p.estado <> 'Entregado'
      AND dt.estado = 'Entregado';
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_limpiar_despachos_tiendas` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` PROCEDURE `sp_limpiar_despachos_tiendas`()
BEGIN
    UPDATE despachos_tiendas
    SET pedido = TRIM(pedido)
    WHERE (pedido LIKE ' %' OR pedido LIKE '% ')
      -- Filtramos solo registros del último mes
      AND fecha_estado >= DATE_SUB(NOW(), INTERVAL 30 DAY);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_limpiar_pedidos_anulados` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` PROCEDURE `sp_limpiar_pedidos_anulados`()
BEGIN
    -- Actualizamos solo los registros que realmente necesitan limpieza
    -- para no afectar el rendimiento ni el timestamp de última actualización innecesariamente
    UPDATE anulados_tiendas
    SET pedido = TRIM(pedido)
    WHERE (pedido LIKE ' %' OR pedido LIKE '% ')
    -- Filtramos solo registros del último mes
    AND fecha_estado >= DATE_SUB(NOW(), INTERVAL 30 DAY);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_limpiar_pedidos_anulados_CD` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` PROCEDURE `sp_limpiar_pedidos_anulados_CD`()
BEGIN
    DELETE p
    FROM pedidos_magento p
    INNER JOIN pedidos_cli pc ON pc.pedido = p.pedido
    INNER JOIN asn a ON a.cli = pc.cli
    WHERE p.origen_stock = 'CD'
      AND p.fecha_compra >= DATE_ADD(CURDATE(), INTERVAL -365 DAY);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_limpiar_pedidos_anulados_Tiendas` */;
DELIMITER ;;
CREATE DEFINER=`he-man`@`%` PROCEDURE `sp_limpiar_pedidos_anulados_Tiendas`()
BEGIN
    DELETE p
    FROM pedidos_magento p
    INNER JOIN anulados_tiendas a ON a.pedido = p.pedido
    WHERE p.origen_stock <> 'CD'
      AND p.fecha_compra >= DATE_ADD(CURDATE(), INTERVAL -365 DAY);
END ;;
DELIMITER ;


