-- Create syntax for TABLE 'almacenes'
CREATE TABLE `almacenes` (
  `ID_Almacen` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Almacen_S` int unsigned DEFAULT NULL,
  `ID_TA` int unsigned DEFAULT NULL,
  `ID_AR` int unsigned DEFAULT NULL,
  `ID_Sucursal` int unsigned NOT NULL,
  `ID_Nivel` int unsigned DEFAULT NULL,
  `Nomeclatura` varchar(10) DEFAULT NULL,
  `Almacen` varchar(50) NOT NULL,
  `Ubicacion` varchar(100) DEFAULT NULL,
  `Virtual` tinyint(1) DEFAULT NULL,
  `IP_ImpPV` varchar(15) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,
  `ImpPV_Master` tinyint(1) DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(50) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Almacen`),
  KEY `ID_Sucursal` (`ID_Sucursal`),
  KEY `ID_Almacen_S` (`ID_Almacen_S`),
  KEY `fk_almacenes_id_ta` (`ID_TA`),
  KEY `fk_almacenes_id_nivel` (`ID_Nivel`),
  KEY `fk_almaces_id_ar` (`ID_AR`),
  CONSTRAINT `fk_almacenes_id_almacen_s` FOREIGN KEY (`ID_Almacen_S`) REFERENCES `almacenes` (`ID_Almacen`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_almacenes_id_nivel` FOREIGN KEY (`ID_Nivel`) REFERENCES `sucursales_niveles` (`ID_Nivel`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_almacenes_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE,
  CONSTRAINT `fk_almacenes_id_ta` FOREIGN KEY (`ID_TA`) REFERENCES `cat_tipos_almacen` (`ID_TA`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_almaces_id_ar` FOREIGN KEY (`ID_AR`) REFERENCES `cat_almacenes_rubro` (`ID_AR`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ban_cuentas'
CREATE TABLE `ban_cuentas` (
  `ID_BC` int unsigned NOT NULL AUTO_INCREMENT,
  `RFC_Empresa` varchar(13) NOT NULL,
  `ID_Banco` int unsigned NOT NULL,
  `Leyenda` varchar(50) NOT NULL,
  `Sucursal` varchar(20) NOT NULL,
  `No_Cuenta` varchar(11) NOT NULL,
  `CLABE` varchar(18) NOT NULL,
  `ID_Moneda` varchar(3) NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_BC`),
  KEY `fk_ban_cuentas_rfc_empresa` (`RFC_Empresa`),
  KEY `fk_ban_cuentas_id_banco` (`ID_Banco`),
  KEY `fk_ban_cuentas_id_moneda` (`ID_Moneda`),
  CONSTRAINT `fk_ban_cuentas_id_banco` FOREIGN KEY (`ID_Banco`) REFERENCES `cat_bancos` (`ID_Banco`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ban_cuentas_id_moneda` FOREIGN KEY (`ID_Moneda`) REFERENCES `cat_monedas` (`ID_Moneda`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ban_cuentas_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ban_cuentas_fp'
CREATE TABLE `ban_cuentas_fp` (
  `ID_BCFP` int NOT NULL AUTO_INCREMENT,
  `ID_BC` int unsigned NOT NULL,
  `ID_FP` varchar(2) NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Mod` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_BCFP`),
  KEY `ID_BC` (`ID_BC`),
  KEY `ID_FP` (`ID_FP`),
  KEY `Activo` (`Activo`),
  CONSTRAINT `fk_ban_cuentas_fp_id_bc` FOREIGN KEY (`ID_BC`) REFERENCES `ban_cuentas` (`ID_BC`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ban_cuentas_fp_id_fp` FOREIGN KEY (`ID_FP`) REFERENCES `cat_formas_pago` (`ID_FP`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ban_movimientos'
CREATE TABLE `ban_movimientos` (
  `ID_BM` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_BC` int unsigned NOT NULL,
  `ID_TM` int unsigned NOT NULL,
  `Fecha` date NOT NULL,
  `ID_FP` varchar(2) NOT NULL,
  `ID_TT` int unsigned DEFAULT NULL,
  `Ref_Banco` varchar(11) DEFAULT NULL,
  `Monto` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Monto_S` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `MXC` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Ref_Banco2` varchar(50) DEFAULT NULL,
  `Ref_Banco3` varchar(30) DEFAULT NULL,
  `Ref_CLABE` varchar(18) DEFAULT NULL,
  `ID_Transferencia` int DEFAULT '0',
  `Observaciones` varchar(500) DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_BM`),
  KEY `fk_ban_movimientos_id_bc` (`ID_BC`),
  KEY `fk_ban_movimientos_id_tm` (`ID_TM`),
  KEY `fk_ban_movimientos_id_fp` (`ID_FP`),
  KEY `fk_ban_movimientos_id_tt` (`ID_TT`),
  CONSTRAINT `fk_ban_movimientos_id_bc` FOREIGN KEY (`ID_BC`) REFERENCES `ban_cuentas` (`ID_BC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ban_movimientos_id_fp` FOREIGN KEY (`ID_FP`) REFERENCES `cat_formas_pago` (`ID_FP`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ban_movimientos_id_tm` FOREIGN KEY (`ID_TM`) REFERENCES `cat_tipos_movimiento` (`ID_TM`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ban_movimientos_id_tt` FOREIGN KEY (`ID_TT`) REFERENCES `cat_tipos_tarjeta` (`ID_TT`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cajas'
CREATE TABLE `cajas` (
  `ID_Caja` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Usuario` int unsigned DEFAULT NULL,
  `ID_Sucursal` int unsigned NOT NULL,
  `ID_Almacen` int unsigned DEFAULT NULL,
  `IP_ImpCV` varchar(15) NOT NULL,
  `Descripcion` varchar(50) NOT NULL,
  `EnUso` tinyint(1) DEFAULT '0',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Caja`),
  KEY `fk_cajas_id_usuario` (`ID_Usuario`),
  KEY `fk_cajas_id_sucursal` (`ID_Sucursal`),
  KEY `fk_cajas_id_almacen` (`ID_Almacen`),
  CONSTRAINT `fk_cajas_id_almacen` FOREIGN KEY (`ID_Almacen`) REFERENCES `almacenes` (`ID_Almacen`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_id_usuario` FOREIGN KEY (`ID_Usuario`) REFERENCES `users` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cajas_bc'
CREATE TABLE `cajas_bc` (
  `ID_CBC` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Caja` int unsigned NOT NULL,
  `ID_BC` int unsigned NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_CBC`),
  KEY `Activo` (`Activo`),
  KEY `fk_cajas_bc_id_caja` (`ID_Caja`),
  KEY `fk_cajas_bc_id_bc` (`ID_BC`),
  CONSTRAINT `fk_cajas_bc_id_bc` FOREIGN KEY (`ID_BC`) REFERENCES `ban_cuentas` (`ID_BC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_bc_id_caja` FOREIGN KEY (`ID_Caja`) REFERENCES `cajas` (`ID_Caja`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cajas_diario'
CREATE TABLE `cajas_diario` (
  `ID_CD` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Caja` int unsigned NOT NULL,
  `ID_Usuario` int unsigned NOT NULL,
  `Fecha` date NOT NULL,
  `Folio` varchar(20) NOT NULL,
  `Fecha_Inicio` datetime NOT NULL,
  `Fecha_Corte` datetime DEFAULT NULL,
  `Monto_Inicio` decimal(14,2) NOT NULL,
  `Monto_Corte` decimal(14,2) NOT NULL,
  `Dec_Efectivo` decimal(14,2) NOT NULL,
  `Dec_TDD` decimal(14,2) NOT NULL,
  `Dec_TDC` decimal(14,2) DEFAULT NULL,
  `Dec_Transferencia` decimal(14,2) NOT NULL,
  `Dec_Vales` decimal(14,2) NOT NULL,
  `Dec_Otros` decimal(14,2) NOT NULL,
  `Dec_Total` decimal(14,2) NOT NULL,
  `Diferencia` decimal(14,2) NOT NULL,
  `ID_Usuario_Alta` int unsigned DEFAULT NULL,
  `ID_Usuario_Corte` int unsigned DEFAULT NULL,
  `ID_Status` int unsigned NOT NULL DEFAULT '1',
  `Vale_Impreso` tinyint(1) NOT NULL DEFAULT '0',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_CD`),
  UNIQUE KEY `Folio` (`Folio`),
  KEY `fk_cajas_diario_id_caja` (`ID_Caja`),
  KEY `fk_cajas_diario_id_usuario` (`ID_Usuario`),
  KEY `fk_cajas_diario_id_status` (`ID_Status`),
  CONSTRAINT `fk_cajas_diario_id_caja` FOREIGN KEY (`ID_Caja`) REFERENCES `cajas` (`ID_Caja`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_id_status` FOREIGN KEY (`ID_Status`) REFERENCES `cat_status_cajas` (`ID_Status`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_id_usuario` FOREIGN KEY (`ID_Usuario`) REFERENCES `users` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cajas_diario_movs'
CREATE TABLE `cajas_diario_movs` (
  `ID_CDM` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_CD` int unsigned NOT NULL,
  `ID_Caja` int unsigned DEFAULT NULL,
  `Fecha` date NOT NULL,
  `Hora` time NOT NULL,
  `ID_Concepto` int unsigned NOT NULL,
  `ID_EC` int unsigned DEFAULT NULL,
  `ID_ECM` int unsigned DEFAULT NULL,
  `RFC` varchar(13) DEFAULT NULL,
  `ID_FP` varchar(2) NOT NULL,
  `ID_TT` int unsigned DEFAULT NULL,
  `Referencia` varchar(20) DEFAULT NULL,
  `Monto` decimal(14,2) NOT NULL,
  `Monto_S` decimal(14,2) NOT NULL,
  `Observaciones` varchar(255) DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_CDM`),
  KEY `fk_cajas_diario_movs_id_cd` (`ID_CD`),
  KEY `fk_cajas_diario_movs_id_caja` (`ID_Caja`),
  KEY `fk_cajas_diario_movs_id_concepto` (`ID_Concepto`),
  KEY `fk_cajas_diario_movs_id_ec` (`ID_EC`),
  KEY `fk_cajas_diario_movs_id_ecm` (`ID_ECM`),
  KEY `fk_cajas_diario_movs_id_fp` (`ID_FP`),
  KEY `fk_cajas_diario_movs_id_tt` (`ID_TT`),
  CONSTRAINT `fk_cajas_diario_movs_id_caja` FOREIGN KEY (`ID_Caja`) REFERENCES `cajas` (`ID_Caja`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_movs_id_cd` FOREIGN KEY (`ID_CD`) REFERENCES `cajas_diario` (`ID_CD`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_movs_id_concepto` FOREIGN KEY (`ID_Concepto`) REFERENCES `cat_cajas_conceptos` (`ID_Concepto`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_movs_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_movs_id_ecm` FOREIGN KEY (`ID_ECM`) REFERENCES `ec_movimientos` (`ID_ECM`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_movs_id_fp` FOREIGN KEY (`ID_FP`) REFERENCES `cat_formas_pago` (`ID_FP`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cajas_diario_movs_id_tt` FOREIGN KEY (`ID_TT`) REFERENCES `cat_tipos_tarjeta` (`ID_TT`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_ae'
CREATE TABLE `cat_ae` (
  `ID_AE` int NOT NULL,
  `CVE_AE` varchar(7) NOT NULL,
  `Actividad` varchar(250) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_almacenes_rubro'
CREATE TABLE `cat_almacenes_rubro` (
  `ID_AR` int unsigned NOT NULL AUTO_INCREMENT,
  `Rubro` varchar(100) NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_AR`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_bancos'
CREATE TABLE `cat_bancos` (
  `ID_Banco` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Llave primaria Banco',
  `ID_SHCP_Sector` varchar(2) NOT NULL DEFAULT '' COMMENT 'Sector SHCP',
  `CVE_Banco` varchar(4) NOT NULL DEFAULT '' COMMENT 'Clave Banco',
  `Banco` varchar(50) NOT NULL DEFAULT '' COMMENT 'Nombre comercial Banco',
  `Razon_Social` varchar(150) NOT NULL DEFAULT '' COMMENT 'Razón Social Banco',
  `RFC` varchar(13) DEFAULT NULL COMMENT 'RFC Banco',
  PRIMARY KEY (`ID_Banco`),
  UNIQUE KEY `Clv` (`CVE_Banco`,`ID_SHCP_Sector`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2010 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_cajas_conceptos'
CREATE TABLE `cat_cajas_conceptos` (
  `ID_Concepto` int unsigned NOT NULL AUTO_INCREMENT,
  `Concepto` varchar(50) NOT NULL,
  `Signo` int NOT NULL,
  PRIMARY KEY (`ID_Concepto`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_categorias'
CREATE TABLE `cat_categorias` (
  `ID_Categoria` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Categoria_S` int unsigned DEFAULT NULL,
  `ID_Sucursal` int unsigned DEFAULT NULL,
  `ID_TC` int unsigned DEFAULT NULL,
  `Categoria` varchar(100) NOT NULL,
  `Prefijo` varchar(5) DEFAULT NULL,
  `Nivel` int DEFAULT NULL,
  `ID_Categoria_N0` int unsigned DEFAULT NULL,
  `ID_Categoria_N1` int unsigned DEFAULT NULL,
  `ID_Cuenta` int DEFAULT NULL,
  `Ultimo_Doc` int DEFAULT NULL,
  `Fecha_UD` date DEFAULT NULL,
  `ID_UD` int DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(50) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Categoria`),
  KEY `ID_Categoria_S` (`ID_Categoria_S`),
  KEY `ID_Categoria_N1` (`ID_Categoria_N1`),
  KEY `ID_Categoria_N0` (`ID_Categoria_N0`),
  KEY `fk_cat_categorias_id_tc` (`ID_TC`),
  KEY `fk_cat_categorias_id_sucursal` (`ID_Sucursal`),
  FULLTEXT KEY `BUSQUEDA` (`Categoria`),
  CONSTRAINT `fk_cat_categorias_id_categoria_n0` FOREIGN KEY (`ID_Categoria_N0`) REFERENCES `cat_categorias` (`ID_Categoria`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_cat_categorias_id_categoria_n1` FOREIGN KEY (`ID_Categoria_N1`) REFERENCES `cat_categorias` (`ID_Categoria`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_cat_categorias_id_categoria_s` FOREIGN KEY (`ID_Categoria_S`) REFERENCES `cat_categorias` (`ID_Categoria`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_cat_categorias_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_cat_categorias_id_tc` FOREIGN KEY (`ID_TC`) REFERENCES `cat_tipos_categoria` (`ID_TC`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_cp'
CREATE TABLE `cat_cp` (
  `ID_CP` int unsigned NOT NULL,
  `Codigo_Postal` varchar(5) NOT NULL,
  `ID_TipoAs` varchar(2) NOT NULL,
  `Asentamiento` varchar(60) NOT NULL,
  `ID_Pais` int unsigned NOT NULL,
  `ID_Estado` int(2) unsigned zerofill NOT NULL,
  `ID_Municipio` int(3) unsigned zerofill NOT NULL,
  `Ciudad` varchar(60) DEFAULT NULL,
  `CVE_Oficina` varchar(5) NOT NULL,
  `Zona` varchar(15) NOT NULL,
  KEY `fk_cat_cp_id_pais` (`ID_Pais`),
  KEY `fk_cat_cp_id_estado` (`ID_Estado`),
  KEY `fk_cat_cp_id_municipio` (`ID_Municipio`),
  CONSTRAINT `fk_cat_cp_id_estado` FOREIGN KEY (`ID_Estado`) REFERENCES `cat_estados` (`ID_Estado`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cat_cp_id_municipio` FOREIGN KEY (`ID_Municipio`) REFERENCES `cat_municipios` (`ID_Municipio`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cat_cp_id_pais` FOREIGN KEY (`ID_Pais`) REFERENCES `cat_paises` (`ID_Pais`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_ec_conceptos'
CREATE TABLE `cat_ec_conceptos` (
  `ID_Concepto` int unsigned NOT NULL AUTO_INCREMENT,
  `Concepto` varchar(50) NOT NULL,
  `Signo` int NOT NULL,
  PRIMARY KEY (`ID_Concepto`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_ec_prods_rechazos'
CREATE TABLE `cat_ec_prods_rechazos` (
  `ID_Rechazo` int unsigned NOT NULL AUTO_INCREMENT,
  `Rechazo` varchar(100) NOT NULL,
  `Abrev` varchar(20) NOT NULL,
  `Activo` int NOT NULL,
  PRIMARY KEY (`ID_Rechazo`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_ec_tiempos'
CREATE TABLE `cat_ec_tiempos` (
  `ID_Tiempo` int unsigned NOT NULL,
  `Tiempo` varchar(20) NOT NULL,
  `Abrev` varchar(20) NOT NULL,
  `Observaciones` varchar(100) DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL,
  PRIMARY KEY (`ID_Tiempo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_estados'
CREATE TABLE `cat_estados` (
  `ID_Estado` int unsigned NOT NULL,
  `ID_Pais` int unsigned NOT NULL,
  `Clv` varchar(2) NOT NULL,
  `c_Estado` varchar(3) NOT NULL,
  `Estado` varchar(100) NOT NULL,
  `Abrev` varchar(50) NOT NULL,
  `Abrev_2` varchar(2) NOT NULL,
  `ID_CIEP` int DEFAULT NULL,
  `U_Year` int NOT NULL,
  `AbrevBC` varchar(4) NOT NULL DEFAULT '',
  PRIMARY KEY (`ID_Estado`),
  KEY `fk_cat_estados_id_pais` (`ID_Pais`),
  CONSTRAINT `fk_cat_estados_id_pais` FOREIGN KEY (`ID_Pais`) REFERENCES `cat_paises` (`ID_Pais`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_formas_pago'
CREATE TABLE `cat_formas_pago` (
  `ID_FP` varchar(2) NOT NULL,
  `Forma_Pago` varchar(50) NOT NULL,
  `EsPredeterminado` tinyint(1) NOT NULL DEFAULT '0',
  `Punto_Venta` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID_FP`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_impuestos'
CREATE TABLE `cat_impuestos` (
  `ID_Impuesto` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_TI` int unsigned NOT NULL,
  `TR` varchar(1) NOT NULL,
  `ID_TF` int unsigned NOT NULL,
  `Descripcion` varchar(50) NOT NULL,
  `P_Imp` decimal(10,4) NOT NULL,
  `EsPredeterminado` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID_Impuesto`),
  KEY `TR` (`TR`),
  KEY `fk_cat_impuestos_id_ti` (`ID_TI`),
  KEY `fk_cat_impuestos_id_tf` (`ID_TF`),
  CONSTRAINT `fk_cat_impuestos_id_tf` FOREIGN KEY (`ID_TF`) REFERENCES `cat_tipos_factor` (`ID_TF`) ON UPDATE CASCADE,
  CONSTRAINT `fk_cat_impuestos_id_ti` FOREIGN KEY (`ID_TI`) REFERENCES `cat_tipos_impuesto` (`ID_TI`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_marcas'
CREATE TABLE `cat_marcas` (
  `ID_Marca` int unsigned NOT NULL AUTO_INCREMENT,
  `Marca` varchar(100) NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(50) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Marca`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_meses'
CREATE TABLE `cat_meses` (
  `ID_Mes` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Periodicidad` varchar(2) NOT NULL DEFAULT '04',
  `Cve_Mes` varchar(2) NOT NULL,
  `Abrev` varchar(3) NOT NULL,
  `Mes` varchar(20) NOT NULL,
  `Dia_Final` varchar(2) NOT NULL,
  PRIMARY KEY (`ID_Mes`),
  KEY `fk_cat_meses_id_periodicidad` (`ID_Periodicidad`),
  CONSTRAINT `fk_cat_meses_id_periodicidad` FOREIGN KEY (`ID_Periodicidad`) REFERENCES `cat_periodicidad` (`ID_Periodicidad`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_modulos'
CREATE TABLE `cat_modulos` (
  `ID_Modulo` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Modulo_S` int unsigned DEFAULT NULL,
  `Modulo` varchar(5) NOT NULL,
  `Descripcion` varchar(100) NOT NULL,
  `EC` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID_Modulo`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_monedas'
CREATE TABLE `cat_monedas` (
  `ID_Moneda` varchar(3) NOT NULL COMMENT 'Clave SAT',
  `Clv_2` varchar(2) NOT NULL,
  `Clv_3` varchar(3) NOT NULL,
  `Codigo` varchar(3) NOT NULL COMMENT 'Clave Buro de Credito',
  `Simbolo` varchar(10) NOT NULL,
  `Moneda` varchar(20) NOT NULL,
  `Imagen` varchar(10) NOT NULL,
  `EsPredeterminado` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID_Moneda`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_municipios'
CREATE TABLE `cat_municipios` (
  `ID_Municipio` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Estado` int unsigned NOT NULL,
  `Clv` varchar(3) NOT NULL,
  `Municipio` varchar(100) NOT NULL,
  `Latitud` varchar(15) DEFAULT NULL,
  `Longitud` varchar(15) DEFAULT NULL,
  `Altitud` varchar(10) DEFAULT NULL,
  `Poblacion` int DEFAULT NULL,
  `Viviendas` int DEFAULT NULL,
  PRIMARY KEY (`ID_Municipio`),
  KEY `fk_cat_municipios_id_estado` (`ID_Estado`),
  CONSTRAINT `fk_cat_municipios_id_estado` FOREIGN KEY (`ID_Estado`) REFERENCES `cat_estados` (`ID_Estado`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2458 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_paises'
CREATE TABLE `cat_paises` (
  `ID_Pais` int unsigned NOT NULL AUTO_INCREMENT,
  `c_Pais` varchar(3) NOT NULL,
  `Pais` varchar(100) NOT NULL,
  `AbrevBC` varchar(3) NOT NULL DEFAULT '',
  PRIMARY KEY (`ID_Pais`)
) ENGINE=InnoDB AUTO_INCREMENT=280 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_periodicidad'
CREATE TABLE `cat_periodicidad` (
  `ID_Periodicidad` varchar(2) NOT NULL,
  `ID_FQ` varchar(1) DEFAULT NULL,
  `Periodicidad` varchar(20) NOT NULL,
  PRIMARY KEY (`ID_Periodicidad`),
  UNIQUE KEY `ID_FQ` (`ID_FQ`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_personalidades'
CREATE TABLE `cat_personalidades` (
  `ID_Personalidad` int unsigned NOT NULL AUTO_INCREMENT,
  `Personalidad` varchar(60) NOT NULL,
  `PF` tinyint(1) NOT NULL DEFAULT '0',
  `PM` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID_Personalidad`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_rf'
CREATE TABLE `cat_rf` (
  `ID_RF` int NOT NULL,
  `ID_Personalidad` int NOT NULL DEFAULT '1',
  `Descripcion` varchar(100) NOT NULL,
  `Fisica` tinyint(1) NOT NULL DEFAULT '0',
  `Moral` tinyint(1) NOT NULL DEFAULT '0',
  `Fecha_Inicio` date NOT NULL,
  `Fecha_Fin` date DEFAULT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_RF`),
  KEY `ID_Personalidad` (`ID_Personalidad`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_status_cajas'
CREATE TABLE `cat_status_cajas` (
  `ID_Status` int unsigned NOT NULL AUTO_INCREMENT,
  `Status` varchar(50) NOT NULL,
  PRIMARY KEY (`ID_Status`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_status_ec'
CREATE TABLE `cat_status_ec` (
  `ID_Status` int unsigned NOT NULL AUTO_INCREMENT,
  `Status` varchar(15) NOT NULL,
  `Descripcion` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID_Status`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_status_ec_partidas'
CREATE TABLE `cat_status_ec_partidas` (
  `ID_Status` int unsigned NOT NULL AUTO_INCREMENT,
  `Status` varchar(50) NOT NULL,
  PRIMARY KEY (`ID_Status`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_status_requisiciones'
CREATE TABLE `cat_status_requisiciones` (
  `ID_Status` int unsigned NOT NULL AUTO_INCREMENT,
  `Status` varchar(50) NOT NULL,
  `Color` varchar(11) DEFAULT NULL,
  PRIMARY KEY (`ID_Status`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_almacen'
CREATE TABLE `cat_tipos_almacen` (
  `ID_TA` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Almacen` varchar(100) NOT NULL,
  PRIMARY KEY (`ID_TA`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_categoria'
CREATE TABLE `cat_tipos_categoria` (
  `ID_TC` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Categoria` varchar(100) NOT NULL,
  PRIMARY KEY (`ID_TC`),
  UNIQUE KEY `uk_tipo_categoria` (`Tipo_Categoria`),
  FULLTEXT KEY `ftk_tipo_categoria` (`Tipo_Categoria`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_concepto'
CREATE TABLE `cat_tipos_concepto` (
  `ID_TC` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Concepto` varchar(30) NOT NULL,
  PRIMARY KEY (`ID_TC`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_ec_cargo'
CREATE TABLE `cat_tipos_ec_cargo` (
  `ID_Tipo_Cargo` int unsigned NOT NULL,
  `Tipo_Cargo` varchar(20) NOT NULL,
  `Valor` int NOT NULL,
  PRIMARY KEY (`ID_Tipo_Cargo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_es'
CREATE TABLE `cat_tipos_es` (
  `ID_TES` int unsigned NOT NULL AUTO_INCREMENT,
  `Abrev` varchar(1) NOT NULL,
  `Tipo_ES` varchar(20) NOT NULL,
  `Signo` decimal(3,2) NOT NULL,
  PRIMARY KEY (`ID_TES`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_factor'
CREATE TABLE `cat_tipos_factor` (
  `ID_TF` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Factor` varchar(20) NOT NULL,
  PRIMARY KEY (`ID_TF`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_factura'
CREATE TABLE `cat_tipos_factura` (
  `ID_TF` int NOT NULL AUTO_INCREMENT,
  `Tipo_Factura` varchar(30) NOT NULL,
  PRIMARY KEY (`ID_TF`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_impuesto'
CREATE TABLE `cat_tipos_impuesto` (
  `ID_TI` int unsigned NOT NULL AUTO_INCREMENT,
  `Cve_Impuesto` varchar(3) NOT NULL,
  `Descripcion` varchar(20) NOT NULL,
  `Retencion` tinyint(1) NOT NULL DEFAULT '0',
  `Traslado` tinyint(1) NOT NULL DEFAULT '0',
  `Compras` tinyint(1) NOT NULL DEFAULT '0',
  `Ventas` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID_TI`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_inventario'
CREATE TABLE `cat_tipos_inventario` (
  `ID_TIN` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Inventario` varchar(100) NOT NULL DEFAULT '',
  PRIMARY KEY (`ID_TIN`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_menu_categoria'
CREATE TABLE `cat_tipos_menu_categoria` (
  `ID_TMC` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_MC` varchar(50) NOT NULL,
  PRIMARY KEY (`ID_TMC`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_movimiento'
CREATE TABLE `cat_tipos_movimiento` (
  `ID_TM` int unsigned NOT NULL,
  `Tipo_Movimiento` varchar(50) NOT NULL,
  `Signo_EC` decimal(3,2) NOT NULL,
  `Signo_BAN` decimal(3,2) NOT NULL,
  PRIMARY KEY (`ID_TM`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_movs_ec'
CREATE TABLE `cat_tipos_movs_ec` (
  `ID_TMEC` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Mov_EC` varchar(100) NOT NULL,
  PRIMARY KEY (`ID_TMEC`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_movs_inventario'
CREATE TABLE `cat_tipos_movs_inventario` (
  `ID_TMI` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_TES` int unsigned NOT NULL,
  `Tipo_Mov` varchar(100) NOT NULL,
  PRIMARY KEY (`ID_TMI`),
  KEY `fk_cat_tipos_movs_inventario_id_tes` (`ID_TES`),
  CONSTRAINT `fk_cat_tipos_movs_inventario_id_tes` FOREIGN KEY (`ID_TES`) REFERENCES `cat_tipos_es` (`ID_TES`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_requisiciones'
CREATE TABLE `cat_tipos_requisiciones` (
  `ID_TipoRQ` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Requisicion` varchar(50) NOT NULL,
  PRIMARY KEY (`ID_TipoRQ`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_tipos_tarjeta'
CREATE TABLE `cat_tipos_tarjeta` (
  `ID_TT` int unsigned NOT NULL AUTO_INCREMENT,
  `Tipo_Tarjeta` varchar(30) NOT NULL,
  `Icono` varchar(30) NOT NULL,
  PRIMARY KEY (`ID_TT`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_um'
CREATE TABLE `cat_um` (
  `ID_UM` varchar(3) NOT NULL,
  `UM` varchar(100) NOT NULL,
  `Abrev` varchar(10) DEFAULT NULL,
  `Activo` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`ID_UM`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'cat_uso_CFDI'
CREATE TABLE `cat_uso_CFDI` (
  `ID_USO` varchar(4) NOT NULL,
  `ID_Personalidad` int unsigned NOT NULL DEFAULT '1',
  `Descripcion` varchar(100) NOT NULL,
  `Fisica` tinyint(1) NOT NULL DEFAULT '0',
  `Moral` tinyint(1) NOT NULL DEFAULT '0',
  `Fecha_Inicio` date NOT NULL,
  `Fecha_Fin` date DEFAULT NULL,
  `EsPredeterminado` tinyint(1) NOT NULL DEFAULT '0',
  `Visible` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_USO`),
  KEY `fk_cat_uso_cfdi_id_personalidad` (`ID_Personalidad`),
  CONSTRAINT `fk_cat_uso_cfdi_id_personalidad` FOREIGN KEY (`ID_Personalidad`) REFERENCES `cat_personalidades` (`ID_Personalidad`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'contribuyentes'
CREATE TABLE `contribuyentes` (
  `RFC` varchar(13) NOT NULL,
  `ID_Personalidad` int DEFAULT NULL,
  `ID_RF` int NOT NULL,
  `Nombre_Contribuyente` varchar(250) NOT NULL,
  `Fecha_Nacimiento` date DEFAULT NULL,
  `Calle` varchar(40) DEFAULT NULL,
  `No_Ext` varchar(20) DEFAULT NULL,
  `No_Int` varchar(20) DEFAULT NULL,
  `Colonia` varchar(60) DEFAULT NULL,
  `ID_Pais` int NOT NULL DEFAULT '1',
  `ID_Estado` int NOT NULL,
  `ID_Municipio` int NOT NULL,
  `Codigo_Postal` varchar(5) NOT NULL,
  `FIEL` tinyint(1) DEFAULT '0',
  `noCertificado` varchar(20) DEFAULT NULL,
  `Latitud` varchar(20) DEFAULT NULL,
  `Longitud` varchar(20) DEFAULT NULL,
  `Altitud` varchar(10) DEFAULT NULL,
  `ID_LN` int DEFAULT NULL,
  `Activo` tinyint NOT NULL DEFAULT '1',
  `Fecha_Mod` datetime NOT NULL,
  `Fecha_Busqueda` datetime DEFAULT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`RFC`),
  KEY `ID_Personalidad` (`ID_Personalidad`),
  KEY `ID_RF` (`ID_RF`),
  KEY `ID_Pais` (`ID_Pais`),
  KEY `ID_Estado` (`ID_Estado`),
  KEY `ID_Municipio` (`ID_Municipio`),
  KEY `Codigo_Postal` (`Codigo_Postal`),
  KEY `ID_LN` (`ID_LN`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'convenios'
CREATE TABLE `convenios` (
  `ID_Convenio` int unsigned NOT NULL AUTO_INCREMENT,
  `RFC_Empresa` varchar(13) NOT NULL,
  `RFC_Titular` varchar(13) DEFAULT NULL,
  `Folio` varchar(20) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,
  `Descripcion` varchar(100) NOT NULL,
  `Fecha_Inicio` datetime NOT NULL,
  `Fecha_Fin` datetime NOT NULL,
  `Por_Descuento` decimal(10,4) NOT NULL,
  `Por_Descorche` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `Factor_PFL` decimal(10,4) NOT NULL DEFAULT '0.0000' COMMENT 'Factor Precio Fuera de Linea',
  `CXC` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1 puede generar cuenta por cobrar,  0 paga paciente',
  `ID_Convenio_PDC` int unsigned DEFAULT NULL COMMENT 'Convenio Pago Deducible y Coaseguros',
  `ID_TM_PDC` int unsigned DEFAULT NULL COMMENT 'Tipo de Movimiento Pago Deducible y Coaseguros',
  `ATC_Hospital` varchar(6) DEFAULT NULL,
  `ATC_Convenio` varchar(6) DEFAULT NULL,
  `Contrato` tinyint(1) NOT NULL DEFAULT '0' COMMENT '¿Requiere Contrato?',
  `ID_FF_I` int unsigned DEFAULT '0' COMMENT 'Folio Fiscal Ingreso',
  `ID_FF_E` int unsigned DEFAULT '0' COMMENT 'Folio Fiscal Egreso',
  `ID_FF_P` int unsigned DEFAULT '0' COMMENT 'Folio Fiscal Pago',
  `ID_TF` int unsigned DEFAULT '0' COMMENT 'cat_tipos_factura',
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Convenio`),
  KEY `ID_FF_I` (`ID_FF_I`),
  KEY `ID_FF_E` (`ID_FF_E`),
  KEY `ID_FF_P` (`ID_FF_P`),
  KEY `RFC_Empresa` (`RFC_Empresa`),
  KEY `RFC_Titular` (`RFC_Titular`),
  KEY `CXC` (`CXC`),
  KEY `ID_Convenio_PDC` (`ID_Convenio_PDC`),
  KEY `ID_TM_PDC` (`ID_TM_PDC`),
  KEY `Contrato` (`Contrato`),
  KEY `ID_TF` (`ID_TF`),
  CONSTRAINT `fk_convenios_id_tf` FOREIGN KEY (`ID_TF`) REFERENCES `cat_tipos_factor` (`ID_TF`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_convenios_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec'
CREATE TABLE `ec` (
  `ID_EC` int unsigned NOT NULL AUTO_INCREMENT,
  `RFC_Empresa` varchar(13) NOT NULL,
  `CVE_EC` varchar(10) NOT NULL,
  `Num_Personas` int NOT NULL DEFAULT '1',
  `Folio` varchar(20) NOT NULL,
  `Fecha_Ingreso` datetime NOT NULL,
  `Fecha_Salida` datetime DEFAULT NULL,
  `ID_Sucursal` int unsigned NOT NULL,
  `ID_Usuario` int unsigned NOT NULL,
  `ID_Moneda` varchar(3) NOT NULL DEFAULT 'MXN',
  `TC` decimal(10,4) NOT NULL DEFAULT '1.0000',
  `T_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `T_Bonificaciones` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `TB_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000' COMMENT 'ec_pacientes cargos precio lista x cantidad',
  `Descuento` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `TN_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Impuestos_Trasladados` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Abonos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Propina` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Tarjeta_Cliente` varchar(19) DEFAULT NULL,
  `Observaciones` varchar(250) DEFAULT NULL,
  `Impresiones` int NOT NULL DEFAULT '0',
  `Folio_Fact` varchar(5) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,
  `Total_CXC` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Saldo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Facturable` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Facturado` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `PXF` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Firmado` tinyint(1) NOT NULL DEFAULT '0',
  `Nota_Auditoria` varchar(250) DEFAULT NULL,
  `ID_Status` int unsigned NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `ID_ECL` int unsigned DEFAULT NULL,
  `Fecha_U_Cargo` datetime DEFAULT NULL,
  `Fecha_U_Abono` datetime DEFAULT NULL,
  `Fecha_U_Factura` date DEFAULT NULL,
  `Actualizar` tinyint(1) DEFAULT '1',
  `Fecha_Actualizacion` datetime DEFAULT NULL,
  `ATC_C_Fecha` datetime DEFAULT NULL,
  `ATC_V_Fecha` datetime DEFAULT NULL,
  `Fecha_Cierre` datetime DEFAULT NULL COMMENT 'Cierra de Cuenta',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_EC`),
  UNIQUE KEY `RFC_Empresa` (`RFC_Empresa`,`Folio`),
  KEY `ID_Status` (`ID_Status`),
  KEY `Actualizar` (`Actualizar`),
  KEY `fk_ec_id_sucursal` (`ID_Sucursal`),
  KEY `fk_ec_id_usuario` (`ID_Usuario`),
  KEY `fk_ec_id_moneda` (`ID_Moneda`),
  KEY `fk_ec_id_ecl` (`ID_ECL`),
  CONSTRAINT `fk_ec_id_ecl` FOREIGN KEY (`ID_ECL`) REFERENCES `ec_log` (`ID_ECL`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_id_moneda` FOREIGN KEY (`ID_Moneda`) REFERENCES `cat_monedas` (`ID_Moneda`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_id_status` FOREIGN KEY (`ID_Status`) REFERENCES `cat_status_ec` (`ID_Status`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_id_usuario` FOREIGN KEY (`ID_Usuario`) REFERENCES `users` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=142 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_cargos'
CREATE TABLE `ec_cargos` (
  `ID_Cargo` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Tipo_Cargo` int unsigned NOT NULL DEFAULT '1',
  `ID_Cargo_Bon` int unsigned DEFAULT NULL,
  `ID_EC` int unsigned NOT NULL,
  `ID_Convenio` int unsigned DEFAULT NULL,
  `ID_Partida` int unsigned NOT NULL,
  `ID_Partida_Paquete` int unsigned DEFAULT NULL,
  `Fecha_Aplicacion` datetime NOT NULL,
  `No_Cargo` int unsigned NOT NULL DEFAULT '1',
  `ID_Sucursal` int unsigned NOT NULL,
  `ID_Almacen` int unsigned DEFAULT NULL,
  `ID_Inventario` int unsigned NOT NULL,
  `Cantidad` decimal(10,4) NOT NULL DEFAULT '1.0000',
  `Costo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Precio_Lista` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Por_Descuento` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Descuento` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `Precio_Unitario` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Impuestos_Trasladados` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Cargo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Bonificacion` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Por_Propina` decimal(14,4) DEFAULT NULL,
  `Propina` decimal(14,4) DEFAULT NULL,
  `Observaciones` varchar(250) DEFAULT NULL,
  `Auditada` tinyint(1) NOT NULL DEFAULT '0',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime DEFAULT NULL,
  `Usr_Alta` varchar(100) DEFAULT NULL,
  `IP_Alta` varchar(15) DEFAULT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Cargo`),
  KEY `Usr_Alta` (`Usr_Alta`),
  KEY `Auditada` (`Auditada`),
  KEY `Activo` (`Activo`),
  KEY `Usr_Mod` (`Usr_Mod`),
  KEY `Fecha_Aplicacion` (`Fecha_Aplicacion`),
  KEY `fk_ec_cargos_id_tipo_cargo` (`ID_Tipo_Cargo`),
  KEY `fk_ec_cargos_id_cargo_bon` (`ID_Cargo_Bon`),
  KEY `fk_ec_cargos_id_ec` (`ID_EC`),
  KEY `fk_ec_cargos_id_sucursal` (`ID_Sucursal`),
  KEY `fk_ec_cargos_id_almacen` (`ID_Almacen`),
  KEY `fk_ec_cargos_id_inventario` (`ID_Inventario`),
  KEY `fk_ec_cargos_id_partida` (`ID_Partida`),
  KEY `fk_ec_cargos_id_convenio` (`ID_Convenio`),
  CONSTRAINT `fk_ec_cargos_id_almacen` FOREIGN KEY (`ID_Almacen`) REFERENCES `almacenes` (`ID_Almacen`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cargos_id_cargo_bon` FOREIGN KEY (`ID_Cargo_Bon`) REFERENCES `ec_cargos` (`ID_Cargo`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cargos_id_convenio` FOREIGN KEY (`ID_Convenio`) REFERENCES `convenios` (`ID_Convenio`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cargos_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cargos_id_inventario` FOREIGN KEY (`ID_Inventario`) REFERENCES `inventario` (`ID_Inventario`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cargos_id_partida` FOREIGN KEY (`ID_Partida`) REFERENCES `ec_partidas` (`ID_Partida`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cargos_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cargos_id_tipo_cargo` FOREIGN KEY (`ID_Tipo_Cargo`) REFERENCES `cat_tipos_ec_cargo` (`ID_Tipo_Cargo`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1082 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_cargos_detalle'
CREATE TABLE `ec_cargos_detalle` (
  `ID_CD` int NOT NULL AUTO_INCREMENT,
  `ID_EC` int NOT NULL,
  `ID_ECC` int DEFAULT '0',
  `ID_Cargo` int NOT NULL,
  `ID_Convenio` int NOT NULL DEFAULT '0',
  `RFC_Cuenta` varchar(13) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'XAXX010101000',
  `Por_Cargo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Por_Descuento` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Descuento` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `ID_ECM` int DEFAULT '0',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `IP_Alta` varchar(15) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `Fecha_Mod` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_CD`),
  UNIQUE KEY `idx_unico_cargos` (`ID_EC`,`ID_Cargo`,`ID_Convenio`,`RFC_Cuenta`,`ID_ECC`) USING BTREE,
  KEY `ID_ECM` (`ID_ECM`),
  KEY `ID_ECC` (`ID_ECC`)
) ENGINE=InnoDB AUTO_INCREMENT=1082 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_conceptos'
CREATE TABLE `ec_conceptos` (
  `ID_Concepto` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_TC` int unsigned NOT NULL COMMENT 'Tipo_Concepto',
  `ID_TM` int unsigned NOT NULL COMMENT 'Tipo_Movimiento',
  `Descripcion` varchar(100) NOT NULL,
  `Banco` tinyint(1) NOT NULL DEFAULT '0',
  `Pago` tinyint(1) NOT NULL DEFAULT '0',
  `Orden` int NOT NULL,
  `ID_Concepto_S` int unsigned DEFAULT '0',
  `ID_Concepto_G` int unsigned DEFAULT '0',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Concepto`),
  KEY `fk_ec_conceptos_id_tc` (`ID_TC`),
  KEY `fk_ec_conceptos_id_tm` (`ID_TM`),
  CONSTRAINT `fk_ec_conceptos_id_tc` FOREIGN KEY (`ID_TC`) REFERENCES `cat_tipos_concepto` (`ID_TC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_conceptos_id_tm` FOREIGN KEY (`ID_TM`) REFERENCES `cat_tipos_movimiento` (`ID_TM`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=204 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_convenios'
CREATE TABLE `ec_convenios` (
  `ID_ECC` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_EC` int unsigned NOT NULL,
  `ID_Convenio` int unsigned NOT NULL,
  `No_Poliza` varchar(20) NOT NULL,
  `Plan` varchar(50) DEFAULT NULL,
  `ID_Contrato` int unsigned DEFAULT '0',
  `ID_Establecimiento` int unsigned DEFAULT '0',
  `TB_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Descuento` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `TN_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Impuestos_Trasladados` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Abonos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_CXC` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Presupuesto_Autorizado` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Deducible` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Honorarios_Medicos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_CHM` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_CGH` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_CNH` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_CAD` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Tope_Coaseguros` decimal(14,2) NOT NULL DEFAULT '0.00',
  `Total_Coaseguros` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Impuestos_Trasladados_DC` decimal(14,4) NOT NULL DEFAULT '0.0000' COMMENT 'Impuestos Trasladados Deducible y Coaseguros',
  `Saldo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `ID_U_Carta` int unsigned DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_ECC`),
  UNIQUE KEY `ECP_Convenio` (`ID_EC`,`ID_Convenio`) USING BTREE,
  KEY `ID_EC` (`ID_EC`),
  KEY `ID_Convenio` (`ID_Convenio`),
  KEY `ID_Carta` (`ID_U_Carta`),
  KEY `ID_Contrato` (`ID_Contrato`),
  KEY `ID_Establecimiento` (`ID_Establecimiento`),
  CONSTRAINT `fk_ec_convenios_id_convenio` FOREIGN KEY (`ID_Convenio`) REFERENCES `convenios` (`ID_Convenio`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_convenios_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_cuentas'
CREATE TABLE `ec_cuentas` (
  `ID_ECC` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_EC` int unsigned NOT NULL,
  `RFC_Cuenta` varchar(13) NOT NULL DEFAULT 'XAXX010101000',
  `ID_USO` varchar(4) NOT NULL DEFAULT 'G03',
  `Por_Cuenta` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `TB_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Descuento` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `TN_Cargos` decimal(14,4) DEFAULT '0.0000',
  `Impuestos_Trasladados` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Cargos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_Abonos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Total_CXC` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Saldo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Por_Propina` decimal(14,4) DEFAULT '0.0000',
  `Propina` decimal(14,4) DEFAULT '0.0000',
  `Descripcion` varchar(100) DEFAULT NULL,
  `ID_ECM` int unsigned DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_ECC`),
  KEY `RFC_Cuenta` (`RFC_Cuenta`),
  KEY `Activo` (`Activo`),
  KEY `fk_ec_cuentas_id_ec` (`ID_EC`),
  KEY `fk_ec_cuentas_id_uso` (`ID_USO`),
  KEY `fk_ec_cuentas_id_ecm` (`ID_ECM`),
  CONSTRAINT `fk_ec_cuentas_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cuentas_id_ecm` FOREIGN KEY (`ID_ECM`) REFERENCES `ec_movimientos` (`ID_ECM`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_cuentas_id_uso` FOREIGN KEY (`ID_USO`) REFERENCES `cat_uso_CFDI` (`ID_USO`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=129 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_log'
CREATE TABLE `ec_log` (
  `ID_ECL` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_EC` int unsigned NOT NULL,
  `ID_Status` int unsigned NOT NULL,
  `Observaciones` varchar(500) DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_ECL`),
  KEY `Activo` (`Activo`),
  KEY `fk_ec_log_id_ec` (`ID_EC`),
  CONSTRAINT `fk_ec_log_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_movimientos'
CREATE TABLE `ec_movimientos` (
  `ID_ECM` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Concepto` int unsigned NOT NULL COMMENT 'ec_conceptos',
  `RFC_Empresa` varchar(13) NOT NULL,
  `ID_Sucursal` int unsigned NOT NULL,
  `RFC` varchar(13) NOT NULL DEFAULT 'XAXX010101000' COMMENT 'RFC del Cliente',
  `ID_EC` int unsigned NOT NULL COMMENT 'ec',
  `ID_ECC` int unsigned NOT NULL COMMENT 'ec_cuentas',
  `ID_USO` varchar(4) DEFAULT NULL COMMENT 'cat_uso_CFDI',
  `ID_CXP` int unsigned NOT NULL DEFAULT '0' COMMENT 'Cuenta por Pagar Asociada',
  `ID_ECM_M` int unsigned NOT NULL DEFAULT '0' COMMENT 'ECM_Master',
  `ID_ECM_O` int unsigned NOT NULL DEFAULT '0' COMMENT 'ECM Origen',
  `ID_CD` int unsigned NOT NULL DEFAULT '0' COMMENT 'cajas_diario',
  `ID_Caja` int unsigned NOT NULL DEFAULT '0' COMMENT 'cajas',
  `ID_BM` int unsigned NOT NULL DEFAULT '0' COMMENT 'ban_movimientos',
  `ID_Periodo` int unsigned NOT NULL DEFAULT '0' COMMENT 'periodos',
  `Fecha_Documento` date NOT NULL,
  `Fecha_Aplicacion` date NOT NULL,
  `Fecha_Vencimiento` date NOT NULL,
  `ID_Moneda` varchar(3) NOT NULL DEFAULT 'MXN',
  `TC` decimal(10,4) NOT NULL DEFAULT '1.0000',
  `Monto_Bruto` decimal(14,4) NOT NULL DEFAULT '0.0000' COMMENT 'Subtotal sin descuento',
  `Descuento` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Monto_Neto` decimal(14,4) NOT NULL DEFAULT '0.0000' COMMENT 'Subtotal con descuento',
  `Impuestos_Trasladados` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Impuestos_Retenidos` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Monto` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Monto_S` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Saldo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Observaciones` varchar(250) DEFAULT NULL,
  `ID_Partida` int NOT NULL DEFAULT '0' COMMENT 'Partida de la Factura',
  `PXF` decimal(14,4) NOT NULL DEFAULT '0.0000' COMMENT 'Pendiente x Facturar',
  `Facturado` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Fecha_U_Movimiento` date DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_ECM`),
  KEY `RFC` (`RFC`),
  KEY `ID_BM` (`ID_BM`),
  KEY `ID_Partida` (`ID_Partida`),
  KEY `Activo` (`Activo`),
  KEY `ID_ECM_M` (`ID_ECM_M`),
  KEY `ID_ECM_O` (`ID_ECM_O`),
  KEY `ID_CD` (`ID_CD`),
  KEY `ID_Periodo` (`ID_Periodo`),
  KEY `ID_CXP` (`ID_CXP`),
  KEY `ID_Caja` (`ID_Caja`),
  KEY `fk_ec_movimientos_id_concepto` (`ID_Concepto`),
  KEY `fk_ec_movimientos_rfc_empresa` (`RFC_Empresa`),
  KEY `fk_ec_movimientos_id_sucursal` (`ID_Sucursal`),
  KEY `fk_ec_movimientos_id_ec` (`ID_EC`),
  KEY `fk_ec_movimientos_id_ecc` (`ID_ECC`),
  KEY `fk_ec_movimientos_id_uso` (`ID_USO`),
  KEY `fk_ec_movimientos_id_moneda` (`ID_Moneda`),
  CONSTRAINT `fk_ec_movimientos_id_concepto` FOREIGN KEY (`ID_Concepto`) REFERENCES `ec_conceptos` (`ID_Concepto`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_movimientos_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_movimientos_id_ecc` FOREIGN KEY (`ID_ECC`) REFERENCES `ec_cuentas` (`ID_ECC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_movimientos_id_moneda` FOREIGN KEY (`ID_Moneda`) REFERENCES `cat_monedas` (`ID_Moneda`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_movimientos_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_movimientos_id_uso` FOREIGN KEY (`ID_USO`) REFERENCES `cat_uso_CFDI` (`ID_USO`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_movimientos_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_partidas'
CREATE TABLE `ec_partidas` (
  `ID_Partida` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Partida_S` int unsigned DEFAULT NULL,
  `ID_Sucursal` int unsigned NOT NULL,
  `ID_EC` int unsigned NOT NULL,
  `ID_Menu` int unsigned DEFAULT NULL,
  `ID_MP` int unsigned DEFAULT NULL COMMENT 'menus_productos',
  `ID_Tiempo` int unsigned DEFAULT NULL COMMENT 'cat_ec_tiempos',
  `Persona` int unsigned DEFAULT NULL COMMENT 'Num de Persona',
  `No_Partida` int unsigned DEFAULT NULL,
  `ID_Inventario` int unsigned NOT NULL,
  `ID_Almacen` int unsigned DEFAULT NULL,
  `Cantidad` decimal(10,4) NOT NULL DEFAULT '1.0000',
  `Observaciones` varchar(250) DEFAULT NULL,
  `Paquete` tinyint unsigned DEFAULT NULL,
  `Cambios` tinyint unsigned DEFAULT NULL,
  `Enviado` datetime DEFAULT NULL,
  `Entregado` datetime DEFAULT NULL,
  `ID_Status` int unsigned NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Inventariado` tinyint(1) DEFAULT NULL,
  `JsonObject` mediumtext,
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Partida`),
  KEY `Activo` (`Activo`),
  KEY `fk_ec_partidas_id_partida_s` (`ID_Partida_S`),
  KEY `fk_ec_partidas_id_sucursal` (`ID_Sucursal`),
  KEY `fk_ec_partidas_id_ec` (`ID_EC`),
  KEY `fk_ec_partidas_id_inventario` (`ID_Inventario`),
  KEY `fk_ec_partidas_id_almacen` (`ID_Almacen`),
  KEY `fk_ec_partidas_id_menu` (`ID_Menu`),
  KEY `fk_ec_partidas_id_mp` (`ID_MP`),
  KEY `fk_ec_partidas_id_tiempo` (`ID_Tiempo`),
  KEY `fk_ec_partidas_id_status` (`ID_Status`),
  CONSTRAINT `fk_ec_partidas_id_almacen` FOREIGN KEY (`ID_Almacen`) REFERENCES `almacenes` (`ID_Almacen`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_inventario` FOREIGN KEY (`ID_Inventario`) REFERENCES `inventario` (`ID_Inventario`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_menu` FOREIGN KEY (`ID_Menu`) REFERENCES `menus` (`ID_Menu`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_mp` FOREIGN KEY (`ID_MP`) REFERENCES `menus_productos` (`ID_MP`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_partida_s` FOREIGN KEY (`ID_Partida_S`) REFERENCES `ec_partidas` (`ID_Partida`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_status` FOREIGN KEY (`ID_Status`) REFERENCES `cat_status_ec_partidas` (`ID_Status`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_id_tiempo` FOREIGN KEY (`ID_Tiempo`) REFERENCES `cat_ec_tiempos` (`ID_Tiempo`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1082 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_partidas_log'
CREATE TABLE `ec_partidas_log` (
  `ID_ECPL` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_TMEC` int unsigned NOT NULL,
  `ID_EC_Origen` int unsigned NOT NULL,
  `ID_EC_Destino` int unsigned DEFAULT NULL,
  `ID_Partida` int unsigned NOT NULL,
  `ID_UsuarioMov` int unsigned NOT NULL,
  `Observaciones` text NOT NULL,
  `Activo` int NOT NULL,
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_ECPL`),
  KEY `fk_ec_partidas_log_id_tmec` (`ID_TMEC`),
  KEY `fk_ec_partidas_log_id_ec_origen` (`ID_EC_Origen`),
  KEY `fk_ec_partidas_log_id_partida` (`ID_Partida`),
  KEY `fk_ec_partidas_log_id_usuariomov` (`ID_UsuarioMov`),
  CONSTRAINT `fk_ec_partidas_log_id_ec_origen` FOREIGN KEY (`ID_EC_Origen`) REFERENCES `ec` (`ID_EC`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_log_id_partida` FOREIGN KEY (`ID_Partida`) REFERENCES `ec_partidas` (`ID_Partida`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_log_id_tmec` FOREIGN KEY (`ID_TMEC`) REFERENCES `cat_tipos_movs_ec` (`ID_TMEC`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_partidas_log_id_usuariomov` FOREIGN KEY (`ID_UsuarioMov`) REFERENCES `users` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_tickets_log'
CREATE TABLE `ec_tickets_log` (
  `ID_TL` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_EC` int unsigned NOT NULL,
  `CVE_EC` varchar(10) NOT NULL DEFAULT '',
  `Ticket_Tipo` varchar(20) NOT NULL DEFAULT '',
  `ID_Usuario_Mov` int unsigned NOT NULL,
  `Fecha_Imp` date NOT NULL,
  `Hora_Imp` time NOT NULL,
  `IP_Impresora` varchar(15) NOT NULL DEFAULT '',
  `Observaciones` text NOT NULL,
  `Activo` int NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_TL`),
  KEY `fk_ec_tickets_log_id_ec` (`ID_EC`),
  KEY `fk_ec_tickets_log_id_usuario_mov` (`ID_Usuario_Mov`),
  CONSTRAINT `fk_ec_tickets_log_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_tickets_log_id_usuario_mov` FOREIGN KEY (`ID_Usuario_Mov`) REFERENCES `users` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=123 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'ec_usuarios'
CREATE TABLE `ec_usuarios` (
  `ID_ECU` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_EC` int unsigned NOT NULL,
  `ID_Usuario` int unsigned NOT NULL,
  `Activo` int NOT NULL,
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_ECU`),
  KEY `fk_ec_usuarios_id_ec` (`ID_EC`),
  KEY `fk_ec_usuarios_id_usuario` (`ID_Usuario`),
  CONSTRAINT `fk_ec_usuarios_id_ec` FOREIGN KEY (`ID_EC`) REFERENCES `ec` (`ID_EC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_ec_usuarios_id_usuario` FOREIGN KEY (`ID_Usuario`) REFERENCES `users` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=142 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'empresas'
CREATE TABLE `empresas` (
  `RFC` varchar(13) NOT NULL,
  `Logo` varchar(50) DEFAULT NULL,
  `Color_1` varchar(7) NOT NULL,
  `Color_2` varchar(7) NOT NULL,
  `EsPredeterminado` tinyint(1) NOT NULL DEFAULT '0',
  `Ventas` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Compras` decimal(14,4) DEFAULT '0.0000',
  `Nomina` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `No_Clientes` int NOT NULL DEFAULT '0',
  `No_Proveedores` int NOT NULL DEFAULT '0',
  `No_Colaboradores` int NOT NULL DEFAULT '0',
  `ID_Impuesto` int NOT NULL DEFAULT '1',
  `Actualizado` tinyint(1) NOT NULL DEFAULT '0',
  `URL_BOX` varchar(100) DEFAULT NULL,
  `Host` varchar(20) DEFAULT NULL,
  `Port` int DEFAULT NULL,
  `Prefijo` varchar(20) DEFAULT NULL,
  `BOX` varchar(20) DEFAULT NULL,
  `PWD` varchar(20) DEFAULT NULL,
  `ID_BOX` int DEFAULT NULL,
  `Fecha_GO` date DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(50) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`RFC`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'failed_jobs'
CREATE TABLE `failed_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `connection` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create syntax for TABLE 'inventario'
CREATE TABLE `inventario` (
  `ID_Inventario` int unsigned NOT NULL AUTO_INCREMENT,
  `RFC_Empresa` varchar(13) DEFAULT NULL,
  `ID_TIN` int unsigned NOT NULL,
  `ID_Categoria` int unsigned NOT NULL,
  `Catalogo` varchar(16) NOT NULL COMMENT 'SKU',
  `Foto` varchar(250) DEFAULT NULL,
  `EAN13` varchar(13) DEFAULT NULL,
  `Concepto` varchar(100) NOT NULL DEFAULT '',
  `ID_Marca` int unsigned DEFAULT NULL,
  `Clave_SAT` varchar(20) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '90101501',
  `ID_UM_E` varchar(3) DEFAULT '',
  `FU` decimal(12,6) NOT NULL DEFAULT '1.000000',
  `ID_UM_S` varchar(3) DEFAULT NULL,
  `Existencia` decimal(12,6) NOT NULL DEFAULT '0.000000',
  `PXS` decimal(12,6) unsigned NOT NULL DEFAULT '0.000000',
  `PXR` decimal(12,6) unsigned NOT NULL DEFAULT '0.000000',
  `Ultimo_Costo` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Costo_Min` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Costo_Promedio` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Costo_Max` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Precio` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `EsInventariable` tinyint(1) NOT NULL DEFAULT '0',
  `EsSerie` tinyint(1) NOT NULL DEFAULT '0',
  `EsLote` tinyint(1) NOT NULL DEFAULT '0',
  `EsConsignacion` tinyint(1) NOT NULL DEFAULT '0',
  `EsCargo` tinyint(1) NOT NULL DEFAULT '0',
  `Tiempo_Surtido` decimal(10,2) unsigned zerofill NOT NULL DEFAULT '00000000.00' COMMENT 'En días',
  `Peso_E` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'Peso UM Entrada en Kg',
  `Peso_S` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'Peso UM Salida en Kg',
  `AutoSolicitudes` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para Paquetes si true then generara Solicitudes en automatico',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Actualizar` tinyint(1) NOT NULL DEFAULT '0',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(50) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL DEFAULT '',
  `IP_Mod` varchar(15) NOT NULL DEFAULT '',
  PRIMARY KEY (`ID_Inventario`),
  UNIQUE KEY `UNQ_RFC_Empresa_Catalogo` (`RFC_Empresa`,`Catalogo`),
  KEY `RFC_Empresa` (`RFC_Empresa`),
  KEY `ID_TIN` (`ID_TIN`),
  KEY `ID_Categoria` (`ID_Categoria`),
  KEY `Clave_SAT` (`Clave_SAT`),
  KEY `ID_UM_E` (`ID_UM_E`),
  KEY `ID_UM_S` (`ID_UM_S`),
  KEY `ID_Marca` (`ID_Marca`),
  KEY `Clave_SAT_2` (`Clave_SAT`),
  KEY `Activo` (`Activo`),
  FULLTEXT KEY `BUSQUEDA` (`Catalogo`,`Concepto`),
  CONSTRAINT `fk_inventario_id_categoria` FOREIGN KEY (`ID_Categoria`) REFERENCES `cat_categorias` (`ID_Categoria`) ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_id_marca` FOREIGN KEY (`ID_Marca`) REFERENCES `cat_marcas` (`ID_Marca`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_id_tin` FOREIGN KEY (`ID_TIN`) REFERENCES `cat_tipos_inventario` (`ID_TIN`) ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_id_um_e` FOREIGN KEY (`ID_UM_E`) REFERENCES `cat_um` (`ID_UM`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_id_um_s` FOREIGN KEY (`ID_UM_S`) REFERENCES `cat_um` (`ID_UM`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=817 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'inventario_movimientos'
CREATE TABLE `inventario_movimientos` (
  `ID_MI` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_TMI` int unsigned NOT NULL,
  `ID_MA` int unsigned NOT NULL COMMENT 'Referencia Obligada a Producto Almacen',
  `RFC_CLIPRO` varchar(13) DEFAULT NULL,
  `CLIPRO` varchar(250) DEFAULT NULL,
  `Fecha_Mov` date NOT NULL,
  `ID_Modulo` int unsigned NOT NULL,
  `ID_Doc` int NOT NULL DEFAULT '0',
  `ID_Prod` int NOT NULL DEFAULT '0',
  `Cantidad` decimal(10,4) unsigned NOT NULL DEFAULT '0.0000',
  `Qty` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `Saldo` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `Costo_Unitario` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Costo_Min` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Costo_Promedio` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Costo_Max` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Costo_Factor` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Factor` decimal(10,4) unsigned NOT NULL DEFAULT '0.0000',
  `Precio` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Observaciones` varchar(250) DEFAULT NULL,
  `Serie` varchar(100) DEFAULT NULL,
  `Lote` varchar(100) DEFAULT NULL,
  `Fecha_Caducidad` date DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_MI`),
  KEY `RFC_CLIPRO` (`RFC_CLIPRO`),
  KEY `ID_Doc` (`ID_Doc`),
  KEY `ID_Prod` (`ID_Prod`),
  KEY `Activo` (`Activo`),
  KEY `fk_inventario_movimientos_id_tmi` (`ID_TMI`),
  KEY `fk_inventario_movimientos_id_ma` (`ID_MA`),
  KEY `fk_inventario_movimientos_id_modulo` (`ID_Modulo`),
  CONSTRAINT `fk_inventario_movimientos_id_ma` FOREIGN KEY (`ID_MA`) REFERENCES `inventario_multialmacen` (`ID_MA`) ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_movimientos_id_modulo` FOREIGN KEY (`ID_Modulo`) REFERENCES `cat_modulos` (`ID_Modulo`) ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_movimientos_id_tmi` FOREIGN KEY (`ID_TMI`) REFERENCES `cat_tipos_movs_inventario` (`ID_TMI`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'inventario_multialmacen'
CREATE TABLE `inventario_multialmacen` (
  `ID_MA` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Almacen` int unsigned NOT NULL,
  `ID_Inventario` int unsigned NOT NULL,
  `RFC_Propietario` varchar(13) DEFAULT NULL COMMENT 'Diferenciador Para Consignas',
  `Stock_Min` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `Stock_Max` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `Existencia` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `Ubicacion` varchar(50) DEFAULT NULL,
  `PXS` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `PXR` decimal(10,4) NOT NULL DEFAULT '0.0000',
  `CPD` decimal(10,4) DEFAULT NULL COMMENT 'Consumo Diario Promedio',
  `DSS` decimal(10,4) DEFAULT NULL COMMENT 'Dias Stock Seguridad',
  `DTS` decimal(10,4) DEFAULT NULL COMMENT 'Dias Tiempo Surtido',
  `PR` decimal(10,4) DEFAULT NULL COMMENT 'PUNTO DE REORDEN (DINAMICO)',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_MA`),
  UNIQUE KEY `Almacen_Catalogo` (`RFC_Propietario`,`ID_Almacen`,`ID_Inventario`) USING BTREE,
  KEY `RFC_Propietario` (`RFC_Propietario`),
  KEY `fk_inventario_multialmacen_id_almacen` (`ID_Almacen`),
  KEY `fk_inventario_multialmacen_id_inventario` (`ID_Inventario`),
  CONSTRAINT `fk_inventario_multialmacen_id_almacen` FOREIGN KEY (`ID_Almacen`) REFERENCES `almacenes` (`ID_Almacen`) ON UPDATE CASCADE,
  CONSTRAINT `fk_inventario_multialmacen_id_inventario` FOREIGN KEY (`ID_Inventario`) REFERENCES `inventario` (`ID_Inventario`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'menus'
CREATE TABLE `menus` (
  `ID_Menu` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Sucursal` int unsigned NOT NULL,
  `Descripcion` varchar(250) NOT NULL,
  `Fecha_Inicio` date NOT NULL,
  `Fecha_Fin` date NOT NULL,
  `Activo` int NOT NULL,
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Menu`),
  KEY `fk_menus_id_sucursal` (`ID_Sucursal`),
  CONSTRAINT `fk_menus_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 COMMENT='Definiciones de Menus Sucursales ';

-- Create syntax for TABLE 'menus_categorias'
CREATE TABLE `menus_categorias` (
  `ID_MC` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_MCS` int unsigned DEFAULT NULL,
  `ID_Menu` int unsigned NOT NULL,
  `ID_TMC` int unsigned DEFAULT NULL,
  `ID_Categoria` int unsigned DEFAULT NULL,
  `ID_Almacen` int unsigned DEFAULT NULL,
  `Descripcion` varchar(250) NOT NULL,
  `Icon` varchar(250) DEFAULT NULL,
  `Orden` int NOT NULL DEFAULT '0',
  `Terminal` int NOT NULL DEFAULT '0',
  `Activo` int NOT NULL,
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_MC`),
  KEY `fk_menus_categorias_id_mcs` (`ID_MCS`),
  KEY `fk_menus_categorias_id_menu` (`ID_Menu`),
  KEY `fk_menus_categorias_id_tmc` (`ID_TMC`),
  KEY `fk_menus_categorias_id_categoria` (`ID_Categoria`),
  KEY `fk_menus_categorias_id_almacen` (`ID_Almacen`),
  CONSTRAINT `fk_menus_categorias_id_almacen` FOREIGN KEY (`ID_Almacen`) REFERENCES `almacenes` (`ID_Almacen`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_menus_categorias_id_categoria` FOREIGN KEY (`ID_Categoria`) REFERENCES `cat_categorias` (`ID_Categoria`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_menus_categorias_id_mcs` FOREIGN KEY (`ID_MCS`) REFERENCES `menus_categorias` (`ID_MC`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_menus_categorias_id_menu` FOREIGN KEY (`ID_Menu`) REFERENCES `menus` (`ID_Menu`) ON UPDATE CASCADE,
  CONSTRAINT `fk_menus_categorias_id_tmc` FOREIGN KEY (`ID_TMC`) REFERENCES `cat_tipos_menu_categoria` (`ID_TMC`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=latin1 COMMENT='Constructor de Categorias para Menus';

-- Create syntax for TABLE 'menus_productos'
CREATE TABLE `menus_productos` (
  `ID_MP` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_MC` int unsigned NOT NULL,
  `ID_Menu` int unsigned NOT NULL,
  `ID_Inventario` int unsigned NOT NULL,
  `Precio_Publico` decimal(14,4) NOT NULL DEFAULT '0.0000',
  `Orden` int NOT NULL DEFAULT '0',
  `ID_Almacen_Print` int unsigned DEFAULT NULL,
  `Activo` int NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  `JsonObject` mediumtext,
  PRIMARY KEY (`ID_MP`),
  KEY `fk_menus_productos_id_mc` (`ID_MC`),
  KEY `fk_menus_productos_id_menu` (`ID_Menu`),
  KEY `fk_menus_productos_id_inventario` (`ID_Inventario`),
  KEY `fk_menus_productos_id_almacen_print` (`ID_Almacen_Print`),
  CONSTRAINT `fk_menus_productos_id_almacen_print` FOREIGN KEY (`ID_Almacen_Print`) REFERENCES `almacenes` (`ID_Almacen`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_menus_productos_id_inventario` FOREIGN KEY (`ID_Inventario`) REFERENCES `inventario` (`ID_Inventario`) ON UPDATE CASCADE,
  CONSTRAINT `fk_menus_productos_id_mc` FOREIGN KEY (`ID_MC`) REFERENCES `menus_categorias` (`ID_MC`) ON UPDATE CASCADE,
  CONSTRAINT `fk_menus_productos_id_menu` FOREIGN KEY (`ID_Menu`) REFERENCES `menus` (`ID_Menu`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=282 DEFAULT CHARSET=latin1 COMMENT='Platillos para Menus desde Inventario';

-- Create syntax for TABLE 'migrations'
CREATE TABLE `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create syntax for TABLE 'password_resets'
CREATE TABLE `password_resets` (
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  KEY `password_resets_email_index` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create syntax for TABLE 'periodos'
CREATE TABLE `periodos` (
  `ID_Periodo` int unsigned NOT NULL AUTO_INCREMENT,
  `RFC_Empresa` varchar(13) NOT NULL,
  `Antiguedad` int unsigned NOT NULL COMMENT 'Dias',
  `Year` int unsigned NOT NULL,
  `ID_Mes` int unsigned NOT NULL,
  `Fecha_Inicio` datetime NOT NULL,
  `Fecha_Fin` datetime NOT NULL,
  `Auditar` tinyint(1) NOT NULL DEFAULT '0',
  `Fecha_Auditoria` datetime DEFAULT NULL,
  `Cerrado` tinyint(1) NOT NULL DEFAULT '0',
  `Fecha_Cierre` datetime DEFAULT NULL,
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Periodo`),
  UNIQUE KEY `uk_periodo` (`RFC_Empresa`,`Year`,`ID_Mes`) USING BTREE,
  KEY `Year` (`Year`),
  KEY `fk_periodos_id_mes` (`ID_Mes`),
  CONSTRAINT `fk_periodos_id_mes` FOREIGN KEY (`ID_Mes`) REFERENCES `cat_meses` (`ID_Mes`) ON UPDATE CASCADE,
  CONSTRAINT `fk_periodos_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'personal_access_tokens'
CREATE TABLE `personal_access_tokens` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tokenable_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tokenable_id` bigint unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `abilities` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `last_used_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `personal_access_tokens_token_unique` (`token`),
  KEY `personal_access_tokens_tokenable_type_tokenable_id_index` (`tokenable_type`,`tokenable_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create syntax for TABLE 'recetas'
CREATE TABLE `recetas` (
  `ID_Receta` int NOT NULL AUTO_INCREMENT,
  `ID_Inventario_M` int unsigned NOT NULL,
  `Cantidad` decimal(10,4) NOT NULL,
  `ID_Inventario_D` int unsigned NOT NULL,
  `ID_Almacen_Print` int DEFAULT NULL,
  `Costo_Unitario` decimal(14,4) DEFAULT NULL,
  `Precio_Lista` decimal(14,4) DEFAULT NULL,
  `Por_Descuento` decimal(10,4) DEFAULT NULL,
  `Descuento` decimal(14,4) DEFAULT NULL,
  `Precio_Unitario` decimal(14,4) DEFAULT NULL,
  `Por_Margen` decimal(10,4) DEFAULT NULL,
  `Margen` decimal(14,4) DEFAULT NULL,
  `Subtotal` decimal(14,2) DEFAULT NULL,
  `Impuestos_Trasladados` decimal(14,2) DEFAULT NULL,
  `Total` decimal(14,2) DEFAULT NULL,
  `Activo` int NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(100) NOT NULL,
  `IP_Alta` varchar(15) NOT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Receta`),
  KEY `fk_recetas_id_inventario_m` (`ID_Inventario_M`),
  KEY `fk_recetas_id_inventario_d` (`ID_Inventario_D`),
  CONSTRAINT `fk_recetas_id_inventario_d` FOREIGN KEY (`ID_Inventario_D`) REFERENCES `inventario` (`ID_Inventario`) ON UPDATE CASCADE,
  CONSTRAINT `fk_recetas_id_inventario_m` FOREIGN KEY (`ID_Inventario_M`) REFERENCES `inventario` (`ID_Inventario`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'requisiciones'
CREATE TABLE `requisiciones` (
  `ID_RQ` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_TipoRQ` int unsigned NOT NULL DEFAULT '1',
  `RFC_Empresa` varchar(13) NOT NULL,
  `ID_Sucursal` int unsigned NOT NULL,
  `ID_Almacen` int unsigned NOT NULL,
  `Folio` varchar(10) NOT NULL,
  `Descripcion` varchar(250) DEFAULT NULL,
  `ID_ECP` int unsigned DEFAULT NULL,
  `ID_Paquete` int unsigned DEFAULT NULL,
  `ID_Usuario` int unsigned NOT NULL,
  `Fecha_Solicitud` datetime NOT NULL,
  `Fecha_Entrega` datetime DEFAULT NULL,
  `Observaciones` varchar(250) DEFAULT NULL,
  `ID_Status` int unsigned NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime NOT NULL,
  `Usr_Alta` varchar(50) DEFAULT NULL,
  `IP_Alta` varchar(15) DEFAULT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_RQ`),
  KEY `ID_Usuario` (`ID_Usuario`),
  KEY `ID_Almacen` (`ID_Almacen`),
  KEY `ID_Status` (`ID_Status`),
  KEY `fk_requisiciones_id_tiporq` (`ID_TipoRQ`),
  KEY `fk_requisiciones_rfc_empresa` (`RFC_Empresa`),
  KEY `fk_requisiciones_id_sucursal` (`ID_Sucursal`),
  CONSTRAINT `fk_requisiciones_id_almacen` FOREIGN KEY (`ID_Almacen`) REFERENCES `almacenes` (`ID_Almacen`) ON UPDATE CASCADE,
  CONSTRAINT `fk_requisiciones_id_status` FOREIGN KEY (`ID_Status`) REFERENCES `cat_status_requisiciones` (`ID_Status`) ON UPDATE CASCADE,
  CONSTRAINT `fk_requisiciones_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE,
  CONSTRAINT `fk_requisiciones_id_tiporq` FOREIGN KEY (`ID_TipoRQ`) REFERENCES `cat_tipos_requisiciones` (`ID_TipoRQ`) ON UPDATE CASCADE,
  CONSTRAINT `fk_requisiciones_id_usuario` FOREIGN KEY (`ID_Usuario`) REFERENCES `users` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_requisiciones_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'requisiciones_productos'
CREATE TABLE `requisiciones_productos` (
  `ID_PRQ` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_RQ` int unsigned NOT NULL,
  `ID_Inventario` int unsigned NOT NULL,
  `Catalogo` varchar(16) NOT NULL,
  `Can_RQ` decimal(12,6) NOT NULL DEFAULT '0.000000',
  `Can_OC` decimal(12,6) NOT NULL DEFAULT '0.000000',
  `Can_TR` decimal(12,6) NOT NULL DEFAULT '0.000000',
  `Can_US` decimal(12,6) DEFAULT NULL COMMENT 'Cantidad USada en paciente',
  `Can_RT` decimal(12,6) DEFAULT NULL COMMENT 'Cantidad RTornada a Almacen',
  `Can_ET` decimal(12,6) DEFAULT NULL,
  `ID_ECP` int DEFAULT NULL,
  `ID_Partida` int DEFAULT NULL,
  `ID_Cargo` int DEFAULT NULL,
  `Observaciones` text,
  `ID_Status` int unsigned NOT NULL DEFAULT '1',
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Alta` datetime DEFAULT NULL,
  `Usr_Alta` varchar(50) DEFAULT NULL,
  `IP_Alta` varchar(15) DEFAULT NULL,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(50) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_PRQ`),
  KEY `ID_RQ` (`ID_RQ`),
  KEY `ID_Inventario` (`ID_Inventario`),
  KEY `ID_Status` (`ID_Status`),
  KEY `ID_ECP` (`ID_ECP`,`ID_Partida`,`ID_Cargo`),
  CONSTRAINT `fk_requisiciones_productos_id_inventario` FOREIGN KEY (`ID_Inventario`) REFERENCES `inventario` (`ID_Inventario`) ON UPDATE CASCADE,
  CONSTRAINT `fk_requisiciones_productos_id_rq` FOREIGN KEY (`ID_RQ`) REFERENCES `requisiciones` (`ID_RQ`) ON UPDATE CASCADE,
  CONSTRAINT `fk_requisiciones_productos_id_status` FOREIGN KEY (`ID_Status`) REFERENCES `cat_status_requisiciones` (`ID_Status`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'sucursales'
CREATE TABLE `sucursales` (
  `ID_Sucursal` int unsigned NOT NULL AUTO_INCREMENT,
  `RFC_Empresa` varchar(13) NOT NULL,
  `Sucursal` varchar(50) NOT NULL,
  `Calle` varchar(40) NOT NULL,
  `No_Ext` varchar(20) NOT NULL,
  `No_Int` varchar(20) DEFAULT NULL,
  `Colonia` varchar(60) NOT NULL,
  `ID_Pais` int unsigned NOT NULL DEFAULT '1',
  `ID_Estado` int unsigned NOT NULL,
  `ID_Municipio` int unsigned NOT NULL,
  `Codigo_Postal` varchar(5) NOT NULL,
  `Latitud` varchar(20) NOT NULL,
  `Longitud` varchar(20) NOT NULL,
  `CLUES` varchar(11) DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL,
  `IP_Mod` varchar(15) NOT NULL,
  PRIMARY KEY (`ID_Sucursal`),
  KEY `ID_Pais` (`ID_Pais`),
  KEY `ID_Estado` (`ID_Estado`),
  KEY `ID_Municipio` (`ID_Municipio`),
  KEY `Codigo_Postal` (`Codigo_Postal`),
  KEY `fk_sucursales_rfc_empresa` (`RFC_Empresa`),
  CONSTRAINT `fk_sucursales_id_estado` FOREIGN KEY (`ID_Estado`) REFERENCES `cat_estados` (`ID_Estado`) ON UPDATE CASCADE,
  CONSTRAINT `fk_sucursales_id_municipio` FOREIGN KEY (`ID_Municipio`) REFERENCES `cat_municipios` (`ID_Municipio`) ON UPDATE CASCADE,
  CONSTRAINT `fk_sucursales_id_pais` FOREIGN KEY (`ID_Pais`) REFERENCES `cat_paises` (`ID_Pais`) ON UPDATE CASCADE,
  CONSTRAINT `fk_sucursales_rfc_empresa` FOREIGN KEY (`RFC_Empresa`) REFERENCES `empresas` (`RFC`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'sucursales_niveles'
CREATE TABLE `sucursales_niveles` (
  `ID_Nivel` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Sucursal` int unsigned NOT NULL,
  `Nivel` varchar(30) NOT NULL,
  `Orden` int NOT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID_Nivel`),
  KEY `fk_sucursales_niveles_id_sucursal` (`ID_Sucursal`),
  CONSTRAINT `fk_sucursales_niveles_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'sys_error'
CREATE TABLE `sys_error` (
  `ID_Error` int NOT NULL AUTO_INCREMENT,
  `archivo` varchar(255) NOT NULL,
  `xaction` varchar(255) NOT NULL DEFAULT '',
  `xactionRes` varchar(255) NOT NULL DEFAULT '',
  `strResult` text,
  `strLog` longtext,
  `Fecha_Mod` datetime NOT NULL,
  `Usr_Mod` varchar(100) NOT NULL DEFAULT '',
  `IP_Mod` varchar(15) NOT NULL DEFAULT '',
  PRIMARY KEY (`ID_Error`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'sys_folios'
CREATE TABLE `sys_folios` (
  `ID_Folio` int unsigned NOT NULL AUTO_INCREMENT,
  `ID_Modulo` int unsigned NOT NULL,
  `Modulo` varchar(5) NOT NULL,
  `Folio_Inicia` int NOT NULL,
  `Folio_Termina` int NOT NULL,
  `Ultimo_Doc` int NOT NULL,
  `Fecha_UD` date NOT NULL,
  `ID_UD` int NOT NULL,
  `Descripcion` varchar(100) NOT NULL DEFAULT '',
  PRIMARY KEY (`ID_Folio`),
  KEY `fk_ec_id_modulo` (`ID_Modulo`),
  CONSTRAINT `fk_ec_id_modulo` FOREIGN KEY (`ID_Modulo`) REFERENCES `cat_modulos` (`ID_Modulo`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'sys_perfiles'
CREATE TABLE `sys_perfiles` (
  `id_perfil` int NOT NULL,
  `perfil` varchar(255) NOT NULL,
  PRIMARY KEY (`id_perfil`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create syntax for TABLE 'users'
CREATE TABLE `users` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ap_paterno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ap_materno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `PIN` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ID_Perfil` int DEFAULT NULL,
  `ID_Sucursal` int unsigned DEFAULT NULL,
  `phone` bigint DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `about_me` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `remember_token` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `Activo` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`),
  UNIQUE KEY `unk_users_pin` (`PIN`),
  KEY `fk_users_id_perfil` (`ID_Perfil`),
  KEY `fk_users_id_sucursal` (`ID_Sucursal`),
  CONSTRAINT `fk_users_id_perfil` FOREIGN KEY (`ID_Perfil`) REFERENCES `sys_perfiles` (`id_perfil`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_users_id_sucursal` FOREIGN KEY (`ID_Sucursal`) REFERENCES `sucursales` (`ID_Sucursal`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create syntax for VIEW 'v_ban_cuentas_fp'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_ban_cuentas_fp`
AS SELECT
   `ban_cuentas_fp`.`ID_BCFP` AS `ID_BCFP`,
   `ban_cuentas_fp`.`ID_BC` AS `ID_BC`,
   `ban_cuentas_fp`.`ID_FP` AS `ID_FP`,
   `ban_cuentas`.`Leyenda` AS `Leyenda`,
   `cat_formas_pago`.`Forma_Pago` AS `Forma_Pago`
FROM ((`ban_cuentas_fp` left join `ban_cuentas` on((`ban_cuentas_fp`.`ID_BC` = `ban_cuentas`.`ID_BC`))) left join `cat_formas_pago` on((`ban_cuentas_fp`.`ID_FP` = `cat_formas_pago`.`ID_FP`))) where ((`ban_cuentas_fp`.`Activo` = 1) and (`ban_cuentas`.`Activo` = 1));

-- Create syntax for VIEW 'v_cajas'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_cajas`
AS SELECT
   `cajas`.`ID_Caja` AS `ID_Caja`,
   `cajas`.`ID_Usuario` AS `ID_Usuario`,
   `cajas`.`ID_Sucursal` AS `ID_Sucursal`,
   `cajas`.`ID_Almacen` AS `ID_Almacen`,
   `cajas`.`IP_ImpCV` AS `IP_ImpCV`,
   `sucursales`.`Sucursal` AS `Sucursal`,
   `cajas`.`Descripcion` AS `Descripcion`,
   `cajas`.`EnUso` AS `EnUso`,
   `users`.`username` AS `Usuario_EnUso`,
   `cajas`.`Activo` AS `Activo`
FROM ((`cajas` left join `sucursales` on((`sucursales`.`ID_Sucursal` = `cajas`.`ID_Sucursal`))) left join `users` on((`users`.`id` = `cajas`.`ID_Usuario`)));

-- Create syntax for VIEW 'v_cajas_bc'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_cajas_bc`
AS SELECT
   `cajas_bc`.`ID_CBC` AS `ID_CBC`,
   `cajas_bc`.`ID_Caja` AS `ID_Caja`,
   `cajas_bc`.`ID_BC` AS `ID_BC`,
   `cajas`.`Descripcion` AS `Caja`,
   `ban_cuentas`.`Leyenda` AS `Leyenda`
FROM ((`cajas_bc` join `cajas` on((`cajas_bc`.`ID_Caja` = `cajas`.`ID_Caja`))) join `ban_cuentas` on((`cajas_bc`.`ID_BC` = `ban_cuentas`.`ID_BC`))) where ((`cajas_bc`.`Activo` = 1) and (`cajas`.`Activo` = 1) and (`ban_cuentas`.`Activo` = 1));

-- Create syntax for VIEW 'v_cajas_diario'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_cajas_diario`
AS SELECT
   `cajas_diario`.`ID_CD` AS `ID_CD`,
   `cajas_diario`.`ID_Caja` AS `ID_Caja`,
   `cajas_diario`.`ID_Usuario` AS `ID_Usuario`,upper(`cajas`.`Descripcion`) AS `Caja`,upper(`users`.`username`) AS `Usuario_Inicio`,
   `cajas_diario`.`Fecha` AS `Fecha`,
   `cajas_diario`.`Folio` AS `Folio`,
   `cajas_diario`.`Fecha_Inicio` AS `Fecha_Inicio`,
   `cajas_diario`.`Fecha_Corte` AS `Fecha_Corte`,
   `cajas_diario`.`Monto_Inicio` AS `Monto_Inicio`,
   `cajas_diario`.`Monto_Corte` AS `Monto_Corte`,
   `cajas_diario`.`Dec_Efectivo` AS `Dec_Efectivo`,
   `cajas_diario`.`Dec_TDC` AS `Dec_TDC`,
   `cajas_diario`.`Dec_TDD` AS `Dec_TDD`,
   `cajas_diario`.`Dec_Transferencia` AS `Dec_Transferencia`,
   `cajas_diario`.`Dec_Vales` AS `Dec_Vales`,
   `cajas_diario`.`Dec_Otros` AS `Dec_Otros`,
   `cajas_diario`.`Dec_Total` AS `Dec_Total`,
   `cajas_diario`.`Diferencia` AS `Diferencia`,
   `cajas_diario`.`ID_Usuario_Alta` AS `ID_Usuario_Alta`,coalesce(`users_3`.`username`,'') AS `Usuario_Alta`,
   `cajas_diario`.`ID_Usuario_Corte` AS `ID_Usuario_Corte`,coalesce(`users_2`.`username`,'') AS `Usuario_Corte`,
   `cajas_diario`.`Vale_Impreso` AS `Vale_Impreso`,
   `cajas_diario`.`ID_Status` AS `ID_Status`,
   `cat_status_cajas`.`Status` AS `Status`,
   `cajas_diario`.`Activo` AS `Activo`
FROM (((((`cajas_diario` left join `users` on((`users`.`id` = `cajas_diario`.`ID_Usuario`))) left join `users` `users_2` on((`users_2`.`id` = `cajas_diario`.`ID_Usuario_Corte`))) left join `users` `users_3` on((`users_3`.`id` = `cajas_diario`.`ID_Usuario_Alta`))) left join `cat_status_cajas` on((`cat_status_cajas`.`ID_Status` = `cajas_diario`.`ID_Status`))) left join `cajas` on((`cajas`.`ID_Caja` = `cajas_diario`.`ID_Caja`))) where (`cajas_diario`.`Activo` = 1) order by `cajas_diario`.`ID_CD` desc;

-- Create syntax for VIEW 'v_cajas_diario_totales'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_cajas_diario_totales`
AS SELECT
   `cajas_diario_movs`.`ID_CD` AS `ID_CD`,
   `cajas_diario_movs`.`ID_Concepto` AS `ID_Concepto`,
   `cajas_diario_movs`.`ID_FP` AS `ID_FP`,
   `cajas_diario_movs`.`ID_TT` AS `ID_TT`,
   `cat_cajas_conceptos`.`Concepto` AS `Concepto`,
   `cat_cajas_conceptos`.`Signo` AS `Signo`,
   `cat_formas_pago`.`Forma_Pago` AS `Forma_Pago`,
   `cat_tipos_tarjeta`.`Tipo_Tarjeta` AS `Tipo_Tarjeta`,sum(`cajas_diario_movs`.`Monto_S`) AS `Monto`
FROM (((`cajas_diario_movs` join `cat_cajas_conceptos` on((`cat_cajas_conceptos`.`ID_Concepto` = `cajas_diario_movs`.`ID_Concepto`))) join `cat_formas_pago` on((`cat_formas_pago`.`ID_FP` = `cajas_diario_movs`.`ID_FP`))) left join `cat_tipos_tarjeta` on((`cat_tipos_tarjeta`.`ID_TT` = `cajas_diario_movs`.`ID_TT`))) where (`cajas_diario_movs`.`Activo` = 1) group by `cajas_diario_movs`.`ID_CD`,`cajas_diario_movs`.`ID_Concepto`,`cajas_diario_movs`.`ID_FP`,`cajas_diario_movs`.`ID_TT` order by `cajas_diario_movs`.`ID_CD` desc;

-- Create syntax for VIEW 'v_cajas_movs'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_cajas_movs`
AS SELECT
   `cajas_diario_movs`.`ID_CDM` AS `ID_CDM`,
   `cajas_diario_movs`.`ID_CD` AS `ID_CD`,
   `cajas_diario_movs`.`ID_Caja` AS `ID_Caja`,
   `cajas_diario_movs`.`Fecha` AS `Fecha`,
   `cajas_diario_movs`.`Hora` AS `Hora`,
   `cajas_diario_movs`.`ID_Concepto` AS `ID_Concepto`,coalesce(`cajas_diario_movs`.`ID_EC`,'') AS `ID_EC`,coalesce(`cajas_diario_movs`.`RFC`,'') AS `RFC`,
   `cajas_diario_movs`.`ID_FP` AS `ID_FP`,coalesce(`cajas`.`Descripcion`,'') AS `Caja`,coalesce(`cajas_diario_movs`.`Referencia`,'') AS `Referencia`,
   `cajas_diario_movs`.`Monto` AS `Monto`,
   `cajas_diario_movs`.`Observaciones` AS `Observaciones`,
   `cat_cajas_conceptos`.`Concepto` AS `Concepto`,coalesce(`ec`.`Folio`,'') AS `Folio`,coalesce(`ec_cuentas`.`Descripcion`,'') AS `Cuenta`,
   `cat_formas_pago`.`Forma_Pago` AS `Forma_Pago`,
   `cajas_diario_movs`.`Activo` AS `Activo`
FROM (((((`cajas_diario_movs` join `cat_cajas_conceptos` on((`cat_cajas_conceptos`.`ID_Concepto` = `cajas_diario_movs`.`ID_Concepto`))) left join `cajas` on((`cajas`.`ID_Caja` = `cajas_diario_movs`.`ID_Caja`))) left join `ec` on((`ec`.`ID_EC` = `cajas_diario_movs`.`ID_EC`))) left join `ec_cuentas` on(((`ec_cuentas`.`RFC_Cuenta` = `cajas_diario_movs`.`RFC`) and (`ec_cuentas`.`ID_EC` = `cajas_diario_movs`.`ID_EC`)))) join `cat_formas_pago` on((`cat_formas_pago`.`ID_FP` = `cajas_diario_movs`.`ID_FP`))) where (`cajas_diario_movs`.`Activo` = 1) order by `cajas_diario_movs`.`ID_CD` desc,`cajas_diario_movs`.`Fecha`,`cajas_diario_movs`.`Hora`;

-- Create syntax for VIEW 'v_contribuyentes'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_contribuyentes`
AS SELECT
   `contribuyentes`.`RFC` AS `RFC`,
   `contribuyentes`.`ID_Personalidad` AS `ID_Personalidad`,
   `contribuyentes`.`ID_RF` AS `ID_RF`,
   `contribuyentes`.`Nombre_Contribuyente` AS `Nombre_Contribuyente`,
   `cpd`.`Personalidad` AS `Personalidad`,
   `crf`.`Descripcion` AS `Regimen_Fiscal`,
   `contribuyentes`.`Fecha_Nacimiento` AS `Fecha_Nacimiento`,
   `contribuyentes`.`Calle` AS `Calle`,
   `contribuyentes`.`No_Ext` AS `No_Ext`,
   `contribuyentes`.`No_Int` AS `No_Int`,
   `contribuyentes`.`Colonia` AS `Colonia`,
   `contribuyentes`.`ID_Municipio` AS `ID_Municipio`,
   `cm`.`Municipio` AS `Municipio`,
   `contribuyentes`.`ID_Estado` AS `ID_Estado`,
   `ce`.`Estado` AS `Estado`,
   `contribuyentes`.`ID_Pais` AS `ID_Pais`,
   `cp`.`Pais` AS `Pais`,
   `contribuyentes`.`Codigo_Postal` AS `Codigo_Postal`,
   `contribuyentes`.`FIEL` AS `FIEL`,
   `contribuyentes`.`noCertificado` AS `noCertificado`,
   `contribuyentes`.`Latitud` AS `Latitud`,
   `contribuyentes`.`Longitud` AS `Longitud`,
   `contribuyentes`.`ID_LN` AS `ID_LN`,
   `contribuyentes`.`Activo` AS `Activo`
FROM (((((`contribuyentes` left join `cat_estados` `ce` on((`ce`.`ID_Estado` = `contribuyentes`.`ID_Estado`))) left join `cat_municipios` `cm` on((`cm`.`ID_Municipio` = `contribuyentes`.`ID_Municipio`))) left join `cat_paises` `cp` on((`cp`.`ID_Pais` = `contribuyentes`.`ID_Pais`))) left join `cat_personalidades` `cpd` on((`cpd`.`ID_Personalidad` = `contribuyentes`.`ID_Personalidad`))) left join `cat_rf` `crf` on((`crf`.`ID_RF` = `contribuyentes`.`ID_RF`))) order by `contribuyentes`.`RFC`;

-- Create syntax for VIEW 'v_ec'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_ec`
AS SELECT
   `ec`.`ID_EC` AS `ID_EC`,
   `ec`.`RFC_Empresa` AS `RFC_Empresa`,
   `s`.`Sucursal` AS `Sucursal`,
   `u`.`username` AS `username`,
   `u`.`name` AS `name`,
   `u`.`ap_paterno` AS `ap_paterno`,
   `u`.`ap_materno` AS `ap_materno`,
   `cs`.`Status` AS `Status`,
   `cs`.`Descripcion` AS `Descripcion`,
   `ec`.`CVE_EC` AS `CVE_EC`,
   `ec`.`Num_Personas` AS `Num_Personas`,
   `ec`.`Folio` AS `Folio`,
   `ec`.`Fecha_Ingreso` AS `Fecha_Ingreso`,
   `ec`.`Fecha_Salida` AS `Fecha_Salida`,
   `ec`.`ID_Sucursal` AS `ID_Sucursal`,
   `ec`.`ID_Usuario` AS `ID_Usuario`,
   `ec`.`ID_Moneda` AS `ID_Moneda`,
   `ec`.`TC` AS `TC`,
   `ec`.`T_Cargos` AS `T_Cargos`,
   `ec`.`T_Bonificaciones` AS `T_Bonificaciones`,
   `ec`.`TB_Cargos` AS `TB_Cargos`,
   `ec`.`Descuento` AS `Descuento`,
   `ec`.`TN_Cargos` AS `TN_Cargos`,
   `ec`.`Impuestos_Trasladados` AS `Impuestos_Trasladados`,
   `ec`.`Total_Cargos` AS `Total_Cargos`,
   `ec`.`Total_Abonos` AS `Total_Abonos`,
   `ec`.`Propina` AS `Propina`,
   `ec`.`Tarjeta_Cliente` AS `Tarjeta_Cliente`,
   `ec`.`Observaciones` AS `Observaciones`,
   `ec`.`Impresiones` AS `Impresiones`,
   `ec`.`Folio_Fact` AS `Folio_Fact`,
   `ec`.`Total_CXC` AS `Total_CXC`,
   `ec`.`Saldo` AS `Saldo`,
   `ec`.`Facturable` AS `Facturable`,
   `ec`.`Facturado` AS `Facturado`,
   `ec`.`PXF` AS `PXF`,
   `ec`.`Firmado` AS `Firmado`,
   `ec`.`Nota_Auditoria` AS `Nota_Auditoria`,
   `ec`.`ID_Status` AS `ID_Status`,
   `ec`.`Activo` AS `Activo`,
   `ec`.`ID_ECL` AS `ID_ECL`,
   `ec`.`Fecha_U_Cargo` AS `Fecha_U_Cargo`,
   `ec`.`Fecha_U_Abono` AS `Fecha_U_Abono`,
   `ec`.`Fecha_U_Factura` AS `Fecha_U_Factura`,
   `ec`.`Actualizar` AS `Actualizar`,
   `ec`.`Fecha_Actualizacion` AS `Fecha_Actualizacion`,
   `ec`.`ATC_C_Fecha` AS `ATC_C_Fecha`,
   `ec`.`ATC_V_Fecha` AS `ATC_V_Fecha`,
   `ec`.`Fecha_Cierre` AS `Fecha_Cierre`,
   `ec`.`Fecha_Alta` AS `Fecha_Alta`,
   `ec`.`Usr_Alta` AS `Usr_Alta`,
   `ec`.`IP_Alta` AS `IP_Alta`,
   `ec`.`Fecha_Mod` AS `Fecha_Mod`,
   `ec`.`Usr_Mod` AS `Usr_Mod`,
   `ec`.`IP_Mod` AS `IP_Mod`
FROM (((`ec` join `sucursales` `s` on((`ec`.`ID_Sucursal` = `s`.`ID_Sucursal`))) join `users` `u` on((`ec`.`ID_Usuario` = `u`.`id`))) join `cat_status_ec` `cs` on((`ec`.`ID_Status` = `cs`.`ID_Status`)));

-- Create syntax for VIEW 'v_ec_bonificaciones_totales'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_ec_bonificaciones_totales`
AS SELECT
   `ec_cargos`.`ID_EC` AS `ID_EC`,coalesce(sum(`ec_cargos`.`Total_Cargo`),0) AS `Total_Bonificaciones_BD`
FROM `ec_cargos` where ((`ec_cargos`.`ID_Tipo_Cargo` = 2) and (`ec_cargos`.`Activo` = 1)) group by `ec_cargos`.`ID_EC`;

-- Create syntax for VIEW 'v_ec_cargos'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_ec_cargos`
AS SELECT
   `ec_cargos`.`ID_Cargo` AS `ID_Cargo`,
   `ec_cargos`.`ID_Tipo_Cargo` AS `ID_Tipo_Cargo`,
   `ec_cargos`.`ID_Cargo_Bon` AS `ID_Cargo_Bon`,
   `ec_cargos`.`ID_EC` AS `ID_EC`,
   `ec_cargos`.`ID_Convenio` AS `ID_Convenio`,
   `ec_cargos`.`ID_Partida` AS `ID_Partida`,
   `ec_cargos`.`ID_Partida_Paquete` AS `ID_Partida_Paquete`,
   `ec_cargos`.`Fecha_Aplicacion` AS `Fecha_Aplicacion`,
   `ec_cargos`.`No_Cargo` AS `No_Cargo`,
   `ec_cargos`.`ID_Sucursal` AS `ID_Sucursal`,
   `ec_cargos`.`ID_Almacen` AS `ID_Almacen`,
   `ec_cargos`.`ID_Inventario` AS `ID_Inventario`,
   `ec_cargos`.`Cantidad` AS `Cantidad`,
   `ec_cargos`.`Costo` AS `Costo`,
   `ec_cargos`.`Precio_Lista` AS `Precio_Lista`,
   `ec_cargos`.`Por_Descuento` AS `Por_Descuento`,
   `ec_cargos`.`Descuento` AS `Descuento`,
   `ec_cargos`.`Precio_Unitario` AS `Precio_Unitario`,
   `ec_cargos`.`Impuestos_Trasladados` AS `Impuestos_Trasladados`,
   `ec_cargos`.`Total_Cargo` AS `Total_Cargo`,(`ec_cargos`.`Total_Cargo` * `cat_tipos_ec_cargo`.`Valor`) AS `Total_Cargo_Signo`,
   `cat_tipos_ec_cargo`.`Tipo_Cargo` AS `Tipo_Cargo`,
   `ec_cargos`.`Observaciones` AS `Observaciones`,
   `ec_cargos`.`Auditada` AS `Auditada`,
   `ec_cargos`.`Activo` AS `Activo`,
   `sucursales`.`Sucursal` AS `Sucursal`,
   `almacenes`.`Almacen` AS `Almacen`,
   `cat_tipos_inventario`.`Tipo_Inventario` AS `Tipo_Inventario`,
   `inventario`.`ID_TIN` AS `ID_TIN`,
   `inventario`.`Catalogo` AS `Catalogo`,
   `inventario`.`Concepto` AS `Concepto`,
   `v_ec_convenios`.`Descripcion` AS `Convenio`,
   `v_ec_convenios`.`No_Poliza` AS `No_Poliza`,
   `v_ec_convenios`.`RFC_Titular` AS `RFC_Titular`,
   `v_ec_convenios`.`Titular_Convenio` AS `Titular_Convenio`,
   `ec_cargos`.`Fecha_Mod` AS `Fecha_Mod`,
   `ec_cargos`.`Fecha_Alta` AS `Fecha_Alta`,
   `ec_cargos`.`Usr_Mod` AS `Usr_Mod`,
   `ec_cargos`.`Usr_Alta` AS `Usr_Alta`,
   `ec_cargos`.`IP_Mod` AS `IP_Mod`,
   `ec_cargos`.`IP_Alta` AS `IP_Alta`
FROM ((((((`ec_cargos` left join `cat_tipos_ec_cargo` on((`cat_tipos_ec_cargo`.`ID_Tipo_Cargo` = `ec_cargos`.`ID_Tipo_Cargo`))) left join `sucursales` on((`sucursales`.`ID_Sucursal` = `ec_cargos`.`ID_Sucursal`))) left join `almacenes` on((`almacenes`.`ID_Almacen` = `ec_cargos`.`ID_Almacen`))) left join `inventario` on((`inventario`.`ID_Inventario` = `ec_cargos`.`ID_Inventario`))) join `cat_tipos_inventario` on((`cat_tipos_inventario`.`ID_TIN` = `inventario`.`ID_TIN`))) left join `v_ec_convenios` on(((`v_ec_convenios`.`ID_Convenio` = `ec_cargos`.`ID_Convenio`) and (`v_ec_convenios`.`ID_EC` = `ec_cargos`.`ID_EC`)))) where (`ec_cargos`.`Activo` = 1);

-- Create syntax for VIEW 'v_ec_cargos_totales'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_ec_cargos_totales`
AS SELECT
   `a`.`ID_EC` AS `ID_EC`,round(sum((`a`.`Precio_Lista` * `a`.`Cantidad`)),4) AS `Subtotal_Bruto`,round(sum((`a`.`Descuento` * `a`.`Cantidad`)),4) AS `Descuento`,round((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))),4) AS `Subtotal_Menos_Desc`,coalesce(`b`.`Total_Bonificaciones_BD`,0) AS `Bonificaciones`,round(((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))) - coalesce(`b`.`Total_Bonificaciones_BD`,0)),4) AS `Subtotal_Neto`,sum(`a`.`Impuestos_Trasladados`) AS `Impuestos_Trasladados_BD`,round((((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))) - coalesce(`b`.`Total_Bonificaciones_BD`,0)) * 0.16),4) AS `Impuestos_Trasladados_Calculado`,round(((((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))) - coalesce(`b`.`Total_Bonificaciones_BD`,0)) * 0.16) - sum(`a`.`Impuestos_Trasladados`)),4) AS `Diff_Impuestos_Trasladados`,round((((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))) - coalesce(`b`.`Total_Bonificaciones_BD`,0)) + (((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))) - coalesce(`b`.`Total_Bonificaciones_BD`,0)) * 0.16)),4) AS `Total_Calculado`,round(((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))) + sum(`a`.`Impuestos_Trasladados`)),4) AS `Solo_Cargos_Calculado`,sum(`a`.`Total_Cargo`) AS `Solo_Cargos_BD`,round((((sum((`a`.`Precio_Lista` * `a`.`Cantidad`)) - sum((`a`.`Descuento` * `a`.`Cantidad`))) + sum(`a`.`Impuestos_Trasladados`)) - sum(`a`.`Total_Cargo`)),4) AS `Diff_Totales`
FROM (`ec_cargos` `a` left join `v_ec_bonificaciones_totales` `b` on((`a`.`ID_EC` = `b`.`ID_EC`))) where ((`a`.`ID_Tipo_Cargo` = 1) and (`a`.`Activo` = 1)) group by `a`.`ID_EC` order by `a`.`ID_EC`;

-- Create syntax for VIEW 'v_ec_convenios'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`177.229.205.14` SQL SECURITY DEFINER VIEW `v_ec_convenios`
AS SELECT
   `ecpc`.`ID_ECC` AS `ID_ECC`,
   `ecpc`.`ID_EC` AS `ID_EC`,
   `ecpc`.`ID_Convenio` AS `ID_Convenio`,upper(`c`.`Folio`) AS `Folio`,upper(`c`.`Descripcion`) AS `Descripcion`,upper(`ecpc`.`No_Poliza`) AS `No_Poliza`,
   `ecpc`.`Activo` AS `Activo`,upper(`c`.`RFC_Titular`) AS `RFC_Titular`,upper(`vc`.`Nombre_Contribuyente`) AS `Titular_Convenio`,
   `ecpc`.`Plan` AS `Plan`,
   `ecpc`.`Presupuesto_Autorizado` AS `Presupuesto_Autorizado`,
   `ecpc`.`Saldo` AS `Saldo`,
   `c`.`Fecha_Inicio` AS `Fecha_Inicio`,
   `c`.`Fecha_Fin` AS `Fecha_Fin`,
   `c`.`Por_Descuento` AS `Por_Descuento`,
   `c`.`Por_Descorche` AS `Por_Descorche`,
   `c`.`Factor_PFL` AS `Factor_PFL`,
   `ecpc`.`ID_Contrato` AS `ID_Contrato`,
   `ecpc`.`ID_Establecimiento` AS `ID_Establecimiento`,
   `ecpc`.`Fecha_Mod` AS `Fecha_Alta`,
   `ecpc`.`Usr_Mod` AS `Usr_Alta`
FROM ((`ec_convenios` `ecpc` join `convenios` `c` on((`c`.`ID_Convenio` = `ecpc`.`ID_Convenio`))) left join `v_contribuyentes` `vc` on((`vc`.`RFC` = `c`.`RFC_Titular`)));

-- Create syntax for VIEW 'v_ec_movimientos'
CREATE ALGORITHM=UNDEFINED DEFINER=`hgrests1_developer`@`189.188.139.115` SQL SECURITY DEFINER VIEW `v_ec_movimientos`
AS SELECT
   `ec_movimientos`.`ID_ECM` AS `ID_ECM`,
   `ec_movimientos`.`Fecha_Alta` AS `Fecha_Alta`,
   `ec_movimientos`.`ID_EC` AS `ID_EC`,
   `ec_movimientos`.`ID_ECC` AS `ID_ECC`,
   `ec_movimientos`.`ID_CD` AS `ID_CD`,
   `ec_movimientos`.`ID_Caja` AS `ID_Caja`,
   `ban_movimientos`.`ID_BM` AS `ID_BM`,
   `ban_movimientos`.`ID_BC` AS `ID_BC`,
   `cajas_diario_movs`.`ID_CDM` AS `ID_CDM`,
   `ban_movimientos`.`ID_TM` AS `ID_TM`,
   `ban_movimientos`.`ID_FP` AS `ID_FP`,
   `ban_movimientos`.`ID_TT` AS `ID_TT`,
   `cajas_diario`.`Folio` AS `Folio_Caja`,
   `cajas`.`Descripcion` AS `Caja`,
   `ban_cuentas`.`Leyenda` AS `Cuenta`,
   `cat_formas_pago`.`Forma_Pago` AS `Forma_Pago`,
   `cat_tipos_tarjeta`.`Tipo_Tarjeta` AS `Tipo_Tarjeta`,
   `ban_movimientos`.`Ref_Banco` AS `Ref_Banco`,
   `ban_movimientos`.`Monto` AS `Monto`,
   `ec_cuentas`.`Descripcion` AS `Cuenta_Paciente`,
   `cat_tipos_movimiento`.`Tipo_Movimiento` AS `Tipo_Movimiento`,
   `ec_movimientos`.`Observaciones` AS `Observaciones`,
   `ec_movimientos`.`Activo` AS `Activo`,
   `ec_movimientos`.`Fecha_Mod` AS `Fecha_Mod`,
   `ec_movimientos`.`Usr_Mod` AS `Usr_Mod`,
   `ec_movimientos`.`IP_Mod` AS `IP_Mod`
FROM (((((((((`ec_movimientos` join `ban_movimientos` on((`ban_movimientos`.`ID_BM` = `ec_movimientos`.`ID_BM`))) join `ban_cuentas` on((`ban_cuentas`.`ID_BC` = `ban_movimientos`.`ID_BC`))) left join `cajas_diario` on((`cajas_diario`.`ID_CD` = `ec_movimientos`.`ID_CD`))) left join `cajas_diario_movs` on((`cajas_diario_movs`.`ID_ECM` = `ec_movimientos`.`ID_ECM`))) left join `ec_cuentas` on((`ec_cuentas`.`ID_ECC` = `ec_movimientos`.`ID_ECC`))) left join `cajas` on((`cajas`.`ID_Caja` = `ec_movimientos`.`ID_Caja`))) join `cat_tipos_movimiento` on((`cat_tipos_movimiento`.`ID_TM` = `ban_movimientos`.`ID_TM`))) join `cat_formas_pago` on((`cat_formas_pago`.`ID_FP` = `ban_movimientos`.`ID_FP`))) left join `cat_tipos_tarjeta` on((`cat_tipos_tarjeta`.`ID_TT` = `ban_movimientos`.`ID_TT`))) where (`ec_movimientos`.`Activo` = 1);