CREATE DATABASE IF NOT EXISTS `vn2008` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */; USE `vn2008`; -- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) -- -- Host: db.verdnatura.es Database: vn2008 -- ------------------------------------------------------ -- Server version 5.6.25-4-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `Agencias` -- DROP TABLE IF EXISTS `Agencias`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Agencias` ( `Id_Agencia` int(11) NOT NULL AUTO_INCREMENT, `Agencia` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Vista` int(11) DEFAULT '0', `m3` double DEFAULT '0', `cod71` tinyint(3) unsigned DEFAULT '0', `web` smallint(1) unsigned zerofill NOT NULL DEFAULT '0', `agency_id` smallint(6) NOT NULL, `agency_service_id` tinyint(4) NOT NULL DEFAULT '1', `inflacion` decimal(5,2) NOT NULL DEFAULT '0.00' COMMENT 'Este valor se utiliza para aumentar el valor del componente porte.', `is_volumetric` tinyint(1) NOT NULL DEFAULT '0', `send_mail` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `show_AgencyName` tinyint(1) DEFAULT '1', `tpv` tinyint(1) NOT NULL DEFAULT '1', `externalAgency` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Agencia`), KEY `Agencias` (`Agencia`), KEY `Vista` (`Vista`) ) ENGINE=InnoDB AUTO_INCREMENT=1103 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Agencias_dits` -- DROP TABLE IF EXISTS `Agencias_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Agencias_dits` ( `idAgencia_dits` int(11) NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idAgencia_dits`) ) ENGINE=InnoDB AUTO_INCREMENT=13306 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Agencias_province` -- DROP TABLE IF EXISTS `Agencias_province`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Agencias_province` ( `province_id` smallint(6) unsigned NOT NULL, `agency_id` smallint(5) unsigned NOT NULL, `zona` tinyint(4) NOT NULL, `warehouse_id` smallint(6) unsigned NOT NULL, `route` tinyint(4) NOT NULL COMMENT 'Etiqueta zeleris', PRIMARY KEY (`province_id`,`agency_id`,`warehouse_id`), KEY `warehouse_id` (`warehouse_id`), KEY `agency_id` (`agency_id`), CONSTRAINT `Agencias_province_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Agencias_province_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Agencias_province_ibfk_3` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`agency_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Agencias_zonas` -- DROP TABLE IF EXISTS `Agencias_zonas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Agencias_zonas` ( `Id_Agencia` int(11) NOT NULL, `zona` tinyint(4) NOT NULL, `price` double NOT NULL, `Id_Article` int(10) NOT NULL DEFAULT '71', `warehouse_id` smallint(6) NOT NULL DEFAULT '1', `porte_minimo` tinyint(1) NOT NULL DEFAULT '0', `inflacion` decimal(5,2) NOT NULL DEFAULT '1.00', PRIMARY KEY (`Id_Agencia`,`zona`,`Id_Article`,`warehouse_id`), KEY `Id_Article` (`Id_Article`), CONSTRAINT `Agencias_zonas_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Agencias_zonas_ibfk_2` FOREIGN KEY (`Id_Agencia`) REFERENCES `Agencias` (`Id_Agencia`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Articles` -- DROP TABLE IF EXISTS `Articles`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Articles` ( `Id_Article` int(11) NOT NULL AUTO_INCREMENT, `Equivalente` int(11) unsigned DEFAULT NULL, `Article` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Medida` int(10) unsigned DEFAULT NULL, `Tallos` int(11) DEFAULT '1', `PVP` double DEFAULT '0', `Imprimir` tinyint(1) NOT NULL DEFAULT '0', `Albaranero` tinyint(1) NOT NULL DEFAULT '0', `iva_group_id` tinyint(4) unsigned NOT NULL DEFAULT '1', `Familia` varchar(3) COLLATE utf8_unicode_ci DEFAULT 'VT', `caja` tinyint(1) NOT NULL DEFAULT '0', `Categoria` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `id_origen` tinyint(2) unsigned NOT NULL, `do_photo` tinyint(4) NOT NULL DEFAULT '0', `Foto` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Color` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `Nicho` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Codintrastat` int(8) unsigned zerofill DEFAULT NULL, `Min` tinyint(1) NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `offer` tinyint(4) NOT NULL DEFAULT '0', `bargain` tinyint(4) NOT NULL DEFAULT '0', `comments` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'renombrar: reference', `tipo_id` smallint(5) unsigned NOT NULL, `generic` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', `producer_id` mediumint(3) unsigned DEFAULT NULL, `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `density` double NOT NULL DEFAULT '167' COMMENT 'Almacena la densidad en kg/m3 para el calculo de los portes, si no se especifica se pone por defecto la del tipo en un trigger', `relevancy` tinyint(1) NOT NULL DEFAULT '0', `expenceFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '7001000000', PRIMARY KEY (`Id_Article`), KEY `Article` (`Article`), KEY `Color` (`Color`), KEY `id_origen` (`id_origen`), KEY `Codintrastat` (`Codintrastat`), KEY `iva_group_id` (`iva_group_id`), KEY `tipo_id` (`tipo_id`), KEY `producer_id` (`producer_id`), KEY `expenceFk_idx` (`expenceFk`), CONSTRAINT `Articles_ibfk_1` FOREIGN KEY (`id_origen`) REFERENCES `Origen` (`id`) ON UPDATE CASCADE, CONSTRAINT `Articles_ibfk_2` FOREIGN KEY (`Codintrastat`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `Articles_ibfk_4` FOREIGN KEY (`iva_group_id`) REFERENCES `iva_group` (`iva_group_id`) ON UPDATE CASCADE, CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE, CONSTRAINT `producer_id` FOREIGN KEY (`producer_id`) REFERENCES `producer` (`producer_id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=297594 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ArticlesBeforeInsert` BEFORE INSERT ON `Articles` FOR EACH ROW BEGIN DECLARE vDensity DOUBLE; DECLARE vInsertId INT; IF NEW.density IS NULL THEN SELECT density INTO vDensity FROM Tipos WHERE tipo_id = NEW.tipo_id; SET NEW.density = vDensity; END IF; IF NEW.Foto IS NULL THEN SELECT `auto_increment` INTO vInsertId FROM `information_schema`.TABLES WHERE `table_name` = 'Articles' AND `table_schema` = DATABASE(); SET NEW.Foto = vInsertId; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_AFTER_INSERT` AFTER INSERT ON `Articles` FOR EACH ROW BEGIN CALL itemTagArrangedUpdate(NEW.Id_Article); INSERT INTO vn.itemTaxCountry(itemFk, countryFk, taxClassFk) SELECT NEW.Id_Article, 1, NEW.iva_group_id; INSERT INTO vn.itemTaxCountry(itemFk, countryFk, taxClassFk) SELECT NEW.Id_Article, 5, NEW.iva_group_id; INSERT INTO vn.itemTaxCountry(itemFk, countryFk, taxClassFk) SELECT NEW.Id_Article, 30, NEW.iva_group_id; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_AFTER_UPDATE` AFTER UPDATE ON `Articles` FOR EACH ROW BEGIN CALL itemTagArrangedUpdate(NEW.Id_Article); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Articles_PVP` -- DROP TABLE IF EXISTS `Articles_PVP`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Articles_PVP` ( `Id_Article` int(11) NOT NULL, `PVP` double DEFAULT NULL, `Id_Cliente` int(11) NOT NULL, `Fecha` date NOT NULL, KEY `id_article_pvp_idx` (`Id_Article`), KEY `id_cliente_pvp_idx` (`Id_Cliente`), CONSTRAINT `id_article_pvp` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `id_cliente_pvp` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los precios para etiquetar los articulos a los clientes'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Articles_botanical` -- DROP TABLE IF EXISTS `Articles_botanical`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Articles_botanical` ( `Id_Article` int(11) NOT NULL, `botanical` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `genus_id` mediumint(8) unsigned DEFAULT NULL, `specie_id` mediumint(8) unsigned DEFAULT NULL, PRIMARY KEY (`Id_Article`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Sustituye a antiguo NomBotanic de Articles'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Articles_botanical_bi` BEFORE INSERT ON `Articles_botanical` FOR EACH ROW BEGIN IF NEW.botanical = '' THEN SET NEW.botanical = NULL; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Articles_botanical_bu` BEFORE UPDATE ON `Articles_botanical` FOR EACH ROW BEGIN IF NEW.botanical = '' THEN SET NEW.botanical = NULL; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Articles_dits` -- DROP TABLE IF EXISTS `Articles_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Articles_dits` ( `idArticles_dits` int(11) NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idArticles_dits`), KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`) ) ENGINE=InnoDB AUTO_INCREMENT=19575 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Articles_nicho` -- DROP TABLE IF EXISTS `Articles_nicho`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Articles_nicho` ( `Id_Article` int(11) NOT NULL AUTO_INCREMENT, `warehouse_id` smallint(6) unsigned NOT NULL DEFAULT '1', `nicho` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `modificationDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`Id_Article`,`warehouse_id`), KEY `Articles_nicho_wh_fk` (`warehouse_id`), CONSTRAINT `Articles_nicho_wh_fk` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Articles_nichos_fk` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=292693 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_nichoBeforeInsert` BEFORE INSERT ON `Articles_nicho` FOR EACH ROW BEGIN -- XXX: Intenta localizar al usuario que introduce BIO en esta tabla. IF NEW.nicho IS NOT NULL AND NEW.nicho LIKE '%BIO%' THEN CALL util.debugAdd ('nicho', NEW.nicho); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_nicho_AFTER_INSERT` AFTER INSERT ON `Articles_nicho` FOR EACH ROW BEGIN DECLARE mailText VARCHAR(90); IF NEW.nicho LIKE 'BIONIC%' THEN SELECT IFNULL(CONCAT(Id_Trabajador, ' ', CodigoTrabajador, ' ' ,Nombre, ' ' , Apellidos),'TRABAJADOR NO ENCONTRADO') INTO mailText FROM Trabajadores WHERE Id_Trabajador = vn2008.get_Trabajador(); SELECT CONCAT(mailText, ' ', Article, ' ', Medida) INTO mailText FROM Articles WHERE Id_Article = NEW.Id_Article; INSERT INTO mail(`to`,reply_to,subject,text) VALUES('pako@verdnatura.es,nelo@verdnatura.es','informatica@verdnatura.es','BIONIC INSERT',mailText); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_nichoBeforeUpdate` BEFORE UPDATE ON `Articles_nicho` FOR EACH ROW BEGIN -- XXX: Intenta localizar al usuario que introduce BIO en esta tabla. IF NOT (NEW.nicho <=> OLD.nicho) AND NEW.nicho LIKE '%BIO%' THEN CALL util.debugAdd ('nicho', NEW.nicho); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_nicho_AFTER_UPDATE` AFTER UPDATE ON `Articles_nicho` FOR EACH ROW BEGIN DECLARE mailText VARCHAR(90); IF NEW.nicho LIKE 'BIONIC%' THEN SELECT IFNULL(CONCAT(Id_Trabajador, ' ', CodigoTrabajador, ' ' ,Nombre, ' ' , Apellidos),'TRABAJADOR NO ENCONTRADO') INTO mailText FROM Trabajadores WHERE Id_Trabajador = vn2008.get_Trabajador(); SELECT CONCAT(mailText, ' ', Article, ' ', Medida) INTO mailText FROM Articles WHERE Id_Article = NEW.Id_Article; INSERT INTO mail(`to`,reply_to,subject,text) VALUES('pako@verdnatura.es,nelo@verdnatura.es','informatica@verdnatura.es','BIONIC UPDATE',mailText); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Articles_old` -- DROP TABLE IF EXISTS `Articles_old`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Articles_old` ( `Id_Article` int(11) NOT NULL DEFAULT '0', `Equivalente` int(11) unsigned DEFAULT NULL, `Article` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Medida` int(10) unsigned DEFAULT NULL, `Tallos` int(11) DEFAULT '1', `PVP` double DEFAULT '0', `Imprimir` tinyint(1) NOT NULL DEFAULT '0', `Albaranero` tinyint(1) NOT NULL DEFAULT '0', `iva_group_id` tinyint(4) unsigned NOT NULL DEFAULT '1', `Familia` varchar(3) COLLATE utf8_unicode_ci DEFAULT 'VT', `caja` tinyint(1) NOT NULL DEFAULT '0', `Categoria` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `id_origen` tinyint(2) unsigned NOT NULL, `do_photo` tinyint(4) NOT NULL DEFAULT '0', `Foto` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Color` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `Nicho` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Codintrastat` int(8) unsigned zerofill DEFAULT NULL, `Min` tinyint(1) NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `offer` tinyint(4) NOT NULL DEFAULT '0', `bargain` tinyint(4) NOT NULL DEFAULT '0', `comments` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'renombrar: reference', `tipo_id` smallint(5) unsigned NOT NULL, `generic` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', `producer_id` mediumint(3) unsigned DEFAULT NULL, `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Baldas` -- DROP TABLE IF EXISTS `Baldas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Baldas` ( `Id_Estanterias` int(11) NOT NULL, `Id_Baldas` int(11) NOT NULL, `h` int(11) NOT NULL, PRIMARY KEY (`Id_Estanterias`,`Id_Baldas`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Bancos` -- DROP TABLE IF EXISTS `Bancos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Bancos` ( `Id_Banco` int(11) NOT NULL DEFAULT '0', `Banco` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Cuenta` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `cash` smallint(6) NOT NULL DEFAULT '0', `warehouse_id` smallint(5) unsigned NOT NULL DEFAULT '1', `entity_id` int(10) unsigned NOT NULL, `activo` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`Id_Banco`), KEY `BancosBanco` (`Banco`), KEY `fk_Bancos_entity1_idx` (`entity_id`), KEY `foreignkey1_idx` (`cash`), CONSTRAINT `foreignkey1` FOREIGN KEY (`cash`) REFERENCES `vn`.`accountingType` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Apunta a la vista vn.Accounting\nLa columna cash es la FK de vn.AccountingType'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Bancos_poliza` -- DROP TABLE IF EXISTS `Bancos_poliza`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Bancos_poliza` ( `poliza_id` int(11) NOT NULL AUTO_INCREMENT, `referencia` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `importe` double NOT NULL, `com_dispuesto` double DEFAULT NULL, `com_no_dispuesto` double DEFAULT NULL, `com_anual` double DEFAULT NULL, `apertura` date NOT NULL, `cierre` date DEFAULT NULL, `Id_Banco` int(11) NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', PRIMARY KEY (`poliza_id`), KEY `Id_Banco_Poliza_idx` (`Id_Banco`), KEY `Id_Poliza_Empresa_idx` (`empresa_id`), CONSTRAINT `Id_Banco_Poliza` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `Id_Poliza_Empresa` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lineas de credito asociadas a cuentas corrientes'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Brasa` -- DROP TABLE IF EXISTS `Brasa`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Brasa` ( `Id_Cliente` int(10) unsigned NOT NULL DEFAULT '0', `Cliente` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Vista` int(10) unsigned NOT NULL DEFAULT '0', `Reg` bigint(21) unsigned NOT NULL DEFAULT '0', `Consumo` double NOT NULL, `Grupo` int(10) unsigned NOT NULL, PRIMARY KEY (`Id_Cliente`), KEY `Index_1` (`Id_Cliente`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Cajas` -- DROP TABLE IF EXISTS `Cajas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Cajas` ( `Id_Caja` int(11) NOT NULL AUTO_INCREMENT, `Cajafecha` date NOT NULL, `Partida` tinyint(1) NOT NULL DEFAULT '0', `Serie` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `Numero` int(11) DEFAULT NULL, `Concepto` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Entrada` decimal(10,2) DEFAULT NULL, `Salida` decimal(10,2) DEFAULT NULL, `Id_Banco` int(11) DEFAULT '1', `Id_Trabajador` int(11) DEFAULT NULL, `empresa_id` smallint(5) unsigned DEFAULT NULL COMMENT 'kakear', `linked` tinyint(4) DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `ok` tinyint(4) NOT NULL DEFAULT '0', `warehouse_id` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'to kak\n', `conciliado` int(2) NOT NULL DEFAULT '0', `Proveedores_account_Id` mediumint(8) unsigned NOT NULL, `id_calculated` varchar(90) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Caja`), UNIQUE KEY `id_calculated_UNIQUE` (`id_calculated`), KEY `CajasCajafecha` (`Cajafecha`), KEY `Id_Banco` (`Id_Banco`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `empresa_id` (`empresa_id`), KEY `warehouse_id` (`warehouse_id`), KEY `fk_Cajas_Proveedores_account1_idx` (`Proveedores_account_Id`), CONSTRAINT `Cajas_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=543259 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`CajasBeforeInsert` BEFORE INSERT ON `Cajas` FOR EACH ROW BEGIN IF IFNULL(NEW.Concepto,"") = "" THEN CALL util.throw ('Error. El concepto esta vacío'); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Cajas eliminadas` -- DROP TABLE IF EXISTS `Cajas eliminadas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Cajas eliminadas` ( `Id_Caja` int(11) NOT NULL DEFAULT '0', `Cajafecha` datetime DEFAULT NULL, `Partida` tinyint(1) NOT NULL DEFAULT '0', `Serie` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `Numero` int(11) DEFAULT NULL, `Concepto` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Entrada` double DEFAULT NULL, `Salida` double DEFAULT NULL, PRIMARY KEY (`Id_Caja`), KEY `CajasCajafecha` (`Cajafecha`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Clases` -- DROP TABLE IF EXISTS `Clases`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Clases` ( `Id_Clase` int(11) NOT NULL DEFAULT '0', `Clase` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Clase`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Clientes` -- DROP TABLE IF EXISTS `Clientes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Clientes` ( `id_cliente` int(11) NOT NULL AUTO_INCREMENT, `cliente` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `descuento` tinyint(3) unsigned NOT NULL DEFAULT '0', `default_address` int(11) DEFAULT NULL, `domicilio` longtext COLLATE utf8_unicode_ci, `if` varchar(14) COLLATE utf8_unicode_ci DEFAULT NULL, `telefono` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `fax` varchar(11) COLLATE utf8_unicode_ci DEFAULT NULL, `e-mail` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL, `cc` varchar(23) COLLATE utf8_unicode_ci DEFAULT NULL, `vencimiento` smallint(6) NOT NULL DEFAULT '5', `recibo` int(11) DEFAULT '1' COMMENT 'Deprecated', `oficial` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Deprecated', `contabilizado` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Deprecated', `movil` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `Cuenta` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `RE` tinyint(1) NOT NULL DEFAULT '0', `poblacion` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, `province_id` smallint(5) unsigned DEFAULT NULL, `codPostal` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL, `razonSocial` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `contacto` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `mayorista` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Deprecated', `reexpedicion` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Deprecated', `invoice` tinyint(1) NOT NULL DEFAULT '1', `notas` text COLLATE utf8_unicode_ci COMMENT 'Deprecated', `notas_administracion` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'Deprecated', `copiaFactura` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Deprecated', `retener` tinyint(1) NOT NULL DEFAULT '0', `congelado` tinyint(1) NOT NULL DEFAULT '0', `Id_Trabajador` int(11) DEFAULT NULL, `credito` double NOT NULL DEFAULT '0', `cyc` double DEFAULT NULL, `Id_Pais` mediumint(8) unsigned NOT NULL DEFAULT '1', `activo` tinyint(1) NOT NULL DEFAULT '1', `gestdoc_id` int(11) DEFAULT NULL, `calidad` int(2) DEFAULT '11', `pay_met_id` tinyint(3) unsigned NOT NULL DEFAULT '5', `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `mail` tinyint(1) NOT NULL DEFAULT '1', `chanel_id` smallint(6) DEFAULT NULL, `vies` tinyint(4) NOT NULL DEFAULT '0', `split_holland` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'eliminar', `sepaFth` tinyint(1) DEFAULT '0' COMMENT 'campo para recibir los escritos de los clientes para el sepa', `sepaVnl` tinyint(1) DEFAULT '0', `coreFth` tinyint(1) DEFAULT '0', `coreVnl` tinyint(1) DEFAULT '0', `risk_calculated` date NOT NULL, `coreVnh` tinyint(1) DEFAULT '0', `real` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Define los clientes cuyas ventas hay que tener en cuenta en los calculos estadisticos.', `clientes_tipo_id` int(11) NOT NULL DEFAULT '1', `postcode_id` int(11) unsigned DEFAULT NULL, `mail_address` int(11) DEFAULT NULL, `codpos` char(5) COLLATE utf8_unicode_ci DEFAULT NULL, `creditInsurance` int(11) DEFAULT NULL, `EYPBC` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Email\nYesterday\nPurchases\nBy\nConsigna', `invoiceByAddress` tinyint(1) DEFAULT '0', `cplusTerIdNifFk` int(11) NOT NULL DEFAULT '1', `isCreatedAsServed` tinyint(1) DEFAULT '0', `hasInvoiceSimplified` tinyint(1) NOT NULL DEFAULT '0', `iban` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id_cliente`), UNIQUE KEY `IF` (`if`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `Id_Pais` (`Id_Pais`), KEY `pay_met_id` (`pay_met_id`), KEY `canal_nuevo_cliente` (`chanel_id`), KEY `Cuenta` (`Cuenta`), KEY `province_id` (`province_id`), KEY `default_address` (`default_address`), KEY `Telefono` (`telefono`), KEY `movil` (`movil`), KEY `tipos_de_cliente_idx` (`clientes_tipo_id`), KEY `codpos` (`codpos`,`codPostal`), KEY `clientes_fk_6_idx` (`cplusTerIdNifFk`), CONSTRAINT `Clientes_ibfk_1` FOREIGN KEY (`Id_Pais`) REFERENCES `Paises` (`Id`) ON UPDATE CASCADE, CONSTRAINT `Clientes_ibfk_2` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `Clientes_ibfk_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `Clientes_ibfk_4` FOREIGN KEY (`default_address`) REFERENCES `Consignatarios` (`id_consigna`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `Clientes_ibfk_5` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `canal_nuevo_cliente` FOREIGN KEY (`chanel_id`) REFERENCES `chanel` (`chanel_id`) ON UPDATE CASCADE, CONSTRAINT `clientes_fk_6` FOREIGN KEY (`cplusTerIdNifFk`) REFERENCES `vn`.`cplusTerIdNif` (`id`) ON UPDATE CASCADE, CONSTRAINT `tipos_de_cliente` FOREIGN KEY (`clientes_tipo_id`) REFERENCES `clientes_tipo` (`clientes_tipo_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=9898 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `ClientesBeforeInsert` BEFORE INSERT ON `Clientes` FOR EACH ROW BEGIN DECLARE isAlreadyUsedIf BOOLEAN; SELECT COUNT(*) INTO isAlreadyUsedIf FROM Clientes WHERE `IF` = TRIM(NEW.`IF`); IF isAlreadyUsedIf THEN CALL util.throw ('Error. El NIF/CIF está repetido'); END IF; CALL pbx.phoneIsValid (NEW.telefono); CALL pbx.phoneIsValid (NEW.movil); CALL pbx.phoneIsValid (NEW.fax); SET NEW.cuenta = 4300000000 + NEW.Id_Cliente; IF NEW.pay_met_id = 4 AND NEW.Vencimiento = 0 THEN SET NEW.Vencimiento = 5; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ClientesAfterInsert` AFTER INSERT ON `vn2008`.`Clientes` FOR EACH ROW BEGIN INSERT INTO Consignatarios SET Id_Cliente = NEW.Id_Cliente, Domicilio = NEW.domicilio, Poblacion = NEW.POBLACION, province_id = NEW.province_id, Codpostal = NEW.CODPOSTAL, Consignatario = NEW.Cliente, Predeterminada = TRUE, Id_Agencia = 2, isEqualizated = NEW.RE; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `ClientesBeforeUpdate` BEFORE UPDATE ON `Clientes` FOR EACH ROW BEGIN DECLARE vEmployee INT; DECLARE vText VARCHAR(255) DEFAULT NULL; DECLARE isAlreadyUsedIf BOOLEAN; SELECT (COUNT(*) > 1) INTO isAlreadyUsedIf FROM Clientes WHERE `IF` = TRIM(NEW.`IF`); IF isAlreadyUsedIf THEN CALL util.throw ('Error. El NIF/CIF está repetido'); END IF; -- Comprueba que el formato de los teléfonos es válido IF !(NEW.telefono <=> OLD.telefono) THEN CALL pbx.phoneIsValid (NEW.telefono); END IF; IF !(NEW.movil <=> OLD.movil) THEN CALL pbx.phoneIsValid (NEW.movil); END IF; IF !(NEW.fax <=> OLD.fax) THEN CALL pbx.phoneIsValid (NEW.fax); END IF; -- Actualiza el crédito IF !(NEW.Credito <=> OLD.Credito) AND IFNULL(NEW.Credito, 0) >= 0 THEN INSERT INTO credit SET Id_Cliente = NEW.Id_Cliente, amount = NEW.Credito, Id_Trabajador = account.userGetId(); END IF; IF vText IS NOT NULL THEN INSERT INTO mail(`to`, reply_to, subject, text) SELECT CONCAT(IF(ac.id,name, 'jgallego'), '@verdnatura.es'), 'administracion@verdnatura.es', CONCAT('Cliente ', NEW.Id_Cliente), CONCAT('Recibida la documentación: ', vText) FROM Trabajadores t LEFT JOIN account.user u ON t.user_id = u.id AND active LEFT JOIN account.account ac ON ac.id = u.id WHERE t.Id_Trabajador = NEW.Id_Trabajador; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Clientes_cedidos` -- DROP TABLE IF EXISTS `Clientes_cedidos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Clientes_cedidos` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL, `Id_Trabajador_old` int(11) NOT NULL, `Id_Trabajador_new` int(11) NOT NULL, `datSTART` date NOT NULL, `datEND` date NOT NULL, `comision_old` double NOT NULL DEFAULT '0.5', `comision_new` double NOT NULL DEFAULT '0.5', PRIMARY KEY (`id`), KEY `trabajador_fk_idx` (`Id_Trabajador_old`), KEY `new_trabajador_fk_idx` (`Id_Trabajador_new`), KEY `cliente_cedido_fk_idx` (`Id_Cliente`), CONSTRAINT `cliente_cedido_fk` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `new_trabajador_fk` FOREIGN KEY (`Id_Trabajador_new`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `trabajador_fk` FOREIGN KEY (`Id_Trabajador_old`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Clientes que se han cambiado de comercial, pero durante un tiempo comisionan a los dos, al anterior y al actual'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Clientes_dits` -- DROP TABLE IF EXISTS `Clientes_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Clientes_dits` ( `idClientes_dits` int(11) NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idClientes_dits`), KEY `idaccion_dits` (`idaccion_dits`), CONSTRAINT `Clientes_dits_ibfk_1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=70647 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Clientes_empresa` -- DROP TABLE IF EXISTS `Clientes_empresa`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Clientes_empresa` ( `Id_Clientes_empresa` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL, `fecha_ini` date NOT NULL, `fecha_fin` date NOT NULL, PRIMARY KEY (`Id_Clientes_empresa`), KEY `empresa_id_idx` (`empresa_id`), CONSTRAINT `empresa_id` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=470483 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Empresa por defecto para crear los tickets'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Clientes_event` -- DROP TABLE IF EXISTS `Clientes_event`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Clientes_event` ( `Id_Cliente` int(11) NOT NULL, `quantity` tinyint(3) unsigned NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`Id_Cliente`), CONSTRAINT `Clientes_event_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Clientes_potenciales` -- DROP TABLE IF EXISTS `Clientes_potenciales`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Clientes_potenciales` ( `id` int(11) NOT NULL, `PAIS` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `ACTIVIDAD` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `NOMBRE` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `PROVINCIA` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, `POBLACION` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CP` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `DIR_POSTAL` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `TELEFONO` varchar(12) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `TELEFONO2` varchar(12) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `FAX` varchar(12) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `E-MAIL` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `pagweb` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `SERVICIOS` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `state_id` smallint(6) DEFAULT '0' COMMENT '0 no se ha hecho nada\n1 ya existe el cliente\n2 cliente conseguido\n3 desestimado', `Id_Trabajador` smallint(6) DEFAULT NULL, `Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`NOMBRE`,`POBLACION`,`DIR_POSTAL`,`TELEFONO`,`TELEFONO2`,`FAX`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Colas` -- DROP TABLE IF EXISTS `Colas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Colas` ( `Id_Cola` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Impresora` tinyint(3) unsigned DEFAULT '0', `Id_Prioridad` tinyint(3) unsigned DEFAULT '2', `Id_Informe` tinyint(3) unsigned DEFAULT '0', `Id_Estado` tinyint(3) unsigned DEFAULT '1', `Hora_Inicio` datetime DEFAULT NULL, `Hora_Fin` datetime DEFAULT NULL, `Cola` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Id_Trabajador` int(11) DEFAULT '20', `Cola2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `Cola3` text COLLATE utf8_unicode_ci, `error` text COLLATE utf8_unicode_ci, PRIMARY KEY (`Id_Cola`), UNIQUE KEY `Id_Impresora_2` (`Id_Impresora`,`Id_Prioridad`,`Id_Informe`,`Id_Estado`,`Cola`,`Id_Trabajador`,`Cola2`), KEY `Id_estado` (`Id_Estado`), KEY `Id_Impresora` (`Id_Impresora`), KEY `Id_Informe` (`Id_Informe`), KEY `Id_Prioridad` (`Id_Prioridad`), KEY `Id_Trabajador` (`Id_Trabajador`), CONSTRAINT `Colas_ibfk_1` FOREIGN KEY (`Id_Informe`) REFERENCES `Informes` (`Id_Informe`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_2` FOREIGN KEY (`Id_Estado`) REFERENCES `Estados` (`Id_Estado`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_3` FOREIGN KEY (`Id_Prioridad`) REFERENCES `Prioridades` (`Id_Prioridad`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_5` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1272 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Colores` -- DROP TABLE IF EXISTS `Colores`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Colores` ( `Id_Color` int(11) NOT NULL DEFAULT '0', `Color` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Color`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Comparativa` -- DROP TABLE IF EXISTS `Comparativa`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Comparativa` ( `Periodo` int(11) NOT NULL, `Id_Article` bigint(20) NOT NULL, `warehouse_id` int(11) NOT NULL, `Cantidad` mediumint(9) NOT NULL DEFAULT '0', `price` mediumint(8) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`Periodo`,`Id_Article`,`warehouse_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Compres` -- DROP TABLE IF EXISTS `Compres`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Compres` ( `Id_Compra` int(11) NOT NULL AUTO_INCREMENT, `Id_Entrada` int(11) NOT NULL DEFAULT '0', `Id_Article` int(11) NOT NULL DEFAULT '90', `Cantidad` int(11) DEFAULT '0', `dispatched` int(11) NOT NULL DEFAULT '0', `Costefijo` decimal(10,3) DEFAULT '0.000', `Portefijo` decimal(10,3) DEFAULT '0.000', `Novincular` tinyint(1) NOT NULL DEFAULT '0', `Etiquetas` int(11) DEFAULT '0', `Packing` int(11) DEFAULT '0', `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', `caja` tinyint(4) NOT NULL COMMENT '0=sin obligar 1=groping 2=packing', `container_id` smallint(5) unsigned NOT NULL DEFAULT '36', `Comisionfija` decimal(10,3) DEFAULT '0.000', `Embalajefijo` decimal(10,3) DEFAULT '0.000', `Nicho` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `Id_Cubo` varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', `Tarifa1` decimal(10,2) DEFAULT '0.00', `Tarifa2` decimal(10,2) DEFAULT '0.00', `Tarifa3` decimal(10,2) DEFAULT '0.00', `PVP` decimal(10,2) DEFAULT '0.00', `Productor` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Vida` int(11) DEFAULT '0', `Id_Trabajador` int(11) DEFAULT '0', `punteo` tinyint(1) NOT NULL DEFAULT '0', `Volumenkk` int(11) DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `cm2kk` int(10) unsigned NOT NULL DEFAULT '0', `buy_edi_id` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Compra`), KEY `CompresId_Trabajador` (`Id_Trabajador`), KEY `Id_Cubo` (`Id_Cubo`), KEY `Id_Entrada` (`Id_Entrada`), KEY `container_id` (`container_id`), KEY `buy_edi_id` (`buy_edi_id`), KEY `itemFk_entryFk` (`Id_Article`,`Id_Entrada`), CONSTRAINT `Compres_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `Compres_ibfk_2` FOREIGN KEY (`Id_Cubo`) REFERENCES `Cubos` (`Id_Cubo`) ON UPDATE CASCADE, CONSTRAINT `Compres_ibfk_3` FOREIGN KEY (`container_id`) REFERENCES `container` (`container_id`) ON UPDATE CASCADE, CONSTRAINT `buy_id` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=230888202 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`compresBeforeInsert` BEFORE INSERT ON `vn2008`.`Compres` FOR EACH ROW BEGIN DECLARE vWarehouse INT; DECLARE vLanding DATE; DECLARE vGroup INT; DECLARE vIsBox BOOL; IF NEW.grouping = 0 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT ='ERROR_GROUPING_ZERO'; END IF; SELECT warehouse_id, landing INTO vWarehouse, vLanding FROM Entradas E JOIN travel T ON T.id = E.travel_id WHERE E.Id_Entrada = NEW.Id_Entrada; SELECT grouping, caja INTO vGroup, vIsBox FROM Compres C JOIN Entradas E USING(Id_Entrada) JOIN travel T ON T.id = E.travel_id WHERE T.landing <= vLanding AND C.Id_Article = NEW.Id_Article AND NOT C.Novincular ORDER BY warehouse_id = vWarehouse DESC,landing DESC, Id_Compra DESC LIMIT 1; SET NEW.grouping = IFNULL(vGroup,IFNULL( NEW.grouping,1)); SET NEW.caja = IFNULL(vIsBox, IFNULL( NEW.caja,0)); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `CompresAfterInsert` AFTER INSERT ON `Compres` FOR EACH ROW BEGIN DECLARE vWarehouse INT; DECLARE vWarehouseOut INT; CALL stock.queueAdd ('buy', NEW.Id_Compra, NULL); SELECT warehouse_id, warehouse_id_out INTO vWarehouse, vWarehouseOut FROM Entradas E JOIN travel T ON T.id = E.travel_id WHERE E.Id_Entrada = NEW.Id_Entrada; -- Actualiza el volumen unitario REPLACE bi.rotacion(Id_Article, warehouse_id, cm3) VALUES (NEW.Id_ARticle, vWarehouse, vn2008.cm3_unidad(NEW.Id_Compra)); IF (SELECT fuente FROM warehouse where id = vWarehouseOut AND id <> 13) AND (SELECT has_notify_passport(NEW.Id_Article,NEW.Id_Compra)) THEN CALL notify_passport(NEW.Id_Article, NEW.Etiquetas, NEW.Packing,NEW.Id_Compra); CALL insert_producer_plantpassport(NEW.Id_Compra); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `CompresBeforeUpdate` BEFORE UPDATE ON `Compres` FOR EACH ROW BEGIN IF NEW.grouping = 0 AND OLD.grouping <> 0 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT ='ERROR_GROUPING_ZERO'; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `CompresAfterUpdate` AFTER UPDATE ON `Compres` FOR EACH ROW BEGIN DECLARE vWarehouse INT; DECLARE vWarehouseOut INT; CALL stock.queueAdd ('buy', NEW.Id_Compra, OLD.Id_Compra); SELECT warehouse_id, warehouse_id_out INTO vWarehouse, vWarehouseOut FROM Entradas E JOIN travel T ON T.id = E.travel_id WHERE E.Id_Entrada = NEW.Id_Entrada; IF NOT(NEW.Id_Cubo <=> OLD.Id_Cubo AND NEW.Id_Entrada <=> OLD.Id_Entrada) THEN REPLACE bi.rotacion(Id_Article, warehouse_id, cm3) VALUES (NEW.Id_ARticle, vWarehouse, vn2008.cm3_unidad(NEW.Id_Compra)); END IF; IF (SELECT fuente FROM warehouse where id = vWarehouseOut AND id <> 13) AND (SELECT has_notify_passport(NEW.Id_Article,NEW.Id_Compra)) > 0 THEN CALL notify_passport(NEW.Id_Article, NEW.Etiquetas, NEW.Packing,NEW.Id_Compra); CALL insert_producer_plantpassport(NEW.Id_Compra); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`CompresAfterDelete` AFTER DELETE ON `Compres` FOR EACH ROW BEGIN DECLARE vProvider INT; CALL stock.queueAdd ('buy', NULL, OLD.Id_Compra); SELECT Id_Proveedor INTO vProvider FROM Entradas WHERE Id_Entrada = OLD.Id_Entrada; IF OLD.Vida > 0 AND vProvider <> 4 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT ='ERROR_DELETING_LIFE'; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Compres_2014` -- DROP TABLE IF EXISTS `Compres_2014`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Compres_2014` ( `Id_Compra` int(11) NOT NULL AUTO_INCREMENT, `Id_Entrada` int(11) NOT NULL DEFAULT '0', `Id_Article` int(11) NOT NULL DEFAULT '90', `Cantidad` int(11) DEFAULT '0', `Costefijo` decimal(10,3) DEFAULT '0.000', `Portefijo` decimal(10,3) DEFAULT '0.000', `Novincular` tinyint(1) NOT NULL DEFAULT '0', `Etiquetas` int(11) DEFAULT '0', `Packing` int(11) DEFAULT '0', `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', `caja` tinyint(4) NOT NULL COMMENT '0=sin obligar 1=groping 2=packing', `container_id` smallint(5) unsigned NOT NULL DEFAULT '36', `Comisionfija` decimal(10,3) DEFAULT '0.000', `Embalajefijo` decimal(10,3) DEFAULT '0.000', `Nicho` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `Id_Cubo` varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', `Tarifa1` decimal(10,2) DEFAULT '0.00', `Tarifa2` decimal(10,2) DEFAULT '0.00', `Tarifa3` decimal(10,2) DEFAULT '0.00', `PVP` decimal(10,2) DEFAULT '0.00', `Productor` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Vida` int(11) DEFAULT '0', `Id_Trabajador` int(11) DEFAULT '0', `punteo` tinyint(1) NOT NULL DEFAULT '0', `Volumenkk` int(11) DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `cm2kk` int(10) unsigned NOT NULL DEFAULT '0', `buy_edi_id` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Compra`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Compres_mark` -- DROP TABLE IF EXISTS `Compres_mark`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Compres_mark` ( `Id_Compra` int(11) NOT NULL, `comment` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `mark` tinyint(1) DEFAULT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`Id_Compra`), CONSTRAINT `Compres_mark_ibfk_1` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Compres_ok` -- DROP TABLE IF EXISTS `Compres_ok`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Compres_ok` ( `Id_Compra` int(11) NOT NULL, `valor` tinyint(3) unsigned NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `original_quantity` double DEFAULT NULL, `Id_Trabajador` int(11) NOT NULL, `Id_Accion` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Id_Compra_ok` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Id_Compra_ok`), KEY `Id_Movimiento` (`Id_Compra`), KEY `Id_Accion` (`Id_Accion`), CONSTRAINT `Compres_ok_ibfk_1` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=14728 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Consignatarios` -- DROP TABLE IF EXISTS `Consignatarios`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Consignatarios` ( `id_consigna` int(11) NOT NULL AUTO_INCREMENT, `Id_cliente` int(11) NOT NULL DEFAULT '0', `warehouse_id` smallint(6) unsigned DEFAULT '1', `domicilio` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `poblacion` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, `province_id` smallint(5) unsigned DEFAULT NULL, `codPostal` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `telefono` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `movil` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `consignatario` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `predeterminada` tinyint(1) NOT NULL DEFAULT '1', `Id_Agencia` int(11) NOT NULL DEFAULT '2', `especificaciones` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `seguro` tinyint(1) NOT NULL DEFAULT '0', `porte` double DEFAULT NULL, `active` tinyint(4) NOT NULL DEFAULT '1', `postcode_id` int(11) unsigned DEFAULT NULL, `longitude` decimal(11,7) DEFAULT NULL, `latitude` decimal(11,7) DEFAULT NULL, `codPos` char(5) COLLATE utf8_unicode_ci DEFAULT NULL, `isEqualizated` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id_consigna`), KEY `Id_Agencia` (`Id_Agencia`), KEY `Id_cliente` (`Id_cliente`), KEY `warehouse_id` (`warehouse_id`), KEY `province_id` (`province_id`), KEY `telefono` (`telefono`), KEY `movil` (`movil`), KEY `CODPOSTAL` (`codPostal`), CONSTRAINT `Consignatarios_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `Consignatarios_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `Consignatarios_ibfk_4` FOREIGN KEY (`Id_Agencia`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `address_customer_id` FOREIGN KEY (`Id_cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=23710 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ConsignatariosBeforeInsert` BEFORE INSERT ON `vn2008`.`Consignatarios` FOR EACH ROW BEGIN DECLARE v_has_default BOOLEAN; DECLARE vIsEqualizated BOOLEAN; CALL pbx.phoneIsValid (NEW.telefono); CALL pbx.phoneIsValid (NEW.movil); SELECT COUNT(*) > 0 INTO v_has_default FROM Consignatarios WHERE Id_Cliente = NEW.Id_Cliente AND Predeterminada <> FALSE; IF NEW.Predeterminada AND v_has_default THEN SET NEW.Predeterminada = FALSE; END IF; IF NEW.isEqualizated IS NULL THEN SELECT RE INTO vIsEqualizated FROM Clientes WHERE Id_Cliente = NEW.Id_Cliente; SET NEW.isEqualizated = vIsEqualizated; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ConsignatariosBeforeUpdate` BEFORE UPDATE ON `vn2008`.`Consignatarios` FOR EACH ROW BEGIN DECLARE vHasDefault BOOLEAN; CALL pbx.phoneIsValid (NEW.telefono); CALL pbx.phoneIsValid (NEW.movil); SELECT COUNT(*) > 0 INTO vHasDefault FROM Consignatarios WHERE Id_Cliente = NEW.Id_Cliente AND Predeterminada <> FALSE; IF NOT OLD.Predeterminada AND NEW.Predeterminada AND vHasDefault THEN SET NEW.Predeterminada = FALSE; END IF; IF NOT NEW.active AND (NEW.active != OLD.active) AND NEW.Predeterminada THEN CALL util.throw ('NO SE PUEDE DESACTIVAR EL CONSIGNATARIO PREDETERMINADO'); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ConsignatariosAfterUpdate` AFTER UPDATE ON `Consignatarios` FOR EACH ROW BEGIN DECLARE vCurDefault INT; DECLARE vNewDefault INT; IF NEW.Predeterminada AND (NEW.Predeterminada != OLD.Predeterminada) THEN UPDATE Clientes SET default_address = NEW.Id_Consigna WHERE Id_cliente = NEW.Id_cliente; END IF; IF NOT NEW.active AND (NEW.active != OLD.active) THEN SELECT default_address INTO vCurDefault FROM Clientes WHERE Id_Cliente = NEW.Id_Cliente; IF vCurDefault = NEW.Id_Consigna THEN SELECT Id_Consigna INTO vNewDefault FROM Consignatarios WHERE Id_Cliente = NEW.Id_Cliente AND active LIMIT 1; UPDATE Clientes SET default_address = vNewDefault WHERE Id_Cliente = NEW.Id_Cliente; END IF; END IF; -- Recargos de equivalencia distintos implican facturacion por consignatario IF NEW.isEqualizated != OLD.isEqualizated THEN IF (SELECT COUNT(*) FROM ( SELECT DISTINCT (isEqualizated = FALSE) as Equ FROM Consignatarios WHERE Id_Cliente = NEW.Id_Cliente ) t1 ) > 1 THEN UPDATE Clientes SET invoiceByAddress = TRUE WHERE Id_Cliente = NEW.Id_Cliente; END IF; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Consignatarios_devices` -- DROP TABLE IF EXISTS `Consignatarios_devices`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Consignatarios_devices` ( `Id_Consigna` int(11) NOT NULL, `serialNumber` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `notas` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Consigna`,`serialNumber`), CONSTRAINT `Condigna_devices` FOREIGN KEY (`Id_Consigna`) REFERENCES `Consignatarios` (`id_consigna`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Contactos` -- DROP TABLE IF EXISTS `Contactos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Contactos` ( `Id_Contacto` int(10) unsigned NOT NULL AUTO_INCREMENT, `Nombre` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Apellidos` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Empresa` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Cargo` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Telefono` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `Movil` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `email` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL, `Fax` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Contacto`), KEY `Telefono` (`Telefono`), KEY `Movil` (`Movil`) ) ENGINE=InnoDB AUTO_INCREMENT=2571 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ContactosBeforeInsert` BEFORE INSERT ON `Contactos` FOR EACH ROW BEGIN CALL pbx.phoneIsValid (NEW.telefono); CALL pbx.phoneIsValid (NEW.movil); CALL pbx.phoneIsValid (NEW.fax); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ContactosBeforeUpdate` BEFORE UPDATE ON `Contactos` FOR EACH ROW BEGIN CALL pbx.phoneIsValid (NEW.telefono); CALL pbx.phoneIsValid (NEW.movil); CALL pbx.phoneIsValid (NEW.fax); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Conteo` -- DROP TABLE IF EXISTS `Conteo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Conteo` ( `Id_Conteo` int(11) NOT NULL AUTO_INCREMENT, `Id_Article` int(11) NOT NULL, `Fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `dispositivo` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `warehouse_id` int(10) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`Id_Conteo`) ) ENGINE=MyISAM AUTO_INCREMENT=1079623 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Conteo_ai` AFTER INSERT ON `Conteo` FOR EACH ROW BEGIN DECLARE intTravel INTEGER; SELECT t.id INTO intTravel FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE landing = CURDATE() AND c.Id_Article = NEW.Id_Article AND warehouse_id = NEW.warehouse_id AND received <> TRUE LIMIT 1; IF (intTravel) then UPDATE travel SET received = TRUE WHERE id = intTravel; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Cubos` -- DROP TABLE IF EXISTS `Cubos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Cubos` ( `Id_Cubo` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `Volumen` double DEFAULT '0', `X` double DEFAULT '0', `Y` double DEFAULT '0', `Z` double DEFAULT '0', `Valor` double DEFAULT '0', `Retornable` tinyint(1) NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `idCubos_Retorno` int(11) DEFAULT NULL, `Bajan` int(11) DEFAULT NULL, `Suben` int(11) DEFAULT NULL, `Base` double DEFAULT NULL, `item_id` int(11) DEFAULT NULL, `pvp` double NOT NULL, `box` tinyint(1) NOT NULL DEFAULT '0', `bultoCubico` double DEFAULT NULL, PRIMARY KEY (`Id_Cubo`), KEY `Article` (`item_id`), CONSTRAINT `Article` FOREIGN KEY (`item_id`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Cubos_Retorno` -- DROP TABLE IF EXISTS `Cubos_Retorno`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Cubos_Retorno` ( `idCubos_Retorno` int(11) NOT NULL AUTO_INCREMENT, `Soporte` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `Vacio` double NOT NULL DEFAULT '0', `Lleno` double NOT NULL DEFAULT '0', PRIMARY KEY (`idCubos_Retorno`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Enlaces Facturas` -- DROP TABLE IF EXISTS `Enlaces Facturas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Enlaces Facturas` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Asiento` int(11) DEFAULT '0', `Apunte` int(11) DEFAULT '0', `Data` datetime DEFAULT NULL, `Concepto` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `Cuenta` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Debe` double DEFAULT NULL, `Haber` double DEFAULT NULL, `Contrapartida` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Contabilizado` tinyint(1) NOT NULL DEFAULT '0', `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `Enlaces@0020Facturas_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=23889 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Entradas` -- DROP TABLE IF EXISTS `Entradas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Entradas` ( `Id_Entrada` int(11) NOT NULL AUTO_INCREMENT, `Id_Proveedor` int(11) NOT NULL DEFAULT '644', `Fecha` datetime NOT NULL, `Referencia` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Anotadoencaja` tinyint(1) NOT NULL DEFAULT '0', `Inventario` tinyint(1) NOT NULL DEFAULT '0', `Notas` longtext COLLATE utf8_unicode_ci, `Confirmada` tinyint(1) NOT NULL DEFAULT '0', `Pedida` tinyint(1) NOT NULL DEFAULT '0', `Redada` tinyint(1) NOT NULL DEFAULT '0', `comision` float NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Notas_Eva` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `travel_id` int(11) unsigned DEFAULT NULL, `Id_Moneda` tinyint(3) unsigned DEFAULT '1', `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `gestdoc_id` int(11) DEFAULT NULL, `recibida_id` mediumint(8) unsigned DEFAULT NULL, `blocked` tinyint(4) NOT NULL DEFAULT '0', `loadPriority` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Entrada`), KEY `Id_Proveedor` (`Id_Proveedor`), KEY `Fecha` (`Fecha`), KEY `travel_id` (`travel_id`), KEY `empresa_id` (`empresa_id`), KEY `gestdoc_id` (`gestdoc_id`), KEY `recibida_id` (`recibida_id`), CONSTRAINT `Entradas_ibfk_1` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_6` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_7` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=131506 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`EntradasBeforeInsert` BEFORE INSERT ON `Entradas` FOR EACH ROW BEGIN IF (SELECT cuenta LIKE '___4______' FROM Proveedores WHERE Id_Proveedor = NEW.Id_Proveedor) THEN SET NEW.Id_Moneda = 2; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`EntradasBeforeUpdate` BEFORE UPDATE ON `vn2008`.`Entradas` FOR EACH ROW BEGIN IF (SELECT Id_Entrada FROM Entradas_Auto WHERE Id_Entrada = NEW.Id_Entrada) AND (NEW.travel_id <> OLD.travel_id) THEN IF (SELECT warehouse_id FROM travel WHERE id = NEW.travel_id) <> (SELECT warehouse_id FROM travel WHERE id = OLD.travel_id) OR (SELECT warehouse_id_out FROM travel WHERE id = NEW.travel_id) <> (SELECT warehouse_id_out FROM travel WHERE id = OLD.travel_id) THEN SET NEW.travel_id = OLD.travel_id; END IF; END IF; IF (NEW.gestdoc_id IS NOT NULL) AND (NEW.gestdoc_id <> OLD.gestdoc_id) THEN UPDATE recibida_entrada re INNER JOIN recibida r ON re.recibida_id = r.id INNER JOIN Entradas e ON e.Id_Entrada = re.Id_Entrada SET r.gestdoc_id = e.gestdoc_id WHERE e.Id_Entrada = NEW.Id_Entrada AND r.gestdoc_id IS NULL; END IF; IF NEW.anotadoencaja <> OLD.anotadoencaja THEN INSERT INTO Entradas_dits (idaccion_dits,Id_Trabajador,Id_Ticket,value_old,value_new) VALUES (105,get_Trabajador(),NEW.Id_Entrada,OLD.anotadoencaja,NEW.anotadoencaja); END IF; IF NEW.Id_Proveedor <> OLD.Id_Proveedor THEN IF (SELECT cuenta LIKE '___4______' FROM Proveedores WHERE Id_Proveedor = NEW.Id_Proveedor) THEN SET NEW.Id_Moneda = 2; END IF; END IF; IF NEW.Id_Moneda != OLD.Id_Moneda OR ((NEW.travel_id != OLD.travel_id) AND NEW.Id_Moneda > 1) THEN SET NEW.comision = getComision(NEW.Id_Entrada, NEW.Id_Moneda); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`EntradasAfterUpdate` AFTER UPDATE ON `Entradas` FOR EACH ROW BEGIN CALL stock.queueAdd ('entry', NEW.Id_Entrada, OLD.Id_Entrada); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`EntradasAfterDelete` AFTER DELETE ON `Entradas` FOR EACH ROW BEGIN CALL stock.queueAdd ('entry', NULL, OLD.Id_Entrada); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Entradas_Auto` -- DROP TABLE IF EXISTS `Entradas_Auto`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Entradas_Auto` ( `Id_Entrada` int(11) NOT NULL, PRIMARY KEY (`Id_Entrada`), CONSTRAINT `Entradas_Auto_ibfk_1` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Entradas_dits` -- DROP TABLE IF EXISTS `Entradas_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Entradas_dits` ( `idEntrada_dits` int(11) NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idEntrada_dits`), KEY `fgkey_entradas_1_idx` (`idaccion_dits`), KEY `fgkey_entradas_2_idx` (`Id_Ticket`), KEY `fgkey_entradas_3_idx` (`Id_Trabajador`), CONSTRAINT `Entradas_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2456079 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Entradas_kop` -- DROP TABLE IF EXISTS `Entradas_kop`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Entradas_kop` ( `Id_Entradas_kop` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Id_Entrada` int(11) NOT NULL, `kop` int(11) DEFAULT NULL, `sub` mediumint(8) unsigned DEFAULT NULL, PRIMARY KEY (`Id_Entradas_kop`), KEY `entradas_entradas_kop_idx` (`Id_Entrada`), CONSTRAINT `entradas_entradas_kop` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=452 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Entradas_orden` -- DROP TABLE IF EXISTS `Entradas_orden`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Entradas_orden` ( `Id_Entrada` int(11) NOT NULL, `orden` int(11) NOT NULL DEFAULT '1' COMMENT '1.- Ordenar por articulo\n2.- Ordenar por compra\n', PRIMARY KEY (`Id_Entrada`), CONSTRAINT `entradas_entradas_orden` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Entradas_stack` -- DROP TABLE IF EXISTS `Entradas_stack`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Entradas_stack` ( `Id_Entrada` int(11) NOT NULL, `label_number` smallint(6) DEFAULT '0', PRIMARY KEY (`Id_Entrada`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Entradas_turno` -- DROP TABLE IF EXISTS `Entradas_turno`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Entradas_turno` ( `Id_Entrada` int(11) NOT NULL, `weekDay` tinyint(2) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Entrada`), CONSTRAINT `entrada_entrada_turno` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Estas entradas se clonan al mismo tiempo que los turnos'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `EnvioMasivo` -- DROP TABLE IF EXISTS `EnvioMasivo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `EnvioMasivo` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Cliente` varchar(40) COLLATE utf8_unicode_ci NOT NULL, `Direccion` varchar(80) COLLATE utf8_unicode_ci NOT NULL, `CP` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `Poblacion` varchar(40) COLLATE utf8_unicode_ci NOT NULL, `Telefono` varchar(9) COLLATE utf8_unicode_ci NOT NULL, `Bultos` int(11) NOT NULL, `Observaciones` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `IdTicket` int(11) NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM AUTO_INCREMENT=3373 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Generación de etiquetas a través de Zeleris con los clientes de esta tabla'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Equipos` -- DROP TABLE IF EXISTS `Equipos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Equipos` ( `id` int(11) NOT NULL AUTO_INCREMENT, `alias` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `trabajador_id` int(11) DEFAULT NULL, `descripcion` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `predet` int(1) unsigned zerofill DEFAULT '0', `Left` int(5) DEFAULT '3000', `Top` int(5) DEFAULT '3000', `Width` int(5) DEFAULT '6360', `Height` int(5) DEFAULT '5595', PRIMARY KEY (`id`), KEY `trabajador_id` (`trabajador_id`), CONSTRAINT `Equipos_ibfk_1` FOREIGN KEY (`trabajador_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Espionajes` -- DROP TABLE IF EXISTS `Espionajes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Espionajes` ( `idEspionaje` int(11) NOT NULL AUTO_INCREMENT, `Id_Trabajador` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Fecha` date DEFAULT NULL, `HoraEntrada` time DEFAULT NULL, `HoraSalida` time DEFAULT NULL, `Id_Equipo` int(11) DEFAULT NULL, PRIMARY KEY (`idEspionaje`), KEY `index` (`Id_Trabajador`,`Fecha`) ) ENGINE=MyISAM AUTO_INCREMENT=75648 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Estados` -- DROP TABLE IF EXISTS `Estados`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Estados` ( `Id_Estado` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `Estado` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Estado`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Estanterias` -- DROP TABLE IF EXISTS `Estanterias`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Estanterias` ( `Id_Estanterias` int(11) NOT NULL AUTO_INCREMENT, `w` int(11) DEFAULT NULL, `d` int(11) DEFAULT NULL, `modelo` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Estanterias`) ) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Estanterias_distri` -- DROP TABLE IF EXISTS `Estanterias_distri`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Estanterias_distri` ( `idEstanterias_distri` int(11) NOT NULL, `posinicial` int(11) NOT NULL, `posfinal` int(11) NOT NULL, `Id_Estanterias` int(11) NOT NULL, PRIMARY KEY (`Id_Estanterias`,`idEstanterias_distri`), KEY `Estanterias_fgkey1_idx` (`Id_Estanterias`), KEY `est_distrib_fgkey1_idx` (`idEstanterias_distri`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Estanterias_distri_name` -- DROP TABLE IF EXISTS `Estanterias_distri_name`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Estanterias_distri_name` ( `idEstanterias_distri` int(11) NOT NULL AUTO_INCREMENT, `Descripcion` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`idEstanterias_distri`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Extractos` -- DROP TABLE IF EXISTS `Extractos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Extractos` ( `Id_Extracto` int(10) unsigned NOT NULL AUTO_INCREMENT, `Fecha` datetime NOT NULL, `Concepto` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Debe` double unsigned zerofill NOT NULL DEFAULT '0000000000000000000000', `Haber` double unsigned zerofill NOT NULL DEFAULT '0000000000000000000000', `Concepto2` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Concepto3` varchar(50) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`Id_Extracto`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Facturas` -- DROP TABLE IF EXISTS `Facturas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Facturas` ( `factura_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Factura` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `Serie` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `Fecha` date DEFAULT NULL, `Importe` decimal(12,2) DEFAULT '0.00', `Vencimiento` datetime DEFAULT NULL, `Id_Banco` int(11) DEFAULT '0', `Id_Cliente` int(11) DEFAULT '0', `Id_Remesa` int(11) DEFAULT NULL, `Remesar` tinyint(1) NOT NULL DEFAULT '0', `BI7` decimal(12,2) DEFAULT '0.00', `BI16` decimal(12,2) DEFAULT '0.00', `RE1` decimal(12,2) DEFAULT '0.00', `RE4` decimal(12,2) DEFAULT '0.00', `IVA7` decimal(12,2) DEFAULT '0.00', `IVA16` decimal(12,2) DEFAULT '0.00', `Id_Trabajador` int(11) DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `liquidacion` smallint(6) DEFAULT '0', `pdf` tinyint(3) unsigned NOT NULL DEFAULT '0', `booked` date DEFAULT NULL, `cplusInvoiceType477Fk` int(10) unsigned NOT NULL DEFAULT '1', `cplusTaxBreakFk` int(10) unsigned NOT NULL DEFAULT '1', `cplusSubjectOpFk` int(10) unsigned NOT NULL DEFAULT '1', `cplusTrascendency477Fk` int(10) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`factura_id`,`Id_Factura`), UNIQUE KEY `Id_Factura` (`Id_Factura`), KEY `Id_Banco` (`Id_Banco`), KEY `Id_Cliente` (`Id_Cliente`), KEY `Id_Remesa` (`Id_Remesa`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `empresa_id` (`empresa_id`), KEY `Fecha` (`Fecha`), KEY `Facturas_ibfk_2_idx` (`cplusInvoiceType477Fk`), KEY `Facturas_ibfk_3_idx` (`cplusSubjectOpFk`), KEY `Facturas_ibfk_4_idx` (`cplusTaxBreakFk`), KEY `Facturas_ibfk_5_idx` (`cplusTrascendency477Fk`), CONSTRAINT `Facturas_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Facturas_ibfk_2` FOREIGN KEY (`cplusInvoiceType477Fk`) REFERENCES `vn`.`cplusInvoiceType477` (`id`) ON UPDATE CASCADE, CONSTRAINT `Facturas_ibfk_3` FOREIGN KEY (`cplusSubjectOpFk`) REFERENCES `vn`.`cplusSubjectOp` (`id`) ON UPDATE CASCADE, CONSTRAINT `Facturas_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `vn`.`cplusTaxBreak` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoice_bank_id` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `invoice_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=436553 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `FacturasBeforeInsert` BEFORE INSERT ON `Facturas` FOR EACH ROW -- Edit trigger body code below this line. Do not edit lines above this one BEGIN DECLARE v_Id_Factura_serie CHAR(9) DEFAULT '0000001'; DECLARE v_Id_Factura INT; DECLARE max_id, intLast, intProv INT; -- Evitamos la generacion de nuevas facturas tras el cese de actividad de EFL IF NEW.empresa_id = 792 AND NEW.Fecha > '2012-12-20' THEN SET NEW.empresa_id = 791; END IF; SELECT IFNULL(MAX(factura_id),0) into max_id from Facturas WHERE Serie LIKE NEW.Serie AND ((Year(NEW.Fecha) = Year(Fecha) AND empresa_id = NEW.empresa_id)); IF max_id THEN SELECT right(max(Id_Factura), LENGTH(Id_Factura)-1) + 1 into v_Id_Factura_serie from Facturas WHERE Serie LIKE NEW.Serie AND ((Year(NEW.Fecha) = Year(Fecha) AND length(Id_Factura) > 6 AND empresa_id = NEW.empresa_id) /*OR (NEW.Serie LIKE 'B' AND length(Id_Factura) > 7)*/); ELSE SELECT CONCAT(digito_factura,RIGHT(YEAR(CURDATE()),1),'00001') INTO v_Id_Factura_serie FROM empresa WHERE id = NEW.empresa_id; /*Primer digito la empresa, segundo el año, despues la numeracion correlativa con 5 digitos*/ END IF; SELECT CONCAT(NEW.serie, lpad(v_Id_Factura_serie,7,'0')) into v_Id_Factura_serie; SET NEW.Id_Factura = v_Id_Factura_serie; /* IF intProv > 0 THEN -- No contabiliza bien las facturas holandesas INSERT INTO recibida(proveedor_id,fecha,sref,empresa_id) VALUES (NEW.empresa_id,NEW.Fecha,NEW.Id_Factura,intProv); SELECT LAST_INSERT_ID() INTO intLast; IF NEW.BI7 > 0 THEN INSERT INTO recibida_iva(recibida_id,iva_id,bi,gastos_id) VALUES(intLast,57,NEW.BI7,'6001000000'); END IF; IF NEW.BI16 > 0 THEN INSERT INTO recibida_iva(recibida_id,iva_id,bi,gastos_id) VALUES(intLast,58,NEW.BI16,'6001000000'); END IF; INSERT INTO recibida_vencimiento(recibida_id,fecha,banco_id,cantidad) SELECT intLast,TIMESTAMPADD(DAY,15,NEW.Fecha),3117,SUM((1 + (IVA / 100)) * bi) FROM recibida r INNER JOIN recibida_iva ri ON r.id = ri.recibida_id INNER JOIN iva_codigo AS i ON ri.iva_id=i.id INNER JOIN Proveedores p ON p.Id_Proveedor=r.proveedor_id LEFT JOIN (SELECT recibida_id, SUM(cantidad) cantidad FROM recibida_vencimiento rv WHERE rv.recibida_id = intLast GROUP BY recibida_id) t ON t.recibida_id = r.id WHERE r.id = intLast ; UPDATE recibida SET contabilizada = 0 WHERE id = intLast; UPDATE recibida SET contabilizada = 1 WHERE id = intLast; END IF; */ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`FacturasAfterInsert` AFTER INSERT ON `Facturas` FOR EACH ROW CALL bi.customer_risk_update (NEW.Id_Cliente, NEW.empresa_id, NEW.Importe) */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`FacturasBeforeUpdate` BEFORE UPDATE ON `Facturas` FOR EACH ROW BEGIN CALL bi.customer_risk_update (OLD.Id_Cliente, OLD.empresa_id, -OLD.Importe); CALL bi.customer_risk_update (NEW.Id_Cliente, NEW.empresa_id, NEW.Importe); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`FacturasBeforeDelete` BEFORE DELETE ON `Facturas` FOR EACH ROW CALL bi.customer_risk_update (OLD.Id_Cliente, OLD.empresa_id, -OLD.Importe) */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Familias` -- DROP TABLE IF EXISTS `Familias`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Familias` ( `Familia` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `Subcuenta` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Descripcion` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Familia`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Forms` -- DROP TABLE IF EXISTS `Forms`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Forms` ( `id` int(11) NOT NULL AUTO_INCREMENT, `titulo` varchar(50) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Gastos` -- DROP TABLE IF EXISTS `Gastos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Gastos` ( `Id_Gasto` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `iva_tipo_id` tinyint(4) NOT NULL, `Gasto` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `conbase` tinyint(4) NOT NULL DEFAULT '1', `isWithheld` tinyint(4) NOT NULL DEFAULT '0', `isForSale` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Gasto`,`iva_tipo_id`), KEY `iva_tipo_id` (`iva_tipo_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Greuges` -- DROP TABLE IF EXISTS `Greuges`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Greuges` ( `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Cliente` int(10) unsigned NOT NULL, `Comentario` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Importe` decimal(10,2) NOT NULL, `Fecha` datetime NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `Greuges_type_id` int(11) DEFAULT NULL, `Id_Ticket` int(11) DEFAULT NULL, PRIMARY KEY (`Id`), KEY `greuges_type_fk_idx` (`Greuges_type_id`), KEY `Id_Ticket_Greuge_Ticket_idx` (`Id_Ticket`), CONSTRAINT `Id_Ticket_Greuge_Ticket` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `greuges_type_fk` FOREIGN KEY (`Greuges_type_id`) REFERENCES `Greuges_type` (`Greuges_type_id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1693670 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Greuges_BEFORE_UPDATE` BEFORE UPDATE ON `Greuges` FOR EACH ROW BEGIN DECLARE vMaxDate DATETIME DEFAULT TIMESTAMPADD(YEAR,1,CURDATE()); IF NEW.Fecha > vMaxDate THEN SET NEW.Fecha = vMaxDate; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Greuges_type` -- DROP TABLE IF EXISTS `Greuges_type`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Greuges_type` ( `Greuges_type_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`Greuges_type_id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Grupos` -- DROP TABLE IF EXISTS `Grupos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Grupos` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Grupo` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `observation_type_id` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `name` (`name`) ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Impresoras` -- DROP TABLE IF EXISTS `Impresoras`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Impresoras` ( `Id_Impresora` tinyint(3) unsigned NOT NULL, `Ruta` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Impresora` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `referencia` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `2C` tinyint(4) DEFAULT '0', PRIMARY KEY (`Id_Impresora`), UNIQUE KEY `referencia` (`referencia`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Informes` -- DROP TABLE IF EXISTS `Informes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Informes` ( `Id_Informe` tinyint(3) unsigned NOT NULL, `Informe` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Informe`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Intrastat` -- DROP TABLE IF EXISTS `Intrastat`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Intrastat` ( `Codintrastat` int(8) unsigned zerofill NOT NULL, `Definicion` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `import` tinyint(4) NOT NULL DEFAULT '0', `iva_group_id` tinyint(3) unsigned NOT NULL DEFAULT '2', `iva_codigo_id` tinyint(2) unsigned NOT NULL DEFAULT '64', PRIMARY KEY (`Codintrastat`), KEY `iva_group_id` (`iva_group_id`), CONSTRAINT `Intrastat_ibfk_1` FOREIGN KEY (`iva_group_id`) REFERENCES `iva_group` (`iva_group_id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Jefes` -- DROP TABLE IF EXISTS `Jefes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Jefes` ( `Id_Trabajador` int(11) NOT NULL, `Id_Jefe` int(11) NOT NULL, `Departamento` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`Id_Trabajador`,`Id_Jefe`), KEY `trabajador_jefe_idx` (`Id_Jefe`), CONSTRAINT `trabajador_jefe` FOREIGN KEY (`Id_Jefe`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `trabajador_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Es una tabla que se rellena desde la comparativa, tomando los datos de postgress.'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Monedas` -- DROP TABLE IF EXISTS `Monedas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Monedas` ( `Id_Moneda` tinyint(3) unsigned NOT NULL, `Moneda` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `Descripcion` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Cambio` double NOT NULL DEFAULT '1', PRIMARY KEY (`Id_Moneda`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Monitoring` -- DROP TABLE IF EXISTS `Monitoring`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Monitoring` ( `id` int(11) NOT NULL AUTO_INCREMENT, `equipo_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `form_id` int(11) NOT NULL, `cliente_id` int(11) NOT NULL, `ticket_id` int(11) NOT NULL, `ODBC_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `equipo_id` (`equipo_id`,`user_id`,`form_id`,`cliente_id`,`ticket_id`), KEY `user_id` (`user_id`), KEY `form_id` (`form_id`), KEY `cliente_id` (`cliente_id`), KEY `ticket_id` (`ticket_id`), CONSTRAINT `Monitoring_ibfk_1` FOREIGN KEY (`equipo_id`) REFERENCES `Equipos` (`id`) ON UPDATE CASCADE, CONSTRAINT `Monitoring_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `Monitoring_ibfk_3` FOREIGN KEY (`form_id`) REFERENCES `Forms` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Movimientos` -- DROP TABLE IF EXISTS `Movimientos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Movimientos` ( `Id_Movimiento` int(11) NOT NULL AUTO_INCREMENT, `Id_Article` int(11) NOT NULL, `Id_Ticket` int(11) NOT NULL, `Concepte` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Cantidad` decimal(10,2) NOT NULL DEFAULT '0.00', `quantity` double(9,1) DEFAULT NULL, `Preu` decimal(10,2) DEFAULT '0.00', `Descuento` tinyint(2) unsigned NOT NULL DEFAULT '0', `CostFixat` decimal(10,2) NOT NULL DEFAULT '0.00', `Reservado` tinyint(1) NOT NULL DEFAULT '0', `OK` tinyint(1) NOT NULL DEFAULT '0', `PrecioFijado` tinyint(1) NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`Id_Movimiento`), KEY `Id_Ticket` (`Id_Ticket`), KEY `itemFk_ticketFk` (`Id_Article`,`Id_Ticket`), CONSTRAINT `Movimientos_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `movement_ticket_id` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=19365826 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`MovimientosAfterInsert` AFTER INSERT ON `Movimientos` FOR EACH ROW BEGIN CALL stock.queueAdd ('sale', NEW.Id_Movimiento, NULL); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `MovimientosBeforeUpdate` BEFORE UPDATE ON `Movimientos` FOR EACH ROW BEGIN IF NEW.Descuento > 100 THEN SET NEW.Descuento = 0; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`MovimientosAfterUpdate` AFTER UPDATE ON `Movimientos` FOR EACH ROW BEGIN CALL stock.queueAdd ('sale', NEW.Id_Movimiento, OLD.Id_Movimiento); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`MovimientosAfterDelete` AFTER DELETE ON `Movimientos` FOR EACH ROW BEGIN CALL stock.queueAdd ('sale', NULL, OLD.Id_Movimiento); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Movimientos_avisar` -- DROP TABLE IF EXISTS `Movimientos_avisar`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Movimientos_avisar` ( `Id_Movimiento` int(11) NOT NULL, `Id_Remitente` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Movimiento`), KEY `Movimiento` (`Id_Movimiento`), KEY `Remitente` (`Id_Remitente`), CONSTRAINT `Id_Movimientos_avisar_fk` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Movimientos_checked` -- DROP TABLE IF EXISTS `Movimientos_checked`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Movimientos_checked` ( `Id_Movimiento` int(11) NOT NULL, `checked` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Movimiento`), CONSTRAINT `fk_Movimientos_checked_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Movimientos_componentes` -- DROP TABLE IF EXISTS `Movimientos_componentes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Movimientos_componentes` ( `Id_Movimiento` int(11) NOT NULL, `Id_Componente` int(11) NOT NULL, `Valor` double NOT NULL, `greuge` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Movimiento`,`Id_Componente`), KEY `fk_mov_comp_idx` (`Id_Componente`), CONSTRAINT `mc_fk1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `mc_fk2` FOREIGN KEY (`Id_Componente`) REFERENCES `bi`.`tarifa_componentes` (`Id_Componente`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Movimientos_mark` -- DROP TABLE IF EXISTS `Movimientos_mark`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Movimientos_mark` ( `Id_Movimiento` int(11) NOT NULL, `valor` tinyint(3) unsigned NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `original_quantity` double DEFAULT NULL, `Id_Trabajador` int(11) NOT NULL, `Id_Accion` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Id_Movimiento_mark` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Id_Movimiento_mark`), KEY `Id_Movimiento` (`Id_Movimiento`) ) ENGINE=InnoDB AUTO_INCREMENT=8792994 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Movimientos_revisar` -- DROP TABLE IF EXISTS `Movimientos_revisar`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Movimientos_revisar` ( `Id_Movimiento` int(11) NOT NULL, `Comentario` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `Revisado` tinyint(1) NOT NULL DEFAULT '0', `Id_Remitente` int(11) DEFAULT NULL, `Id_Destinatario` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Movimiento`), KEY `Remitente` (`Id_Remitente`), KEY `Destinatario` (`Id_Destinatario`), CONSTRAINT `Movimientos_revisar_ibfk_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Objetivos` -- DROP TABLE IF EXISTS `Objetivos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Objetivos` ( `Periodo` int(11) NOT NULL, `Objetivo` double NOT NULL, PRIMARY KEY (`Periodo`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Ordenes` -- DROP TABLE IF EXISTS `Ordenes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Ordenes` ( `Id_ORDEN` int(11) NOT NULL AUTO_INCREMENT, `ORDEN` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `datORDEN` datetime DEFAULT NULL, `datTICKET` datetime DEFAULT NULL, `CodVENDEDOR` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `CodCOMPRADOR` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT 'NOE', `CANTIDAD` int(11) DEFAULT NULL, `PRECIOMAX` double DEFAULT NULL, `PREU` double DEFAULT NULL, `Id_ARTICLE` double DEFAULT NULL, `Id_CLIENTE` int(11) DEFAULT NULL, `COMENTARIO` longtext COLLATE utf8_unicode_ci, `OK` tinyint(1) NOT NULL DEFAULT '0', `TOTAL` int(11) DEFAULT NULL, `datCOMPRA` datetime DEFAULT NULL, `KO` tinyint(1) NOT NULL DEFAULT '0', `Id_Movimiento` int(11) DEFAULT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`Id_ORDEN`), UNIQUE KEY `Id_Movimiento_UNIQUE` (`Id_Movimiento`), KEY `Id_ARTICLE` (`Id_ARTICLE`), KEY `Id_CLIENTE` (`Id_CLIENTE`), KEY `Id_Comprador` (`CodCOMPRADOR`), KEY `Id_Movimiento` (`Id_Movimiento`), KEY `Id_Vendedor` (`CodVENDEDOR`) ) ENGINE=InnoDB AUTO_INCREMENT=25397 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Origen` -- DROP TABLE IF EXISTS `Origen`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Origen` ( `id` tinyint(2) unsigned NOT NULL AUTO_INCREMENT, `Abreviatura` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `Origen` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `warehouse_id` smallint(5) unsigned DEFAULT '4', `bandera` blob, `nl` tinyint(4) NOT NULL DEFAULT '0', `Id_Paises` mediumint(8) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `Abreviatura` (`Abreviatura`), KEY `warehouse_id` (`warehouse_id`), KEY `Id_Paises` (`Id_Paises`), CONSTRAINT `Origen_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Pagares` -- DROP TABLE IF EXISTS `Pagares`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Pagares` ( `kk_Vencimiento` datetime DEFAULT NULL, `kk_Importe` double DEFAULT '0', `Fechaemision` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Pagare` int(11) NOT NULL AUTO_INCREMENT, `Concepto` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `kk_id_proveedor` int(11) DEFAULT NULL, `kk_empresa_id` smallint(5) unsigned DEFAULT NULL, `pago_id` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`Id_Pagare`), KEY `empresa_id` (`kk_empresa_id`), KEY `pago_id` (`pago_id`), CONSTRAINT `Pagares_ibfk_2` FOREIGN KEY (`pago_id`) REFERENCES `pago` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2834 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Paises` -- DROP TABLE IF EXISTS `Paises`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Paises` ( `Id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Pais` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `CEE` tinyint(1) NOT NULL DEFAULT '1', `Codigo` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `Id_Moneda` tinyint(3) unsigned NOT NULL DEFAULT '1', `Id_Paisreal` mediumint(8) unsigned NOT NULL COMMENT 'Pais Real(apaño por culpa del España Exento)', `nst_geo_id` int(11) DEFAULT NULL, `nst_name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `geoFk` int(11) DEFAULT NULL, PRIMARY KEY (`Id`), KEY `Id_Paisreal` (`Id_Paisreal`) ) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Permisos` -- DROP TABLE IF EXISTS `Permisos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Permisos` ( `Id_Grupo` int(10) unsigned NOT NULL, `Id_Trabajador` int(10) unsigned NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', PRIMARY KEY (`Id_Grupo`,`Id_Trabajador`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `Permisos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Permisos_ibfk_2` FOREIGN KEY (`Id_Grupo`) REFERENCES `Grupos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `PreciosEspeciales` -- DROP TABLE IF EXISTS `PreciosEspeciales`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `PreciosEspeciales` ( `Id_PrecioEspecial` int(11) NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL DEFAULT '0', `Id_Article` int(11) NOT NULL DEFAULT '0', `PrecioEspecial` double NOT NULL DEFAULT '0', PRIMARY KEY (`Id_PrecioEspecial`), UNIQUE KEY `Id_Cliente_2` (`Id_Cliente`,`Id_Article`), KEY `Id_Article` (`Id_Article`), KEY `Id_Cliente` (`Id_Cliente`), CONSTRAINT `sp_article_id` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `sp_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `{01A99AF1-3D3F-4B15-AC0C-C7A834F319A3}` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `{EE4ADEF6-0AC6-401F-B7C4-D797972FC065}` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Prioridades` -- DROP TABLE IF EXISTS `Prioridades`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Prioridades` ( `Id_Prioridad` tinyint(3) unsigned NOT NULL DEFAULT '0', `Prioridad` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Prioridad`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Proveedores` -- DROP TABLE IF EXISTS `Proveedores`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Proveedores` ( `Id_Proveedor` int(11) NOT NULL AUTO_INCREMENT, `Proveedor` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `cuenta` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Domicilio` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `CP` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Localidad` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `provinciakk` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `province_id` smallint(5) unsigned DEFAULT NULL, `pais_id` mediumint(8) unsigned DEFAULT NULL, `NIF` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `oficial` tinyint(1) NOT NULL DEFAULT '1', `Agricola` tinyint(1) NOT NULL DEFAULT '0', `cuentaret` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `Telefono` varchar(16) COLLATE utf8_unicode_ci DEFAULT NULL, `Fax` varchar(16) COLLATE utf8_unicode_ci DEFAULT NULL, `ComisionProveedor` float NOT NULL DEFAULT '0', `Alias` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `pay_met_id` tinyint(3) unsigned NOT NULL, `pay_day` tinyint(4) unsigned DEFAULT NULL, `pay_dem_id` tinyint(3) unsigned NOT NULL DEFAULT '7', `odbc_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `serious` tinyint(1) unsigned zerofill DEFAULT '1', `notas` text COLLATE utf8_unicode_ci, `postcode_id` int(11) unsigned DEFAULT NULL, `codpos` char(5) COLLATE utf8_unicode_ci DEFAULT NULL, `active` tinyint(4) DEFAULT '1', PRIMARY KEY (`Id_Proveedor`), UNIQUE KEY `cuenta` (`cuenta`), UNIQUE KEY `NIF` (`NIF`), KEY `pais_id` (`pais_id`), KEY `pay_met_id` (`pay_met_id`), KEY `province_id` (`province_id`), KEY `pay_dem_id` (`pay_dem_id`), KEY `codpos` (`codpos`,`CP`), CONSTRAINT `Id_Pais` FOREIGN KEY (`pais_id`) REFERENCES `Paises` (`Id`) ON UPDATE CASCADE, CONSTRAINT `pay_dem_id` FOREIGN KEY (`pay_dem_id`) REFERENCES `pay_dem` (`id`) ON UPDATE CASCADE, CONSTRAINT `pay_met_id` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `province_id` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2393 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Proveedores_account` -- DROP TABLE IF EXISTS `Proveedores_account`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Proveedores_account` ( `Id_Proveedores_account` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Id_Proveedor` int(11) NOT NULL, `IBAN` varchar(30) CHARACTER SET utf8 DEFAULT NULL, `office` varchar(4) CHARACTER SET utf8 DEFAULT NULL, `DC` varchar(2) CHARACTER SET utf8 DEFAULT NULL, `number` varchar(10) CHARACTER SET utf8 DEFAULT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `bic_sufix` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '', `entity_id` int(10) DEFAULT NULL, `Id_Banco` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Proveedores_account`), KEY `fk_proveedores_proveedores_account_idx` (`Id_Proveedor`), KEY `fk_Proveedores_account_entity1_idx` (`entity_id`), KEY `fk_banco_prov_account_idx` (`Id_Banco`), CONSTRAINT `fk_banco_prov_account` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=581 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Proveedores_cargueras` -- DROP TABLE IF EXISTS `Proveedores_cargueras`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Proveedores_cargueras` ( `Id_Proveedor` int(11) NOT NULL, PRIMARY KEY (`Id_Proveedor`), CONSTRAINT `proveedores_cargueras_fk1` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla de espcializacion para señalar las compañias que prestan servicio de transitario'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Proveedores_comunicados` -- DROP TABLE IF EXISTS `Proveedores_comunicados`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Proveedores_comunicados` ( `Id_Proveedor` int(11) NOT NULL, `escrito_id` int(11) NOT NULL, `fecha` timestamp NULL DEFAULT CURRENT_TIMESTAMP, KEY `Proveedor` (`Id_Proveedor`), KEY `Escrito` (`escrito_id`), CONSTRAINT `Proveedores_comunicados_ibfk_3` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `Proveedores_comunicados_ibfk_4` FOREIGN KEY (`escrito_id`) REFERENCES `Proveedores_escritos` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Proveedores_escritos` -- DROP TABLE IF EXISTS `Proveedores_escritos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Proveedores_escritos` ( `id` int(11) NOT NULL AUTO_INCREMENT, `escrito` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `informe` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Proveedores_gestdoc` -- DROP TABLE IF EXISTS `Proveedores_gestdoc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Proveedores_gestdoc` ( `Id_Proveedor` int(11) NOT NULL, `gestdoc_id` int(11) NOT NULL, PRIMARY KEY (`Id_Proveedor`,`gestdoc_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Recibos` -- DROP TABLE IF EXISTS `Recibos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Recibos` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Id_Factura` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Entregado` decimal(10,2) NOT NULL DEFAULT '0.00', `Pendiente` decimal(10,2) NOT NULL DEFAULT '0.00', `Fechacobro` datetime DEFAULT NULL, `Id_Trabajador` int(11) DEFAULT '0', `Id_Banco` int(11) DEFAULT '0', `Id_Cliente` int(11) DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `conciliado` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', PRIMARY KEY (`Id`), KEY `Id_Banco` (`Id_Banco`), KEY `Id_Cliente` (`Id_Cliente`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `Recibos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Recibos_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibo_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=428776 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`RecibosAfterInsert` AFTER INSERT ON `Recibos` FOR EACH ROW CALL bi.customer_risk_update (NEW.Id_Cliente, NEW.empresa_id, -NEW.Entregado) */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`RecibosBeforeUpdate` BEFORE UPDATE ON `Recibos` FOR EACH ROW BEGIN CALL bi.customer_risk_update (OLD.Id_Cliente, OLD.empresa_id, OLD.Entregado); CALL bi.customer_risk_update (NEW.Id_Cliente, NEW.empresa_id, -NEW.Entregado); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`RecibosBeforeDelete` BEFORE DELETE ON `Recibos` FOR EACH ROW CALL bi.customer_risk_update (OLD.Id_Cliente, OLD.empresa_id, OLD.Entregado) */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Recibos_recorded` -- DROP TABLE IF EXISTS `Recibos_recorded`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Recibos_recorded` ( `Id_Recibos` int(11) NOT NULL, `recorded` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Marcado si se ha contabilizado', PRIMARY KEY (`Id_Recibos`), CONSTRAINT `Recibos_recorded_ibfk_1` FOREIGN KEY (`Id_Recibos`) REFERENCES `Recibos` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recibos (Contrareembolso) contabilizados'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Relaciones` -- DROP TABLE IF EXISTS `Relaciones`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Relaciones` ( `Id_Relacion` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Contacto` int(10) unsigned NOT NULL, `Id_Proveedor` int(10) unsigned DEFAULT NULL, `Id_Cliente` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`Id_Relacion`), KEY `Id_Contacto` (`Id_Contacto`), KEY `Id_Proveedor` (`Id_Proveedor`), KEY `Id_Cliente` (`Id_Cliente`) ) ENGINE=InnoDB AUTO_INCREMENT=2573 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Remesas` -- DROP TABLE IF EXISTS `Remesas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Remesas` ( `Id_Remesa` int(11) NOT NULL AUTO_INCREMENT, `Fecha Remesa` datetime DEFAULT NULL, `Banco` int(11) DEFAULT '0', `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', PRIMARY KEY (`Id_Remesa`), KEY `Id_Banco` (`Banco`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `Remesas_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Remesas_ibfk_2` FOREIGN KEY (`Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=985 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Reservas` -- DROP TABLE IF EXISTS `Reservas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Reservas` ( `Id_Reserva` int(11) NOT NULL AUTO_INCREMENT, `Id_Ticket` int(11) DEFAULT '0', `Fecha` datetime DEFAULT NULL, `Alias` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `article` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `medida` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `categoria` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `color` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `origen` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `cantidad` int(11) DEFAULT '0', `Id_Article` double DEFAULT '0', PRIMARY KEY (`Id_Reserva`), KEY `Id_1` (`Id_Ticket`), KEY `Id_Article` (`Id_Article`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Rutas` -- DROP TABLE IF EXISTS `Rutas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Rutas` ( `Id_Ruta` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Trabajador` int(10) unsigned DEFAULT NULL, `Fecha` date NOT NULL, `Id_Vehiculo` int(10) unsigned DEFAULT NULL, `Id_Agencia` int(11) DEFAULT NULL, `Hora` datetime DEFAULT NULL, `ok` tinyint(1) unsigned NOT NULL DEFAULT '0', `km_start` mediumint(9) NOT NULL, `km_end` mediumint(9) NOT NULL, `date_start` datetime NOT NULL, `date_end` datetime NOT NULL, `gestdoc_id` int(11) DEFAULT NULL, `cost` double unsigned DEFAULT NULL, `m3` decimal(10,1) unsigned DEFAULT NULL, PRIMARY KEY (`Id_Ruta`), KEY `Id_Agencia` (`Id_Agencia`), KEY `Fecha` (`Fecha`), KEY `gestdoc_id` (`gestdoc_id`), CONSTRAINT `Rutas_ibfk_1` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=34256 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Rutas_au` AFTER UPDATE ON `Rutas` FOR EACH ROW BEGIN IF IFNULL(NEW.gestdoc_id,0) <> IFNULL(OLD.gestdoc_id,0) AND NEW.gestdoc_id > 0 THEN -- JGF 09/09/14 cuando se añade un gestdoc a una ruta, se le asigna automagicamente a todos sus Tickets -- Inserta el gestdoc en todos los tickets de la ruta INSERT INTO tickets_gestdoc(Id_Ticket,gestdoc_id) SELECT Id_Ticket, NEW.gestdoc_id FROM Tickets WHERE Id_Ruta = NEW.Id_Ruta ON DUPLICATE KEY UPDATE gestdoc_id = NEW.gestdoc_id; -- Update del firmado UPDATE Tickets t JOIN tickets_gestdoc tg ON t.Id_Ticket = tg.Id_Ticket SET Firmado = 1 WHERE t.Id_Ruta = NEW.Id_Ruta; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Rutas_Master` -- DROP TABLE IF EXISTS `Rutas_Master`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Rutas_Master` ( `id` int(11) NOT NULL AUTO_INCREMENT, `warehouse_id` smallint(6) unsigned DEFAULT NULL, `km` int(11) DEFAULT NULL, `bultos` int(11) NOT NULL, `vehiculos_coste` decimal(10,2) DEFAULT NULL, `personal_coste` decimal(10,2) DEFAULT NULL, `vehiculos_numero` decimal(10,2) DEFAULT NULL, `personal_numero` decimal(10,2) DEFAULT NULL, `gasoil` int(11) DEFAULT NULL, `autonomos` decimal(10,2) DEFAULT NULL, `año` int(11) DEFAULT NULL, `mes` int(11) DEFAULT NULL, `gastos` decimal(10,2) DEFAULT NULL, `bultos_autonomos` int(11) DEFAULT NULL, `coste_km` decimal(10,2) DEFAULT NULL, `coste_bulto` decimal(10,2) DEFAULT NULL, `coste_bulto_autonomo` decimal(10,2) DEFAULT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `fk_rutas_warehouse_id_idx` (`warehouse_id`), CONSTRAINT `fk_rutas_warehouse_id` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Rutas_dits` -- DROP TABLE IF EXISTS `Rutas_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Rutas_dits` ( `idRutas_dits` int(11) unsigned NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) unsigned NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idRutas_dits`), KEY `index2` (`idaccion_dits`), KEY `index3` (`Id_Ticket`), KEY `index4` (`Id_Trabajador`), CONSTRAINT `fk_Id_Trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fk_Id_ruta` FOREIGN KEY (`Id_Ticket`) REFERENCES `Rutas` (`Id_Ruta`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_action_dits` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=300164 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Rutas_monitor` -- DROP TABLE IF EXISTS `Rutas_monitor`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Rutas_monitor` ( `Id_Ruta` int(10) unsigned NOT NULL, `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Ubicacion` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `pedidosEncajados` int(11) DEFAULT NULL, `pedidosLibres` int(11) DEFAULT NULL, `bultos` int(11) DEFAULT NULL, `notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `pedidosProduccion` int(11) DEFAULT NULL, `fecha` date DEFAULT NULL, `dockFk` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Ruta`), KEY `Rutas_monitor_fk_2_idx` (`dockFk`), CONSTRAINT `Rutas_monitor_fk_1` FOREIGN KEY (`Id_Ruta`) REFERENCES `Rutas` (`Id_Ruta`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Rutas_monitor_fk_2` FOREIGN KEY (`dockFk`) REFERENCES `dock` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Permite ubicar y controlar el estado de preparacion de las rutas'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Salarios` -- DROP TABLE IF EXISTS `Salarios`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Salarios` ( `Id_Trabajador` int(11) NOT NULL, `Salario_Bruto` double DEFAULT '0', `Incentivo` double DEFAULT '0', `SS` double DEFAULT '0', `warehouse_id` smallint(6) NOT NULL DEFAULT '1', PRIMARY KEY (`Id_Trabajador`), CONSTRAINT `trabajadaor_id` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Saldos_Prevision` -- DROP TABLE IF EXISTS `Saldos_Prevision`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Saldos_Prevision` ( `Saldos_Prevision_id` int(11) NOT NULL AUTO_INCREMENT, `Descripcion` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Importe` double NOT NULL DEFAULT '0', `Fecha` date NOT NULL, `Id_Banco` int(11) DEFAULT NULL, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', PRIMARY KEY (`Saldos_Prevision_id`), KEY `Fecha_indice` (`Fecha`), KEY `banco_prevision_idx` (`Id_Banco`), KEY `empresa_prevision_idx` (`empresa_id`), CONSTRAINT `banco_prevision` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `empresa_prevision` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir '; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Series` -- DROP TABLE IF EXISTS `Series`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Series` ( `Id_Serie` varchar(2) COLLATE utf8_unicode_ci NOT NULL, `Serie` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, `Cuenta` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Serie`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Split_lines` -- DROP TABLE IF EXISTS `Split_lines`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Split_lines` ( `Id_Split_lines` int(11) NOT NULL AUTO_INCREMENT, `Id_Split` int(11) NOT NULL, `Id_Article` int(11) DEFAULT NULL, `Id_Compra` int(11) DEFAULT NULL, PRIMARY KEY (`Id_Split_lines`), KEY `Id_Split` (`Id_Split`), KEY `Id_Compra` (`Id_Compra`), CONSTRAINT `Id_Compra` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Split_lines_ibfk_1` FOREIGN KEY (`Id_Split`) REFERENCES `Splits` (`Id_Split`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=309585 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Splits` -- DROP TABLE IF EXISTS `Splits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Splits` ( `Id_Split` int(11) NOT NULL AUTO_INCREMENT, `Id_Ticket` int(11) DEFAULT NULL, `Id_Entrada` int(11) DEFAULT NULL, `Fecha` datetime DEFAULT NULL, `Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Split`), KEY `Id_Entrada` (`Id_Entrada`) ) ENGINE=InnoDB AUTO_INCREMENT=36069 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Stockcontrol` -- DROP TABLE IF EXISTS `Stockcontrol`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Stockcontrol` ( `Id_Control` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Article` int(11) NOT NULL, `Id_Remitente` int(11) NOT NULL, `Id_Solver` int(11) NOT NULL, `Problema` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `Solucion` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `Listo` tinyint(1) NOT NULL, `Air` tinyint(1) NOT NULL, `Datestart` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `Dateend` datetime DEFAULT NULL, PRIMARY KEY (`Id_Control`), KEY `Id_Article` (`Id_Article`), KEY `Id_Remitente` (`Id_Remitente`), KEY `Id_Solver` (`Id_Solver`), CONSTRAINT `Stockcontrol_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_2` FOREIGN KEY (`Id_Remitente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_3` FOREIGN KEY (`Id_Solver`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=23181 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Tickets` -- DROP TABLE IF EXISTS `Tickets`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tickets` ( `Id_Ticket` int(11) NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL DEFAULT '0', `warehouse_id` smallint(6) unsigned NOT NULL DEFAULT '1', `Fecha` datetime NOT NULL, `Alias` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Notas` longtext COLLATE utf8_unicode_ci, `Factura` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `factura_id` int(10) unsigned DEFAULT NULL COMMENT 'eliminar', `Anotadoencaja` tinyint(1) NOT NULL DEFAULT '0', `Id_Consigna` int(11) NOT NULL DEFAULT '0', `Id_Trabajador` int(11) DEFAULT NULL, `Observaciones` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'eliminar', `Firmado` tinyint(1) NOT NULL DEFAULT '0', `Etiquetasemitidas` tinyint(1) NOT NULL DEFAULT '0', `PedidoImpreso` tinyint(1) NOT NULL DEFAULT '0', `Bultos` smallint(10) unsigned DEFAULT '0', `Localizacion` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `Hora` int(11) DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `blocked` tinyint(1) NOT NULL DEFAULT '1', `Solucion` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `Id_Ruta` int(10) unsigned DEFAULT NULL, `Prioridad` tinyint(3) unsigned DEFAULT NULL, `priority` tinyint(1) unsigned NOT NULL DEFAULT '1', `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `Id_Agencia` int(11) NOT NULL, `landing` date DEFAULT NULL, `boxed` tinyint(2) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Ticket`), KEY `Id_Cliente` (`Id_Cliente`), KEY `Id_Consigna` (`Id_Consigna`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `warehouse_id` (`warehouse_id`), KEY `empresa_id` (`empresa_id`), KEY `Id_Agencia` (`Id_Agencia`), KEY `Factura` (`Factura`), KEY `Fecha` (`Fecha`), KEY `Id_Ruta` (`Id_Ruta`), KEY `warehouse_date` (`warehouse_id`,`Fecha`), CONSTRAINT `Tickets_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `Tickets_ibfk_5` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Tickets_ibfk_6` FOREIGN KEY (`Id_Consigna`) REFERENCES `Consignatarios` (`id_consigna`) ON UPDATE CASCADE, CONSTRAINT `Tickets_ibfk_8` FOREIGN KEY (`Id_Agencia`) REFERENCES `Agencias` (`Id_Agencia`), CONSTRAINT `Tickets_ibfk_9` FOREIGN KEY (`Id_Ruta`) REFERENCES `Rutas` (`Id_Ruta`) ON UPDATE CASCADE, CONSTRAINT `ticket_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `tickets_fk10` FOREIGN KEY (`Factura`) REFERENCES `Facturas` (`Id_Factura`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1726093 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `TicketsBeforeInsert` BEFORE INSERT ON `Tickets` FOR EACH ROW BEGIN /* DECLARE strEspecif VARCHAR(255); DECLARE intId_Agencia INTEGER; DECLARE auxprovince INTEGER; DECLARE intemp INTEGER; -- Si el cliente es de Canarias se le asigna la empresa ORN SELECT province_id INTO auxprovince FROM Consignatarios WHERE Id_Consigna = NEW.Id_Consigna; IF (auxprovince = 49 OR auxprovince = 33) AND NEW.Id_Cliente <> 5270 THEN SET intemp = 1381; END IF; IF intemp THEN SET NEW.empresa_id = intemp; END IF; */ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`TicketsAfterInsert` AFTER INSERT ON `vn2008`.`Tickets` FOR EACH ROW BEGIN /* borrar cuando se canvie el insert ticket en la APP mobil */ DECLARE vEmployee INT; SELECT Id_Trabajador INTO vEmployee FROM Trabajadores WHERE user_id = account.userGetId(); IF vEmployee IS NULL THEN SET vEmployee = 20; END IF; IF NEW.Id_Cliente = 400 OR NEW.Id_Cliente = 200 THEN INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) SELECT id, NEW.Id_Ticket, vEmployee FROM state WHERE `code` = 'DELIVERED'; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `TicketsBeforeUpdate` BEFORE UPDATE ON `Tickets` FOR EACH ROW BEGIN DECLARE vAgency INT; DECLARE vEmployee INT; DECLARE vIsCee TINYINT; DECLARE vHasVies TINYINT; SELECT Id_Trabajador INTO vEmployee FROM Trabajadores WHERE user_id = account.userGetId(); IF vEmployee IS NULL THEN SET vEmployee = 20; END IF; -- Comprobación de VIES IF NEW.empresa_id <> OLD.empresa_id THEN SELECT CEE INTO vIsCee FROM Proveedores AS pr INNER JOIN Paises p ON p.Id = pr.pais_id WHERE Id_Proveedor = NEW.empresa_id; SELECT isVies INTO vHasVies FROM vn.`client` WHERE id = OLD.Id_Cliente; IF vIsCee = 1 AND NOT vHasVies Then CALL util.throw("NO_VALID_VIES"); END IF; END IF; IF NEW.Fecha < '2001-01-01' THEN SET NEW.Id_Ruta = NULL; IF NEW.Fecha < '2000-01-01' then SET NEW.Fecha = OLD.Fecha; END IF; INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) VALUES(17, NEW.Id_Ticket, vEmployee); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`TicketsAfterUpdate` AFTER UPDATE ON `Tickets` FOR EACH ROW BEGIN IF NEW.Id_Ruta IS NULL AND OLD.Id_Ruta IS NOT NULL THEN INSERT INTO vn.routeLog(originFk, userFk, `action`, description) VALUES (OLD.Id_Ruta, account.userGetId(), 'update', CONCAT('Saca el ticket ', OLD.Id_Ticket, ' de la ruta')); ELSEIF NOT (NEW.Id_Ruta <=> OLD.Id_Ruta) THEN INSERT INTO vn.routeLog(originFk, userFk, `action`, description) VALUES (NEW.Id_Ruta, account.userGetId(), 'update', CONCAT('Añade el ticket ', OLD.Id_Ticket, ' a la ruta')); END IF; CALL stock.queueAdd ('ticket', NEW.Id_Ticket, OLD.Id_Ticket); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Tickets_dits` -- DROP TABLE IF EXISTS `Tickets_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tickets_dits` ( `idTickets_dits` int(11) NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idTickets_dits`), KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`), CONSTRAINT `Tickets_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=56280004 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Tickets_stack` -- DROP TABLE IF EXISTS `Tickets_stack`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tickets_stack` ( `Id_Ticket` int(11) NOT NULL, `orden` smallint(5) unsigned NOT NULL, `label_number` smallint(6) DEFAULT '0', `preparado` tinyint(4) DEFAULT '0', PRIMARY KEY (`Id_Ticket`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Orden para imprimir los F5.Se borra autom. lo de 2 meses'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Tickets_state` -- DROP TABLE IF EXISTS `Tickets_state`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tickets_state` ( `Id_Ticket` int(11) NOT NULL DEFAULT '0', `inter_id` int(11) NOT NULL, `state_name` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`Id_Ticket`), KEY `double_foreign` (`Id_Ticket`,`inter_id`), CONSTRAINT `Id_Ticket` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `double_foreign` FOREIGN KEY (`Id_Ticket`, `inter_id`) REFERENCES `vncontrol`.`inter` (`Id_Ticket`, `inter_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Tickets_turno` -- DROP TABLE IF EXISTS `Tickets_turno`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tickets_turno` ( `Id_Ticket` int(11) NOT NULL AUTO_INCREMENT, `weekDay` tinyint(1) DEFAULT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6', PRIMARY KEY (`Id_Ticket`), CONSTRAINT `Id_Ticket_fk` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1713122 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Tintas` -- DROP TABLE IF EXISTS `Tintas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tintas` ( `Id_Tinta` char(3) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Tinta` blob NOT NULL, `Orden` int(11) NOT NULL, `ball` blob, `cargex` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Tinta`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Tipos` -- DROP TABLE IF EXISTS `Tipos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tipos` ( `tipo_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `Id_Tipo` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `Tipo` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `Orden` int(11) DEFAULT '0', `Temperatura` tinyint(1) unsigned NOT NULL DEFAULT '0', `reino_id` int(10) unsigned NOT NULL, `Id_Trabajador` int(11) NOT NULL, `inventory` tinyint(4) NOT NULL DEFAULT '1', `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `f11` tinyint(4) NOT NULL DEFAULT '0', `father_id` smallint(5) DEFAULT NULL, `transaction` tinyint(4) NOT NULL DEFAULT '0', `confeccion` int(10) unsigned DEFAULT NULL, `location` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `life` smallint(5) unsigned DEFAULT NULL, `maneuver` double NOT NULL DEFAULT '0.21', `target` double NOT NULL DEFAULT '0.15', `top_margin` double NOT NULL DEFAULT '0.3', `profit` double NOT NULL DEFAULT '0.02', `FV` tinyint(3) DEFAULT '1', `density` double NOT NULL DEFAULT '167' COMMENT 'Almacena el valor por defecto de la densidad en kg/m3 para el calculo de los portes aereos, en articulos se guarda la correcta', `promo` double NOT NULL DEFAULT '0', `box` tinyint(4) NOT NULL DEFAULT '0', `CYM` int(11) NOT NULL DEFAULT '0', `isPackaging` tinyint(1) NOT NULL DEFAULT '0', `hasComponents` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`Id_Tipo`), UNIQUE KEY `tipo_id_UNIQUE` (`tipo_id`), KEY `Trabajador` (`Id_Trabajador`), KEY `reino_id` (`reino_id`), KEY `Tipos_fk3_idx` (`confeccion`), CONSTRAINT `Tipos_fk3` FOREIGN KEY (`confeccion`) REFERENCES `vn`.`confectionType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `Tipos_ibfk_1` FOREIGN KEY (`reino_id`) REFERENCES `reinos` (`id`) ON UPDATE CASCADE, CONSTRAINT `Trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=221 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Protege la tabla tipos de updates para los 4 parámetros de los compradores, en funcion del valor del campo CodigoRojo de tblContadores.'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Tipos_bu` BEFORE UPDATE ON `Tipos` FOR EACH ROW -- Edit trigger body code below this line. Do not edit lines above this one BEGIN DECLARE strCOD VARCHAR(40); SELECT CodigoRojo INTO strCOD FROM tblContadores LIMIT 1; IF strCOD <> 'tipos' THEN SET NEW.maneuver = OLD.maneuver ; SET NEW.target = OLD.target ; SET NEW.top_margin = OLD.top_margin ; SET NEW.profit = OLD.profit ; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Tipos_f11` -- DROP TABLE IF EXISTS `Tipos_f11`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tipos_f11` ( `f11_id` tinyint(4) NOT NULL AUTO_INCREMENT, `description` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`f11_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Trabajadores` -- DROP TABLE IF EXISTS `Trabajadores`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Trabajadores` ( `Id_Trabajador` int(11) NOT NULL AUTO_INCREMENT, `CodigoTrabajador` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `Nombre` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Apellidos` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Password` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `extension` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `sub` int(11) unsigned DEFAULT NULL, `user` varchar(20) CHARACTER SET utf8 DEFAULT NULL, `Contrato_Tipo` varchar(30) CHARACTER SET utf8 DEFAULT 'no dejar vacio' COMMENT 'campo obsoleto, actualmente se rellena en laboral', `Categoria_Laboral` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Fecha_Inicio` datetime DEFAULT NULL, `Fecha_Fin` datetime DEFAULT NULL, `Notas` varchar(254) COLLATE utf8_unicode_ci DEFAULT NULL, `Foto` blob, `dni` varchar(9) COLLATE utf8_unicode_ci DEFAULT NULL, `address` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `date_birth` date NOT NULL, `marital_status` enum('soltero/a','casado/a') COLLATE utf8_unicode_ci NOT NULL, `phone` varchar(9) COLLATE utf8_unicode_ci NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL, `Id_Cliente_Interno` int(11) DEFAULT NULL, `user_id` int(10) unsigned DEFAULT NULL, `boss` int(11) NOT NULL DEFAULT '2', `DniExpiration` datetime DEFAULT NULL, PRIMARY KEY (`Id_Trabajador`), UNIQUE KEY `CodigoTrabajador_UNIQUE` (`CodigoTrabajador`), UNIQUE KEY `user` (`user`), UNIQUE KEY `user_id_UNIQUE` (`user_id`), UNIQUE KEY `Id_Cliente_Interno` (`Id_Cliente_Interno`), KEY `sub` (`sub`), CONSTRAINT `Clientes` FOREIGN KEY (`Id_Cliente_Interno`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `Trabajadores_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1020 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`TrabajadoresBeforeInsert` BEFORE INSERT ON `Trabajadores` FOR EACH ROW BEGIN IF NEW.password = '' THEN SET NEW.password = 'FALLO'; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`TrabajadoresBeforeUpdate` BEFORE UPDATE ON `Trabajadores` FOR EACH ROW BEGIN IF NEW.password = '' THEN SET NEW.password = 'FALLO'; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Tramos` -- DROP TABLE IF EXISTS `Tramos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tramos` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Tramo` time NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `Tramo` (`Tramo`) ) ENGINE=MyISAM AUTO_INCREMENT=50 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Ubicator` -- DROP TABLE IF EXISTS `Ubicator`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Ubicator` ( `Id_Estanterias` int(11) NOT NULL, `Date` date NOT NULL, `w` int(11) DEFAULT '0', `d` int(11) DEFAULT '0', `h` int(11) DEFAULT '0', `Id_Cubo` int(11) NOT NULL, `Id_Article` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `V_edi_item_track` -- DROP TABLE IF EXISTS `V_edi_item_track`; /*!50001 DROP VIEW IF EXISTS `V_edi_item_track`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `V_edi_item_track` AS SELECT 1 AS `item_id`, 1 AS `s1`, 1 AS `s2`, 1 AS `s3`, 1 AS `s4`, 1 AS `s5`, 1 AS `s6`, 1 AS `kop`, 1 AS `pac`, 1 AS `cat`, 1 AS `ori`, 1 AS `pro`, 1 AS `sub`, 1 AS `package`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `Vehiculos` -- DROP TABLE IF EXISTS `Vehiculos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Vehiculos` ( `Id_Vehiculo` int(10) unsigned NOT NULL AUTO_INCREMENT, `Matricula` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `Modelo` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `Marca` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `m3` double DEFAULT NULL, `active` tinyint(4) NOT NULL DEFAULT '1', `warehouseFk` smallint(6) unsigned DEFAULT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Vehiculo`), KEY `empresa_id` (`empresa_id`), KEY `provinceFk_idx` (`warehouseFk`), CONSTRAINT `Vehiculos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `provinceFk` FOREIGN KEY (`warehouseFk`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=361 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `Vehiculos_consumo` -- DROP TABLE IF EXISTS `Vehiculos_consumo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Vehiculos_consumo` ( `Vehiculos_consumo_id` int(11) NOT NULL AUTO_INCREMENT, `Id_Vehiculo` int(10) unsigned NOT NULL, `fecha` date NOT NULL, `km` int(20) unsigned NOT NULL, `litros` double unsigned NOT NULL, `precio` double unsigned NOT NULL, `adblue` decimal(10,2) NOT NULL DEFAULT '0.00', `peajes` double DEFAULT NULL, `descuento` double DEFAULT NULL, `silla` int(11) NOT NULL DEFAULT '0' COMMENT 'indica si han repostado en la gasolinera de la rotonda', `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `otros` double DEFAULT NULL, PRIMARY KEY (`Vehiculos_consumo_id`,`Id_Vehiculo`), KEY `fk_Vehiculos_consumo_Vehiculos_idx` (`Id_Vehiculo`), CONSTRAINT `fk_Vehiculos_consumo_Vehiculos` FOREIGN KEY (`Id_Vehiculo`) REFERENCES `Vehiculos` (`Id_Vehiculo`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=6848 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `VerEspionaje` -- DROP TABLE IF EXISTS `VerEspionaje`; /*!50001 DROP VIEW IF EXISTS `VerEspionaje`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `VerEspionaje` AS SELECT 1 AS `CodigoTrabajador`, 1 AS `Fecha`, 1 AS `HoraEntrada`, 1 AS `HoraSalida`, 1 AS `Id_Equipo`, 1 AS `Id_Trabajador`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `Vistas` -- DROP TABLE IF EXISTS `Vistas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Vistas` ( `vista_id` int(11) NOT NULL AUTO_INCREMENT, `vista` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`vista_id`), UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `XDiario` -- DROP TABLE IF EXISTS `XDiario`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `XDiario` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ASIEN` double DEFAULT NULL, `FECHA` datetime DEFAULT NULL, `SUBCTA` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `CONTRA` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `CONCEPTO` varchar(50) CHARACTER SET utf8 DEFAULT NULL, `EURODEBE` decimal(10,2) DEFAULT NULL, `EUROHABER` decimal(10,2) DEFAULT NULL, `BASEEURO` decimal(10,2) DEFAULT NULL, `SERIE` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `FACTURA` varchar(8) COLLATE utf8_unicode_ci DEFAULT '0', `BASEIMPO` decimal(10,2) DEFAULT NULL, `IVA` decimal(10,2) DEFAULT NULL, `RECEQUIV` decimal(10,2) DEFAULT '0.00', `DOCUMENTO` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `DEPARTA` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `CLAVE` int(11) DEFAULT NULL, `ESTADO` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `NCASADO` decimal(10,2) DEFAULT NULL, `TCASADO` decimal(10,2) DEFAULT NULL, `TRANS` decimal(10,2) DEFAULT NULL, `CAMBIO` decimal(10,2) DEFAULT NULL, `DEBEME` decimal(10,2) DEFAULT NULL, `HABERME` decimal(10,2) DEFAULT NULL, `PTAHABER` decimal(10,2) DEFAULT NULL, `AUXILIAR` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `SUCURSAL` varchar(4) COLLATE utf8_unicode_ci DEFAULT NULL, `PTADEBE` decimal(10,2) DEFAULT NULL, `CODDIVISA` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `IMPAUXME` decimal(10,2) DEFAULT NULL, `MONEDAUSO` varchar(1) COLLATE utf8_unicode_ci DEFAULT '2', `NOCONV` tinyint(1) NOT NULL DEFAULT '0', `NUMEROINV` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOOPE` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `NFACTICK` tinyint(1) NOT NULL DEFAULT '1', `TERIDNIF` tinyint(1) NOT NULL DEFAULT '2', `TERNIF` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'I.F.', `TERNOM` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Nombre Importador', `OPBIENES` tinyint(1) NOT NULL DEFAULT '1', `TIPOFAC` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOIVA` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `L340` tinyint(2) NOT NULL DEFAULT '0', `enlazado` tinyint(1) NOT NULL DEFAULT '0', `FECHA_EX` date DEFAULT NULL COMMENT 'FEcha de expedicion de la factura', `LRECT349` tinyint(1) NOT NULL DEFAULT '0', `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `LDIFADUAN` tinyint(4) NOT NULL DEFAULT '0', `METAL` tinyint(1) NOT NULL DEFAULT '0', `METALIMP` decimal(10,2) NOT NULL DEFAULT '0.00', `FECHA_OP` date DEFAULT NULL COMMENT 'FEcha de operacion', `FACTURAEX` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Numero de factura del proveedor', `TIPOCLAVE` int(3) DEFAULT NULL, `TIPOEXENCI` int(3) DEFAULT NULL, `TIPONOSUJE` int(3) DEFAULT NULL, `TIPOFACT` int(3) DEFAULT NULL, `TIPORECTIF` int(3) DEFAULT NULL, `SERIE_RT` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `FACTU_RT` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `BASEIMP_RT` decimal(10,2) DEFAULT NULL, `BASEIMP_RF` decimal(10,2) DEFAULT NULL, `RECTIFICA` int(1) NOT NULL DEFAULT '0', `FECHA_RT` date DEFAULT NULL, `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `FECREGCON` date DEFAULT NULL, PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `XDiario_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=3121688 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `XDiario_KK` -- DROP TABLE IF EXISTS `XDiario_KK`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `XDiario_KK` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ASIEN` double DEFAULT NULL, `FECHA` date DEFAULT NULL, `SUBCTA` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `CONTRA` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `CONCEPTO` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, `EURODEBE` decimal(10,2) DEFAULT NULL, `EUROHABER` decimal(10,2) DEFAULT NULL, `BASEEURO` decimal(10,2) DEFAULT NULL, `SERIE` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `FACTURA` varchar(8) COLLATE utf8_unicode_ci DEFAULT '0', `BASEIMPO` decimal(10,2) DEFAULT NULL, `IVA` decimal(10,2) DEFAULT NULL, `RECEQUIV` decimal(10,2) DEFAULT '0.00', `DOCUMENTO` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `DEPARTA` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `CLAVE` int(11) DEFAULT NULL, `ESTADO` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `NCASADO` decimal(10,2) DEFAULT NULL, `TCASADO` decimal(10,2) DEFAULT NULL, `TRANS` decimal(10,2) DEFAULT NULL, `CAMBIO` decimal(10,2) DEFAULT NULL, `DEBEME` decimal(10,2) DEFAULT NULL, `HABERME` decimal(10,2) DEFAULT NULL, `PTAHABER` decimal(10,2) DEFAULT NULL, `AUXILIAR` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `SUCURSAL` varchar(4) COLLATE utf8_unicode_ci DEFAULT NULL, `PTADEBE` decimal(10,2) DEFAULT NULL, `CODDIVISA` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `IMPAUXME` decimal(10,2) DEFAULT NULL, `MONEDAUSO` varchar(1) COLLATE utf8_unicode_ci DEFAULT '2', `NOCONV` tinyint(1) NOT NULL DEFAULT '0', `NUMEROINV` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOOPE` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `NFACTICK` tinyint(1) NOT NULL DEFAULT '1', `TERIDNIF` tinyint(1) NOT NULL DEFAULT '2', `TERNIF` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'I.F.', `TERNOM` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Nombre Importador', `OPBIENES` tinyint(1) NOT NULL DEFAULT '1', `TIPOFAC` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOIVA` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `L340` tinyint(2) NOT NULL DEFAULT '0', `enlazado` tinyint(1) NOT NULL DEFAULT '0', `FECHA_EX` date DEFAULT NULL COMMENT 'FEcha de expedicion de la factura', `LRECT349` tinyint(1) NOT NULL DEFAULT '0', `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `LDIFADUAN` tinyint(4) NOT NULL DEFAULT '0', `METAL` tinyint(1) NOT NULL DEFAULT '0', `METALIMP` decimal(10,2) NOT NULL DEFAULT '0.00', `FECHA_OP` date DEFAULT NULL COMMENT 'FEcha de operacion', `FACTURAEX` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Numero de factura del proveedor', `TIPOCLAVE` int(3) DEFAULT NULL, `TIPOEXENCI` int(3) DEFAULT NULL, `TIPONOSUJE` int(3) DEFAULT NULL, `TIPOFACT` int(3) DEFAULT NULL, `TIPORECTIF` int(3) DEFAULT NULL, `SERIE_RT` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `FACTU_RT` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `BASEIMP_RT` decimal(10,2) DEFAULT NULL, `BASEIMP_RF` decimal(10,2) DEFAULT NULL, `RECTIFICA` int(1) NOT NULL DEFAULT '0', `FECHA_RT` date DEFAULT NULL, PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `__Cartera_Ventas` -- DROP TABLE IF EXISTS `__Cartera_Ventas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `__Cartera_Ventas` ( `CodigoTrabajador` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `Mes` int(2) DEFAULT NULL, `Año` int(4) DEFAULT NULL, `Motivo` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `Importe` double DEFAULT NULL, `Id_Ticket` bigint(20) DEFAULT NULL, `Semana` int(2) DEFAULT NULL, `Cliente` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, KEY `INDEX1` (`Id_Ticket`), KEY `INDEX2` (`Mes`,`Año`,`Id_Ticket`), KEY `INDEX3` (`CodigoTrabajador`,`Mes`,`Año`,`Id_Ticket`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `accion_dits` -- DROP TABLE IF EXISTS `accion_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `accion_dits` ( `idaccion_dits` int(11) NOT NULL AUTO_INCREMENT, `accion` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idaccion_dits`), UNIQUE KEY `accion_UNIQUE` (`accion`) ) ENGINE=InnoDB AUTO_INCREMENT=166 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `account_conciliacion` -- DROP TABLE IF EXISTS `account_conciliacion`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `account_conciliacion` ( `idaccount_conciliacion` int(11) NOT NULL AUTO_INCREMENT, `Id_Proveedores_account` mediumint(8) unsigned NOT NULL, `Fechaoperacion` datetime NOT NULL, `FechaValor` datetime NOT NULL, `importe` double NOT NULL, `Concepto` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `DebeHaber` smallint(6) NOT NULL, `id_calculated` varchar(90) COLLATE utf8_unicode_ci DEFAULT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`idaccount_conciliacion`), UNIQUE KEY `idaccount_conciliacion_UNIQUE` (`idaccount_conciliacion`), KEY `fg_accconciliacion_key1_idx` (`Id_Proveedores_account`), KEY `index_id_calculated` (`id_calculated`), CONSTRAINT `fg_key1_accountconc` FOREIGN KEY (`Id_Proveedores_account`) REFERENCES `Proveedores_account` (`Id_Proveedores_account`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=26801 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`account_conciliacion_BEFORE_INSERT` BEFORE INSERT ON `account_conciliacion` FOR EACH ROW set new.id_calculated = replace( replace( replace( replace( concat(new.Id_Proveedores_account,new.Fechaoperacion,new.importe,new.Concepto,new.DebeHaber) ,' ','') ,":",'') ,'-','') ,'.','') */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Temporary view structure for view `account_customer` -- DROP TABLE IF EXISTS `account_customer`; /*!50001 DROP VIEW IF EXISTS `account_customer`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `account_customer` AS SELECT 1 AS `description`, 1 AS `iban`, 1 AS `entity_id`, 1 AS `office`, 1 AS `dc`, 1 AS `number`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `account_detail` -- DROP TABLE IF EXISTS `account_detail`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `account_detail` ( `account_detail_id` int(11) NOT NULL AUTO_INCREMENT, `value` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `account_detail_type_id` int(11) NOT NULL, `Id_Proveedores_account` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`account_detail_id`), KEY `fk_account_detail_account_detail_type1_idx` (`account_detail_type_id`), KEY `fk_account_detail_Proveedores_account1_idx` (`Id_Proveedores_account`), CONSTRAINT `fk_account_detail_account_detail_type1` FOREIGN KEY (`account_detail_type_id`) REFERENCES `account_detail_type` (`account_detail_type_id`) ON UPDATE CASCADE, CONSTRAINT `fk_account_detail_account_id_proveedores_account` FOREIGN KEY (`Id_Proveedores_account`) REFERENCES `Proveedores_account` (`Id_Proveedores_account`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `account_detail_type` -- DROP TABLE IF EXISTS `account_detail_type`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `account_detail_type` ( `account_detail_type_id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`account_detail_type_id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `accumulatorsReadingDate` -- DROP TABLE IF EXISTS `accumulatorsReadingDate`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `accumulatorsReadingDate` ( `id` int(11) NOT NULL AUTO_INCREMENT, `pagoSdcfk` int(11) NOT NULL, `readingDate` date NOT NULL COMMENT 'dia en que se revisa la cotizacion del dolar', `amount` double DEFAULT NULL COMMENT 'cantidad aumentada tras la lectura del tipo de cambio', PRIMARY KEY (`id`), KEY `pagoSdcFk_idx` (`pagoSdcfk`), CONSTRAINT `pagoSdcFk` FOREIGN KEY (`pagoSdcfk`) REFERENCES `pago_sdc` (`pago_sdc_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=269 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `agencia_descuadre` -- DROP TABLE IF EXISTS `agencia_descuadre`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `agencia_descuadre` ( `agencia_descuadre_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Ticket` int(11) NOT NULL, `date` date NOT NULL, `price` double(7,2) NOT NULL, `Consignatario` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Tipo` varchar(30) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`agencia_descuadre_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `agency` -- DROP TABLE IF EXISTS `agency`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `agency` ( `agency_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `warehouse_id` smallint(5) unsigned DEFAULT NULL COMMENT 'A nulo si se puede enrutar desde todos los almacenes', `por_volumen` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Si el calculo del porte se hacer por volumen', `Id_Banco` int(11) NOT NULL DEFAULT '8' COMMENT 'para realizar los reembolsos', `warehouse_alias_id` smallint(5) unsigned DEFAULT NULL, `propios` tinyint(1) NOT NULL DEFAULT '0', `zone_label` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`agency_id`), KEY `warehouse_id` (`warehouse_id`), KEY `Id_Banco` (`Id_Banco`), KEY `agencias_alias_idx` (`warehouse_alias_id`), CONSTRAINT `agency_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `agency_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=225 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`agency_ai` AFTER INSERT ON `vn2008`.`agency` FOR EACH ROW BEGIN INSERT INTO Agencias(Agencia,agency_id) VALUES(NEW.name,NEW.agency_id); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `agency_hour` -- DROP TABLE IF EXISTS `agency_hour`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `agency_hour` ( `agency_hour_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `week_day` tinyint(3) unsigned DEFAULT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6', `agency_id` smallint(5) unsigned DEFAULT NULL, `warehouse_id` smallint(5) unsigned DEFAULT NULL, `province_id` smallint(5) unsigned DEFAULT NULL, `subtract_day` tinyint(10) unsigned NOT NULL COMMENT 'dias a restar de la Fecha de entrega', `max_hour` tinyint(3) unsigned NOT NULL COMMENT 'maxima hora hasta la cual se pueden hacer pedidos', PRIMARY KEY (`agency_hour_id`), UNIQUE KEY `week_day` (`week_day`,`agency_id`,`warehouse_id`,`province_id`,`max_hour`), KEY `agency_id` (`agency_id`), KEY `warehouse_id` (`warehouse_id`), KEY `province_id` (`province_id`), CONSTRAINT `agency_hour_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`agency_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=4164 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`agency_hourBeforeInsert` BEFORE INSERT ON `agency_hour` FOR EACH ROW BEGIN DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; IF NEW.week_day IS NULL AND NEW.province_id IS NULL AND NEW.subtract_day = 0 AND NEW.max_hour = 0 THEN CALL util.throw ('FILL_MORE_FIELDS'); END IF; SELECT COUNT(*) INTO vAlreadyExists FROM vn2008.agency_hour WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour AND NEW.agency_id <=> agency_id; IF vAlreadyExists > 1 THEN CALL util.throw('ALREADY_EXISTS'); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`agency_hour_AFTER_UPDATE` AFTER UPDATE ON `agency_hour` FOR EACH ROW BEGIN DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; SELECT COUNT(*) INTO vAlreadyExists FROM vn2008.agency_hour WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour AND NEW.agency_id <=> agency_id; IF vAlreadyExists > 1 THEN CALL util.throw('ALREADY_EXISTS'); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `agency_warehouse` -- DROP TABLE IF EXISTS `agency_warehouse`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `agency_warehouse` ( `agency_id` smallint(5) unsigned NOT NULL, `warehouse_id` smallint(5) unsigned NOT NULL DEFAULT '1', `Vista` tinyint(3) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`agency_id`,`warehouse_id`), KEY `warehouse_id` (`warehouse_id`), CONSTRAINT `agency_warehouse_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`agency_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_warehouse_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Indica la vista para cada agencia'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `agency_weekday_bonus` -- DROP TABLE IF EXISTS `agency_weekday_bonus`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `agency_weekday_bonus` ( `id` int(11) NOT NULL AUTO_INCREMENT, `warehouse_id` smallint(6) unsigned DEFAULT NULL, `agency_id` smallint(5) unsigned DEFAULT NULL, `weekDay` tinyint(3) unsigned NOT NULL, `zona` tinyint(4) DEFAULT NULL, `bonus` decimal(10,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `airline` -- DROP TABLE IF EXISTS `airline`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `airline` ( `airline_id` smallint(2) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`airline_id`) ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `airport` -- DROP TABLE IF EXISTS `airport`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `airport` ( `airport_id` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`airport_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `albaran` -- DROP TABLE IF EXISTS `albaran`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `albaran` ( `albaran_id` int(11) NOT NULL AUTO_INCREMENT, `ref` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `note` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL, `fecha` date NOT NULL, `fecha_entrega` date DEFAULT NULL, `valor` double DEFAULT NULL, `Id_Proveedor` int(11) NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL, `warehouse_id` smallint(6) unsigned NOT NULL, `albaran_state_id` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL COMMENT 'Id_Trabajador hace referencia a la persona que ha introducido el albarán', `Id_Responsable` int(11) NOT NULL, `department_id` int(11) NOT NULL, `recibida_id` mediumint(8) unsigned DEFAULT NULL, PRIMARY KEY (`albaran_id`), KEY `fk_albaran_Proveedores_idx` (`Id_Proveedor`), KEY `fk_albaran_empresa1_idx` (`empresa_id`), KEY `fk_albaran_warehouse1_idx` (`warehouse_id`), KEY `fk_albaran_albaran_state1_idx` (`albaran_state_id`), KEY `fk_albaran_Trabajadores1_idx` (`Id_Trabajador`), KEY `fk_albaran_Trabajadores2_idx` (`Id_Responsable`), KEY `fk_albaran_department1_idx` (`department_id`), KEY `fk_albaran_recibida_idx` (`recibida_id`), CONSTRAINT `fk_albaran_Proveedores` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_Trabajadores1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_Trabajadores2` FOREIGN KEY (`Id_Responsable`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_albaran_state1` FOREIGN KEY (`albaran_state_id`) REFERENCES `albaran_state` (`albaran_state_id`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_department1` FOREIGN KEY (`department_id`) REFERENCES `department` (`department_id`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_empresa1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_recibida` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_albaran_warehouse1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1920 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `albaran_gestdoc` -- DROP TABLE IF EXISTS `albaran_gestdoc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `albaran_gestdoc` ( `gestdoc_id` int(11) NOT NULL, `albaran_id` int(11) NOT NULL, PRIMARY KEY (`gestdoc_id`,`albaran_id`), KEY `fk_albaran_gestdoc_gestdoc1_idx` (`gestdoc_id`), KEY `fk_albaran_gestdoc_albaran1_idx` (`albaran_id`), CONSTRAINT `fk_albaran_gestdoc_albaran1` FOREIGN KEY (`albaran_id`) REFERENCES `albaran` (`albaran_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_albaran_gestdoc_gestdoc1` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `albaran_state` -- DROP TABLE IF EXISTS `albaran_state`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `albaran_state` ( `albaran_state_id` int(11) NOT NULL AUTO_INCREMENT, `state` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`albaran_state_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `awb` -- DROP TABLE IF EXISTS `awb`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb` ( `id` smallint(11) unsigned NOT NULL AUTO_INCREMENT, `codigo` varchar(18) COLLATE utf8_unicode_ci NOT NULL, `bultos` float unsigned NOT NULL, `peso` float unsigned DEFAULT NULL, `MYSQL_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `transitario_id` int(11) NOT NULL DEFAULT '582', `iva_id` tinyint(3) unsigned DEFAULT '62', `duakk` varchar(18) COLLATE utf8_unicode_ci DEFAULT NULL, `gestdoc_id` int(11) DEFAULT NULL, `importe` double NOT NULL DEFAULT '0', `carguera_id` int(11) DEFAULT NULL, `m3` double unsigned DEFAULT NULL, `stems` int(10) unsigned DEFAULT NULL, `flight_id` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `volume_weight` float unsigned DEFAULT NULL, `hb` decimal(10,1) unsigned DEFAULT NULL, `rate` decimal(10,2) unsigned DEFAULT NULL, `booked` datetime DEFAULT NULL, `issued` datetime DEFAULT NULL, `operated` datetime DEFAULT NULL, `bookEntried` date DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `codigo_UNIQUE` (`codigo`), KEY `proveedor_id` (`transitario_id`), KEY `iva_id` (`iva_id`), KEY `carguera_id` (`carguera_id`), KEY `flight_id` (`flight_id`), CONSTRAINT `awb_ibfk_1` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2282 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `awb_ai` AFTER INSERT ON `awb` FOR EACH ROW BEGIN DECLARE lastrecibida_id INT; INSERT INTO recibida(proveedor_id,fecha,empresa_id) VALUES(NEW.transitario_id,CURDATE(),442); SELECT last_insert_id() into lastrecibida_id; INSERT INTO awb_recibida(awb_id,recibida_id) VALUES(NEW.id,lastrecibida_id); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`awb_au` AFTER UPDATE ON `awb` FOR EACH ROW begin IF NEW.importe <> OLD.importe THEN CALL buy_tarifas_awb(NEW.codigo); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `awb_component` -- DROP TABLE IF EXISTS `awb_component`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_component` ( `awb_id` smallint(11) unsigned DEFAULT NULL, `Id_Proveedor` int(11) NOT NULL, `Fecha` date NOT NULL, `awb_component_type_id` mediumint(3) unsigned DEFAULT NULL, `awb_role_id` tinyint(1) unsigned NOT NULL DEFAULT '1', `awb_unit_id` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `value` decimal(10,2) DEFAULT NULL, `Id_Moneda` tinyint(3) unsigned NOT NULL DEFAULT '2', `recibida_id` mediumint(8) unsigned DEFAULT NULL, UNIQUE KEY `unique_idx` (`awb_id`,`Id_Proveedor`,`awb_component_type_id`,`Fecha`), KEY `Id_Moneda` (`Id_Moneda`), KEY `awb_component_fk` (`awb_component_type_id`), KEY `awb_role_fk` (`awb_role_id`), KEY `awb_unit_fk` (`awb_unit_id`), CONSTRAINT `Id_Monedafk` FOREIGN KEY (`Id_Moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON DELETE CASCADE, CONSTRAINT `awb_component_` FOREIGN KEY (`awb_component_type_id`) REFERENCES `awb_component_type` (`awb_component_type_id`) ON UPDATE CASCADE, CONSTRAINT `awb_role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `awb_component_template` -- DROP TABLE IF EXISTS `awb_component_template`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_component_template` ( `awb_component_template_id` int(11) NOT NULL AUTO_INCREMENT, `carguera_id` int(11) DEFAULT NULL, `airport_in` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `airport_out` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `airline_id` smallint(2) unsigned DEFAULT NULL, `awb_component_type_id` mediumint(3) unsigned NOT NULL, `Fecha` date NOT NULL, `awb_role_id` tinyint(1) unsigned NOT NULL, `awb_unit_id` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `value` decimal(10,3) DEFAULT NULL, `max_value` decimal(10,2) unsigned DEFAULT NULL, `min_value` decimal(10,2) unsigned DEFAULT NULL, `Id_Moneda` tinyint(3) unsigned NOT NULL DEFAULT '2', PRIMARY KEY (`awb_component_template_id`), UNIQUE KEY `carguera_id_UNIQUE` (`carguera_id`,`airport_in`,`airport_out`,`airline_id`,`awb_component_type_id`,`Fecha`), KEY `Id_Moneda` (`Id_Moneda`), KEY `airline_idx` (`airline_id`), KEY `role_idx` (`awb_role_id`), KEY `awb_unit_fk1` (`awb_unit_id`), CONSTRAINT `Id_Moneda` FOREIGN KEY (`Id_Moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk1` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE, CONSTRAINT `role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=400 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `awb_component_type` -- DROP TABLE IF EXISTS `awb_component_type`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_component_type` ( `awb_component_type_id` mediumint(3) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`awb_component_type_id`) ) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' '; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `awb_gestdoc` -- DROP TABLE IF EXISTS `awb_gestdoc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_gestdoc` ( `awb_gestdoc_id` int(11) NOT NULL AUTO_INCREMENT, `awb_id` smallint(11) unsigned NOT NULL, `gestdoc_id` int(11) NOT NULL, PRIMARY KEY (`awb_gestdoc_id`), KEY `awb_gestdoc_awb_fk` (`awb_id`), KEY `awb_gestdoc_gestdoc_fk` (`gestdoc_id`), CONSTRAINT `awb_gestdoc_awb_fk` FOREIGN KEY (`awb_id`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `awb_gestdoc_gestdoc_fk` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1988 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `awb_recibida` -- DROP TABLE IF EXISTS `awb_recibida`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_recibida` ( `awb_id` smallint(5) unsigned NOT NULL, `recibida_id` mediumint(8) unsigned NOT NULL, `dua` varchar(18) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`recibida_id`), KEY `awb_id` (`awb_id`), CONSTRAINT `awb_recibida_ibfk_1` FOREIGN KEY (`awb_id`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `awb_recibida_ibfk_2` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `awb_recibida_ad` AFTER DELETE ON `awb_recibida` FOR EACH ROW IF (SELECT COUNT(*) FROM recibida_iva where recibida_id = OLD.recibida_id) = 0 AND (SELECT COUNT(*) FROM recibida_vencimiento where recibida_id = OLD.recibida_id) = 0 AND (SELECT contabilizada FROM recibida WHERE id = OLD.recibida_id) = 0 THEN DELETE FROM recibida WHERE id = OLD.recibida_id; END IF */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `awb_role` -- DROP TABLE IF EXISTS `awb_role`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_role` ( `awb_role_id` tinyint(1) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`awb_role_id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' '; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `awb_unit` -- DROP TABLE IF EXISTS `awb_unit`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_unit` ( `awb_unit_id` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `operation` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`awb_unit_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='tipos de unidades'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `awb_volume` -- DROP TABLE IF EXISTS `awb_volume`; /*!50001 DROP VIEW IF EXISTS `awb_volume`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `awb_volume` AS SELECT 1 AS `awb_id`, 1 AS `volume`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `balance_nest_tree` -- DROP TABLE IF EXISTS `balance_nest_tree`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `balance_nest_tree` ( `lft` int(11) DEFAULT NULL, `rgt` int(11) DEFAULT NULL, `name` text COLLATE utf8_unicode_ci, `id` int(11) NOT NULL AUTO_INCREMENT, `Id_Gasto` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=381 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `barcodes` -- DROP TABLE IF EXISTS `barcodes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `barcodes` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Article` int(11) NOT NULL, `code` varchar(22) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), UNIQUE KEY `Id_Article_2` (`Id_Article`,`code`), KEY `Id_Article` (`Id_Article`), CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=33147 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `bionic_updating_options` -- DROP TABLE IF EXISTS `bionic_updating_options`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `bionic_updating_options` ( `buo_id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`buo_id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla pondremos las distintas opciones que se ofrecen al comecial o al cliente al cambiar alguno de los parametros básicos de un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `botanic_export` -- DROP TABLE IF EXISTS `botanic_export`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `botanic_export` ( `botanic_export_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `edi_genus_id` mediumint(8) unsigned NOT NULL, `edi_specie_id` mediumint(8) unsigned DEFAULT NULL, `Id_Paises` mediumint(8) unsigned DEFAULT NULL, `restriction` enum('Sin restriccion','Importacion Prohibida','Se Requiere Certificado','pasaporte individual','declaracion origen') CHARACTER SET utf8 NOT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`botanic_export_id`), KEY `Id_Paises` (`Id_Paises`), CONSTRAINT `botanic_export_ibfk_1` FOREIGN KEY (`Id_Paises`) REFERENCES `Paises` (`Id`) ) ENGINE=InnoDB AUTO_INCREMENT=274 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Especifica los generos y especies prohibidos en paises'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`botanic_exportBeforeInsert` BEFORE INSERT ON `botanic_export` FOR EACH ROW BEGIN IF (SELECT botanic_export_is_updatable (NEW.edi_genus_id, NEW.edi_specie_id, NEW.id_Paises, NEW.restriction) ) > 0 THEN CALL util.throw ('Datos duplicados'); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `businessReasonEnd` -- DROP TABLE IF EXISTS `businessReasonEnd`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `businessReasonEnd` ( `id` tinyint(3) NOT NULL AUTO_INCREMENT, `reason` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `business_labour_payrroll` -- DROP TABLE IF EXISTS `business_labour_payrroll`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `business_labour_payrroll` ( `business_id` int(11) NOT NULL, `cod_tarifa` int(11) NOT NULL, `cod_categoria` int(11) NOT NULL, `cod_contrato` int(11) NOT NULL, `importepactado` double NOT NULL DEFAULT '0', PRIMARY KEY (`business_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `buy_edi` -- DROP TABLE IF EXISTS `buy_edi`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `buy_edi` ( `id` int(11) NOT NULL AUTO_INCREMENT, `barcode` char(15) COLLATE utf8_unicode_ci DEFAULT NULL, `entry_year` smallint(5) unsigned NOT NULL, `delivery_number` bigint(20) unsigned DEFAULT NULL, `fec` date DEFAULT NULL, `hor` time DEFAULT NULL, `now` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `ptj` mediumint(8) unsigned DEFAULT NULL, `ref` int(11) NOT NULL, `item` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `pac` int(11) DEFAULT '0', `qty` int(10) unsigned NOT NULL, `ori` varchar(3) COLLATE utf8_unicode_ci DEFAULT 'NL', `cat` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `agj` int(11) DEFAULT NULL, `kop` int(11) DEFAULT NULL, `ptd` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `sub` mediumint(8) unsigned DEFAULT NULL, `pro` mediumint(8) unsigned NOT NULL, `pri` double NOT NULL, `package` int(10) unsigned DEFAULT NULL, `auction` smallint(5) unsigned DEFAULT NULL, `klo` smallint(5) unsigned DEFAULT NULL, `k01` smallint(5) unsigned DEFAULT NULL, `k02` smallint(5) unsigned DEFAULT NULL, `k03` tinyint(3) unsigned DEFAULT NULL, `k04` tinyint(3) unsigned DEFAULT NULL, `s1` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `s2` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `s3` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `s4` varchar(4) COLLATE utf8_unicode_ci DEFAULT NULL, `s5` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `s6` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `ok` tinyint(4) NOT NULL DEFAULT '0', `trolley_id` int(11) DEFAULT NULL, `scanned` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `barcode_year` (`barcode`,`entry_year`), UNIQUE KEY `delivery_number` (`delivery_number`), KEY `ref` (`ref`), KEY `ptj` (`ptj`), KEY `pro` (`pro`), KEY `kop` (`kop`), KEY `barcode` (`barcode`) ) ENGINE=InnoDB AUTO_INCREMENT=620925 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `buy_edi_k012` -- DROP TABLE IF EXISTS `buy_edi_k012`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `buy_edi_k012` ( `buy_edi_k012_id` smallint(6) unsigned NOT NULL, `description` varchar(50) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`buy_edi_k012_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Características negativas de los articulos de subasta'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `buy_edi_k03` -- DROP TABLE IF EXISTS `buy_edi_k03`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `buy_edi_k03` ( `buy_edi_k03_id` tinyint(3) unsigned NOT NULL, `description` varchar(50) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`buy_edi_k03_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Características fitosanitarias de los articulos de subasta'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `buy_edi_k04` -- DROP TABLE IF EXISTS `buy_edi_k04`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `buy_edi_k04` ( `buy_edi_k04_id` tinyint(3) unsigned NOT NULL, `description` varchar(50) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`buy_edi_k04_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Características calidad de los articulos de subasta'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `call_information` -- DROP TABLE IF EXISTS `call_information`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `call_information` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Descripcio` text COLLATE utf8_unicode_ci NOT NULL, `Conclusio` tinyint(3) unsigned NOT NULL, `Id_Cliente` int(11) NOT NULL, `fecha` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=164 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `call_option` -- DROP TABLE IF EXISTS `call_option`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `call_option` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `descripcion` varchar(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `callings` -- DROP TABLE IF EXISTS `callings`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `callings` ( `id` int(11) NOT NULL, `motivo` varchar(105) COLLATE utf8_unicode_ci DEFAULT NULL, `tel1` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `tel2` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `situacion` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `callingtasksKK` -- DROP TABLE IF EXISTS `callingtasksKK`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `callingtasksKK` ( `id` int(11) NOT NULL AUTO_INCREMENT, `instruccion` varchar(99) COLLATE utf8_unicode_ci DEFAULT NULL, `tel1` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `tel2` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `situacion` varchar(99) COLLATE utf8_unicode_ci DEFAULT NULL, `closed` tinyint(1) DEFAULT '0', `Id_Trabajador` tinyint(4) DEFAULT NULL, `Id_Prioridad` tinyint(4) DEFAULT '2', `selected` tinyint(4) DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `cdr` -- DROP TABLE IF EXISTS `cdr`; /*!50001 DROP VIEW IF EXISTS `cdr`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `cdr` AS SELECT 1 AS `calldate`, 1 AS `clid`, 1 AS `src`, 1 AS `dst`, 1 AS `dcontext`, 1 AS `channel`, 1 AS `dstchannel`, 1 AS `lastapp`, 1 AS `lastdata`, 1 AS `duration`, 1 AS `billsec`, 1 AS `disposition`, 1 AS `amaflags`, 1 AS `accountcode`, 1 AS `uniqueid`, 1 AS `userfield`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `chanel` -- DROP TABLE IF EXISTS `chanel`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `chanel` ( `chanel_id` smallint(6) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`chanel_id`) ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Canal por el que nos ha conocido un cliente y se ha dado de'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `chat` -- DROP TABLE IF EXISTS `chat`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `chat` ( `chat_id` int(11) NOT NULL AUTO_INCREMENT, `Id_Trabajador` int(11) NOT NULL, `msg` varchar(254) COLLATE utf8_unicode_ci DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`chat_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Para chatear los compradores, en el frmRESERVE de la COMPARATIVA'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `city` -- DROP TABLE IF EXISTS `city`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `city` ( `city_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `province_id` smallint(6) unsigned DEFAULT NULL, `nst_geo_id` int(11) DEFAULT NULL, `nst_name` varchar(50) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`city_id`), UNIQUE KEY `province_city_pk` (`province_id`,`name`), KEY `NST_CITY_FK_idx` (`nst_geo_id`), CONSTRAINT `nst_geo_city` FOREIGN KEY (`nst_geo_id`) REFERENCES `nst`.`geo` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `province_city_fk` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=4423 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`city_BEFORE_INSERT` BEFORE INSERT ON `city` FOR EACH ROW BEGIN SET new.nst_name = new.`name`; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`city_AFTER_DELETE` AFTER DELETE ON `city` FOR EACH ROW BEGIN CALL nst.del(OLD.nst_geo_id); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `cl_act` -- DROP TABLE IF EXISTS `cl_act`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_act` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Movimiento` int(11) DEFAULT NULL, `cl_main_id` int(10) unsigned NOT NULL, `Id_Trabajador` int(11) NOT NULL DEFAULT '20', `cl_sol_id` tinyint(4) DEFAULT NULL, `greuge` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `cl_main_id` (`cl_main_id`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `Id_Movimiento` (`Id_Movimiento`), KEY `cl_sol_id` (`cl_sol_id`), CONSTRAINT `cl_act_ibfk_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_4` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=75045 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_cau` -- DROP TABLE IF EXISTS `cl_cau`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_cau` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `cl_main_id` int(10) unsigned NOT NULL, `cl_res_id` int(10) unsigned NOT NULL DEFAULT '1', `Id_Trabajador` int(11) NOT NULL DEFAULT '20', `cl_mot_id` int(10) unsigned NOT NULL DEFAULT '1', `cl_con_id` int(10) unsigned NOT NULL DEFAULT '1', `cl_dev` tinyint(3) unsigned NOT NULL DEFAULT '1', `cl_sol` tinyint(3) unsigned NOT NULL DEFAULT '2', PRIMARY KEY (`id`), KEY `cl_main_id` (`cl_main_id`), KEY `cl_res_id` (`cl_res_id`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `cl_mot_id` (`cl_mot_id`), KEY `cl_con_id` (`cl_con_id`), KEY `cl_dev` (`cl_dev`), KEY `cl_sol` (`cl_sol`), CONSTRAINT `cl_cau_ibfk_10` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_11` FOREIGN KEY (`cl_dev`) REFERENCES `cl_dev` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_12` FOREIGN KEY (`cl_sol`) REFERENCES `cl_sol` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_6` FOREIGN KEY (`cl_res_id`) REFERENCES `cl_res` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_7` FOREIGN KEY (`cl_mot_id`) REFERENCES `cl_mot` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_8` FOREIGN KEY (`cl_con_id`) REFERENCES `cl_con` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_9` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=42200 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_con` -- DROP TABLE IF EXISTS `cl_con`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_con` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `consecuencia` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Consecuencias de los motivos'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_dep` -- DROP TABLE IF EXISTS `cl_dep`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_dep` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `departamento` varchar(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Departamentos para las quejas'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_det` -- DROP TABLE IF EXISTS `cl_det`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_det` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `cl_main_id` int(10) unsigned NOT NULL, `Id_Movimiento` int(11) DEFAULT NULL, `cl_que_id` int(10) unsigned NOT NULL DEFAULT '1', `cl_pet_id` int(1) unsigned NOT NULL DEFAULT '1', `numero` double DEFAULT NULL, PRIMARY KEY (`id`), KEY `Id_Movimiento` (`Id_Movimiento`), KEY `cl_pet_id` (`cl_pet_id`), KEY `cl_que_id` (`cl_que_id`), KEY `cl_main_id` (`cl_main_id`), CONSTRAINT `cl_det_ibfk_5` FOREIGN KEY (`cl_que_id`) REFERENCES `cl_que` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_6` FOREIGN KEY (`cl_pet_id`) REFERENCES `cl_pet` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_7` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_8` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=104163 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_dev` -- DROP TABLE IF EXISTS `cl_dev`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_dev` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `devolucion` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Método por el cual el cliente nos devuelve la mercancía'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_est` -- DROP TABLE IF EXISTS `cl_est`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_est` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `estado` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Estados posibles de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_main` -- DROP TABLE IF EXISTS `cl_main`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_main` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Fecha` datetime NOT NULL, `cl_dep_id` tinyint(3) unsigned DEFAULT NULL, `cl_est_id` int(10) unsigned NOT NULL DEFAULT '1', `notas` text COLLATE utf8_unicode_ci, `Id_Cliente` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `sensib` int(1) unsigned NOT NULL DEFAULT '3', `mana` tinyint(1) NOT NULL DEFAULT '0', `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `cl_dep_id` (`cl_dep_id`), KEY `cl_est_id` (`cl_est_id`), KEY `Id_Cliente` (`Id_Cliente`), KEY `Id_Trabajador` (`Id_Trabajador`), CONSTRAINT `cl_main_ibfk_3` FOREIGN KEY (`cl_est_id`) REFERENCES `cl_est` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_4` FOREIGN KEY (`cl_dep_id`) REFERENCES `cl_dep` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_5` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=44214 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_mot` -- DROP TABLE IF EXISTS `cl_mot`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_mot` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `motivo` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Motivos de las fallos'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_pet` -- DROP TABLE IF EXISTS `cl_pet`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_pet` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `peticion` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Peticiones de los cliente en relacion a las quejas'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_que` -- DROP TABLE IF EXISTS `cl_que`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_que` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `queja` varchar(25) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queja por linea de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_res` -- DROP TABLE IF EXISTS `cl_res`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_res` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `responsable` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `sensibility` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'if=1 >sensib >culpa', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Responsables de las causas'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cl_sol` -- DROP TABLE IF EXISTS `cl_sol`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cl_sol` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `solucion` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Solucion ofrecida a la reclamación'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `clientMana` -- DROP TABLE IF EXISTS `clientMana`; /*!50001 DROP VIEW IF EXISTS `clientMana`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `clientMana` AS SELECT 1 AS `Id_Cliente`, 1 AS `ManaUnitario`, 1 AS `ManaTotal`, 1 AS `Id_Ticket`, 1 AS `Id_Article`, 1 AS `Concepte`, 1 AS `Cantidad`, 1 AS `Preu`, 1 AS `Fecha`, 1 AS `Id_Movimiento`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `client_observation` -- DROP TABLE IF EXISTS `client_observation`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `client_observation` ( `client_observation_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `text` text COLLATE utf8_unicode_ci NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`client_observation_id`), KEY `Id_Trabajador` (`Id_Trabajador`), KEY `Id_Cliente` (`Id_Cliente`), CONSTRAINT `client_observation_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `client_observation_ibfk_2` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=51051 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `clientes_gestdoc` -- DROP TABLE IF EXISTS `clientes_gestdoc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientes_gestdoc` ( `Id_Cliente` int(11) NOT NULL, `gest_doc_id` int(11) NOT NULL, PRIMARY KEY (`Id_Cliente`,`gest_doc_id`), KEY `gest_doc_id` (`gest_doc_id`), CONSTRAINT `clientes_gestdoc_ibfk_2` FOREIGN KEY (`gest_doc_id`) REFERENCES `gestdoc` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `clientes_gestdoc_ibfk_3` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `clientes_regalos_enc` -- DROP TABLE IF EXISTS `clientes_regalos_enc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientes_regalos_enc` ( `Id_Cliente` int(11) NOT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `Id_Regalo` int(11) NOT NULL, PRIMARY KEY (`Id_Cliente`,`Id_Regalo`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `clientes_regalos_lista_enc` -- DROP TABLE IF EXISTS `clientes_regalos_lista_enc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientes_regalos_lista_enc` ( `Id_Regalo` int(11) NOT NULL AUTO_INCREMENT, `Descripcion` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `Activo` bit(1) NOT NULL DEFAULT b'0', `foto` blob, `datstart` date DEFAULT NULL, `datend` date DEFAULT NULL, `warehouse_id` smallint(6) unsigned DEFAULT '1', `province_id` smallint(5) unsigned DEFAULT NULL, PRIMARY KEY (`Id_Regalo`) ) ENGINE=MyISAM AUTO_INCREMENT=27 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `clientes_tipo` -- DROP TABLE IF EXISTS `clientes_tipo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientes_tipo` ( `clientes_tipo_id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(20) CHARACTER SET utf8 NOT NULL, `tipo` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`clientes_tipo_id`), UNIQUE KEY `code_UNIQUE` (`code`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Establece categorias para poder agrupar las ventas'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `commission` -- DROP TABLE IF EXISTS `commission`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `commission` ( `commisision_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `percentage` tinyint(3) unsigned NOT NULL, `value` float unsigned NOT NULL, PRIMARY KEY (`commisision_id`) ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `config` -- DROP TABLE IF EXISTS `config`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `config` ( `id` int(11) NOT NULL, `generic_item` int(11) NOT NULL COMMENT 'Id del artículo genérico', `edi_entry` int(11) NOT NULL COMMENT 'Entrada usada para los EKTs', `lastMana` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `config_host` -- DROP TABLE IF EXISTS `config_host`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `config_host` ( `config_host_id` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `warehouse` smallint(6) unsigned NOT NULL DEFAULT '1', `empresa_id` smallint(6) unsigned NOT NULL DEFAULT '442', `caja` int(11) DEFAULT '13', `Id_Impresora` tinyint(3) unsigned DEFAULT '27', `Permanente` tinyint(1) unsigned DEFAULT '1', `route_days_before` smallint(6) DEFAULT '2', `route_days_after` smallint(6) DEFAULT '1', PRIMARY KEY (`config_host_id`), KEY `warehouse` (`warehouse`), KEY `empresa_id` (`empresa_id`), KEY `caja` (`caja`), KEY `Id_Impresora` (`Id_Impresora`), CONSTRAINT `config_host_ibfk_1` FOREIGN KEY (`caja`) REFERENCES `Bancos` (`Id_Banco`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `config_host_ibfk_2` FOREIGN KEY (`warehouse`) REFERENCES `warehouse` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `config_host_ibfk_3` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `config_host_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Sustituye al antiguo TPV_Settings'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `config_host_forms` -- DROP TABLE IF EXISTS `config_host_forms`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `config_host_forms` ( `config_host_id` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `formname` varchar(56) COLLATE utf8_unicode_ci NOT NULL, `x` int(8) NOT NULL, `y` int(8) NOT NULL, `h` int(8) NOT NULL, `l` int(8) NOT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`config_host_id`,`formname`), CONSTRAINT `config_host_form_ibfk_1` FOREIGN KEY (`config_host_id`) REFERENCES `config_host` (`config_host_id`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registra las posiciones de los formularios'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `consignatarios_observation` -- DROP TABLE IF EXISTS `consignatarios_observation`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `consignatarios_observation` ( `consignatarios_observation_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Id_Consigna` int(11) NOT NULL, `observation_type_id` tinyint(3) unsigned NOT NULL, `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`consignatarios_observation_id`), UNIQUE KEY `Id_Consigna` (`Id_Consigna`,`observation_type_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2798 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `container` -- DROP TABLE IF EXISTS `container`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `container` ( `container_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `Continente` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`container_id`) ) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cooler_path` -- DROP TABLE IF EXISTS `cooler_path`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cooler_path` ( `cooler_path_id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`cooler_path_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define el orden en que se imprimen los F5'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cooler_path_detail` -- DROP TABLE IF EXISTS `cooler_path_detail`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cooler_path_detail` ( `cooler_path_detail_id` int(11) NOT NULL AUTO_INCREMENT, `cooler_path_id` int(11) NOT NULL DEFAULT '1', `pasillo` varchar(3) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`cooler_path_id`,`pasillo`), UNIQUE KEY `cooler_path_detail_id_UNIQUE` (`cooler_path_detail_id`) ) ENGINE=InnoDB AUTO_INCREMENT=94 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cp` -- DROP TABLE IF EXISTS `cp`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cp` ( `cp_id` int(11) NOT NULL AUTO_INCREMENT, `cpd` int(11) NOT NULL, `cph` int(11) NOT NULL, `zone_id` smallint(6) DEFAULT NULL, `town` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`cp_id`) ) ENGINE=InnoDB AUTO_INCREMENT=77 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relacio de codis postals i el municipi al qual se asigna'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `credit` -- DROP TABLE IF EXISTS `credit`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `credit` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL, `amount` double unsigned NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Trabajador` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `workers_fk_idx` (`Id_Trabajador`), KEY `credit_ClienteFk` (`Id_Cliente`), CONSTRAINT `credit_ClienteFk` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workers_fk` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=57446 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `credit_card` -- DROP TABLE IF EXISTS `credit_card`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `credit_card` ( `credit_card_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Id_Cliente` int(10) NOT NULL, `number` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `expiration_month` tinyint(2) unsigned zerofill NOT NULL, `expiration_year` tinyint(2) unsigned zerofill NOT NULL, `priority` tinyint(3) unsigned NOT NULL DEFAULT '1', `obs` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`credit_card_id`), KEY `Id_Cliente` (`Id_Cliente`), CONSTRAINT `credit_card_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=956 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cyc` -- DROP TABLE IF EXISTS `cyc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cyc` ( `Id_Cliente` int(11) NOT NULL, `Riesgo` double DEFAULT NULL, `Fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `cyc_id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`cyc_id`), KEY `Cliente` (`Id_Cliente`), CONSTRAINT `Cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=467096 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que estan clasificados en Credito y Cau'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `cyc_declaration` -- DROP TABLE IF EXISTS `cyc_declaration`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cyc_declaration` ( `factura_id` int(10) unsigned NOT NULL, `Riesgo` double DEFAULT NULL, `Fecha` date NOT NULL, `Vencimiento` int(10) NOT NULL DEFAULT '0', PRIMARY KEY (`factura_id`), CONSTRAINT `Factura` FOREIGN KEY (`factura_id`) REFERENCES `Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registro de las facturas declaradas a cyc'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `daily_task_log` -- DROP TABLE IF EXISTS `daily_task_log`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `daily_task_log` ( `consulta` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `definitivo` -- DROP TABLE IF EXISTS `definitivo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `definitivo` ( `definitivo_id` int(11) NOT NULL, `empresa_id` int(11) NOT NULL, `desde` bigint(20) NOT NULL, `hasta` bigint(20) NOT NULL, `fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`definitivo_id`,`empresa_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `department` -- DROP TABLE IF EXISTS `department`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `department` ( `department_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `lft` int(11) NOT NULL, `rgt` int(11) NOT NULL, `Id_Trabajador` int(11) DEFAULT NULL COMMENT 'Id_Trabajador es el jefe del departamento', PRIMARY KEY (`department_id`), UNIQUE KEY `lft_UNIQUE` (`lft`), UNIQUE KEY `rgt_UNIQUE` (`rgt`), UNIQUE KEY `name_UNIQUE` (`name`), KEY `fk_department_Trabajadores1_idx` (`Id_Trabajador`), CONSTRAINT `fk_department_Trabajadores1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `device` -- DROP TABLE IF EXISTS `device`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `device` ( `device_id` int(11) NOT NULL AUTO_INCREMENT, `sn` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `model` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`device_id`), UNIQUE KEY `device_id_UNIQUE` (`device_id`), UNIQUE KEY `sn_UNIQUE` (`sn`) ) ENGINE=InnoDB AUTO_INCREMENT=158 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `device_user` -- DROP TABLE IF EXISTS `device_user`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `device_user` ( `device_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, PRIMARY KEY (`device_id`,`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `dhl` -- DROP TABLE IF EXISTS `dhl`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `dhl` ( `codigo_postal` mediumint(8) unsigned NOT NULL, `frecuencia` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`codigo_postal`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `dock` -- DROP TABLE IF EXISTS `dock`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `dock` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `xPos` int(11) DEFAULT NULL, `yPos` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) ) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Soporta la estructura de muelles de paletizacion'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `duaDismissed` -- DROP TABLE IF EXISTS `duaDismissed`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `duaDismissed` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ticketFk` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`,`ticketFk`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `edi_article` -- DROP TABLE IF EXISTS `edi_article`; /*!50001 DROP VIEW IF EXISTS `edi_article`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_article` AS SELECT 1 AS `id`, 1 AS `product_name`, 1 AS `name`, 1 AS `plant_id`, 1 AS `group_id`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_bucket` -- DROP TABLE IF EXISTS `edi_bucket`; /*!50001 DROP VIEW IF EXISTS `edi_bucket`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_bucket` AS SELECT 1 AS `bucket_id`, 1 AS `bucket_type_id`, 1 AS `description`, 1 AS `x_size`, 1 AS `y_size`, 1 AS `z_size`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_bucket_type` -- DROP TABLE IF EXISTS `edi_bucket_type`; /*!50001 DROP VIEW IF EXISTS `edi_bucket_type`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_bucket_type` AS SELECT 1 AS `bucket_type_id`, 1 AS `description`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_feature` -- DROP TABLE IF EXISTS `edi_feature`; /*!50001 DROP VIEW IF EXISTS `edi_feature`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_feature` AS SELECT 1 AS `item_id`, 1 AS `feature_type_id`, 1 AS `feature_value`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_genus` -- DROP TABLE IF EXISTS `edi_genus`; /*!50001 DROP VIEW IF EXISTS `edi_genus`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_genus` AS SELECT 1 AS `genus_id`, 1 AS `latin_genus_name`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_item_feature` -- DROP TABLE IF EXISTS `edi_item_feature`; /*!50001 DROP VIEW IF EXISTS `edi_item_feature`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_item_feature` AS SELECT 1 AS `item_id`, 1 AS `presentation_order`, 1 AS `feature`, 1 AS `regulation_type`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_plant` -- DROP TABLE IF EXISTS `edi_plant`; /*!50001 DROP VIEW IF EXISTS `edi_plant`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_plant` AS SELECT 1 AS `plant_id`, 1 AS `genus_id`, 1 AS `specie_id`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_specie` -- DROP TABLE IF EXISTS `edi_specie`; /*!50001 DROP VIEW IF EXISTS `edi_specie`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_specie` AS SELECT 1 AS `specie_id`, 1 AS `genus_id`, 1 AS `latin_species_name`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_supplier` -- DROP TABLE IF EXISTS `edi_supplier`; /*!50001 DROP VIEW IF EXISTS `edi_supplier`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_supplier` AS SELECT 1 AS `supplier_id`, 1 AS `company_name`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `edi_testigos` -- DROP TABLE IF EXISTS `edi_testigos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `edi_testigos` ( `id` smallint(6) NOT NULL AUTO_INCREMENT, `table` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `field` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `testigo` varchar(5) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `edi_type` -- DROP TABLE IF EXISTS `edi_type`; /*!50001 DROP VIEW IF EXISTS `edi_type`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_type` AS SELECT 1 AS `type_id`, 1 AS `type_group_id`, 1 AS `description`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `edi_value` -- DROP TABLE IF EXISTS `edi_value`; /*!50001 DROP VIEW IF EXISTS `edi_value`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `edi_value` AS SELECT 1 AS `type_id`, 1 AS `type_value`, 1 AS `type_description`, 1 AS `entry_date`, 1 AS `expiry_date`, 1 AS `change_date_time`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `emp_day_pay` -- DROP TABLE IF EXISTS `emp_day_pay`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `emp_day_pay` ( `id` smallint(5) unsigned NOT NULL, `emp_day_pay` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`,`emp_day_pay`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `empresa` -- DROP TABLE IF EXISTS `empresa`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `empresa` ( `id` smallint(5) unsigned NOT NULL, `abbreviation` char(3) COLLATE utf8_unicode_ci DEFAULT NULL, `registro` varchar(120) COLLATE utf8_unicode_ci NOT NULL, `gerente_id` int(11) NOT NULL, `alta` date NOT NULL, `baja` date DEFAULT NULL, `logo` longblob, `oficial` tinyint(1) unsigned NOT NULL DEFAULT '1', `cyc` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', `rgb` varchar(6) COLLATE utf8_unicode_ci NOT NULL, `mail` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `cuno` blob, `ODBC_DATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, `Id_Cliente` int(11) DEFAULT NULL, `digito_factura` int(2) DEFAULT NULL, `Id_Proveedores_account` mediumint(8) unsigned DEFAULT NULL, `morosidad` tinyint(4) NOT NULL DEFAULT '0', `empresa_grupo` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `gerente_id` (`gerente_id`), KEY `empresa_cliente_idx` (`Id_Cliente`), KEY `Id_Proveedores_account` (`Id_Proveedores_account`), KEY `empresa_grupo_fk_idx` (`empresa_grupo`), CONSTRAINT `empresa_cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `empresa_ibfk_1` FOREIGN KEY (`gerente_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fk_empresa_grupo` FOREIGN KEY (`empresa_grupo`) REFERENCES `empresa_grupo` (`empresa_grupo_id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `empresa_grupo` -- DROP TABLE IF EXISTS `empresa_grupo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `empresa_grupo` ( `empresa_grupo_id` int(11) NOT NULL AUTO_INCREMENT, `grupo` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`empresa_grupo_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `entity` -- DROP TABLE IF EXISTS `entity`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `entity` ( `pais_id` mediumint(8) unsigned NOT NULL DEFAULT '1', `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `bic` varchar(11) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`entity_id`), UNIQUE KEY `bic_UNIQUE` (`bic`), KEY `fg_entity1_idx` (`pais_id`), CONSTRAINT `fg_entity1` FOREIGN KEY (`pais_id`) REFERENCES `Paises` (`Id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=10227 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `escritos` -- DROP TABLE IF EXISTS `escritos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `escritos` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `abrev` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `descripcion` varchar(105) COLLATE utf8_unicode_ci NOT NULL, `visible` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `escritos_det` -- DROP TABLE IF EXISTS `escritos_det`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `escritos_det` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Cliente` int(10) unsigned NOT NULL, `escritos_id` int(10) unsigned NOT NULL, `fecha` datetime NOT NULL, `Id_Trabajador` int(10) unsigned NOT NULL, `Saldo` float NOT NULL, `empresa_id` smallint(5) unsigned DEFAULT NULL, `escritos_detcol` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `userFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `escritos_det_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=14112 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `expeditions` -- DROP TABLE IF EXISTS `expeditions`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `expeditions` ( `expeditions_id` int(11) NOT NULL AUTO_INCREMENT, `agency_id` int(11) NOT NULL, `ticket_id` int(10) NOT NULL, `EsBulto` int(11) DEFAULT '1', `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `reembolso` bit(1) DEFAULT b'0', `recogida` bit(1) DEFAULT b'0', `Id_Article` int(11) DEFAULT NULL, `counter` smallint(5) unsigned NOT NULL, `checked` tinyint(4) NOT NULL DEFAULT '0', `workerFk` int(11) DEFAULT NULL, PRIMARY KEY (`expeditions_id`), KEY `index1` (`agency_id`), KEY `index2` (`EsBulto`), KEY `index3` (`odbc_date`), KEY `index4` (`ticket_id`), CONSTRAINT `Id_Agencia` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2168723 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `expeditionsBeforeInsert` BEFORE INSERT ON `expeditions` FOR EACH ROW -- Edit trigger body code below this line. Do not edit lines above this one BEGIN DECLARE intcounter INT; IF NEW.EsBulto > 0 THEN UPDATE Tickets SET Bultos = nz(Bultos) + 1 WHERE Id_Ticket = NEW.ticket_id; SELECT IFNULL(MAX(counter),0) +1 INTO intcounter FROM expeditions e INNER JOIN Tickets t1 ON e.ticket_id = t1.Id_Ticket LEFT JOIN vn.ticketState ts ON ts.ticket = t1.Id_Ticket INNER JOIN Tickets t2 ON t2.Id_Consigna = t1.Id_Consigna AND DATE(t2.Fecha) = DATE(t1.Fecha) AND t1.warehouse_id = t2.warehouse_id WHERE t2.Id_Ticket = NEW.ticket_id AND ts.alertLevel < 3 AND t1.empresa_id = t2.empresa_id AND t1.Id_Agencia = t2.Id_Agencia; SET NEW.`counter` = intcounter; END IF; SET NEW.workerFk=get_Trabajador(); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`expeditionsBeforeUpdate` BEFORE UPDATE ON `vn2008`.`expeditions` FOR EACH ROW -- Edit trigger body code below this line. Do not edit lines above this one BEGIN IF NEW.counter <> OLD.counter THEN IF (SELECT COUNT(*) FROM expeditions e INNER JOIN Tickets t1 ON e.ticket_id = t1.Id_Ticket INNER JOIN Tickets t2 ON t2.Id_Consigna = t1.Id_Consigna AND DATE(t2.Fecha) = DATE(t1.Fecha) WHERE t1.Id_Ticket = NEW.ticket_id AND counter = NEW.counter) > 0 THEN SET NEW.expeditions_id = NULL; END IF; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`expeditionsAfterUpdate` AFTER UPDATE ON `expeditions` FOR EACH ROW BEGIN CALL cache.barcodes_expeditions_update(NEW.expeditions_id); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`expeditionsBeforeDelete` BEFORE DELETE ON `expeditions` FOR EACH ROW BEGIN DECLARE trabajador integer DEFAULT NULL; SELECT Id_Trabajador into trabajador from Trabajadores where user_id = account.userGetId(); if trabajador is null then SET trabajador = 33; end if; UPDATE Tickets SET Bultos = (SELECT COUNT(counter)-1 FROM expeditions WHERE ticket_id = OLD.ticket_id and EsBulto) WHERE Id_Ticket = OLD.ticket_id; INSERT INTO Tickets_dits (idaccion_dits,Id_Trabajador,Id_Ticket,value_old,value_new) SELECT 133/*Borra expedition*/,trabajador,OLD.ticket_id,CONCAT(OLD.odbc_date,',Bultos:',OLD.counter,',Embalaje:',OLD.EsBulto),user() FROM Tickets WHERE Id_Ticket = OLD.ticket_id ; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `expeditions_deleted` -- DROP TABLE IF EXISTS `expeditions_deleted`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `expeditions_deleted` ( `expeditions_id` int(11) NOT NULL AUTO_INCREMENT, `agency_id` int(11) NOT NULL, `ticket_id` int(10) NOT NULL, `EsBulto` int(11) DEFAULT '1', `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `reembolso` bit(1) DEFAULT b'0', `recogida` bit(1) DEFAULT b'0', `Id_Article` int(11) DEFAULT NULL, `counter` smallint(5) unsigned NOT NULL, `checked` tinyint(4) NOT NULL DEFAULT '0', `completed` tinyint(4) DEFAULT '0', `expedicion` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Id_Trabajador` int(11) DEFAULT NULL, PRIMARY KEY (`expeditions_id`), KEY `index1` (`agency_id`), KEY `index2` (`EsBulto`), KEY `index3` (`odbc_date`), KEY `index4` (`ticket_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2168610 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `expeditions_pictures` -- DROP TABLE IF EXISTS `expeditions_pictures`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `expeditions_pictures` ( `Id_Article` int(11) NOT NULL, `NoImprimirEtiqueta` bit(1) DEFAULT b'0', PRIMARY KEY (`Id_Article`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `filtros` -- DROP TABLE IF EXISTS `filtros`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `filtros` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `sql` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `Estanteria` tinyint(1) DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `financialProductType` -- DROP TABLE IF EXISTS `financialProductType`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `financialProductType` ( `id` varchar(2) COLLATE utf8_unicode_ci NOT NULL, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `description_UNIQUE` (`description`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Distintos tipos de productos financieros: seguros de cambio, polizas de credito, acumuladores....'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `flight` -- DROP TABLE IF EXISTS `flight`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `flight` ( `flight_id` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `duration` tinyint(2) unsigned DEFAULT NULL, `route` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `days` varchar(7) COLLATE utf8_unicode_ci DEFAULT NULL, `airline_id` smallint(2) unsigned DEFAULT NULL, `airport_out` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `airport_in` varchar(3) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`flight_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `form_query` -- DROP TABLE IF EXISTS `form_query`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `form_query` ( `form_query_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `query` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `response1` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `response2` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `type_id` enum('gest_doc') COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`form_query_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `gastos_resumen` -- DROP TABLE IF EXISTS `gastos_resumen`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `gastos_resumen` ( `Id_Gasto` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `year` int(4) NOT NULL, `month` int(2) NOT NULL, `importe` decimal(10,2) DEFAULT NULL, `empresa_id` int(11) NOT NULL, PRIMARY KEY (`Id_Gasto`,`year`,`month`,`empresa_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Sirve para resumir los gastos que se ponen a mano en el contaplus'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `gestdoc` -- DROP TABLE IF EXISTS `gestdoc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `gestdoc` ( `id` int(11) NOT NULL AUTO_INCREMENT, `gesttip_id` int(11) NOT NULL DEFAULT '1', `sref` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `brief` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL, `emp_id` smallint(5) unsigned NOT NULL DEFAULT '791', `orden` mediumint(8) unsigned DEFAULT NULL, `file` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, `original` tinyint(4) NOT NULL DEFAULT '0', `trabajador_id` int(11) NOT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `gestdoccol` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `warehouse_id` smallint(5) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `emp_id` (`emp_id`,`orden`,`warehouse_id`), KEY `trabajador_id` (`trabajador_id`), KEY `warehouse_id` (`warehouse_id`) ) ENGINE=InnoDB AUTO_INCREMENT=766622 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`gestdoc_bi` BEFORE INSERT ON `vn2008`.`gestdoc` FOR EACH ROW BEGIN DECLARE intORD int; IF NEW.warehouse_id = 44 THEN SET NEW.warehouse_id = 1; END IF; IF NEW.original THEN SELECT 1 + MAX(orden) INTO intORD FROM gestdoc WHERE emp_id = NEW.emp_id AND warehouse_id = NEW.warehouse_id ; SET NEW.orden = IFNULL(intORD,1) ; END IF; -- Marca Firmado a uno cada vez que se escanea un Ticket de forma que desaparezca del TNAC JGF 27/08/13 IF NEW.gesttip_id = 14 THEN UPDATE Tickets SET Firmado = 1 WHERE Id_Ticket = NEW.sref; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`gestdoc_bu` BEFORE UPDATE ON `vn2008`.`gestdoc` FOR EACH ROW BEGIN DECLARE intORD int; IF (NEW.original <> 0) AND (OLD.original = 0) AND (NEW.orden IS NULL) THEN SELECT 1 + MAX(orden) INTO intORD FROM gestdoc WHERE emp_id = NEW.emp_id AND warehouse_id = NEW.warehouse_id; SET NEW.orden = IFNULL(intORD,1); END IF; IF ((NEW.orden = 0) OR NEW.orden IS NULL) AND (OLD.orden <> 0) THEN SET NEW.original = 0; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `gesttip` -- DROP TABLE IF EXISTS `gesttip`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `gesttip` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tipo` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `path` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `guillen` -- DROP TABLE IF EXISTS `guillen`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `guillen` ( `bulto` tinyint(3) unsigned NOT NULL, `1` float unsigned NOT NULL, `2` float unsigned NOT NULL, `re_exp` float unsigned NOT NULL, PRIMARY KEY (`bulto`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `guillen_carry` -- DROP TABLE IF EXISTS `guillen_carry`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `guillen_carry` ( `carry` tinyint(3) unsigned NOT NULL, `1` float unsigned NOT NULL, `2` float unsigned NOT NULL, `re_exp` float unsigned NOT NULL, PRIMARY KEY (`carry`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `integra2` -- DROP TABLE IF EXISTS `integra2`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `integra2` ( `postal_code` mediumint(8) unsigned NOT NULL, `frequency` tinyint(3) unsigned NOT NULL, `warehouse_id` smallint(5) unsigned NOT NULL, PRIMARY KEY (`postal_code`,`frequency`,`warehouse_id`), KEY `postal_code` (`postal_code`), KEY `warehouse_id` (`warehouse_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `integra2_escala` -- DROP TABLE IF EXISTS `integra2_escala`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `integra2_escala` ( `province_id` smallint(6) unsigned NOT NULL, `warehouse_id` smallint(6) unsigned NOT NULL, PRIMARY KEY (`province_id`,`warehouse_id`), KEY `warehouse_escala_idx` (`warehouse_id`), CONSTRAINT `province_escala` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `warehouse_escala` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `integra2_province` -- DROP TABLE IF EXISTS `integra2_province`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `integra2_province` ( `province_id` smallint(6) unsigned NOT NULL, `franquicia` varchar(65) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`province_id`), CONSTRAINT `integra2_province_id` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `intervalos` -- DROP TABLE IF EXISTS `intervalos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `intervalos` ( `id` int(11) NOT NULL, `hour` time NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `intrastat_data` -- DROP TABLE IF EXISTS `intrastat_data`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `intrastat_data` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `recibida_id` mediumint(8) unsigned NOT NULL, `neto` decimal(10,2) DEFAULT NULL, `intrastat_id` int(8) unsigned zerofill NOT NULL DEFAULT '06049190', `importe` double NOT NULL, `unidades` int(11) NOT NULL, `Paises_Id` mediumint(8) unsigned DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `valorestadistico` double NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `intrastat_id` (`intrastat_id`), KEY `recibida` (`recibida_id`), CONSTRAINT `intrastat_data_ibfk_1` FOREIGN KEY (`intrastat_id`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `intrastat_data_ibfk_2` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=60070 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `invoiceCorrection` -- DROP TABLE IF EXISTS `invoiceCorrection`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `invoiceCorrection` ( `correctingFk` int(10) unsigned NOT NULL COMMENT 'Factura rectificativa', `correctedFk` int(10) unsigned NOT NULL COMMENT 'Factura rectificada', `cplusRectificationTypeFk` int(10) unsigned NOT NULL, `cplusInvoiceType477Fk` int(10) unsigned NOT NULL, `invoiceCorrectionTypeFk` int(11) NOT NULL DEFAULT '3', PRIMARY KEY (`correctingFk`), KEY `correctedFk_idx` (`correctedFk`), KEY `invoiceCorrection_ibfk_1_idx` (`cplusRectificationTypeFk`), KEY `cplusInvoiceTyoeFk_idx` (`cplusInvoiceType477Fk`), KEY `invoiceCorrectionTypeFk_idx` (`invoiceCorrectionTypeFk`), CONSTRAINT `corrected_fk` FOREIGN KEY (`correctedFk`) REFERENCES `Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `correcting_fk` FOREIGN KEY (`correctingFk`) REFERENCES `Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cplusInvoiceTyoeFk` FOREIGN KEY (`cplusInvoiceType477Fk`) REFERENCES `vn`.`cplusInvoiceType477` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceCorrectionType_Fk33` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `vn`.`invoiceCorrectionType` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceCorrection_ibfk_1` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relacion entre las facturas rectificativas y las rectificadas.'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `invoice_observation` -- DROP TABLE IF EXISTS `invoice_observation`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `invoice_observation` ( `invoice_observation_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `desde` date NOT NULL, `hasta` date NOT NULL, `serie` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '0', `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`invoice_observation_id`) ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `itemTag` -- DROP TABLE IF EXISTS `itemTag`; /*!50001 DROP VIEW IF EXISTS `itemTag`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `itemTag` AS SELECT 1 AS `id`, 1 AS `itemFk`, 1 AS `tagFk`, 1 AS `value`, 1 AS `priority`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `itemTagArranged` -- DROP TABLE IF EXISTS `itemTagArranged`; /*!50001 DROP VIEW IF EXISTS `itemTagArranged`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `itemTagArranged` AS SELECT 1 AS `itemFk`, 1 AS `tag1`, 1 AS `val1`, 1 AS `tag2`, 1 AS `val2`, 1 AS `tag3`, 1 AS `val3`, 1 AS `tag4`, 1 AS `val4`, 1 AS `tag5`, 1 AS `val5`, 1 AS `tag6`, 1 AS `val6`, 1 AS `description`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `item_catalog` -- DROP TABLE IF EXISTS `item_catalog`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `item_catalog` ( `item_id` int(11) unsigned NOT NULL, `available` mediumint(9) NOT NULL, `fixed` tinyint(1) NOT NULL DEFAULT '0', `price` double DEFAULT NULL, `s1` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `s2` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `discount` tinyint(3) unsigned, `grouping` decimal(10,0) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `item_entry_in` -- DROP TABLE IF EXISTS `item_entry_in`; /*!50001 DROP VIEW IF EXISTS `item_entry_in`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `item_entry_in` AS SELECT 1 AS `warehouse_id`, 1 AS `dat`, 1 AS `item_id`, 1 AS `amount`, 1 AS `received`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `item_entry_out` -- DROP TABLE IF EXISTS `item_entry_out`; /*!50001 DROP VIEW IF EXISTS `item_entry_out`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `item_entry_out` AS SELECT 1 AS `warehouse_id`, 1 AS `dat`, 1 AS `item_id`, 1 AS `amount`, 1 AS `delivered`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `item_entry_outkk` -- DROP TABLE IF EXISTS `item_entry_outkk`; /*!50001 DROP VIEW IF EXISTS `item_entry_outkk`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `item_entry_outkk` AS SELECT 1 AS `warehouse_id`, 1 AS `dat`, 1 AS `item_id`, 1 AS `amount`, 1 AS `delivered`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `item_out` -- DROP TABLE IF EXISTS `item_out`; /*!50001 DROP VIEW IF EXISTS `item_out`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `item_out` AS SELECT 1 AS `warehouse_id`, 1 AS `dat`, 1 AS `item_id`, 1 AS `amount`, 1 AS `ok`, 1 AS `Reservado`, 1 AS `ready`, 1 AS `invoice`, 1 AS `alertLevel`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `iva_codigo` -- DROP TABLE IF EXISTS `iva_codigo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `iva_codigo` ( `id` tinyint(2) unsigned NOT NULL AUTO_INCREMENT, `fecha` date NOT NULL, `codigo` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `iva_tipo_id` tinyint(2) NOT NULL, `iva` decimal(4,1) NOT NULL DEFAULT '0.0', `recargo` decimal(4,1) NOT NULL DEFAULT '0.0', `tipo` char(1) COLLATE utf8_unicode_ci NOT NULL, `link` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'las que tienen el mismo valor se contabilizan emparejadas', `isActive` tinyint(2) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `iva_tipo_id` (`iva_tipo_id`), KEY `codigo` (`codigo`), KEY `tipo_index` (`tipo`), CONSTRAINT `iva_codigo_ibfk_1` FOREIGN KEY (`iva_tipo_id`) REFERENCES `iva_tipo` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `iva_group` -- DROP TABLE IF EXISTS `iva_group`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `iva_group` ( `iva_group_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `code` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'R', PRIMARY KEY (`iva_group_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `iva_group_codigo` -- DROP TABLE IF EXISTS `iva_group_codigo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `iva_group_codigo` ( `iva_group_id` tinyint(3) unsigned NOT NULL, `date` date NOT NULL, `iva_codigo_id` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`iva_group_id`,`date`,`iva_codigo_id`), KEY `iva_codigo_id` (`iva_codigo_id`), CONSTRAINT `iva_group_codigo_ibfk_1` FOREIGN KEY (`iva_group_id`) REFERENCES `iva_group` (`iva_group_id`) ON UPDATE CASCADE, CONSTRAINT `iva_group_codigo_ibfk_2` FOREIGN KEY (`iva_codigo_id`) REFERENCES `iva_codigo` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `iva_tipo` -- DROP TABLE IF EXISTS `iva_tipo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `iva_tipo` ( `id` tinyint(2) NOT NULL AUTO_INCREMENT, `alias` varchar(6) COLLATE utf8_unicode_ci NOT NULL, `serie_id` char(1) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOOPE` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' ', `descripcion` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `Id_Pais` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `serie_id` (`serie_id`), KEY `Id_Pais` (`Id_Pais`), CONSTRAINT `iva_tipo_ibfk_1` FOREIGN KEY (`Id_Pais`) REFERENCES `Paises` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `jerarquia` -- DROP TABLE IF EXISTS `jerarquia`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `jerarquia` ( `worker_id` int(11) NOT NULL, `boss_id` int(11) NOT NULL, `vinculado` tinyint(3) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`worker_id`,`boss_id`), KEY `worker_trabajador` (`worker_id`), KEY `boss_trabajador` (`boss_id`), CONSTRAINT `boss_trabajador` FOREIGN KEY (`boss_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `worker_trabajador` FOREIGN KEY (`worker_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `killme` -- DROP TABLE IF EXISTS `killme`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `killme` ( `Id_Article` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `language` -- DROP TABLE IF EXISTS `language`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `language` ( `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `active` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`code`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `link` -- DROP TABLE IF EXISTS `link`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `link` ( `Id_Cliente` int(11) NOT NULL, `Id_Proveedor` int(11) NOT NULL, PRIMARY KEY (`Id_Cliente`,`Id_Proveedor`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `log_articles` -- DROP TABLE IF EXISTS `log_articles`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `log_articles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Id_Article` int(11) NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Fecha_old` datetime DEFAULT NULL, `cantidad_old` double DEFAULT NULL, `Id_Ticket_old` int(11) DEFAULT NULL, `wh_old` smallint(6) unsigned DEFAULT NULL, `Fecha_new` datetime DEFAULT NULL, `cantidad_new` double DEFAULT NULL, `Id_Ticket_new` int(11) DEFAULT NULL, `wh_new` smallint(6) DEFAULT NULL, `accion` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `Id_Article_log` (`Id_Article`), KEY `Id_Ticket_log` (`Id_Ticket_old`), KEY `Id_Ticket_new_log` (`Id_Ticket_new`), CONSTRAINT `Id_Article_log_Articles` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los movimientos de los articulos para intentar encontrar los procesos que generan negativos'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `mail` -- DROP TABLE IF EXISTS `mail`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mail` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `to` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `reply_to` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `subject` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `text` text COLLATE utf8_unicode_ci NOT NULL, `sent` tinyint(2) NOT NULL DEFAULT '0', `DATE_ODBC` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `path` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `error` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'OK', `senderFk` int(11) DEFAULT NULL, `recipientFk` int(11) DEFAULT NULL, `plainTextBody` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1209471 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `mail_templates` -- DROP TABLE IF EXISTS `mail_templates`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mail_templates` ( `id` int(11) NOT NULL AUTO_INCREMENT, `countryCode` char(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'ES', `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `subject` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `body` text COLLATE utf8_unicode_ci NOT NULL, `attachment` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`,`countryCode`,`name`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `mandato` -- DROP TABLE IF EXISTS `mandato`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mandato` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL, `Id_mandato` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, `FAlta` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `Fbaja` timestamp NULL DEFAULT NULL, `idmandato_tipo` smallint(5) NOT NULL, PRIMARY KEY (`id`), KEY `mandato_fgkey1_idx` (`Id_Cliente`), KEY `mandato_fgkey2_idx` (`empresa_id`), KEY `mandato_fgkey3_idx` (`idmandato_tipo`), CONSTRAINT `mandato_fgkey1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey2` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey3` FOREIGN KEY (`idmandato_tipo`) REFERENCES `mandato_tipo` (`idmandato_tipo`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=14000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 trigger mandato_ins before insert on mandato for each row begin if (NEW.Id_mandato IS NULL) THEN SET NEW.Id_mandato=CONCAT(NEW.Id_Cliente,'-',(SELECT AUTO_INCREMENT from information_schema.TABLES where TABLE_SCHEMA='vn2008' and TABLE_NAME='mandato')); end if; end */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `mandato_tipo` -- DROP TABLE IF EXISTS `mandato_tipo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mandato_tipo` ( `idmandato_tipo` smallint(5) NOT NULL AUTO_INCREMENT, `Nombre` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`idmandato_tipo`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `movement_label` -- DROP TABLE IF EXISTS `movement_label`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `movement_label` ( `Id_movimiento` int(11) NOT NULL, `label` mediumint(8) unsigned NOT NULL, `stem` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`Id_movimiento`), CONSTRAINT `movement_label_ibfk_1` FOREIGN KEY (`Id_movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `movement_label_au` AFTER UPDATE ON `movement_label` FOR EACH ROW -- Edit trigger body code below this line. Do not edit lines above this one IF NEW.stem >= (SELECT Cantidad FROM Movimientos WHERE Id_Movimiento = NEW.Id_Movimiento) THEN UPDATE Movimientos SET OK = 1 WHERE Id_Movimiento = NEW.Id_Movimiento; END IF */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Temporary view structure for view `new_viewkk` -- DROP TABLE IF EXISTS `new_viewkk`; /*!50001 DROP VIEW IF EXISTS `new_viewkk`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `new_viewkk` AS SELECT 1 AS `id`, 1 AS `worker`, 1 AS `document`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `nichos` -- DROP TABLE IF EXISTS `nichos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `nichos` ( `id` varchar(5) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `observation_type` -- DROP TABLE IF EXISTS `observation_type`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `observation_type` ( `observation_type_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`observation_type_id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `order` -- DROP TABLE IF EXISTS `order`; /*!50001 DROP VIEW IF EXISTS `order`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `order` AS SELECT 1 AS `id`, 1 AS `date_make`, 1 AS `date_send`, 1 AS `customer_id`, 1 AS `delivery_method_id`, 1 AS `agency_id`, 1 AS `address_id`, 1 AS `note`, 1 AS `confirmed`, 1 AS `is_bionic`, 1 AS `source_app`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `order_Tickets` -- DROP TABLE IF EXISTS `order_Tickets`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `order_Tickets` ( `order_id` int(10) unsigned NOT NULL, `Id_Ticket` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Ticket`,`order_id`), KEY `order_id` (`order_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `order_component` -- DROP TABLE IF EXISTS `order_component`; /*!50001 DROP VIEW IF EXISTS `order_component`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `order_component` AS SELECT 1 AS `order_row_id`, 1 AS `component_id`, 1 AS `price`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `order_row` -- DROP TABLE IF EXISTS `order_row`; /*!50001 DROP VIEW IF EXISTS `order_row`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `order_row` AS SELECT 1 AS `id`, 1 AS `order_id`, 1 AS `item_id`, 1 AS `warehouse_id`, 1 AS `shipment`, 1 AS `amount`, 1 AS `price`, 1 AS `rate`, 1 AS `created`, 1 AS `Id_Movimiento`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `pago` -- DROP TABLE IF EXISTS `pago`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `pago` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `fecha` date NOT NULL, `id_proveedor` int(11) NOT NULL, `importe` decimal(10,2) NOT NULL DEFAULT '0.00', `id_moneda` tinyint(3) unsigned NOT NULL DEFAULT '1', `divisa` decimal(10,2) DEFAULT NULL, `id_banco` int(11) NOT NULL DEFAULT '0', `pay_met_id` tinyint(3) unsigned NOT NULL, `g_bancarios` double(6,2) unsigned NOT NULL DEFAULT '0.00', `concepte` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `conciliado` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', `pago_sdc_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), KEY `id_banco` (`id_banco`), KEY `id_moneda` (`id_moneda`), KEY `pay_met` (`pay_met_id`), KEY `proveedor_pago` (`id_proveedor`), KEY `fk_pago_pago_sdc1_idx` (`pago_sdc_id`), CONSTRAINT `pago_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `pago_ibfk_2` FOREIGN KEY (`id_banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `pago_moneda` FOREIGN KEY (`id_moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `pago_pay_met` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `proveedor_pago` FOREIGN KEY (`id_proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=38197 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `pago_bi` BEFORE INSERT ON `pago` FOR EACH ROW -- Edit trigger body code below this line. Do not edit lines above this one BEGIN DECLARE cuenta_banco,cuenta_proveedor DOUBLE; DECLARE max_asien INT; DECLARE bolCASH BOOLEAN; -- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH SELECT (cash = 1) INTO bolCASH FROM Bancos WHERE Bancos.Id_Banco = NEW.id_banco ; IF bolCASH THEN -- AND NEW.id_pago <> 1 SELECT Cuenta INTO cuenta_banco FROM Bancos WHERE Id_Banco = NEW.id_banco; SELECT Cuenta INTO cuenta_proveedor FROM Proveedores WHERE Id_Proveedor=NEW.id_proveedor; SELECT MAX(asien)+1 INTO max_asien FROM XDiario; INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id) SELECT max_asien,NEW.fecha,SUBCTA,CONTRA,NEW.concepte,EURODEBE,EUROHABER,NEW.empresa_id FROM ( SELECT cuenta_banco SUBCTA,cuenta_proveedor CONTRA, 0 EURODEBE, NEW.importe + NEW.g_bancarios EUROHABER UNION ALL SELECT cuenta_proveedor SUBCTA, cuenta_banco CONTRA, NEW.importe EURODEBE, 0 EUROHABER) gf; IF NEW.g_bancarios <> 0 THEN INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id) SELECT max_asien,NEW.fecha,IF(Id = 1,6260000002,IF(CEE = 1,6260000003,6260000004)),cuenta_banco,NEW.concepte, NEW.g_bancarios,0,NEW.empresa_id FROM Proveedores pr JOIN Paises pa ON pr.pais_id = pa.Id WHERE Id_Proveedor = NEW.id_proveedor; END IF; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `pago_sdc` -- DROP TABLE IF EXISTS `pago_sdc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `pago_sdc` ( `pago_sdc_id` int(11) NOT NULL AUTO_INCREMENT, `importe` decimal(10,2) NOT NULL, `fecha` date NOT NULL, `vencimiento` date NOT NULL, `entity_id` int(10) unsigned NOT NULL, `ref` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `rate` decimal(10,4) NOT NULL, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `financialProductTypefk` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'SC', `pago_sdccol` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `upperBarrier` decimal(10,2) DEFAULT NULL, `lowerBarrier` decimal(10,2) DEFAULT NULL, `strike` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`pago_sdc_id`), KEY `empresa_sdc_idx` (`empresa_id`), KEY `financial_type_fk_idx` (`financialProductTypefk`), KEY `pago_sdc_entity_fk_idx` (`entity_id`), CONSTRAINT `empresa_sdc` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `financial_type_fk` FOREIGN KEY (`financialProductTypefk`) REFERENCES `financialProductType` (`id`) ON UPDATE CASCADE, CONSTRAINT `pago_sdc_entity_fk` FOREIGN KEY (`entity_id`) REFERENCES `entity` (`entity_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Seguros de cambio'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `pay_dem` -- DROP TABLE IF EXISTS `pay_dem`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `pay_dem` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `pay_dem` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `pay_dem_det` -- DROP TABLE IF EXISTS `pay_dem_det`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `pay_dem_det` ( `id` tinyint(3) unsigned NOT NULL, `detalle` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`,`detalle`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `pay_met` -- DROP TABLE IF EXISTS `pay_met`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `pay_met` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `solucion` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `deudaviva` tinyint(3) unsigned zerofill NOT NULL DEFAULT '000', `graceDays` int(11) unsigned NOT NULL DEFAULT '0', `ibanRequired` tinyint(3) DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_basess` -- DROP TABLE IF EXISTS `payroll_basess`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_basess` ( `id_payroll_Basess` int(11) NOT NULL AUTO_INCREMENT, `empresa_id` int(10) NOT NULL, `id_tipobasess` int(11) NOT NULL, `valor` double NOT NULL, `fechadesde` date NOT NULL, `fechahasta` date DEFAULT NULL, `contratotemporal` tinyint(1) DEFAULT '0', PRIMARY KEY (`id_payroll_Basess`), KEY `payroll_basess_1_idx` (`id_tipobasess`), KEY `payroll_basess_2_idx` (`empresa_id`), CONSTRAINT `payroll_basess_1` FOREIGN KEY (`id_tipobasess`) REFERENCES `payroll_tipobasess` (`id_payroll_tipobasess`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `payroll_basess_2` FOREIGN KEY (`empresa_id`) REFERENCES `payroll_centros` (`empresa_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_bonificaciones` -- DROP TABLE IF EXISTS `payroll_bonificaciones`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_bonificaciones` ( `codtrabajador` int(11) NOT NULL, `codempresa` int(11) NOT NULL, `Fecha` date NOT NULL, `bonificacionSS` double NOT NULL, PRIMARY KEY (`codtrabajador`,`codempresa`,`Fecha`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_categorias` -- DROP TABLE IF EXISTS `payroll_categorias`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_categorias` ( `codcategoria` int(11) NOT NULL, `descripcion` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `Tarifa` tinyint(4) NOT NULL, PRIMARY KEY (`codcategoria`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_centros` -- DROP TABLE IF EXISTS `payroll_centros`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_centros` ( `cod_centro` int(11) NOT NULL, `Centro` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `nss_cotizacion` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `domicilio` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `poblacion` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `cp` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `empresa_id` int(10) NOT NULL, `codempresa` int(11) DEFAULT NULL, PRIMARY KEY (`cod_centro`,`empresa_id`), KEY `payroll_centros_ix1` (`empresa_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_conceptos` -- DROP TABLE IF EXISTS `payroll_conceptos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_conceptos` ( `conceptoid` int(11) NOT NULL, `concepto` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`conceptoid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_contratos` -- DROP TABLE IF EXISTS `payroll_contratos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_contratos` ( `CodContrato` int(11) NOT NULL, `TipoCotizacion` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `DescContrato` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`CodContrato`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_datos` -- DROP TABLE IF EXISTS `payroll_datos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_datos` ( `codtrabajador` int(11) NOT NULL, `codempresa` int(10) NOT NULL, `Fecha` date NOT NULL, `conceptoid` int(11) NOT NULL, `orden` tinyint(4) DEFAULT NULL, `dias` smallint(6) DEFAULT NULL, `Importe` decimal(8,2) NOT NULL, `DH` tinyint(4) DEFAULT NULL, `T_Paga` tinyint(4) NOT NULL, `TributaIRPF` tinyint(4) NOT NULL, PRIMARY KEY (`codtrabajador`,`codempresa`,`conceptoid`,`Fecha`), KEY `fgkey_payrolldatos_1_idx` (`conceptoid`), CONSTRAINT `fgkey_payrolldatos_1` FOREIGN KEY (`conceptoid`) REFERENCES `payroll_conceptos` (`conceptoid`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_embargos` -- DROP TABLE IF EXISTS `payroll_embargos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_embargos` ( `codtrabajador` int(11) NOT NULL, `codempresa` int(10) NOT NULL, `conceptoid` int(11) NOT NULL, `Fecha` date NOT NULL, `pagado` double NOT NULL, `pendiente` double DEFAULT NULL, `total` double NOT NULL, PRIMARY KEY (`codtrabajador`,`codempresa`,`Fecha`,`conceptoid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_employee` -- DROP TABLE IF EXISTS `payroll_employee`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_employee` ( `CodTrabajador` int(11) NOT NULL, `Person_id` int(11) NOT NULL, `nss` varchar(23) COLLATE utf8_unicode_ci NOT NULL, `codpuesto` int(10) NOT NULL, `codempresa` int(10) NOT NULL, `codcontrato` int(10) NOT NULL, `FAntiguedad` date NOT NULL, `grupotarifa` int(10) NOT NULL, `codcategoria` int(10) NOT NULL, `ContratoTemporal` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`CodTrabajador`,`codempresa`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_pagarini` -- DROP TABLE IF EXISTS `payroll_pagarini`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_pagarini` ( `fecha` date NOT NULL, `person_id` int(11) NOT NULL, `saldotpv` double NOT NULL DEFAULT '0', `saldolab` double NOT NULL DEFAULT '0', `saldoprod` double NOT NULL DEFAULT '0', `saldobruto` double NOT NULL DEFAULT '0', `business_id` int(11) NOT NULL, `exportado` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`fecha`,`person_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_pais` -- DROP TABLE IF EXISTS `payroll_pais`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_pais` ( `codpais` int(11) NOT NULL, `pais` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`codpais`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payroll_tipobasess` -- DROP TABLE IF EXISTS `payroll_tipobasess`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payroll_tipobasess` ( `id_payroll_tipobasess` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id_payroll_tipobasess`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `payrroll_apEmpresarial` -- DROP TABLE IF EXISTS `payrroll_apEmpresarial`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `payrroll_apEmpresarial` ( `id` int(11) NOT NULL AUTO_INCREMENT, `codTrabajador` int(11) NOT NULL, `Fecha` date NOT NULL, `CosteEmpresaAT` decimal(8,2) NOT NULL, `costeEmpresaCC` decimal(8,2) NOT NULL, `costeEmpresaDesempleo` decimal(8,2) NOT NULL, `costeEmpresaFP` decimal(8,2) NOT NULL, `costeEmpresaFogasa` decimal(8,2) NOT NULL, `costeEmpresaExtra` decimal(8,2) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1654 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `person_user` -- DROP TABLE IF EXISTS `person_user`; /*!50001 DROP VIEW IF EXISTS `person_user`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `person_user` AS SELECT 1 AS `id`, 1 AS `mysql_user_id`, 1 AS `name`, 1 AS `password`, 1 AS `active`, 1 AS `last_pass_change`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `person_user_idtrabajador` -- DROP TABLE IF EXISTS `person_user_idtrabajador`; /*!50001 DROP VIEW IF EXISTS `person_user_idtrabajador`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `person_user_idtrabajador` AS SELECT 1 AS `Id_Trabajador`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `plantpassport` -- DROP TABLE IF EXISTS `plantpassport`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `plantpassport` ( `producer_id` mediumint(3) unsigned NOT NULL, `plantpassport_authority_id` mediumint(3) unsigned NOT NULL, `number` varchar(25) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`producer_id`,`plantpassport_authority_id`), KEY `plantpassport_authority_idx` (`plantpassport_authority_id`), KEY `producer_id_idx` (`producer_id`), CONSTRAINT `plantpassport_authority` FOREIGN KEY (`plantpassport_authority_id`) REFERENCES `plantpassport_authority` (`plantpassport_authority_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `producer` FOREIGN KEY (`producer_id`) REFERENCES `producer` (`producer_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='tiene la asignacion de cada productor con la autoridad certificadora'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `plantpassport_authority` -- DROP TABLE IF EXISTS `plantpassport_authority`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `plantpassport_authority` ( `plantpassport_authority_id` mediumint(3) unsigned NOT NULL, `denomination` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Paises_Id` mediumint(8) unsigned DEFAULT NULL, PRIMARY KEY (`plantpassport_authority_id`), UNIQUE KEY `denomination_UNIQUE` (`denomination`), KEY `Pais_id_idx` (`Paises_Id`), CONSTRAINT `Pais_id` FOREIGN KEY (`Paises_Id`) REFERENCES `Paises` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='entidades certificadoras'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `preparation_exception` -- DROP TABLE IF EXISTS `preparation_exception`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `preparation_exception` ( `exception_day` date NOT NULL COMMENT 'preparation day', `warehouse_id` smallint(6) unsigned DEFAULT NULL, `percentage` tinyint(2) NOT NULL DEFAULT '0', UNIQUE KEY `exception_day_UNIQUE` (`exception_day`), UNIQUE KEY `warehouse_id_UNIQUE` (`warehouse_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `preparation_percentage` -- DROP TABLE IF EXISTS `preparation_percentage`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `preparation_percentage` ( `week_day` tinyint(1) unsigned NOT NULL COMMENT 'preparation day. Funcion de mysql Lunes = 0, Domingo = 6', `warehouse_id` smallint(6) unsigned DEFAULT NULL, `percentage` tinyint(2) NOT NULL DEFAULT '0', UNIQUE KEY `week_day_UNIQUE` (`week_day`), UNIQUE KEY `warehouse_id_UNIQUE` (`warehouse_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `price_fixed` -- DROP TABLE IF EXISTS `price_fixed`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `price_fixed` ( `item_id` int(10) NOT NULL, `rate_0` double NOT NULL, `rate_1` double NOT NULL, `rate_2` double NOT NULL, `rate_3` double NOT NULL, `date_start` date NOT NULL, `date_end` date NOT NULL, `bonus` double NOT NULL DEFAULT '0', `warehouse_id` smallint(5) unsigned NOT NULL DEFAULT '0', `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `price_fixed_id` int(11) NOT NULL AUTO_INCREMENT, `grouping` smallint(5) DEFAULT NULL, `Packing` int(11) DEFAULT NULL, `caja` tinyint(4) DEFAULT NULL, PRIMARY KEY (`item_id`,`date_start`,`date_end`,`warehouse_id`), UNIQUE KEY `price_fixed_id_UNIQUE` (`price_fixed_id`), KEY `item_id` (`item_id`), KEY `date_start` (`date_start`), KEY `date_end` (`date_end`), KEY `warehouse_id` (`warehouse_id`), CONSTRAINT `price_fixed_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=50361 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`price_fixed_bi` BEFORE INSERT ON `vn2008`.`price_fixed` FOR EACH ROW BEGIN DECLARE v_aux DATE; IF NEW.date_start > NEW.date_end THEN SET v_aux = NEW.date_start; SET NEW.date_start = NEW.date_end; SET NEW.date_end = v_aux; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`price_fixed_bu` BEFORE UPDATE ON `vn2008`.`price_fixed` FOR EACH ROW BEGIN DECLARE v_aux DATE; IF NEW.date_start > NEW.date_end THEN SET v_aux = NEW.date_start; SET NEW.date_start = NEW.date_end; SET NEW.date_end = v_aux; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `producer` -- DROP TABLE IF EXISTS `producer`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `producer` ( `producer_id` mediumint(3) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `visible` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`producer_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3517 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `profile_labour_payroll` -- DROP TABLE IF EXISTS `profile_labour_payroll`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `profile_labour_payroll` ( `profile_id` int(11) NOT NULL, `codpais` int(11) NOT NULL, `nivelformativo` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `NSSProvincia` tinyint(2) unsigned zerofill NOT NULL, `NssNumero` varchar(8) COLLATE utf8_unicode_ci NOT NULL, `NssDC` char(2) COLLATE utf8_unicode_ci NOT NULL, `sexo` enum('H','M') COLLATE utf8_unicode_ci NOT NULL, `estadocivil` enum('S','C') COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`profile_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `proveedores_clientes` -- DROP TABLE IF EXISTS `proveedores_clientes`; /*!50001 DROP VIEW IF EXISTS `proveedores_clientes`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `proveedores_clientes` AS SELECT 1 AS `Id_Proveedor`, 1 AS `Proveedor`, 1 AS `Id_Cliente`, 1 AS `Cliente`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `provider_account_customer` -- DROP TABLE IF EXISTS `provider_account_customer`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `provider_account_customer` ( `account_id` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`account_id`), CONSTRAINT `provider_account_customer_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `Proveedores_account` (`Id_Proveedores_account`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Bank accounts used for customer transfers'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `province` -- DROP TABLE IF EXISTS `province`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `province` ( `province_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `Paises_Id` mediumint(8) unsigned NOT NULL, `warehouse_id` smallint(6) unsigned DEFAULT NULL COMMENT 'warehouse responsable de las rutas', `zone` tinyint(4) DEFAULT NULL, `nst_geo_id` int(11) DEFAULT NULL, `nst_name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `geoFk` int(11) DEFAULT NULL, PRIMARY KEY (`province_id`), KEY `Paises_Id` (`Paises_Id`), KEY `warehouse_Id` (`warehouse_id`), KEY `provicne_zone_fk_idx` (`zone`), CONSTRAINT `province_ibfk_1` FOREIGN KEY (`Paises_Id`) REFERENCES `Paises` (`Id`) ON UPDATE CASCADE, CONSTRAINT `province_zone_fk` FOREIGN KEY (`zone`) REFERENCES `zones` (`zone_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `warehouse_Id` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=192 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`provinceBeforeInsert` BEFORE INSERT ON `province` FOR EACH ROW BEGIN IF NEW.`name` = '' THEN CALL util.throw ('EMPTY_NAME'); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`provinceBeforeUpdate` BEFORE UPDATE ON `province` FOR EACH ROW BEGIN IF NEW.`name` = '' THEN CALL util.throw ('EMPTY_NAME'); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `rec_translator` -- DROP TABLE IF EXISTS `rec_translator`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `rec_translator` ( `Id_Article` int(11) NOT NULL, `denominacion` varchar(85) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`Id_Article`,`denominacion`), KEY `id_article_rec_idx` (`Id_Article`), CONSTRAINT `id_article_rec` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Equipara las denominaciones de las fincas de ecuador con nuestro Id_Article'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `recibida` -- DROP TABLE IF EXISTS `recibida`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recibida` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `num_recibida` mediumint(11) unsigned DEFAULT NULL COMMENT 'insertado por Trigger', `serie` char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'R', `proveedor_id` int(11) NOT NULL, `fecha` date NOT NULL COMMENT 'Fecha de emision de la factura', `sref` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', `contabilizada` tinyint(1) NOT NULL DEFAULT '0', `moneda_id` tinyint(3) unsigned NOT NULL DEFAULT '1', `MYSQL_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', `gestdoc_id` int(11) DEFAULT NULL, `dateBooking` date DEFAULT NULL COMMENT 'Fecha de contabilizacion', `dateOperation` date DEFAULT NULL COMMENT 'Fecha de entrega de la mercancia o el suministro', `cplusInvoiceType472Fk` int(10) unsigned DEFAULT '1', `cplusRectificationTypeFk` int(10) unsigned DEFAULT '1', `cplusSubjectOpFk` int(10) unsigned DEFAULT '1', `cplusTaxBreakFk` int(10) unsigned DEFAULT '1', `cplusTrascendency472Fk` int(10) unsigned DEFAULT '1', `bookEntried` date NOT NULL, PRIMARY KEY (`id`), KEY `proveedor_id` (`proveedor_id`), KEY `empresa_id` (`empresa_id`), KEY `serie` (`serie`), KEY `num_recibida_2` (`num_recibida`), KEY `gestdoc_id` (`gestdoc_id`), KEY `fecha` (`fecha`), KEY `recibida_ibfk_3_idx` (`cplusSubjectOpFk`), KEY `recibida_ibfk_4_idx` (`cplusTaxBreakFk`), KEY `recibida_ibfk_5_idx` (`cplusInvoiceType472Fk`), KEY `recibida_ibfk_6` (`cplusRectificationTypeFk`), KEY `recibida_ibfk_7` (`cplusTrascendency472Fk`), CONSTRAINT `recibida_ibfk_1` FOREIGN KEY (`proveedor_id`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_2` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_3` FOREIGN KEY (`cplusSubjectOpFk`) REFERENCES `vn`.`cplusSubjectOp` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `vn`.`cplusTaxBreak` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_5` FOREIGN KEY (`cplusInvoiceType472Fk`) REFERENCES `vn`.`cplusInvoiceType472` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_6` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_7` FOREIGN KEY (`cplusTrascendency472Fk`) REFERENCES `vn`.`cplusTrascendency472` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=62257 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`recibida_bi` BEFORE INSERT ON `vn2008`.`recibida` FOR EACH ROW BEGIN DECLARE v_serie CHAR(1) DEFAULT 'R'; DECLARE v_num_recibida INT; DECLARE pais_emisor, pais_receptor INT; DECLARE vActive TINYINT; SELECT pais_id, active into pais_emisor, vActive FROM Proveedores WHERE Id_Proveedor = NEW.proveedor_id; SELECT pais_id into pais_receptor FROM Proveedores WHERE Id_Proveedor = NEW.empresa_id; IF vActive = 0 THEN CALL util.throw('INACTIVE_PROVIDER'); END IF; SELECT CASE WHEN (SELECT Cuenta FROM Proveedores where Id_Proveedor = NEW.proveedor_id) LIKE '___3______' THEN 'C' WHEN (SELECT pais_emisor=pais_receptor from Paises p1 join Paises p2 ON p2.Id = pais_receptor AND p1.Id = pais_emisor where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'R' WHEN (SELECT pais_emisor <> pais_receptor from Paises p1 join Paises p2 ON p2.Id = pais_receptor AND p1.Id = pais_emisor where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' WHEN (SELECT pais_emisor<>pais_receptor from Paises p1 join Paises p2 ON p2.Id = pais_receptor AND p1.Id = pais_emisor where NOT p1.CEE < 2 AND not p1.Id = 1) = 1 THEN 'W' END INTO v_serie; SET NEW.serie = v_serie; IF v_serie LIKE 'W' THEN SELECT IFNULL(MAX(num_recibida) + 1,1) INTO v_num_recibida FROM recibida WHERE serie LIKE NEW.serie AND YEAR(fecha) = YEAR(NEW.fecha) AND empresa_id = NEW.empresa_id; SET NEW.num_recibida = v_num_recibida; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `recibida_bu` BEFORE UPDATE ON `recibida` FOR EACH ROW -- Edit trigger body code below this line. Do not edit lines above this one BEGIN DECLARE cta_proveed VARCHAR(10); DECLARE cta_proveeda VARCHAR(10); DECLARE v_num_recibida INT; DECLARE dblRefRate,dblRefMin,dblRef DOUBLE; DECLARE vActive TINYINT; SELECT active INTO vActive FROM Proveedores WHERE Id_Proveedor = NEW.proveedor_id; IF vActive = 0 THEN CALL util.throw('INACTIVE_PROVIDER'); END IF; IF NEW.empresa_id <> OLD.empresa_id THEN SET NEW.num_recibida = NULL; SET NEW.contabilizada = FALSE ; END IF; /* PAK 27/11/17 ESto tiene pinta de no hacer falta.... IF NEW.contabilizada = 1 AND OLD.contabilizada = 0 AND NEW.fecha < '2017-07-01' THEN SELECT rate INTO dblRefRate FROM reference_rate WHERE date = (SELECT MAX(date) FROM reference_rate WHERE date <= (SELECT t.shipment FROM recibida_entrada re INNER JOIN Entradas e ON e.Id_Entrada = re.Id_Entrada LEFT JOIN travel t ON t.id = e.travel_id WHERE re.awb_recibida = NEW.id GROUP BY re.awb_recibida)); SELECT rate INTO dblRefMin FROM reference_min WHERE date=(SELECT MAX(date) FROM reference_min WHERE date<=(SELECT t.shipment FROM recibida_entrada re INNER JOIN Entradas e ON e.Id_Entrada = re.Id_Entrada LEFT JOIN travel t ON t.id = e.travel_id WHERE re.awb_recibida = NEW.id GROUP BY re.awb_recibida)); -- IF dblRefMin < dblRefRate THEN -- SET dblRef = dblRefRate; -- ELSE -- SET dblRef =dblRefMin; -- END IF; SELECT IFNULL(MAX(r.num_recibida) + 1,1) INTO v_num_recibida FROM recibida r WHERE r.serie LIKE NEW.serie AND YEAR(r.fecha) = YEAR(NEW.fecha) AND r.empresa_id = NEW.empresa_id GROUP BY r.empresa_id; SET NEW.num_recibida = IFNULL(v_num_recibida,1); SELECT REPLACE(cuenta,' ','') INTO cta_proveed FROM Proveedores WHERE Id_Proveedor=NEW.proveedor_id; INSERT INTO XDiario(ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE, EUROHABER,BASEEURO, SERIE,FACTURA,IVA,DOCUMENTO, L340,LRECT349,TIPOOPE,AUXILIAR,empresa_id,LDIFADUAN) SELECT a,NEW.fecha,subcta,contra,concepto,eurodebe,eurohaber,baseeuro,serie,NEW.sref,iva, (SELECT CONCAT(serie,'/', LPAD(v_num_recibida,5,'0'))),l340,LRECT349,TIPOOPE,AUXILIAR,NEW.empresa_id,LDIFADUAN FROM (SELECT MAX(ASIEN) + 1 as a FROM XDiario) t INNER JOIN ( SELECT *,NEW.serie,0 LDIFADUAN FROM (SELECT CONCAT('s/fra',RIGHT(sref,8),':',LEFT(Proveedor, 10)) concepto FROM Proveedores INNER JOIN recibida ON Id_Proveedor = proveedor_id WHERE id = NEW.id) t4 INNER JOIN( -- Linea del proveedor/acreedor SELECT subcta,'' contra,eurodebe,ROUND(SUM(eurohaber) + 0.0001,2) eurohaber,baseeuro,0 iva, l340,LRECT349,TIPOOPE,'' AUXILIAR FROM ( SELECT cta_proveed subcta, NULL eurodebe, ROUND((1+(iva/100)*(r.serie = 'R'))*SUM(bi),2) eurohaber, NULL baseeuro,ri.recibida_id, 0 l340,0 LRECT349,' ' TIPOOPE FROM recibida r INNER JOIN recibida_iva ri ON ri.recibida_id = r.id INNER JOIN iva_codigo ic ON ri.iva_id = ic.id INNER JOIN Proveedores p ON p.Id_Proveedor=r.proveedor_id INNER JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id WHERE r.id = NEW.id GROUP BY iva) t GROUP BY recibida_id UNION ALL -- Linea de iva SELECT ic.codigo,cta_proveed contra, ROUND(iva/100*SUM(ri.bi) + 0.0001,2) eurodebe, NULL eurohaber, ROUND(SUM(ri.bi),2) baseeuro,iva, 1 l340,(NOT ((p.pais_id <> p2.pais_id) AND pa.CEE < 2)) LRECT349,TIPOOPE, IF(pa.CEE < 2 AND ri2.gastos_id IS NULL,'','*') AUXILIAR FROM recibida r INNER JOIN recibida_iva ri ON ri.recibida_id = r.id LEFT JOIN recibida_iva ri2 ON ri2.recibida_id = r.id AND ri2.gastos_id LIKE '4751______' INNER JOIN iva_codigo ic ON ri.iva_id = ic.id INNER JOIN iva_tipo it ON it.id = ic.iva_tipo_id INNER JOIN Gastos g ON ri.gastos_id = g.Id_Gasto AND g.iva_tipo_id = ic.iva_tipo_id INNER JOIN Proveedores p ON p.Id_Proveedor=r.proveedor_id INNER JOIN Paises pa ON p.pais_id = pa.Id INNER JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id INNER JOIN Paises pa2 ON p2.pais_id = pa2.Id WHERE r.id = NEW.id AND ic.tipo <> '-' AND link GROUP BY iva -- JGF 2016-05-05 g.conbase UNION ALL -- Linea iva inversor sujeto pasivo SELECT ic2.codigo,cta_proveed contra, NULL eurodebe, ROUND(ic2.iva/100*SUM(bi) + 0.0001,2) eurohaber, ROUND(SUM(bi),2) baseeuro,ic2.iva, 1 l340,0 LRECT349,TIPOOPE,'*' AUXILIAR FROM recibida r INNER JOIN recibida_iva ri ON ri.recibida_id = r.id INNER JOIN iva_codigo ic ON ri.iva_id = ic.id INNER JOIN iva_codigo ic2 ON ic2.link = ic.link AND ic.id <> ic2.id INNER JOIN iva_tipo it ON ic.iva_tipo_id = it.id WHERE r.id = NEW.id AND ic2.link GROUP BY ic2.iva UNION ALL -- Linea de Gastos SELECT if(gastos_id LIKE '4751______',LPAD(RIGHT(cta_proveed ,5),10,gastos_id),gastos_id),cta_proveed , if(gastos_id LIKE '4751______',NULL,ABS(ROUND(SUM(bi),2))) , if(gastos_id LIKE '4751______',ABS(ROUND(SUM(bi),2)),NULL) , NULL ,0, 0 l340,0 LRECT349,' ' TIPOOPE,'' AUXILIAR FROM recibida r INNER JOIN recibida_iva ri ON ri.recibida_id = r.id INNER JOIN Proveedores p ON p.Id_Proveedor=r.proveedor_id WHERE r.id = NEW.id AND gastos_id <> 5660000002 GROUP BY gastos_id UNION ALL -- Iva Importacion pendiente -- JGF 17/02/15 cambia la forma de declarar este tipo de importaciones, sólo afecta a transitarios SELECT '4700000999',NULL,NULL ,ROUND(SUM(importe * (iva/100)),2),NULL ,0, 0 l340,0 LRECT349,' ' TIPOOPE,'' AUXILIAR FROM recibida r JOIN recibida_intrastat ri ON r.id = ri.recibida_id JOIN Intrastat i ON i.Codintrastat = ri.Codintrastat JOIN iva_codigo ic ON ic.id = i.iva_codigo_id WHERE ri.recibida_id = NEW.id GROUP BY ri.recibida_id ) t2 UNION ALL -- Extracomunitarias gasto contra proveedor/acreedor SELECT CONCAT('COMPRA s/fra ',sref,':',LEFT(p.Proveedor, 10)) concepto ,gastos_id,cuenta, ROUND(SUM(bi)/IF(r.serie='W' AND ri.divisa IS NULL,dblRefRate,1)* (re.percentage / 100),2),NULL ,IF( @a:=@a+1 ,NULL,NULL) ,0, 0 l340,0 LRECT349,' ' TIPOOPE,'' AUXILIAR,r.serie,0 LDIFADUAN FROM recibida_entrada re INNER JOIN recibida_iva ri ON re.recibida_id = ri.recibida_id INNER JOIN recibida r ON r.id = ri.recibida_id INNER JOIN Proveedores p ON p.Id_Proveedor = r.proveedor_id INNER JOIN Entradas e ON e.Id_Entrada = re.Id_Entrada LEFT JOIN travel t ON t.id = e.travel_id INNER JOIN (SELECT @a:=0,@cont:=1,@total:=0,@base:=2) t1 WHERE re.awb_recibida = NEW.id AND re.percentage GROUP BY r.id UNION ALL -- Extracomunitarias proveedor contra gasto SELECT CONCAT('COMPRA s/fra ',sref,':',LEFT(p.Proveedor, 10)) concepto ,p.cuenta subcta,gastos_id, NULL eurodebe, ROUND((1+(iva/100)*(r.serie = 'R'))*SUM(bi)/IF(r.serie='W' AND ri.divisa IS NULL,dblRefRate,1)* (re.percentage / 100),2) eurohaber, NULL baseeuro,0 iva, 0 l340,0 LRECT349,' ' TIPOOPE,'' AUXILIAR,r.serie,0 LDIFADUAN -- antes sols iva FROM recibida_entrada re INNER JOIN recibida_iva ri ON re.recibida_id = ri.recibida_id INNER JOIN recibida r ON r.id = ri.recibida_id INNER JOIN iva_codigo ic ON ri.iva_id = ic.id INNER JOIN Proveedores p ON Id_Proveedor = r.proveedor_id INNER JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id WHERE re.awb_recibida = NEW.id AND re.percentage GROUP BY r.id UNION ALL -- Linea de iva adquisicion SELECT CONCAT('ADQUI. INTRA FRA ',sref),ic.codigo,p.cuenta contra, ROUND(iva/100*SUM(ri.importe) + 0.0001,2) eurodebe, NULL eurohaber, ROUND(SUM(ri.importe),2) baseeuro,iva, 1 l340,1 LRECT349,TIPOOPE,'' AUXILIAR,r.serie,0 LDIFADUAN FROM awb_recibida ar JOIN awb a ON ar.awb_id = a.id JOIN iva_codigo ic ON a.iva_id = ic.id JOIN iva_tipo it ON ic.iva_tipo_id = it.id JOIN Proveedores p ON a.transitario_id = p.Id_Proveedor JOIN recibida_intrastat ri ON ri.recibida_id = ar.recibida_id JOIN recibida r ON r.id = ri.recibida_id JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id WHERE ar.recibida_id = NEW.id AND (p.pais_id <> p2.pais_id) GROUP BY iva UNION ALL -- Linea de iva adquisicion SELECT CONCAT('ADQUI. INTRA FRA ',sref),ic2.codigo,p.cuenta contra, NULL eurodebe, ROUND(ic2.iva/100*SUM(ri.importe) + 0.0001,2) eurohaber, ROUND(SUM(ri.importe),2) baseeuro,ic2.iva, 1 l340,0 LRECT349, TIPOOPE,'' AUXILIAR,r.serie,0 LDIFADUAN FROM awb_recibida ar JOIN awb a ON ar.awb_id = a.id JOIN iva_codigo ic ON a.iva_id = ic.id JOIN iva_codigo ic2 ON ic2.link = ic.link AND ic.id <> ic2.id JOIN iva_tipo it ON ic.iva_tipo_id = it.id JOIN Proveedores p ON a.transitario_id = p.Id_Proveedor JOIN recibida_intrastat ri ON ri.recibida_id = ar.recibida_id JOIN recibida r ON r.id = ar.recibida_id JOIN Proveedores p1 ON p1.Id_Proveedor = r.proveedor_id JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id WHERE ar.recibida_id = NEW.id AND (p.pais_id <> p2.pais_id) GROUP BY ic2.iva UNION ALL -- Linea iva importacion SELECT concepto,subcta,Cuenta, IF (NOT ((ppais_id <> p2pais_id) AND CEE < 2), eurodebe ,NULL)eurodebe,eurohaber,baseeuro, iva, IF(@total:=@total+eurodebe ,0,0) l340, 0 LRECT349, IF(@cont:=@cont+1,'','') TIPOOPE,'*' AUXILIAR,serie,1 LDIFADUAN FROM ( SELECT CONCAT('COMPRA FRA ',p.Proveedor) concepto,ic2.codigo subcta,p.Cuenta,ic2.iva, ROUND(sum(costefijo * Cantidad / sub1.costetotal * sub2.importe)*(ic2.iva/100),2) eurodebe,NULL eurohaber, -- JGF 17/02/15 canvie 0.21 per ic.iva ROUND(sum(costefijo * Cantidad / sub1.costetotal * sub2.importe),2) baseeuro,r.serie,pa.CEE,pa.Id_Paisreal ppais_id, p2.pais_id p2pais_id,SUM(sub3.SumIntrastat *(ic2.iva/100)) SumIntrastat, p.Id_Proveedor,Codintrastat FROM awb_recibida ar JOIN recibida_entrada re ON ar.recibida_id = re.awb_recibida JOIN Compres c ON c.Id_Entrada = re.Id_Entrada INNER JOIN Articles a ON a.Id_Article = c.Id_Article INNER JOIN ( SELECT a.Codintrastat, sum(c.costefijo * c.Cantidad) as costetotal FROM Compres c JOIN Articles a ON a.Id_Article = c.Id_Article JOIN recibida_entrada re ON re.Id_Entrada = c.Id_Entrada JOIN awb_recibida ar ON ar.recibida_id = re.awb_recibida JOIN awb aw ON ar.awb_id = aw.id WHERE ar.recibida_id = NEW.id AND re.percentage GROUP BY a.Codintrastat ) sub1 USING(Codintrastat) INNER JOIN ( SELECT Codintrastat,ri.importe, i.iva_codigo_id FROM recibida_intrastat ri JOIN Intrastat i USING(Codintrastat) WHERE ri.recibida_id = NEW.id ) sub2 USING(Codintrastat) INNER JOIN ( SELECT SUM(ri.importe) SumIntrastat FROM recibida_intrastat ri WHERE ri.recibida_id = NEW.id ) sub3 JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor JOIN Paises pa ON p.pais_id = pa.Id JOIN recibida r ON r.id = re.recibida_id JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id JOIN iva_codigo ic2 ON ic2.id = sub2.iva_codigo_id -- JGF 15/04/15 nou canvi llei (Ali) WHERE re.awb_recibida = NEW.id AND re.percentage -- canvie el cta_proveed like '___1______' per cero cuidao en les van de put GROUP BY p.Id_Proveedor, sub2.iva_codigo_id ) t3 GROUP BY Id_Proveedor, iva)t4; -- linea que estava a l'ultim WHERE END IF; */ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`recibida_au` AFTER UPDATE ON `recibida` FOR EACH ROW BEGIN IF NEW.fecha != OLD.fecha OR NEW.moneda_id != OLD.moneda_id THEN CALL recibidaIvaDivisaUpdate(NEW.id); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `recibida_agricola` -- DROP TABLE IF EXISTS `recibida_agricola`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recibida_agricola` ( `recibida_id` mediumint(8) unsigned NOT NULL, `num` smallint(5) unsigned NOT NULL, PRIMARY KEY (`recibida_id`), CONSTRAINT `recibida_agricola_ibfk_1` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `recibida_entrada` -- DROP TABLE IF EXISTS `recibida_entrada`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recibida_entrada` ( `recibida_entrada_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `recibida_id` mediumint(8) unsigned NOT NULL, `Id_Entrada` int(11) NOT NULL, `percentage` decimal(10,2) unsigned NOT NULL DEFAULT '0.00', `awb_recibida` mediumint(8) unsigned NOT NULL, `Contabilizado` tinyint(3) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`recibida_entrada_id`), KEY `awb_recibida` (`awb_recibida`), KEY `Id_Entrada` (`Id_Entrada`), KEY `recibida_id` (`recibida_id`), CONSTRAINT `recibida_entrada_ibfk_2` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=9455 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `recibida_entrada_bi` BEFORE INSERT ON `recibida_entrada` FOR EACH ROW BEGIN DECLARE intRecibida INT; IF NEW.recibida_id = 0 THEN SELECT recibida_id INTO intRecibida FROM recibida_entrada WHERE Id_Entrada = NEW.Id_Entrada; SET NEW.recibida_id = intRecibida; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `recibida_entrada_bu` BEFORE UPDATE ON `recibida_entrada` FOR EACH ROW BEGIN DECLARE intRecibida INT; IF NEW.recibida_id = 0 THEN SELECT recibida_id INTO intRecibida FROM recibida_entrada WHERE Id_Entrada = NEW.Id_Entrada; SET NEW.recibida_id = intRecibida; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `recibida_intrastat` -- DROP TABLE IF EXISTS `recibida_intrastat`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recibida_intrastat` ( `recibida_id` mediumint(8) unsigned NOT NULL, `Codintrastat` int(8) unsigned zerofill NOT NULL, `importe` decimal(10,2) NOT NULL, PRIMARY KEY (`recibida_id`,`Codintrastat`), KEY `Codintrastat` (`Codintrastat`), KEY `recibida_id` (`recibida_id`), CONSTRAINT `recibida_intrastat_ibfk_1` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `recibida_intrastat_ibfk_2` FOREIGN KEY (`Codintrastat`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `recibida_iva` -- DROP TABLE IF EXISTS `recibida_iva`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recibida_iva` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `recibida_id` mediumint(8) unsigned NOT NULL, `iva_id` tinyint(2) unsigned NOT NULL, `bi` decimal(10,2) NOT NULL, `gastos_id` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `divisa` decimal(10,2) DEFAULT NULL, `MYSQL_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `gastos_id` (`gastos_id`), KEY `recibida_id` (`recibida_id`), KEY `recibida_iva_ibfk_2` (`iva_id`), CONSTRAINT `recibida_iva_ibfk_2` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_5` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_6` FOREIGN KEY (`gastos_id`) REFERENCES `Gastos` (`Id_Gasto`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=82588 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `recibida_vencimiento` -- DROP TABLE IF EXISTS `recibida_vencimiento`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recibida_vencimiento` ( `id` int(11) NOT NULL AUTO_INCREMENT, `recibida_id` mediumint(8) unsigned NOT NULL, `fecha` date NOT NULL, `banco_id` int(11) NOT NULL DEFAULT '3117', `cantidad` decimal(10,2) NOT NULL DEFAULT '0.00', `divisa` decimal(10,2) DEFAULT NULL, `stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `recibida_id` (`recibida_id`), KEY `banco_id` (`banco_id`), CONSTRAINT `recibida_vencimiento_ibfk_6` FOREIGN KEY (`banco_id`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibida_vencimiento_ibfk_7` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=80263 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`recibida_vencimiento_bi` BEFORE INSERT ON `vn2008`.`recibida_vencimiento` FOR EACH ROW BEGIN IF NEW.cantidad = 0 THEN SET NEW.id = 5; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `recovery` -- DROP TABLE IF EXISTS `recovery`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recovery` ( `recovery_id` int(11) NOT NULL AUTO_INCREMENT, `Id_Cliente` int(11) NOT NULL DEFAULT '0', `dstart` date NOT NULL COMMENT 'Fecha a partir de la que comienza el recobro', `dend` date DEFAULT NULL COMMENT 'Fecha en la que acaba', `amount` double NOT NULL, `period` tinyint(3) unsigned NOT NULL DEFAULT '7', PRIMARY KEY (`recovery_id`), KEY `cliente_idx` (`Id_Cliente`), CONSTRAINT `cliente333` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `cliente_cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=244 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntaremos los acuerdos de recobro semanal a '; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `recovery_asset` -- DROP TABLE IF EXISTS `recovery_asset`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recovery_asset` ( `recovery_asset_id` int(11) NOT NULL AUTO_INCREMENT, `dreceipt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `amount` double NOT NULL, `Id_Cliente` int(11) NOT NULL, PRIMARY KEY (`recovery_asset_id`), KEY `Cliente_Recovery_detalle_idx` (`Id_Cliente`), CONSTRAINT `Cliente_Recovery_detalle` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=723 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla se registra el detalle de los recobros definid'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `reference_min` -- DROP TABLE IF EXISTS `reference_min`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `reference_min` ( `date` date NOT NULL, `rate` decimal(10,4) NOT NULL, `moneda_id` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`date`,`moneda_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `reference_rate` -- DROP TABLE IF EXISTS `reference_rate`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `reference_rate` ( `moneda_id` tinyint(3) unsigned NOT NULL, `date` date NOT NULL, `rate` float unsigned NOT NULL, PRIMARY KEY (`moneda_id`,`date`), KEY `date` (`date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `reinos` -- DROP TABLE IF EXISTS `reinos`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `reinos` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `reino` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `orden` int(10) unsigned DEFAULT NULL, `display` tinyint(4) NOT NULL DEFAULT '1', `color` char(6) COLLATE utf8_unicode_ci DEFAULT NULL, `efimero` int(11) NOT NULL DEFAULT '0' COMMENT 'Sirve para filtrar aquellos reinos que tienen precios estables', `mercancia` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `reparacion` -- DROP TABLE IF EXISTS `reparacion`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `reparacion` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_user` int(2) DEFAULT NULL, `config_host` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `problema` text COLLATE utf8_unicode_ci NOT NULL, `solucion` text COLLATE utf8_unicode_ci NOT NULL, `estado` enum('No atendida','Vista','En Proceso','Solucionada') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'No atendida', `fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `id_reparador` int(2) DEFAULT NULL, `ref` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `articulo` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, `marca` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `config_host` (`config_host`), KEY `id_user` (`id_user`), KEY `id_reparador` (`id_reparador`), CONSTRAINT `reparacion_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `reparacion_ibfk_2` FOREIGN KEY (`config_host`) REFERENCES `config_host` (`config_host_id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `reparacion_ibfk_4` FOREIGN KEY (`id_reparador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `rolekk` -- DROP TABLE IF EXISTS `rolekk`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `rolekk` ( `role_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`role_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `rounding` -- DROP TABLE IF EXISTS `rounding`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `rounding` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `amount` double NOT NULL DEFAULT '0', `price` double DEFAULT '0', `discount` double NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `route` -- DROP TABLE IF EXISTS `route`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `route` ( `agency_id` smallint(5) unsigned NOT NULL, `week_day` tinyint(3) unsigned NOT NULL COMMENT 'weekday de access el domingo = 1, sabado = 7. Intentar cambiar al de Mysql Lunes = 0', PRIMARY KEY (`agency_id`,`week_day`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `ruta_location` -- DROP TABLE IF EXISTS `ruta_location`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ruta_location` ( `Id_Ruta` int(10) unsigned NOT NULL, `longitude` decimal(11,7) NOT NULL, `latitude` decimal(11,7) NOT NULL, `time_location` datetime NOT NULL, PRIMARY KEY (`Id_Ruta`), CONSTRAINT `Id_Ruta_Location` FOREIGN KEY (`Id_Ruta`) REFERENCES `Rutas` (`Id_Ruta`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `salarioDits` -- DROP TABLE IF EXISTS `salarioDits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `salarioDits` ( `idSalario_dits` int(11) NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idSalario_dits`) ) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `scan` -- DROP TABLE IF EXISTS `scan`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `scan` ( `id` int(11) NOT NULL AUTO_INCREMENT, `lft` int(11) NOT NULL, `rgt` int(11) NOT NULL, `name` varchar(45) CHARACTER SET utf8 DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=41296 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `scan_line` -- DROP TABLE IF EXISTS `scan_line`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `scan_line` ( `scan_line_id` int(11) NOT NULL AUTO_INCREMENT, `scan_id` int(11) NOT NULL, `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`scan_line_id`), KEY `id_scan_id_idx` (`scan_id`), CONSTRAINT `id_scan_id` FOREIGN KEY (`scan_id`) REFERENCES `scan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=553359 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `sharingcart` -- DROP TABLE IF EXISTS `sharingcart`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sharingcart` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Id_Trabajador` int(11) NOT NULL, `datSTART` date NOT NULL, `datEND` date NOT NULL, `Id_Suplente` int(11) NOT NULL, `odbc_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `Worker` (`Id_Trabajador`), KEY `Suplent` (`Id_Suplente`), CONSTRAINT `Suplent_key` FOREIGN KEY (`Id_Suplente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `Trabajador_key` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=1680 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sharingcart_bi` BEFORE INSERT ON `sharingcart` FOR EACH ROW BEGIN SET NEW.datSTART = GREATEST(CURDATE(),NEW.datSTART); SET NEW.datEND = GREATEST(CURDATE(),NEW.datEND); IF NEW.Id_Trabajador = NEW.Id_Suplente THEN SET NEW.Id_Trabajador = NULL; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sharingcart_bu` BEFORE UPDATE ON `sharingcart` FOR EACH ROW BEGIN SET NEW.datSTART = GREATEST(CURDATE(),NEW.datSTART); SET NEW.datEND = GREATEST(CURDATE(),NEW.datEND); IF NEW.Id_Trabajador = NEW.Id_Suplente THEN SET NEW.Id_Trabajador = NULL; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `sharingclient` -- DROP TABLE IF EXISTS `sharingclient`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sharingclient` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Id_Trabajador` int(11) NOT NULL, `datSTART` date NOT NULL, `datEND` date NOT NULL, `Id_Cliente` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `Worker` (`Id_Trabajador`), KEY `Client` (`Id_Cliente`), CONSTRAINT `Clients_key` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `Trabajadores_key` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`sharingclient_BEFORE_INSERT` BEFORE INSERT ON `sharingclient` FOR EACH ROW BEGIN SET NEW.datEND = GREATEST(CURDATE(),NEW.datEND); SET NEW.datSTART = GREATEST(CURDATE(),NEW.datSTART); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`sharingclient_BEFORE_UPDATE` BEFORE UPDATE ON `sharingclient` FOR EACH ROW BEGIN SET NEW.datEND = GREATEST(CURDATE(),NEW.datEND); SET NEW.datSTART = GREATEST(CURDATE(),NEW.datSTART); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Temporary view structure for view `sms` -- DROP TABLE IF EXISTS `sms`; /*!50001 DROP VIEW IF EXISTS `sms`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `sms` AS SELECT 1 AS `id`, 1 AS `Id_trabajador`, 1 AS `Id_Cliente`, 1 AS `from`, 1 AS `to`, 1 AS `text`, 1 AS `sent`, 1 AS `response`, 1 AS `DATE_ODBC`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `split` -- DROP TABLE IF EXISTS `split`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `split` ( `edi_id` int(11) NOT NULL, `customer_id` int(11) NOT NULL, `quantity` int(11) NOT NULL, KEY `edi_id` (`edi_id`,`customer_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `state` -- DROP TABLE IF EXISTS `state`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `state` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `order` tinyint(3) unsigned DEFAULT NULL, `alert_level` int(11) NOT NULL DEFAULT '0', `code` varchar(45) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `tag` -- DROP TABLE IF EXISTS `tag`; /*!50001 DROP VIEW IF EXISTS `tag`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `tag` AS SELECT 1 AS `id`, 1 AS `name`, 1 AS `free`, 1 AS `isQuantitatif`, 1 AS `sourceTable`, 1 AS `unit`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `tarifa_componentes` -- DROP TABLE IF EXISTS `tarifa_componentes`; /*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `tarifa_componentes` AS SELECT 1 AS `Id_Componente`, 1 AS `Componente`, 1 AS `tarifa_componentes_series_id`, 1 AS `tarifa_class`, 1 AS `tax`, 1 AS `is_renewable`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `tarifa_componentes_series` -- DROP TABLE IF EXISTS `tarifa_componentes_series`; /*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `tarifa_componentes_series` AS SELECT 1 AS `tarifa_componentes_series_id`, 1 AS `Serie`, 1 AS `base`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `tarifas` -- DROP TABLE IF EXISTS `tarifas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tarifas` ( `tarifa_id` int(11) NOT NULL AUTO_INCREMENT, `fecha` date NOT NULL, `warehouse_id` smallint(6) unsigned NOT NULL, `t0` double NOT NULL, `t1` double NOT NULL, `t2` double NOT NULL, `t3` double NOT NULL, PRIMARY KEY (`tarifa_id`), KEY `tarifa_warehouse` (`warehouse_id`), CONSTRAINT `tarifa_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `tblContadores` -- DROP TABLE IF EXISTS `tblContadores`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tblContadores` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ochoa` int(10) unsigned NOT NULL, `nfactura` int(11) DEFAULT '0', `nasiento` int(11) DEFAULT '0', `serieA` int(11) DEFAULT '0', `serieE` int(11) DEFAULT '0', `serieR` int(11) DEFAULT '0', `serieC` int(11) DEFAULT '0', `SerieH` int(11) NOT NULL, `serieP` int(11) DEFAULT '0', `serieT` int(11) DEFAULT '0', `FechaInventario` datetime DEFAULT NULL, `serieM` int(11) DEFAULT '0', `HistoricoArticulo` int(11) DEFAULT '0', `week_goal` int(11) DEFAULT NULL, `Rutafotos` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `numCaja` int(11) DEFAULT '0', `CodigoRojo` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `Tablet_Hora` datetime DEFAULT NULL, `t0` int(11) NOT NULL DEFAULT '0', `t1` int(11) NOT NULL DEFAULT '0', `t2` int(11) NOT NULL DEFAULT '0', `t3` int(11) NOT NULL DEFAULT '0', `cc` double NOT NULL DEFAULT '0', `palet` double NOT NULL DEFAULT '0', `campaign` datetime NOT NULL, `campaign_life` tinyint(3) unsigned NOT NULL, `truck_days` tinyint(3) unsigned NOT NULL, `tasa_transporte` double NOT NULL, `escaner_path` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `turnoimpreso` int(4) DEFAULT NULL, `truck_length` int(11) DEFAULT '24', `fuel_consumption` int(11) DEFAULT NULL, `petrol` decimal(10,1) DEFAULT NULL, `maintenance` decimal(10,1) DEFAULT NULL, `hour_price` decimal(10,1) DEFAULT NULL, `meter_price` decimal(10,1) DEFAULT NULL, `km_price` decimal(10,1) DEFAULT NULL, `route_option` int(11) DEFAULT '1', `dbproduccion` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`tblContadores_bi` BEFORE INSERT ON `tblContadores` FOR EACH ROW BEGIN DECLARE v_count INT; SELECT COUNT(*) INTO v_count FROM tblContadores; IF v_count > 0 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'ONLY_ONE_ROW_ALLOWED'; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `tblIVA` -- DROP TABLE IF EXISTS `tblIVA`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tblIVA` ( `tipoiva` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `iva` smallint(6) NOT NULL DEFAULT '0', `cuenta` double DEFAULT '0', `cuentaRE` double DEFAULT '0', `cuentaivaRE` double DEFAULT '0', `REQ` double DEFAULT '0', PRIMARY KEY (`tipoiva`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `template_bionic_component` -- DROP TABLE IF EXISTS `template_bionic_component`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `template_bionic_component` ( `warehouse_id` smallint(5) unsigned NOT NULL, `item_id` int(11) NOT NULL, `component_id` int(10) unsigned NOT NULL, `cost` decimal(10,4) NOT NULL, KEY `item_warehouse` (`item_id`,`warehouse_id`) USING BTREE, KEY `item_warehouse_component` (`item_id`,`warehouse_id`,`component_id`) USING HASH ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `template_bionic_lot` -- DROP TABLE IF EXISTS `template_bionic_lot`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `template_bionic_lot` ( `warehouse_id` smallint(5) unsigned NOT NULL, `item_id` int(11) NOT NULL, `available` double DEFAULT NULL, `buy_id` int(11) DEFAULT NULL, `fix` tinyint(3) unsigned DEFAULT '0', KEY `item_id` (`item_id`), KEY `item_warehouse` (`item_id`,`warehouse_id`) USING HASH ) ENGINE=MEMORY DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `template_bionic_price` -- DROP TABLE IF EXISTS `template_bionic_price`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `template_bionic_price` ( `warehouse_id` smallint(5) unsigned NOT NULL, `item_id` int(11) NOT NULL, `rate` tinyint(3) unsigned NOT NULL, `items` int(11) DEFAULT NULL, `grouping` int(11) DEFAULT NULL, `price` decimal(10,2) DEFAULT NULL, KEY `item_id` (`item_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `thermograph` -- DROP TABLE IF EXISTS `thermograph`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `thermograph` ( `thermograph_id` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `model` enum('TL30','SENSITECH','TREKVIEW1','TREKVIEW2','DISPOSABLE') COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`thermograph_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `ticketCreationData` -- DROP TABLE IF EXISTS `ticketCreationData`; /*!50001 DROP VIEW IF EXISTS `ticketCreationData`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `ticketCreationData` AS SELECT 1 AS `DiadelaSemana`, 1 AS `Hora`, 1 AS `Fecha`, 1 AS `Dispositivo`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `ticket_location` -- DROP TABLE IF EXISTS `ticket_location`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ticket_location` ( `Id_Ticket` int(11) NOT NULL, `longitude` decimal(11,7) DEFAULT NULL, `latitude` decimal(11,7) DEFAULT NULL, PRIMARY KEY (`Id_Ticket`), CONSTRAINT `Id_Ticket_Location` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `ticket_observation` -- DROP TABLE IF EXISTS `ticket_observation`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ticket_observation` ( `ticket_observation_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `Id_Ticket` int(11) NOT NULL, `observation_type_id` tinyint(3) unsigned NOT NULL, `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`ticket_observation_id`), UNIQUE KEY `Id_Ticket` (`Id_Ticket`,`observation_type_id`), KEY `observation_type_id` (`observation_type_id`), CONSTRAINT `ticket_observation_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticket_observation_ibfk_2` FOREIGN KEY (`observation_type_id`) REFERENCES `observation_type` (`observation_type_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=955646 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `tickets_gestdoc` -- DROP TABLE IF EXISTS `tickets_gestdoc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tickets_gestdoc` ( `Id_Ticket` int(11) NOT NULL, `gestdoc_id` int(11) NOT NULL, PRIMARY KEY (`Id_Ticket`,`gestdoc_id`), KEY `gestdoc_id` (`gestdoc_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `time` -- DROP TABLE IF EXISTS `time`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `time` ( `date` date NOT NULL, `period` int(6) NOT NULL, `month` int(2) NOT NULL, `year` int(4) NOT NULL, `day` int(2) NOT NULL, `week` int(2) NOT NULL, PRIMARY KEY (`date`), KEY `day_index` (`day`) USING HASH, KEY `week_index` (`week`) USING HASH, KEY `year_index` (`year`) USING HASH, KEY `month_index` (`month`) USING HASH, KEY `periodo` (`period`) USING HASH ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla de referencia para las semanas, años y meses'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `tipsa` -- DROP TABLE IF EXISTS `tipsa`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tipsa` ( `kilos` tinyint(3) unsigned NOT NULL, `importe` double unsigned NOT NULL, `zona` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`kilos`,`zona`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `tmpNEWTARIFAS` -- DROP TABLE IF EXISTS `tmpNEWTARIFAS`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tmpNEWTARIFAS` ( `Id_Cliente` int(11) NOT NULL, `Cliente` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `Consumo_medio_mensual` double(17,0) DEFAULT NULL, `Tarifa_Actual` int(11) DEFAULT '0', `Nueva_Tarifa` int(11) DEFAULT NULL, `Id_Trabajador` int(11) DEFAULT '20', PRIMARY KEY (`Id_Cliente`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `transport` -- DROP TABLE IF EXISTS `transport`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `transport` ( `wday` tinyint(4) NOT NULL, PRIMARY KEY (`wday`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `travel` -- DROP TABLE IF EXISTS `travel`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `travel` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `shipment` date DEFAULT NULL, `shipment_hour` time DEFAULT NULL, `landing` date NOT NULL, `landing_hour` time DEFAULT NULL, `warehouse_id` smallint(6) unsigned DEFAULT NULL, `warehouse_id_out` smallint(6) unsigned DEFAULT NULL, `agency_id` int(11) DEFAULT NULL, `ref` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `delivered` tinyint(1) NOT NULL DEFAULT '0', `received` tinyint(1) NOT NULL DEFAULT '0', `m3` decimal(10,2) unsigned DEFAULT NULL, `kg` decimal(10,0) unsigned DEFAULT NULL, `cargoSupplierFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `shipment_2` (`shipment`,`landing`,`warehouse_id`,`warehouse_id_out`,`agency_id`,`ref`), KEY `agency_id` (`agency_id`), KEY `shipment` (`shipment`), KEY `landing` (`landing`), KEY `warehouse_landing` (`warehouse_id`,`landing`), KEY `warehouse_out_shipment` (`warehouse_id_out`,`shipment`), KEY `travel_ibfk_4_idx` (`cargoSupplierFk`), CONSTRAINT `travel_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouse_id_out`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_4` FOREIGN KEY (`cargoSupplierFk`) REFERENCES `Proveedores` (`Id_Proveedor`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=96345 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `travelBeforeInsert` BEFORE INSERT ON `travel` FOR EACH ROW BEGIN -- Evita fechas absurdas IF NEW.landing < TIMESTAMPADD(YEAR, -10, CURDATE()) OR NEW.shipment < TIMESTAMPADD(YEAR, -10, CURDATE()) OR NEW.landing < NEW.shipment THEN SET NEW.landing = NULL; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `travelBeforeUpdate` BEFORE UPDATE ON `travel` FOR EACH ROW BEGIN DECLARE trabajador INT; -- Volem permetre dates iguals de eixida i arribada per al magatzems filiats en warehouse_tree IF NEW.landing < NEW.shipment THEN SET NEW.shipment = NEW.landing; END IF; -- Evita fechas absurdas IF NEW.landing < TIMESTAMPADD(YEAR,-10, CURDATE()) OR NEW.shipment < TIMESTAMPADD(YEAR,-10,CURDATE()) THEN SET NEW.landing = NULL; END IF; -- Ditacio para averiguar cuando se marca como delivered = true los travels, pues aparecen por la mañana sin explicacion IF ABS(NEW.delivered) > ABS(OLD.delivered) THEN SELECT Id_Trabajador into trabajador from Trabajadores where user_id = account.userGetId(); INSERT INTO travel_dits (idaccion_dits,Id_Trabajador,Id_Ticket,value_old,value_new) VALUES (89/*Cambia delivered*/,IFNULL(trabajador,20),NEW.id,OLD.delivered,CONCAT(NEW.delivered,' desde ' ,user())); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`travelAfterUpdate` AFTER UPDATE ON `travel` FOR EACH ROW BEGIN CALL stock.queueAdd ('travel', NEW.id, OLD.id); IF NEW.shipment != OLD.shipment THEN UPDATE Entradas SET comision = getComision(Id_Entrada, Id_Moneda) WHERE travel_id = NEW.id; END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`travelAfterDelete` AFTER DELETE ON `travel` FOR EACH ROW BEGIN CALL stock.queueAdd ('travel', NULL, OLD.id); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `travel_dits` -- DROP TABLE IF EXISTS `travel_dits`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `travel_dits` ( `idtravel_dits` int(11) NOT NULL AUTO_INCREMENT, `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, `Id_Trabajador` int(11) NOT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idtravel_dits`), KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`), CONSTRAINT `travel_dits_ibfk_1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=143118 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `travel_pattern` -- DROP TABLE IF EXISTS `travel_pattern`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `travel_pattern` ( `travel_pattern_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `week_start` tinyint(3) unsigned NOT NULL, `week_end` tinyint(3) unsigned NOT NULL, `warehouse_out` smallint(5) unsigned NOT NULL, `warehouse_in` smallint(5) unsigned NOT NULL, `agency_id` int(11) NOT NULL, `day_out` tinyint(3) unsigned NOT NULL, `duration` tinyint(3) unsigned NOT NULL, `ref` varchar(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`travel_pattern_id`), KEY `warehouse_out` (`warehouse_out`), KEY `warehouse_in` (`warehouse_in`), KEY `agency_id` (`agency_id`), CONSTRAINT `travel_pattern_ibfk_3` FOREIGN KEY (`warehouse_out`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_pattern_ibfk_4` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_pattern_ibfk_5` FOREIGN KEY (`warehouse_in`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=317 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `travel_reserve` -- DROP TABLE IF EXISTS `travel_reserve`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `travel_reserve` ( `travel_reserve_id` int(11) NOT NULL AUTO_INCREMENT, `travel_id` int(11) unsigned NOT NULL, `Id_Trabajador` int(11) NOT NULL, `reserved` decimal(4,1) DEFAULT NULL, `buyed` decimal(4,1) DEFAULT NULL, `askingfor` decimal(4,1) DEFAULT NULL, `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `labeled` decimal(4,1) unsigned NOT NULL DEFAULT '0.0', PRIMARY KEY (`Id_Trabajador`,`travel_id`), UNIQUE KEY `travel_reserve_id_UNIQUE` (`travel_reserve_id`), KEY `travel_travel_reserve_idx` (`travel_id`), KEY `traveL_buyer_id_idx` (`Id_Trabajador`), CONSTRAINT `travel_reserve_ibfk_1` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla almacenamos los m3 que cada comprador tiene asignados, por travel.'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `travel_thermograph` -- DROP TABLE IF EXISTS `travel_thermograph`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `travel_thermograph` ( `thermograph_id` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `odbc_date` date NOT NULL, `warehouse_id` smallint(6) unsigned NOT NULL, `travel_id` int(10) unsigned DEFAULT NULL, `temperature` enum('COOL','WARM') COLLATE utf8_unicode_ci NOT NULL, `result` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `gestdoc_id` int(11) DEFAULT NULL, PRIMARY KEY (`thermograph_id`,`odbc_date`), KEY `thermograph_fk_idx` (`thermograph_id`), KEY `gestdoc_fk_idx` (`gestdoc_id`), KEY `travel_id` (`travel_id`), KEY `warehouse_id` (`warehouse_id`), CONSTRAINT `gestdoc_fk` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON UPDATE CASCADE, CONSTRAINT `thermograph_fk` FOREIGN KEY (`thermograph_id`) REFERENCES `thermograph` (`thermograph_id`) ON UPDATE CASCADE, CONSTRAINT `travel_fk` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`id`), CONSTRAINT `travel_thermograph_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registra cada termografo que se ha introducido en cada travel'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `trolley` -- DROP TABLE IF EXISTS `trolley`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `trolley` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `ref` varchar(4) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=132 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `turn` -- DROP TABLE IF EXISTS `turn`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `turn` ( `number` int(11) NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`number`,`odbc_date`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `unary` -- DROP TABLE IF EXISTS `unary`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `unary` ( `id` int(11) NOT NULL AUTO_INCREMENT, `parent` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `idunary_UNIQUE` (`id`), KEY `unary_parent_idx` (`parent`), CONSTRAINT `unary_parent` FOREIGN KEY (`parent`) REFERENCES `unary` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=852 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `unaryScanFilter` -- DROP TABLE IF EXISTS `unaryScanFilter`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `unaryScanFilter` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `filter` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `unary_scan` -- DROP TABLE IF EXISTS `unary_scan`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `unary_scan` ( `unary_id` int(11) NOT NULL, `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `type` set('BUYS','EXPEDITIONS') COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`unary_id`), KEY `scan_unary_idx` (`unary_id`), CONSTRAINT `unary_scan` FOREIGN KEY (`unary_id`) REFERENCES `unary` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `unary_scan_line` -- DROP TABLE IF EXISTS `unary_scan_line`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `unary_scan_line` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `unary_id` int(11) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id_UNIQUE` (`id`), KEY `unary_line_idx` (`unary_id`), CONSTRAINT `unary_line` FOREIGN KEY (`unary_id`) REFERENCES `unary_scan` (`unary_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=8462 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `unary_scan_line_buy` -- DROP TABLE IF EXISTS `unary_scan_line_buy`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `unary_scan_line_buy` ( `scan_line_id` int(11) NOT NULL, `Id_Article` int(11) NOT NULL, PRIMARY KEY (`scan_line_id`), UNIQUE KEY `scan_line_id_UNIQUE` (`scan_line_id`), KEY `Id_Article_buy_idx` (`Id_Article`), CONSTRAINT `Id_Article_buy` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `scan_line_id_patriarcal` FOREIGN KEY (`scan_line_id`) REFERENCES `unary_scan_line` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `unary_scan_line_expedition` -- DROP TABLE IF EXISTS `unary_scan_line_expedition`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `unary_scan_line_expedition` ( `scan_line_id` int(11) NOT NULL, `expedition_id` int(11) NOT NULL, PRIMARY KEY (`scan_line_id`), UNIQUE KEY `scan_line_id_UNIQUE` (`scan_line_id`), KEY `expedition_id_scan_idx` (`expedition_id`), CONSTRAINT `expedition_id_scan` FOREIGN KEY (`expedition_id`) REFERENCES `expeditions` (`expeditions_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `unary_source` -- DROP TABLE IF EXISTS `unary_source`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `unary_source` ( `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `v_Agenda` -- DROP TABLE IF EXISTS `v_Agenda`; /*!50001 DROP VIEW IF EXISTS `v_Agenda`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_Agenda` AS SELECT 1 AS `Tipo`, 1 AS `Id`, 1 AS `Nombre`, 1 AS `Telephone`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_Agenda2` -- DROP TABLE IF EXISTS `v_Agenda2`; /*!50001 DROP VIEW IF EXISTS `v_Agenda2`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_Agenda2` AS SELECT 1 AS `Tipo`, 1 AS `Id`, 1 AS `Nombre`, 1 AS `Telefono`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_Articles_botanical` -- DROP TABLE IF EXISTS `v_Articles_botanical`; /*!50001 DROP VIEW IF EXISTS `v_Articles_botanical`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_Articles_botanical` AS SELECT 1 AS `Id_Article`, 1 AS `edi_botanic`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_Movimientos_Volumen_shipping_charge` -- DROP TABLE IF EXISTS `v_Movimientos_Volumen_shipping_charge`; /*!50001 DROP VIEW IF EXISTS `v_Movimientos_Volumen_shipping_charge`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_Movimientos_Volumen_shipping_charge` AS SELECT 1 AS `Id_Ticket`, 1 AS `Id_Movimiento`, 1 AS `Fecha`, 1 AS `price`, 1 AS `freight`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_Ordenes` -- DROP TABLE IF EXISTS `v_Ordenes`; /*!50001 DROP VIEW IF EXISTS `v_Ordenes`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_Ordenes` AS SELECT 1 AS `Id_ORDEN`, 1 AS `ORDEN`, 1 AS `datORDEN`, 1 AS `datTICKET`, 1 AS `CodVENDEDOR`, 1 AS `CodCOMPRADOR`, 1 AS `CANTIDAD`, 1 AS `PRECIOMAX`, 1 AS `PREU`, 1 AS `Id_ARTICLE`, 1 AS `Id_CLIENTE`, 1 AS `COMENTARIO`, 1 AS `OK`, 1 AS `TOTAL`, 1 AS `datCOMPRA`, 1 AS `KO`, 1 AS `Id_Movimiento`, 1 AS `odbc_date`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_XDiario_ALL` -- DROP TABLE IF EXISTS `v_XDiario_ALL`; /*!50001 DROP VIEW IF EXISTS `v_XDiario_ALL`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_XDiario_ALL` AS SELECT 1 AS `empresa_id`, 1 AS `SUBCTA`, 1 AS `Eurodebe`, 1 AS `Eurohaber`, 1 AS `Fecha`, 1 AS `FECHA_EX`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_accion` -- DROP TABLE IF EXISTS `v_accion`; /*!50001 DROP VIEW IF EXISTS `v_accion`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_accion` AS SELECT 1 AS `accion_id`, 1 AS `accion`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_account` -- DROP TABLE IF EXISTS `v_account`; /*!50001 DROP VIEW IF EXISTS `v_account`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_account` AS SELECT 1 AS `user_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_analisis_ventas` -- DROP TABLE IF EXISTS `v_analisis_ventas`; /*!50001 DROP VIEW IF EXISTS `v_analisis_ventas`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_analisis_ventas` AS SELECT 1 AS `Familia`, 1 AS `Reino`, 1 AS `Comercial`, 1 AS `Comprador`, 1 AS `Provincia`, 1 AS `almacen`, 1 AS `Año`, 1 AS `Mes`, 1 AS `Semana`, 1 AS `Vista`, 1 AS `Importe`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_awb_volumen` -- DROP TABLE IF EXISTS `v_awb_volumen`; /*!50001 DROP VIEW IF EXISTS `v_awb_volumen`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_awb_volumen` AS SELECT 1 AS `awb_id`, 1 AS `codigo`, 1 AS `importe`, 1 AS `Vol_Total`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_barcodes` -- DROP TABLE IF EXISTS `v_barcodes`; /*!50001 DROP VIEW IF EXISTS `v_barcodes`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_barcodes` AS SELECT 1 AS `code`, 1 AS `Id_Article`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_barcodes_plus` -- DROP TABLE IF EXISTS `v_barcodes_plus`; /*!50001 DROP VIEW IF EXISTS `v_barcodes_plus`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_barcodes_plus` AS SELECT 1 AS `code`, 1 AS `Id_Article`, 1 AS `Article`, 1 AS `Medida`, 1 AS `Color`, 1 AS `Categoria`, 1 AS `Producer`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_botanic_export` -- DROP TABLE IF EXISTS `v_botanic_export`; /*!50001 DROP VIEW IF EXISTS `v_botanic_export`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_botanic_export` AS SELECT 1 AS `Nom_botanic`, 1 AS `Id_Paises`, 1 AS `restriction`, 1 AS `description`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_compres` -- DROP TABLE IF EXISTS `v_compres`; /*!50001 DROP VIEW IF EXISTS `v_compres`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_compres` AS SELECT 1 AS `Familia`, 1 AS `reino_id`, 1 AS `Id_Compra`, 1 AS `Id_Entrada`, 1 AS `Id_Article`, 1 AS `Cantidad`, 1 AS `Costefijo`, 1 AS `Portefijo`, 1 AS `Novincular`, 1 AS `Etiquetas`, 1 AS `Packing`, 1 AS `grouping`, 1 AS `Comisionfija`, 1 AS `Embalajefijo`, 1 AS `Nicho`, 1 AS `Id_Cubo`, 1 AS `Tarifa1`, 1 AS `Tarifa2`, 1 AS `Tarifa3`, 1 AS `PVP`, 1 AS `Vida`, 1 AS `Id_Trabajador`, 1 AS `punteo`, 1 AS `odbc_date`, 1 AS `Inventario`, 1 AS `Id_Proveedor`, 1 AS `Fecha`, 1 AS `Confirmada`, 1 AS `Redada`, 1 AS `empresa_id`, 1 AS `travel_id`, 1 AS `Pedida`, 1 AS `recibida_id`, 1 AS `id`, 1 AS `shipment`, 1 AS `landing`, 1 AS `warehouse_id`, 1 AS `warehouse_id_out`, 1 AS `agency_id`, 1 AS `ref`, 1 AS `delivered`, 1 AS `received`, 1 AS `Article`, 1 AS `Medida`, 1 AS `Tallos`, 1 AS `caja`, 1 AS `Categoria`, 1 AS `id_origen`, 1 AS `Tipo`, 1 AS `tipo_id`, 1 AS `Color`, 1 AS `Min`, 1 AS `Coste`, 1 AS `fuente`, 1 AS `iva_group_id`, 1 AS `cm3`, 1 AS `producer_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_departure_limit` -- DROP TABLE IF EXISTS `v_departure_limit`; /*!50001 DROP VIEW IF EXISTS `v_departure_limit`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_departure_limit` AS SELECT 1 AS `warehouse_id`, 1 AS `fecha`, 1 AS `hora`, 1 AS `minSpeed`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_descuadre_bionic` -- DROP TABLE IF EXISTS `v_descuadre_bionic`; /*!50001 DROP VIEW IF EXISTS `v_descuadre_bionic`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_descuadre_bionic` AS SELECT 1 AS `Id_Ticket`, 1 AS `Alias`, 1 AS `Concepte`, 1 AS `suma_componente`, 1 AS `Preu`, 1 AS `Descuento`, 1 AS `diferencia`, 1 AS `Fecha`, 1 AS `benvenut`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_descuadre_porte` -- DROP TABLE IF EXISTS `v_descuadre_porte`; /*!50001 DROP VIEW IF EXISTS `v_descuadre_porte`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_descuadre_porte` AS SELECT 1 AS `Id_Ticket`, 1 AS `suma_componente`, 1 AS `teorico_agencia`, 1 AS `diferencia`, 1 AS `Fecha`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_descuadre_porte2` -- DROP TABLE IF EXISTS `v_descuadre_porte2`; /*!50001 DROP VIEW IF EXISTS `v_descuadre_porte2`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_descuadre_porte2` AS SELECT 1 AS `Id_Ticket`, 1 AS `suma_componente`, 1 AS `Fecha`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_empresa` -- DROP TABLE IF EXISTS `v_empresa`; /*!50001 DROP VIEW IF EXISTS `v_empresa`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_empresa` AS SELECT 1 AS `logo`, 1 AS `id`, 1 AS `registro`, 1 AS `gerente_id`, 1 AS `alta`, 1 AS `Nombre`, 1 AS `Apellidos`, 1 AS `Proveedor`, 1 AS `Domicilio`, 1 AS `CP`, 1 AS `Localidad`, 1 AS `NIF`, 1 AS `Telefono`, 1 AS `Alias`, 1 AS `abbreviation`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_encajado` -- DROP TABLE IF EXISTS `v_encajado`; /*!50001 DROP VIEW IF EXISTS `v_encajado`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_encajado` AS SELECT 1 AS `hora`, 1 AS `minuto`, 1 AS `cm3`, 1 AS `warehouse_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_encajado_ultima_hora` -- DROP TABLE IF EXISTS `v_encajado_ultima_hora`; /*!50001 DROP VIEW IF EXISTS `v_encajado_ultima_hora`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_encajado_ultima_hora` AS SELECT 1 AS `m3`, 1 AS `warehouse_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_expeditions_shipping_charge` -- DROP TABLE IF EXISTS `v_expeditions_shipping_charge`; /*!50001 DROP VIEW IF EXISTS `v_expeditions_shipping_charge`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_expeditions_shipping_charge` AS SELECT 1 AS `Id_Ticket`, 1 AS `shipping_charge`, 1 AS `Fecha`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_expeditions_shipping_charge2` -- DROP TABLE IF EXISTS `v_expeditions_shipping_charge2`; /*!50001 DROP VIEW IF EXISTS `v_expeditions_shipping_charge2`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_expeditions_shipping_charge2` AS SELECT 1 AS `Id_Ticket`, 1 AS `shipping_charge`, 1 AS `Fecha`, 1 AS `warehouse_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_fallo` -- DROP TABLE IF EXISTS `v_fallo`; /*!50001 DROP VIEW IF EXISTS `v_fallo`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_fallo` AS SELECT 1 AS `queja_id`, 1 AS `accion_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_inter` -- DROP TABLE IF EXISTS `v_inter`; /*!50001 DROP VIEW IF EXISTS `v_inter`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_inter` AS SELECT 1 AS `inter_id`, 1 AS `state_id`, 1 AS `nota`, 1 AS `odbc_date`, 1 AS `Id_Ticket`, 1 AS `Id_Trabajador`, 1 AS `Id_supervisor`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_jerarquia` -- DROP TABLE IF EXISTS `v_jerarquia`; /*!50001 DROP VIEW IF EXISTS `v_jerarquia`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_jerarquia` AS SELECT 1 AS `Id_Trabajador`, 1 AS `boss_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_location` -- DROP TABLE IF EXISTS `v_location`; /*!50001 DROP VIEW IF EXISTS `v_location`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_location` AS SELECT 1 AS `longitude`, 1 AS `latitude`, 1 AS `Id_Consigna`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_mana_spellers` -- DROP TABLE IF EXISTS `v_mana_spellers`; /*!50001 DROP VIEW IF EXISTS `v_mana_spellers`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_mana_spellers` AS SELECT 1 AS `Id_Trabajador`, 1 AS `size`, 1 AS `used`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_miriam` -- DROP TABLE IF EXISTS `v_miriam`; /*!50001 DROP VIEW IF EXISTS `v_miriam`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_miriam` AS SELECT 1 AS `Id_Article`, 1 AS `Concepte`, 1 AS `Cantidad`, 1 AS `Preu`, 1 AS `Descuento`, 1 AS `Fecha`, 1 AS `Id_Cliente`, 1 AS `Importe`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_movimientos_log` -- DROP TABLE IF EXISTS `v_movimientos_log`; /*!50001 DROP VIEW IF EXISTS `v_movimientos_log`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_movimientos_log` AS SELECT 1 AS `idmovimientos_log`, 1 AS `Id_Movimiento`, 1 AS `odbc_date`, 1 AS `Id_Trabajador`, 1 AS `field_name`, 1 AS `new_value`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_movimientos_mark` -- DROP TABLE IF EXISTS `v_movimientos_mark`; /*!50001 DROP VIEW IF EXISTS `v_movimientos_mark`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_movimientos_mark` AS SELECT 1 AS `Id_Movimiento`, 1 AS `Accion`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_pedidos_auto_preparados` -- DROP TABLE IF EXISTS `v_pedidos_auto_preparados`; /*!50001 DROP VIEW IF EXISTS `v_pedidos_auto_preparados`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_pedidos_auto_preparados` AS SELECT 1 AS `CodigoTrabajador`, 1 AS `Id_Ticket`, 1 AS `Momento`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_pedidos_auto_preparadoskk` -- DROP TABLE IF EXISTS `v_pedidos_auto_preparadoskk`; /*!50001 DROP VIEW IF EXISTS `v_pedidos_auto_preparadoskk`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_pedidos_auto_preparadoskk` AS SELECT 1 AS `CodigoTrabajador`, 1 AS `Fecha`, 1 AS `Id_Ticket`, 1 AS `Momento`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_phonebook` -- DROP TABLE IF EXISTS `v_phonebook`; /*!50001 DROP VIEW IF EXISTS `v_phonebook`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_phonebook` AS SELECT 1 AS `Id_Cliente`, 1 AS `Telefono`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_price_fixed` -- DROP TABLE IF EXISTS `v_price_fixed`; /*!50001 DROP VIEW IF EXISTS `v_price_fixed`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_price_fixed` AS SELECT 1 AS `warehouse_id`, 1 AS `item_id`, 1 AS `rate_0`, 1 AS `rate_1`, 1 AS `rate_2`, 1 AS `rate_3`, 1 AS `date_start`, 1 AS `date_end`, 1 AS `bonus`, 1 AS `grouping`, 1 AS `Packing`, 1 AS `caja`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_price_fixed_group` -- DROP TABLE IF EXISTS `v_price_fixed_group`; /*!50001 DROP VIEW IF EXISTS `v_price_fixed_group`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_price_fixed_group` AS SELECT 1 AS `warehouse_id`, 1 AS `item_id`, 1 AS `rate_0`, 1 AS `rate_1`, 1 AS `rate_2`, 1 AS `rate_3`, 1 AS `date_start`, 1 AS `date_end`, 1 AS `bonus`, 1 AS `grouping`, 1 AS `Packing`, 1 AS `caja`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_session` -- DROP TABLE IF EXISTS `v_session`; /*!50001 DROP VIEW IF EXISTS `v_session`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_session` AS SELECT 1 AS `id`, 1 AS `CodigoTrabajador`, 1 AS `Id_Trabajador`, 1 AS `Id_Cliente`, 1 AS `Cliente`, 1 AS `Fecha`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_ticket_amount` -- DROP TABLE IF EXISTS `v_ticket_amount`; /*!50001 DROP VIEW IF EXISTS `v_ticket_amount`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_ticket_amount` AS SELECT 1 AS `Id_Ticket`, 1 AS `amount`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_trabajadores` -- DROP TABLE IF EXISTS `v_trabajadores`; /*!50001 DROP VIEW IF EXISTS `v_trabajadores`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_trabajadores` AS SELECT 1 AS `CodigoTrabajador`, 1 AS `Nombre`, 1 AS `Fecha_Inicio`, 1 AS `Password`, 1 AS `user`, 1 AS `Apellidos`, 1 AS `Id_Trabajador`, 1 AS `Foto`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_user` -- DROP TABLE IF EXISTS `v_user`; /*!50001 DROP VIEW IF EXISTS `v_user`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_user` AS SELECT 1 AS `id`, 1 AS `mysql_user_id`, 1 AS `name`, 1 AS `password`, 1 AS `active`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_ventes` -- DROP TABLE IF EXISTS `v_ventes`; /*!50001 DROP VIEW IF EXISTS `v_ventes`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_ventes` AS SELECT 1 AS `Agencia`, 1 AS `Categoria`, 1 AS `tipo_id`, 1 AS `Medida`, 1 AS `Article`, 1 AS `Color`, 1 AS `Id_Cliente`, 1 AS `Tipo`, 1 AS `Factura`, 1 AS `warehouse_id`, 1 AS `Id_Movimiento`, 1 AS `Id_Article`, 1 AS `Familia`, 1 AS `Id_Ticket`, 1 AS `Concepte`, 1 AS `Cantidad`, 1 AS `quantity`, 1 AS `Preu`, 1 AS `Descuento`, 1 AS `CostFixat`, 1 AS `Reservado`, 1 AS `OK`, 1 AS `PrecioFijado`, 1 AS `odbc_date`, 1 AS `Fecha`, 1 AS `FechaCompleta`, 1 AS `Alias`, 1 AS `Id_Consigna`, 1 AS `Importe`, 1 AS `Origen`, 1 AS `reino_id`, 1 AS `invoice`, 1 AS `producer_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_venteskk` -- DROP TABLE IF EXISTS `v_venteskk`; /*!50001 DROP VIEW IF EXISTS `v_venteskk`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_venteskk` AS SELECT 1 AS `Agencia`, 1 AS `Categoria`, 1 AS `tipo_id`, 1 AS `Medida`, 1 AS `Article`, 1 AS `Color`, 1 AS `Id_Cliente`, 1 AS `Tipo`, 1 AS `Factura`, 1 AS `warehouse_id`, 1 AS `Id_Movimiento`, 1 AS `Id_Article`, 1 AS `Familia`, 1 AS `Id_Ticket`, 1 AS `Concepte`, 1 AS `Cantidad`, 1 AS `quantity`, 1 AS `Preu`, 1 AS `Descuento`, 1 AS `CostFixat`, 1 AS `Reservado`, 1 AS `OK`, 1 AS `PrecioFijado`, 1 AS `odbc_date`, 1 AS `Fecha`, 1 AS `FechaCompleta`, 1 AS `Alias`, 1 AS `Id_Consigna`, 1 AS `Importe`, 1 AS `Origen`, 1 AS `reino_id`, 1 AS `invoice`, 1 AS `producer_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_warehouse` -- DROP TABLE IF EXISTS `v_warehouse`; /*!50001 DROP VIEW IF EXISTS `v_warehouse`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_warehouse` AS SELECT 1 AS `id`, 1 AS `almacen`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_xsubclien` -- DROP TABLE IF EXISTS `v_xsubclien`; /*!50001 DROP VIEW IF EXISTS `v_xsubclien`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_xsubclien` AS SELECT 1 AS `Id_Cliente`, 1 AS `empresa_id`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_xsubcuentas` -- DROP TABLE IF EXISTS `v_xsubcuentas`; /*!50001 DROP VIEW IF EXISTS `v_xsubcuentas`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_xsubcuentas` AS SELECT 1 AS `COD`, 1 AS `TITULO`, 1 AS `NIF`, 1 AS `DOMICILIO`, 1 AS `POBLACION`, 1 AS `PROVINCIA`, 1 AS `CODPOSTAL`, 1 AS `country_code`, 1 AS `empresa_id`, 1 AS `EMAIL`, 1 AS `IDNIF`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `v_xsubprov` -- DROP TABLE IF EXISTS `v_xsubprov`; /*!50001 DROP VIEW IF EXISTS `v_xsubprov`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `v_xsubprov` AS SELECT 1 AS `proveedor_id`, 1 AS `empresa_id`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `versiones` -- DROP TABLE IF EXISTS `versiones`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `versiones` ( `programa` varchar(11) COLLATE utf8_unicode_ci NOT NULL, `version` int(11) NOT NULL, `critical` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`programa`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `viaxpress` -- DROP TABLE IF EXISTS `viaxpress`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `viaxpress` ( `codigo_postal` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `zona` tinyint(4) NOT NULL DEFAULT '2', `m_t` tinyint(4) NOT NULL DEFAULT '0', `POBLACION` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `PROVINCIA` varchar(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`codigo_postal`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `vnCreditClassification` -- DROP TABLE IF EXISTS `vnCreditClassification`; /*!50001 DROP VIEW IF EXISTS `vnCreditClassification`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `vnCreditClassification` AS SELECT 1 AS `id`, 1 AS `client`, 1 AS `dateStart`, 1 AS `dateEnd`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `vnCreditInsurance` -- DROP TABLE IF EXISTS `vnCreditInsurance`; /*!50001 DROP VIEW IF EXISTS `vnCreditInsurance`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `vnCreditInsurance` AS SELECT 1 AS `id`, 1 AS `creditClassification`, 1 AS `credit`, 1 AS `creationDate`, 1 AS `grade`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `vnSolunionCAP` -- DROP TABLE IF EXISTS `vnSolunionCAP`; /*!50001 DROP VIEW IF EXISTS `vnSolunionCAP`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `vnSolunionCAP` AS SELECT 1 AS `creditInsurance`, 1 AS `dateStart`, 1 AS `dateEnd`, 1 AS `dateLeaving`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `warehouse` -- DROP TABLE IF EXISTS `warehouse`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse` ( `id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `fuente` tinyint(1) unsigned NOT NULL DEFAULT '0', `address_name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `delay` double NOT NULL DEFAULT '0.004', `reserve` tinyint(4) NOT NULL DEFAULT '0', `tpv` tinyint(2) unsigned zerofill NOT NULL DEFAULT '00', `Id_Paises` mediumint(8) unsigned NOT NULL DEFAULT '1', `zone_label` tinyint(4) NOT NULL DEFAULT '0', `comisionantes` tinyint(4) NOT NULL DEFAULT '0', `inventario` tinyint(2) NOT NULL DEFAULT '0', `is_comparative` tinyint(2) NOT NULL DEFAULT '0' COMMENT 'Si esta a true,en la comparativa muestra el stock de este almacen, cuando no se especifica almacen.', `valuatedInventory` tinyint(2) NOT NULL DEFAULT '0', `isManaged` tinyint(2) NOT NULL DEFAULT '0', `hasConfectionTeam` tinyint(1) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`), KEY `Id_Paises` (`Id_Paises`), CONSTRAINT `warehouse_ibfk_1` FOREIGN KEY (`Id_Paises`) REFERENCES `Paises` (`Id`) ) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `warehouse_ai` AFTER INSERT ON `warehouse` FOR EACH ROW begin IF NEW.Fuente THEN INSERT INTO warehouse_alias (alias) VALUES(NEW.`name`); INSERT INTO warehouse_joined(warehouse_id,warehouse_alias_id) VALUES(NEW.id,LAST_INSERT_ID()); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `warehouse_au` AFTER UPDATE ON `warehouse` FOR EACH ROW begin IF NEW.fuente IS TRUE and OLD.fuente IS FALSE then INSERT INTO warehouse_alias (alias) VALUES(NEW.`name`); INSERT INTO warehouse_joined(warehouse_id,warehouse_alias_id) VALUES(NEW.id,LAST_INSERT_ID()); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `warehouse_alias` -- DROP TABLE IF EXISTS `warehouse_alias`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse_alias` ( `warehouse_alias_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `alias` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`warehouse_alias_id`) ) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `warehouse_filtro` -- DROP TABLE IF EXISTS `warehouse_filtro`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse_filtro` ( `warehouse_id` smallint(6) unsigned NOT NULL, `Id_Trabajador` int(11) NOT NULL, `ok` tinyint(3) unsigned DEFAULT '1', PRIMARY KEY (`Id_Trabajador`,`warehouse_id`), KEY `wh_worker_idx` (`Id_Trabajador`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla que permite filtrar los almacenes que muestra la comparativa, recordando la selección personal del usuario'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `warehouse_group` -- DROP TABLE IF EXISTS `warehouse_group`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse_group` ( `warehouse_alias_id` smallint(5) unsigned NOT NULL DEFAULT '22', `warehouse_id` smallint(5) unsigned NOT NULL, PRIMARY KEY (`warehouse_alias_id`,`warehouse_id`), KEY `warehosue_group_ware_idx` (`warehouse_id`), CONSTRAINT `warehosue_group_ware` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `warehouse_group_alias` FOREIGN KEY (`warehouse_alias_id`) REFERENCES `warehouse_alias` (`warehouse_alias_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Agrupa warehouses '; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `warehouse_joined` -- DROP TABLE IF EXISTS `warehouse_joined`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse_joined` ( `warehouse_id` smallint(5) unsigned NOT NULL, `warehouse_alias_id` smallint(5) unsigned NOT NULL, PRIMARY KEY (`warehouse_id`,`warehouse_alias_id`), CONSTRAINT `warehouse_joined_ibfk_3` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `warehouse_lc` -- DROP TABLE IF EXISTS `warehouse_lc`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse_lc` ( `whin` smallint(6) unsigned NOT NULL, `whout` smallint(6) unsigned NOT NULL, `m3` double NOT NULL DEFAULT '15', `days` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`whin`,`whout`), KEY `whout_wh_idx` (`whout`), CONSTRAINT `whin_wh` FOREIGN KEY (`whin`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `whout_wh` FOREIGN KEY (`whout`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Warehouses cost for linking'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `warehouse_pickup` -- DROP TABLE IF EXISTS `warehouse_pickup`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse_pickup` ( `warehouse_id` smallint(5) unsigned NOT NULL, `agency_id` int(11) DEFAULT NULL, PRIMARY KEY (`warehouse_id`), UNIQUE KEY `agency_id` (`agency_id`,`warehouse_id`), CONSTRAINT `warehouse_pickup_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `warehouse_pickup_ibfk_2` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `warehouse_tree_bidi` -- DROP TABLE IF EXISTS `warehouse_tree_bidi`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouse_tree_bidi` ( `father` tinyint(1) unsigned NOT NULL, `son` tinyint(1) unsigned NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `wh_selection` -- DROP TABLE IF EXISTS `wh_selection`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `wh_selection` ( `Id_Trabajador` int(11) NOT NULL, `warehouse_id` smallint(6) unsigned NOT NULL, PRIMARY KEY (`Id_Trabajador`,`warehouse_id`), KEY `Trabajadores` (`Id_Trabajador`), KEY `Warehouse` (`warehouse_id`), CONSTRAINT `Trabajadores` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `Warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Permite que los usuarios seleccionen los almacenes que van a'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `widget` -- DROP TABLE IF EXISTS `widget`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `widget` ( `widget_id` int(11) NOT NULL, `chr` int(11) NOT NULL, PRIMARY KEY (`widget_id`), UNIQUE KEY `chr_UNIQUE` (`chr`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `wks` -- DROP TABLE IF EXISTS `wks`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `wks` ( `wk` int(10) unsigned NOT NULL, `yr` int(10) unsigned NOT NULL, `vwk` int(10) unsigned NOT NULL, `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `comments` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=626 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `workcenter_holiday` -- DROP TABLE IF EXISTS `workcenter_holiday`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workcenter_holiday` ( `workcenter_id` int(11) NOT NULL, `day` double NOT NULL, `year` smallint(6) NOT NULL, PRIMARY KEY (`workcenter_id`,`day`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `workerDocument` -- DROP TABLE IF EXISTS `workerDocument`; /*!50001 DROP VIEW IF EXISTS `workerDocument`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `workerDocument` AS SELECT 1 AS `id`, 1 AS `worker`, 1 AS `document`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `workerTeam` -- DROP TABLE IF EXISTS `workerTeam`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workerTeam` ( `id` int(11) NOT NULL AUTO_INCREMENT, `team` int(11) NOT NULL, `user` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `user_team_idx` (`user`), CONSTRAINT `user_team` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `workerTeamCollegues` -- DROP TABLE IF EXISTS `workerTeamCollegues`; /*!50001 DROP VIEW IF EXISTS `workerTeamCollegues`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `workerTeamCollegues` AS SELECT 1 AS `workerId`, 1 AS `collegueId`*/; SET character_set_client = @saved_cs_client; -- -- Temporary view structure for view `workerTeam_kk` -- DROP TABLE IF EXISTS `workerTeam_kk`; /*!50001 DROP VIEW IF EXISTS `workerTeam_kk`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `workerTeam_kk` AS SELECT 1 AS `team`, 1 AS `user`, 1 AS `id`, 1 AS `Id_Trabajador`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `zeleris` -- DROP TABLE IF EXISTS `zeleris`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `zeleris` ( `codigo_postal` mediumint(8) unsigned NOT NULL, `franja` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`codigo_postal`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Temporary view structure for view `zoneNickname` -- DROP TABLE IF EXISTS `zoneNickname`; /*!50001 DROP VIEW IF EXISTS `zoneNickname`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `zoneNickname` AS SELECT 1 AS `warehouse_id`, 1 AS `agency_id`, 1 AS `zona`, 1 AS `alias`*/; SET character_set_client = @saved_cs_client; -- -- Table structure for table `zones` -- DROP TABLE IF EXISTS `zones`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `zones` ( `zone_id` tinyint(4) NOT NULL, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `printingOrder` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`zone_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Zonas de reparto'; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping events for database 'vn2008' -- /*!50106 SET @save_time_zone= @@TIME_ZONE */ ; /*!50106 DROP EVENT IF EXISTS `cierre automatico` */; DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; /*!50003 SET @saved_cs_results = @@character_set_results */ ;; /*!50003 SET @saved_col_connection = @@collation_connection */ ;; /*!50003 SET character_set_client = utf8mb4 */ ;; /*!50003 SET character_set_results = utf8mb4 */ ;; /*!50003 SET collation_connection = utf8mb4_general_ci */ ;; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; /*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `cierre automatico` ON SCHEDULE EVERY 1 DAY STARTS '2016-05-25 23:00:00' ON COMPLETION NOT PRESERVE DISABLE COMMENT 'Realiza el cierre de todos los Warehouse' DO INSERT INTO `vn2008`.`Colas` (`Id_Informe`,`Cola`) VALUES ('2',CURDATE()) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; /*!50003 SET character_set_results = @saved_cs_results */ ;; /*!50003 SET collation_connection = @saved_col_connection */ ;; /*!50106 DROP EVENT IF EXISTS `closeTickets` */;; DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; /*!50003 SET @saved_cs_results = @@character_set_results */ ;; /*!50003 SET @saved_col_connection = @@collation_connection */ ;; /*!50003 SET character_set_client = utf8mb4 */ ;; /*!50003 SET character_set_results = utf8mb4 */ ;; /*!50003 SET collation_connection = utf8mb4_general_ci */ ;; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; /*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `closeTickets` ON SCHEDULE EVERY 1 DAY STARTS '2017-06-23 07:20:00' ON COMPLETION NOT PRESERVE DISABLE COMMENT 'Vuelve a realizar el cierre del dia anterior por la mañana.' DO INSERT INTO `vn2008`.`Colas` (`Id_Informe`,`Cola`) VALUES ('2',DATE_ADD(CURDATE(), INTERVAL -1 DAY)) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; /*!50003 SET character_set_results = @saved_cs_results */ ;; /*!50003 SET collation_connection = @saved_col_connection */ ;; /*!50106 DROP EVENT IF EXISTS `item_cache_cleaner` */;; DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; /*!50003 SET @saved_cs_results = @@character_set_results */ ;; /*!50003 SET @saved_col_connection = @@collation_connection */ ;; /*!50003 SET character_set_client = utf8mb4 */ ;; /*!50003 SET character_set_results = utf8mb4 */ ;; /*!50003 SET collation_connection = utf8mb4_general_ci */ ;; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; /*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `item_cache_cleaner` ON SCHEDULE EVERY 30 SECOND STARTS '2014-06-30 13:38:27' ON COMPLETION NOT PRESERVE DISABLE COMMENT 'Cleans the item cache' DO CALL item_cache_cleaner () */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; /*!50003 SET character_set_results = @saved_cs_results */ ;; /*!50003 SET collation_connection = @saved_col_connection */ ;; DELIMITER ; /*!50106 SET TIME_ZONE= @save_time_zone */ ; -- -- Dumping routines for database 'vn2008' -- /*!50003 DROP FUNCTION IF EXISTS `AltaEmpleado` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `AltaEmpleado`(strCodTrabajador varchar(3),strNombre varchar(50),strApellidos varchar(50),strDni varchar(9), strDomicilio longtext,strCodPostal varchar(5),strPoblacion varchar(25),provinceId smallint(5), intempresa_id smallint(5),strMovil varchar(11)) RETURNS varchar(50) CHARSET utf8 BEGIN DECLARE RETORNO varchar(50) DEFAULT 'Empleado creado CORRECTAMENTE'; DECLARE tmpUserId INT(11) DEFAULT 0; DECLARE intId_Cliente int(11) DEFAULT 0; DECLARE Cod_Trabajador VARCHAR(8) DEFAULT strCodTrabajador; DECLARE strPassword VARCHAR(50); DECLARE strSambaNombre VARCHAR(30); samba:BEGIN proc:BEGIN -- IF (boolCrearSamba) THEN -- SELECT Id_Cliente_Interno INTO intId_Cliente FROM Trabajadores WHERE Nombre=strNombre and Apellidos=strApellidos; -- SELECT CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),'.',intId_Cliente) INTO strPassword; -- LEAVE proc; -- END IF; -- Tabla Clientes SELECT COUNT(*) INTO intId_Cliente FROM Clientes WHERE `IF`=strDni; IF (intId_Cliente=0) THEN -- SELECT IFNULL(province_id,1) INTO intprovince_id FROM province WHERE `name`=strProvincia; SELECT MAX(Id_Cliente)+1 INTO intId_Cliente FROM Clientes WHERE Id_Cliente<999999; INSERT INTO Clientes (Id_Cliente,Cliente,Domicilio,`IF`,Telefono,province_id,Poblacion,CodPostal,RazonSocial,Contacto,Oficial,Descuento) SELECT intId_Cliente,Concat('TR ',strNombre,' ',StrApellidos),strDomicilio,strDni,strMovil,provinceId,strPoblacion,strCodPostal, CONCAT(strApellidos,' ',strNombre),strNombre,1,3; ELSE SELECT id_cliente INTO intId_Cliente FROM Clientes WHERE `IF`=strDni; END IF; SELECT CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),'.',intId_Cliente) INTO strPassword; -- Tabla Trabajadores IF (SELECT COUNT(*) FROM Trabajadores WHERE Nombre=strNombre AND Apellidos=strApellidos)=0 THEN IF strCodTrabajador IS NULL THEN SET Cod_Trabajador = CONCAT(LEFT(strNombre, 1), LEFT(strApellidos, 1), MID(strApellidos, (LOCATE(' ', strApellidos) + 1), 1)); END IF; IF (SELECT COUNT(*) FROM Trabajadores WHERE CodigoTrabajador=Cod_Trabajador) > 0 THEN SET Cod_Trabajador = CONCAT(Cod_Trabajador, (FLOOR(RAND() * 100))); END IF; SELECT CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),'.',intId_Cliente) INTO strPassword; INSERT INTO Trabajadores (CodigoTrabajador,Nombre,Apellidos,`Password`,dni,empresa_id,id_Cliente_Interno) SELECT Cod_Trabajador,strNombre,strApellidos,LCASE(strPassword),strDni,intempresa_id,intId_Cliente; ELSE SET RETORNO="CodigoTrabajador Existente"; END IF; -- LEAVE SAMBA; END; -- PROC -- Tabla Account, lo crea como usuario y en samba -- Obtengo el nombre sin espacios SET strSambaNombre = REPLACE(strNombre,' ',''); IF (SELECT COUNT(*) FROM account.user WHERE `name`=convert(strNombre USING utf8) COLLATE utf8_general_ci)>0 THEN -- Si existe cojo la inicial del nombre+1º apellido SELECT CONCAT(LEFT(strNombre,1),CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),intId_Cliente)) INTO strSambaNombre; END IF; IF (SELECT COUNT(*) FROM account.user where id=intId_Cliente)=0 THEN INSERT INTO account.user (id,role,`name`,`password`,active) VALUES (intId_Cliente,1,lcase(strSambaNombre),MD5(LCASE(strPassword)),1); INSERT INTO account.account (id,lastchange,`expire`,user_id) values (intId_Cliente,CURRENT_DATE(),CURRENT_DATE(),intId_Cliente); UPDATE Trabajadores SET user_id=intId_Cliente WHERE Id_Cliente_Interno=intId_Cliente; ELSE INSERT INTO account.user (role,`name`,`password`,active) VALUES (1,lcase(strSambaNombre),MD5(LCASE(strPassword)),1); SET tmpUserId = LAST_INSERT_ID(); INSERT INTO account.account (id,lastchange,`expire`,user_id) values (tmpUserId,CURRENT_DATE(),CURRENT_DATE(),tmpUserId); UPDATE Trabajadores SET user_id=tmpUserId WHERE Id_Cliente_Interno=intId_Cliente; END IF; REPLACE INTO account.mailAliasAccount(mailAlias, account) VALUES (48,intId_Cliente); END; -- samba RETURN RETORNO; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `AltaEmpleadokk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `AltaEmpleadokk`(strCodTrabajador varchar(3),strNombre varchar(50),strApellidos varchar(50),strDni varchar(9), strDomicilio longtext,strCodPostal varchar(5),strPoblacion varchar(25),provinceId smallint(5), intempresa_id smallint(5),strMovil varchar(11)) RETURNS varchar(50) CHARSET utf8 BEGIN DECLARE RETORNO varchar(50) DEFAULT 'Empleado creado CORRECTAMENTE'; DECLARE tmpUserId INT(11) DEFAULT 0; DECLARE intId_Cliente int(11) DEFAULT 0; DECLARE Cod_Trabajador VARCHAR(8) DEFAULT strCodTrabajador; DECLARE strPassword VARCHAR(50); DECLARE strSambaNombre VARCHAR(30); samba:BEGIN proc:BEGIN -- IF (boolCrearSamba) THEN -- SELECT Id_Cliente_Interno INTO intId_Cliente FROM Trabajadores WHERE Nombre=strNombre and Apellidos=strApellidos; -- SELECT CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),'.',intId_Cliente) INTO strPassword; -- LEAVE proc; -- END IF; -- Tabla Clientes SELECT COUNT(*) INTO intId_Cliente FROM Clientes WHERE `IF`=strDni; IF (intId_Cliente=0) THEN -- SELECT IFNULL(province_id,1) INTO intprovince_id FROM province WHERE `name`=strProvincia; SELECT MAX(Id_Cliente)+1 INTO intId_Cliente FROM Clientes WHERE Id_Cliente<999999; INSERT INTO Clientes (Id_Cliente,Cliente,Domicilio,`IF`,Telefono,province_id,Poblacion,CodPostal,RazonSocial,Contacto,Oficial,Descuento) SELECT intId_Cliente,Concat('TR ',strNombre,' ',StrApellidos),strDomicilio,strDni,strMovil,provinceId,strPoblacion,strCodPostal, CONCAT(strApellidos,' ',strNombre),strNombre,1,3; ELSE SELECT id_cliente INTO intId_Cliente FROM Clientes WHERE `IF`=strDni; END IF; SELECT CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),'.',intId_Cliente) INTO strPassword; -- Tabla Trabajadores IF (SELECT COUNT(*) FROM Trabajadores WHERE Nombre=strNombre AND Apellidos=strApellidos)=0 THEN IF strCodTrabajador IS NULL THEN SET Cod_Trabajador = CONCAT(LEFT(strNombre, 1), LEFT(strApellidos, 1), MID(strApellidos, (LOCATE(' ', strApellidos) + 1), 1)); END IF; IF (SELECT COUNT(*) FROM Trabajadores WHERE CodigoTrabajador=Cod_Trabajador) > 0 THEN SET Cod_Trabajador = CONCAT(Cod_Trabajador, (FLOOR(RAND() * 100))); END IF; SELECT CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),'.',intId_Cliente) INTO strPassword; INSERT INTO Trabajadores (CodigoTrabajador,Nombre,Apellidos,`Password`,dni,empresa_id,id_Cliente_Interno) SELECT Cod_Trabajador,strNombre,strApellidos,LCASE(strPassword),strDni,intempresa_id,intId_Cliente; ELSE SET RETORNO="CodigoTrabajador Existente"; END IF; -- LEAVE SAMBA; END; -- PROC -- Tabla Account, lo crea como usuario y en samba -- Obtengo el nombre sin espacios SET strSambaNombre = REPLACE(strNombre,' ',''); IF (SELECT COUNT(*) FROM account.user WHERE `name`=convert(strNombre USING utf8) COLLATE utf8_general_ci)>0 THEN -- Si existe cojo la inicial del nombre+1º apellido SELECT CONCAT(LEFT(strNombre,1),CONCAT(IF(INSTR(StrApellidos,' ')=0,StrApellidos,LEFT(strApellidos,INSTR(StrApellidos,' ')-1)),intId_Cliente)) INTO strSambaNombre; END IF; IF (SELECT COUNT(*) FROM account.user where id=intId_Cliente)=0 THEN INSERT INTO account.user (id,role,`name`,`password`,active) VALUES (intId_Cliente,1,lcase(strSambaNombre),MD5(LCASE(strPassword)),1); INSERT INTO account.account (id,lastchange,`expire`,user_id) values (intId_Cliente,CURRENT_DATE(),CURRENT_DATE(),intId_Cliente); UPDATE Trabajadores SET user_id=intId_Cliente WHERE Id_Cliente_Interno=intId_Cliente; ELSE INSERT INTO account.user (role,`name`,`password`,active) VALUES (1,lcase(strSambaNombre),MD5(LCASE(strPassword)),1); SET tmpUserId = LAST_INSERT_ID(); INSERT INTO account.account (id,lastchange,`expire`,user_id) values (tmpUserId,CURRENT_DATE(),CURRENT_DATE(),tmpUserId); UPDATE Trabajadores SET user_id=tmpUserId WHERE Id_Cliente_Interno=intId_Cliente; END IF; REPLACE INTO account.mailAliasAccount(mailAlias, account) VALUES (48,intId_Cliente); END; -- samba RETURN RETORNO; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `articod` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `articod`(intArt INT) RETURNS varchar(70) CHARSET utf8 COLLATE utf8_unicode_ci BEGIN DECLARE strArt VARCHAR(70); SELECT CONCAT(Article,' ', Medida, ' ',Color) INTO strArt FROM Articles WHERE Id_Article = intArt; RETURN strArt; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `asiento` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `asiento`( v_asiento INT ,v_date DATE ,v_subaccount VARCHAR(12) ,v_account VARCHAR(12) ,v_concept VARCHAR(25) ,v_debit DOUBLE ,v_credit DOUBLE ,v_euro DOUBLE ,v_serial CHAR(1) ,v_invoice VARCHAR(8) ,v_vat DOUBLE ,v_re DOUBLE ,v_aux TINYINT ,v_company INT ) RETURNS int(11) BEGIN IF v_asiento IS NULL THEN SELECT MAX(ASIEN) + 1 INTO v_asiento FROM XDiario FOR UPDATE; END IF; INSERT INTO XDiario SET ASIEN = v_asiento ,FECHA = v_date ,SUBCTA = v_subaccount ,CONTRA = v_account ,CONCEPTO = v_concept ,EURODEBE = v_debit ,EUROHABER = v_credit ,BASEEURO = v_euro ,SERIE = v_serial ,FACTURA = v_invoice ,IVA = v_vat ,RECEQUIV = v_re ,AUXILIAR = IF(v_aux = FALSE, NULL, '*') ,MONEDAUSO = 2 ,empresa_id = v_company; RETURN v_asiento; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `Averiguar_ComercialCliente` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `Averiguar_ComercialCliente`(v_customer INT, v_date DATE) RETURNS varchar(3) CHARSET utf8 DETERMINISTIC BEGIN /** * Dado un id cliente y una fecha, devuelve su comercial. * Para más información ir a Averiguar_ComercialCliente_Id() * * @param v_customer El id del cliente * @param v_date Fecha a comprobar * @return El código del comercial para la fecha dada **/ DECLARE v_employee CHAR(3); DECLARE v_salesperson INT; SET v_salesperson = Averiguar_ComercialCliente_Id(v_customer, v_date); SELECT CodigoTrabajador INTO v_employee FROM Trabajadores WHERE Id_Trabajador = v_salesperson; RETURN IFNULL(v_employee, '---'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `Averiguar_ComercialCliente_Id` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `Averiguar_ComercialCliente_Id`(v_customer INT, v_date DATE) RETURNS int(11) DETERMINISTIC BEGIN /** * Dado un id cliente y una fecha, devuelve su comercial para ese dia, teniendo * en cuenta la jerarquía de las tablas: 1º la de sharingclient, 2º la de * sharingcart y tercero la de clientes. * * @param v_customer El id del cliente * @param v_date Fecha a comprobar * @return El id del comercial para la fecha dada **/ DECLARE v_salesperson INT DEFAULT NULL; DECLARE v_substitute INT DEFAULT NULL; DECLARE v_loop BOOLEAN; -- Obtiene el comercial original y el de sharingclient SELECT c.Id_Trabajador, s.Id_Trabajador INTO v_salesperson, v_substitute FROM Clientes c LEFT JOIN sharingclient s ON c.Id_Cliente = s.Id_Cliente AND v_date BETWEEN s.datSTART AND s.datEND WHERE c.Id_Cliente = v_customer ORDER BY s.id LIMIT 1; -- Si no hay ninguno en sharingclient busca en sharingcart IF v_substitute IS NOT NULL THEN SET v_salesperson = v_substitute; ELSEIF v_salesperson IS NOT NULL THEN DROP TEMPORARY TABLE IF EXISTS tmp.stack; CREATE TEMPORARY TABLE tmp.stack (INDEX (substitute)) ENGINE = MEMORY SELECT v_salesperson substitute; l: LOOP SELECT Id_Suplente INTO v_substitute FROM sharingcart WHERE v_date BETWEEN datSTART AND datEND AND Id_Trabajador = v_salesperson ORDER BY id LIMIT 1; IF v_substitute IS NULL THEN LEAVE l; END IF; SELECT COUNT(*) > 0 INTO v_loop FROM tmp.stack WHERE substitute = v_substitute; IF v_loop THEN LEAVE l; END IF; INSERT INTO tmp.stack SET substitute = v_substitute; SET v_salesperson = v_substitute; END LOOP; DROP TEMPORARY TABLE tmp.stack; END IF; RETURN v_salesperson; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `Averiguar_ComercialCliente_IdTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `Averiguar_ComercialCliente_IdTicket`(v_ticket INT) RETURNS varchar(3) CHARSET utf8 DETERMINISTIC BEGIN /** * Dado un id ticket, devuelve su comercial. * Para más información ir a Averiguar_ComercialCliente_Id() * * @param v_customer El id del cliente * @param v_date Fecha a comprobar * @return El código del comercial para la fecha dada **/ DECLARE v_customer INT; DECLARE v_date DATE; SELECT id_cliente, fecha INTO v_customer, v_date FROM Tickets WHERE id_ticket = v_ticket; RETURN Averiguar_ComercialCliente(v_customer, v_date); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `Averiguar_ComercialCliente_IdTicket_Id` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `Averiguar_ComercialCliente_IdTicket_Id`(v_ticket INT) RETURNS int(11) DETERMINISTIC BEGIN /** * Dado un id ticket, devuelve su comercial. * Para más información ir a Averiguar_ComercialCliente_Id() * * @param v_customer El id del cliente * @param v_date Fecha a comprobar * @return El id del comercial para la fecha dada **/ DECLARE v_customer INT; DECLARE v_date DATE; SELECT id_cliente, fecha INTO v_customer, v_date FROM Tickets WHERE id_ticket = v_ticket; RETURN Averiguar_ComercialCliente_Id(v_customer, v_date); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `Averiguar_Comprador` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `Averiguar_Comprador`(idARTICLE INT) RETURNS varchar(3) CHARSET utf8 BEGIN -- Devuelve la abreviatura del comprador del articulo DECLARE buyer VARCHAR(3); SELECT CodigoTrabajador INTO buyer FROM Trabajadores t JOIN Tipos tp on tp.Id_Trabajador = t.Id_Trabajador JOIN Articles a on a.tipo_id = tp.tipo_id WHERE Id_Article = idARTICLE; RETURN buyer; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `base_ticket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `base_ticket`(Id_Ticket INT) RETURNS double BEGIN DECLARE base DOUBLE; SELECT red(SUM(Cantidad * Preu * (100 - Descuento) / 100)) into base FROm Movimientos m INNER JOIN Tickets t USING (Id_Ticket) WHERE t.Id_Ticket = Id_Ticket; RETURN base; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `bionicCalcReverse` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `bionicCalcReverse`(vWarehouse INT, vMargin DECIMAL(10,3), vRetailedPrice DECIMAL(10,3), vM3 DECIMAL(10,3), vConsigna INT, vAgencia INT) RETURNS decimal(10,3) BEGIN DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.3; DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT DEFAULT 138000; DECLARE vCost DECIMAL(10,4) DEFAULT 0; DECLARE vCustomer INT; DECLARE vRecovery DECIMAL(10,4) DEFAULT 0; DECLARE vMana DECIMAL(10,4) DEFAULT 0; DECLARE vPort DECIMAL(10,4) DEFAULT 0; SELECT Id_Cliente INTO vCustomer FROM Consignatarios WHERE Id_Consigna = vConsigna; -- Recobro SELECT ROUND(LEAST(recobro,0.25), 3) INTO vRecovery FROM bi.claims_ratio WHERE Id_Cliente = vCustomer AND recobro > 0.009; -- Componente de maná automático, en función del maná acumulado por el comercial. SELECT ROUND(prices_modifier_rate, 3) INTO vMana FROM Clientes c JOIN bs.mana_spellers ms ON c.Id_Trabajador = ms.Id_Trabajador WHERE ms.prices_modifier_activated AND c.Id_Cliente = vCustomer; -- Reparto SELECT COEFICIENTE_DE_INFLACION_GENERAL * ROUND( vM3 * az.price * az.inflacion / VOLUMEN_CAJA_VERDNATURA, 4 ) INTO vPort FROM vn2008.Agencias a JOIN vn2008.Consignatarios c ON c.Id_Consigna = vConsigna AND a.Id_Agencia = vAgencia JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = vWarehouse AND ap.province_id = c.province_id JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = vAgencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = vWarehouse; -- Modificacion de precio por dia de preparacion del pedido -- No aplicada SET vCost = ((vRetailedPrice - vPort) / ( 1 + (vRecovery + vMana))) - vMargin; RETURN vCost; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `botanic_export_is_updatable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `botanic_export_is_updatable`(v_edi_genus_id MEDIUMINT,v_edi_specie_id MEDIUMINT,v_id_Paises MEDIUMINT,v_restriction MEDIUMINT) RETURNS int(11) BEGIN DECLARE is_updatable INTEGER; SELECT COUNT(*) INTO is_updatable FROM botanic_export WHERE edi_genus_id = v_edi_genus_id AND (v_edi_specie_id = edi_specie_id OR IFNULL(v_edi_specie_id,edi_specie_id) IS NULL) AND (v_id_Paises = Id_Paises OR IFNULL(v_id_Paises,Id_Paises) IS NULL) AND v_restriction = restriction; RETURN is_updatable; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `buffer_name` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `buffer_name`(v_date DATE, v_wh INT) RETURNS varchar(11) CHARSET utf8 BEGIN RETURN CONCAT('b', YEAR(v_date), MONTH(v_date), DAY(v_date), IFNULL(v_wh, 0)); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `buyingAbsoluteCost` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `buyingAbsoluteCost`(vCompra BIGINT) RETURNS int(11) BEGIN /** * Devuelve el coste completo de una compra * * @param vCompra Id_Compra a calcular * @return Suma de los 4 componentes del coste */ DECLARE vCost DOUBLE; SELECT IFNULL(Costefijo,0) + IFNULL(Portefijo,0) + IFNULL(Embalajefijo,0) + IFNULL(Comisionfija,0) INTO vCost FROM Compres WHERE Id_Compra = vCompra; RETURN vCost; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `cc_to_iban` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `cc_to_iban`(cc VARCHAR(20)) RETURNS varchar(4) CHARSET utf8 DETERMINISTIC BEGIN DECLARE iban VARCHAR(4); select CONCAT('ES', RIGHT( concat(0, 98- mod( concat( mod( concat( mod( concat( mod( substring(cc,1,8), 97), substring(cc,9,8) ), 97), substring( concat( cc, 142800 ), 17, 8 ) ), 97), substring( concat( cc, 142800 ), 25, 2 ) ), 97) ) ,2) )into iban; RETURN iban; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `cm3` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = latin1 */ ; /*!50003 SET character_set_results = latin1 */ ; /*!50003 SET collation_connection = latin1_swedish_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `cm3`(v_buy_id INT) RETURNS int(11) BEGIN DECLARE id_CUB VARCHAR(10); DECLARE id_ART INT; SELECT Id_Cubo, Id_Article INTO id_CUB, id_ART FROM Compres c WHERE c.Id_compra = v_buy_id; RETURN cm3_2(id_CUB, id_ART); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `cm3_2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `cm3_2`(id_CUB VARCHAR(10), id_ART INT) RETURNS int(11) BEGIN DECLARE v_cm3 INT; SELECT SUM(IF(b.Volumen > 0, b.Volumen, x * y * IF(z = 0, Medida + 10, z) )) INTO v_cm3 FROM Cubos b INNER JOIN Articles a ON Id_Article = id_ART WHERE Id_Cubo = id_CUB; RETURN v_cm3; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `cm3_unidad` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `cm3_unidad`(v_buy_id INT) RETURNS int(11) BEGIN DECLARE id_CUB VARCHAR(10); DECLARE id_ART INT; DECLARE intPACK INT; SELECT Id_Cubo, Id_Article, Packing INTO id_CUB, id_ART, intPACK FROM Compres c WHERE c.Id_compra = v_buy_id; RETURN ifnull(round(cm3_2(id_CUB, id_ART)/intPACK),0); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `code_to_id` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `code_to_id`(idART VARCHAR(22)) RETURNS int(11) DETERMINISTIC BEGIN DECLARE idchecked INT; set idchecked = (SELECT Id_Article FROM barcodes WHERE code = idART); IF idchecked THEN RETURN idchecked; END IF; IF idART > 6000000 THEN SELECT Id_Article INTO idchecked FROM Compres WHERE Id_Compra = idART; ELSE SET idchecked = CAST(idART AS SIGNED); END IF; RETURN idchecked; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `code_to_id2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `code_to_id2`(idART VARCHAR(22)) RETURNS int(11) BEGIN DECLARE idchecked INT; SELECT IFNULL(Id_Article,COUNT(*)) INTO idchecked FROM barcodes WHERE code = idART LIMIT 1; IF idchecked THEN RETURN idchecked; END IF; IF idART > 6000000 THEN /*SELECT Id_Article INTO idchecked FROM Compres WHERE Id_Compra = idART;*/ SET idchecked = CAST(idART AS SIGNED); ELSE SET idchecked = CAST(idART AS SIGNED); END IF; RETURN idchecked; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `cub` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = latin1 */ ; /*!50003 SET character_set_results = latin1 */ ; /*!50003 SET collation_connection = latin1_swedish_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `cub`(v_buy_id INT) RETURNS int(11) BEGIN DECLARE v_cm3 INT; SELECT SUM(Etiquetas * IF(b.Volumen > 0, b.Volumen, IF(z = 0, x * y * (Medida + 10), x * y * z ) )) INTO v_cm3 FROM Compres c INNER JOIN Cubos b USING (Id_Cubo) INNER JOIN Articles a USING (Id_Article) WHERE c.Id_compra = v_buy_id; RETURN v_cm3; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `currate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `currate`() RETURNS double BEGIN DECLARE dblRATE DOUBLE; SELECT rate INTO dblRATE FROM reference_rate ORDER BY date DESC LIMIT 1 ; RETURN dblRATE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `date_inv` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = latin1 */ ; /*!50003 SET character_set_results = latin1 */ ; /*!50003 SET collation_connection = latin1_swedish_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `date_inv`() RETURNS datetime DETERMINISTIC BEGIN RETURN (SELECT FechaInventario FROM tblContadores LIMIT 1); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `DAYEND` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `DAYEND`(v_date DATE) RETURNS datetime DETERMINISTIC BEGIN RETURN TIMESTAMP(v_date,'23:59:59'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `FIRSTDAYOFYEAR` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `FIRSTDAYOFYEAR`(datFEC DATE) RETURNS date BEGIN DECLARE datRETURNS DATE; SELECT TIMESTAMPADD(DAY, -1 * DAYOFYEAR(datFEC) + 1, datFEC) INTO datRETURNS; RETURN datRETURNS; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `f_periodo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `f_periodo`(datFEC date) RETURNS int(7) DETERMINISTIC BEGIN DECLARE intPeriod INT; SELECT Year(datFEC) * 100 + week(datFEC) into intPeriod; RETURN intPeriod; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getBouquetId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `getBouquetId`( vName VARCHAR(50), vType int, vSize int, vColour VARCHAR(5) ) RETURNS int(11) BEGIN /** * De vuelve el ID del ramo. Si no existe uno parecido, lo crea. * * @param vName Nombre del artículo * @param vType Tipo de flor/planta * @param vSize Tamaño del ramo * @param vColour Color del ramo * @return ID del ramo */ DECLARE bouquetId INT(11); CALL vn2008.createBouquet(vName, vType, vSize, vColour, @vItem); SET bouquetId = (SELECT @vItem); RETURN bouquetId; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getComision` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `getComision`(vEntry INT, vMoneda INT) RETURNS int(11) BEGIN DECLARE vComision INT; SELECT IFNULL(round(-100 * (1 - (1 / rm.rate))),0) INTO vComision FROM Entradas e JOIN travel tr ON tr.id = e.travel_id LEFT JOIN reference_min rm ON rm.moneda_id = vMoneda AND tr.shipment >= rm.`date` WHERE e.Id_Entrada = vEntry ORDER BY rm.date DESC LIMIT 1; RETURN vComision; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getInvoiceWeight` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `getInvoiceWeight`(vInvoice VARCHAR(15)) RETURNS decimal(10,2) BEGIN DECLARE vTotalWeight DECIMAL(10,2); SELECT SUM(IFNULL(tallos,1) * Cantidad * a.density) sumTotal INTO vTotalWeight FROM Tickets t LEFT JOIN Movimientos m ON m.Id_Ticket = t.Id_Ticket LEFT JOIN Articles a ON a.Id_Article = m.Id_Article LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id WHERE t.Factura = vInvoice AND Codintrastat; RETURN vTotalWeight; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getShippingFromTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `getShippingFromTicket`(vTicket INTEGER) RETURNS decimal(10,2) BEGIN DECLARE vValue DECIMAL(10,2); SELECT SUM(Valor * m.Cantidad) INTO vValue FROM Movimientos_componentes mc JOIN Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento JOIN bi.tarifa_componentes tc ON mc.Id_Componente = tc.Id_Componente JOIN bi.tarifa_componentes_series tcs ON tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id AND tcs.tarifa_componentes_series_id = 6 WHERE m.Id_Ticket = vTicket; RETURN vValue; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `get_special_price` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `get_special_price`(intArticle int(11),intCliente int(11)) RETURNS decimal(10,2) BEGIN DECLARE price DECIMAL(10,2); SELECT rate_3 INTO price FROM price_fixed WHERE item_id = intArticle AND CURDATE() BETWEEN date_start AND date_end order by odbc_date DESC limit 1; SELECT precioespecial INTO price FROM PreciosEspeciales WHERE Id_Article = intArticle and Id_Cliente = intCliente ; RETURN price; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `get_Trabajador` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `get_Trabajador`() RETURNS int(11) DETERMINISTIC BEGIN RETURN IFNULL((SELECT Id_Trabajador FROM Trabajadores WHERE user_id = account.userGetId()),20); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `has_notify_passport` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `has_notify_passport`(idA INT, idCompra INT) RETURNS tinyint(1) BEGIN DECLARE has_passport BOOLEAN; DECLARE is_already_sent BOOLEAN; SELECT COUNT(*) INTO has_passport FROM vn2008.botanic_export be JOIN vn2008.Articles_botanical ab ON be.edi_genus_id = ab.genus_id AND IFNULL(be.edi_specie_id, ab.specie_id) = ab.specie_id AND be.restriction = 'Se Requiere Certificado' JOIN vn2008.Articles a ON a.Id_Article = ab.Id_Article JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id WHERE ab.Id_Article = idA AND t.reino_id = 2; IF has_passport THEN SELECT COUNT(*) INTO is_already_sent FROM mail M JOIN vn2008.Compres c ON c.Id_Compra = idCompra WHERE `text` LIKE CONCAT('%',c.buy_edi_id,'%') limit 1; END IF; RETURN has_passport && NOT is_already_sent; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `intrastat_neto` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `intrastat_neto`( intINSTRASTAT INTEGER,intUNIDADES INTEGER) RETURNS double BEGIN DECLARE n DOUBLE; select ROUND(intUNIDADES / (sum(MEDIA) / count(media)),2) into n from ( select *, unidades / neto MEDIA FROM intrastat_data WHERE intrastat_id = intINSTRASTAT and neto and unidades > 0 ORDER BY odbc_date DESC limit 50) t; -- JGF 01/06 per a evitar Kg en negatiu RETURN n/2; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `is_bionic` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `is_bionic`(intTicket INT) RETURNS tinyint(1) BEGIN DECLARE bolIsBionic boolean; SELECT (COUNT(*) > 0) INTO bolIsBionic FROM order_Tickets ot WHERE ot.Id_Ticket = intTicket; RETURN bolIsBionic; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `lang` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `lang`() RETURNS char(2) CHARSET utf8 DETERMINISTIC BEGIN RETURN IFNULL(@lang, 'es'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `next_venc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `next_venc`( datFecha DATE,intDia INT,intPayDay INT) RETURNS date BEGIN DECLARE n DATE; DECLARE datVenc DATE; DECLARE intVenc INT; SELECT TIMESTAMPADD(DAY,intDia,datFecha) INTO datVenc; SELECT DAY(datVenc) INTO intVenc; SELECT MIN(TIMESTAMPADD(MONTH,(intVenc > intPayDay),DATE_FORMAT(datVenc,CONCAT('%y/%m/',intPayDay)))) INTO n; RETURN n; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `next_venctesting` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `next_venctesting`( datFecha DATE,intDia INT,intPayDay INT) RETURNS date BEGIN DECLARE n DATE; DECLARE datVenc DATE; DECLARE intVenc INT; SELECT TIMESTAMPADD(DAY,intDia,datFecha) INTO datVenc; SELECT DAY(datVenc) INTO intVenc; SELECT IFNULL ( TIMESTAMPADD ( MONTH, (intVenc > intPayDay), DATE_FORMAT ( datVenc, CONCAT('%y/%m/',intPayDay) ) ), LAST_DAY(datVenc) ) INTO n; RETURN n; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `nz` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `nz`(dblCANTIDAD DOUBLE) RETURNS double DETERMINISTIC BEGIN DECLARE dblRESULT DOUBLE; SET dblRESULT = IFNULL(dblCANTIDAD,0); RETURN dblRESULT; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `paymentday` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `paymentday`(vDated DATE, vDayToPay INT) RETURNS date BEGIN DECLARE vDued DATE; SET vDued = vn.getDueDate(vDated, vDayToPay); RETURN vDued; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `periodo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `periodo`(datFEC DATETIME) RETURNS int(6) DETERMINISTIC BEGIN DECLARE intPERIODO INt; SET intPERIODO = YEAR(datFEC) * 100 + MONTH(datFEC); RETURN intPERIODO; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `periodo_day` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `periodo_day`(datFEC DATETIME) RETURNS int(8) DETERMINISTIC BEGIN DECLARE intPERIODO INt; SET intPERIODO = YEAR(datFEC) * 10000 + MONTH(datFEC) * 100 + DAY(datFEC); RETURN intPERIODO; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `porte` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `porte`(intId_Ticket INT) RETURNS double BEGIN DECLARE dblprice DOUBLE; SELECT SUM(`az`.`price`) INTO dblprice FROM (((((`expeditions` `e` JOIN `Tickets` `t` ON ((`e`.`ticket_id` = `t`.`Id_Ticket`))) JOIN `Consignatarios` `c` ON ((`c`.`Id_Consigna` = `t`.`Id_Consigna`))) JOIN `Agencias` `a` ON ((`a`.`Id_Agencia` = `t`.`Id_Agencia`))) JOIN `Agencias_province` `ap` ON (((`t`.`warehouse_id` = `ap`.`warehouse_id`) AND (`ap`.`province_id` = `c`.`province_id`) AND (`ap`.`agency_id` = `a`.`agency_id`)))) JOIN `Agencias_zonas` `az` ON (((`az`.`Id_Agencia` = `t`.`Id_Agencia`) AND (`az`.`zona` = `ap`.`zona`) AND (`t`.`warehouse_id` = `az`.`warehouse_id`) AND (`az`.`Id_Article` = `e`.`EsBulto`)))) WHERE ((`t`.`Fecha` >= '2015-10-01') AND (`t`.`empresa_id` IN (442 , 791))) AND t.Id_Ticket = intId_Ticket GROUP BY `t`.`Id_Ticket`; RETURN dblprice; /* DECLARE intId_Agencia INT; DECLARE int_agency_id SMALLINT; DECLARE int_province_id SMALLINT; DECLARE bolCOD71 TINYINT(1); DECLARE intPorte DOUBLE DEFAULT -1; DECLARE dayofweek TINYINT(1) default 0; DECLARE suplemento DOUBLE DEFAULT 9.41; DECLARE strCodPostal VARCHAR(5); DECLARE intWarehouse_id SMALLINT; DECLARE dbldescuento DOUBLE DEFAULT 0; DECLARE intVista TINYINT(1); DECLARE dblvolumen DOUBLE; SET @porte := 0; SELECT a.agency_id, t.Id_Agencia, cod71, Porte,c.CODPOSTAL,t.warehouse_id,c.province_id,cli.Descuento,IFNULL(ag.Vista,a.Vista), por_volumen INTO int_agency_id,intId_Agencia, bolCOD71,intPorte,strCodPostal,intWarehouse_id,int_province_id,dbldescuento,intVista,dblvolumen FROM Tickets t JOIN Consignatarios c USING(Id_Consigna) JOIN Agencias a ON t.Id_Agencia = a.Id_Agencia JOIN agency agn ON agn.agency_id = a.agency_id JOIN Clientes cli on c.Id_Cliente=cli.Id_Cliente LEFT JOIN agency_warehouse ag ON ag.agency_id = a.agency_id WHERE Id_Ticket = intId_Ticket limit 1; IF bolCOD71 THEN IF intId_Agencia = 47 THEN -- Si es viaxpress SELECT price INTO dblprice FROM Agencias_zonas az INNER JOIN viaxpress USING(zona) WHERE Id_Agencia = 47 AND codigo_postal = strCodPostal AND az.warehouse_id = intWarehouse_id; ELSE SELECT price INTO dblprice FROM Agencias_zonas az WHERE Id_Agencia = intId_Agencia AND 71 = Id_Article AND az.warehouse_id = intWarehouse_id AND zona = (SELECT zona FROM Agencias_province WHERE warehouse_id = intWarehouse_id AND agency_id = int_agency_id and province_id = int_province_id); END IF; ELSE SELECT 0 INTO dblprice; END IF; */ END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `red` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `red`( intCANTIDAD DOUBLE) RETURNS double DETERMINISTIC BEGIN DECLARE n DOUBLE; SET n = SIGN(intCANTIDAD) * TRUNCATE( (ABS(intCANTIDAD) * 100) + 0.5001 ,0) /100 ; RETURN n; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `risk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `risk`(datMax DATE, intCustomer INT) RETURNS decimal(10,2) BEGIN /** * Deprecated * * Utilizar vn.clientGetDebt **/ DECLARE decRisk DECIMAL(10,2) DEFAULT 0; SELECT vn.clientGetDebt(intCustomer,datMax) INTO decRisk; RETURN decRisk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `semana` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `semana`(datFec DATETIME) RETURNS int(11) DETERMINISTIC BEGIN /* DECLARE intWeek TINYINT DEFAULT WEEK(datFec, 1); DECLARE intYear SMALLINT DEFAULT YEAR(datFec); -- La funcio week dona un error en els primers dies del any -- Por convención, consideraremos que el año tiene siempre 52 semanas, y la 53 se incorpora a la 1 del año siguiente. -- Mysql week function smells, so ... IF intWeek > 52 THEN SET intWeek = 1; IF MONTH(datFec) = 12 THEN SET intYear = intYear + 1; SET intWeek = 1; END IF; END IF; RETURN intYear * 100 + intWeek; */ RETURN vnperiod(datFec); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `shipmentDay` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `shipmentDay`(landingDay INT, intervalDays INT) RETURNS int(11) BEGIN /* PAK 01/09/16 * * Devuelve el weekday resultante de restar al landingDay los dias de intervalDays * */ DECLARE resultDay INT; SET resultDay = (landingDay + 7 - (intervalDays mod 7)) mod 7; RETURN resultDay; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_freight` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_freight`(idT INT) RETURNS decimal(10,3) BEGIN DECLARE dblFreight DECIMAL(10,2); /* DECLARE intWh INTEGER; DECLARE datFecha DATE; SELECT warehouse_id, Fecha INTO intWh,datFecha FROM Tickets WHERE Id_Ticket = idT; CALL item_last_buy_(intWh,datFecha); SELECT SUM((`M`.`Cantidad` * (CM3(`b`.`buy_id`) / 1000000 /`C`.`Packing`) * `az`.`price` / 0.08)) INTO dblFreight FROM Movimientos M JOIN t_item_last_buy b on M.Id_Article = b.item_id JOIN Compres C ON C.Id_Compra = b.buy_id JOIN Tickets t on t.Id_Ticket = M.Id_Ticket JOIN `Consignatarios` `cn` ON (`cn`.`Id_Consigna` = `t`.`Id_Consigna`) JOIN `Agencias` `a` ON (`a`.`Id_Agencia` = `t`.`Id_Agencia`) JOIN `Agencias_province` `ap` ON (`t`.`warehouse_id` = `ap`.`warehouse_id`) AND (`ap`.`province_id` = `cn`.`province_id`) AND (`ap`.`agency_id` = `a`.`agency_id`) JOIN `Agencias_zonas` `az` ON (`az`.`Id_Agencia` = `t`.`Id_Agencia`) AND (`az`.`zona` = `ap`.`zona`) AND (`t`.`warehouse_id` = `az`.`warehouse_id`) AND (`az`.`Id_Article` = 71) WHERE M.Id_Ticket = idT; DROP TEMPORARY TABLE t_item_last_buy; */ SELECT sum(freight) INTO dblFreight FROM v_Movimientos_Volumen_shipping_charge WHERE Id_Ticket = idT; RETURN dblFreight; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_state` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_state`( strFAC VARCHAR(15), intIMP TINYINT(1), intETI TINYINT(1), intBLO TINYINT(1) ) RETURNS varchar(15) CHARSET utf8 BEGIN CASE WHEN strFAC IS NOT NULL AND strFAC != '' THEN RETURN 'FACTURADO'; WHEN intETI <> 0 THEN RETURN 'ALBARAN'; WHEN intIMP <> 0 THEN RETURN 'PREPARACION'; WHEN intBLO <> 0 THEN RETURN 'BLOQUEADO'; ELSE RETURN 'LIBRE'; END CASE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_state_2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_state_2`( idTICKET INT(11) ) RETURNS varchar(15) CHARSET utf8 BEGIN DECLARE strVAR VARCHAR(15); SELECT ticket_state(Factura, PedidoImpreso, Etiquetasemitidas, Blocked) INTO strVAR FROM Tickets WHERE Id_Ticket = idTICKET; RETURN strVAR; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_state_3` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_state_3`( idTICKET INT(11) ) RETURNS varchar(15) CHARSET utf8 BEGIN DECLARE strVAR VARCHAR(15); DECLARE strNAM VARCHAR(15); DECLARE fltID FLOAT DEFAULT 0; DECLARE strfac VARCHAR(15); DECLARE inteti tinyint; DECLARE intimp tinyint; DECLARE intblk tinyint; SELECT s.`name`,id INTO strNAM,fltID FROM Tickets t INNER JOIN vncontrol.inter i USING(Id_Ticket) INNER JOIN state s ON s.id = i.state_id WHERE Id_Ticket = idTICKET ORDER BY i.odbc_date DESC,i.state_id DESC LIMIT 1; SELECT Factura, PedidoImpreso, Etiquetasemitidas, Blocked INTO strfac,intimp,inteti,intblk FROM Tickets WHERE Id_Ticket = idTICKET; CASE WHEN strfac <> '' AND fltID < 11 THEN RETURN 'FACTURADO'; WHEN inteti <> 0 AND fltID < 11 THEN RETURN 'ALBARAN' ; WHEN intimp <> 0 AND fltID <= 5 THEN RETURN 'EN PREPARACION'; WHEN fltID > 0 THEN RETURN strNAM; ELSE RETURN 'LIBRE'; END CASE; RETURN strVAR; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_total` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_total`(ticket_id INT) RETURNS double BEGIN /** * Calcula el total con IVA de un ticket. * * @deprecated Use function vn.ticketGetTotal() instead * * @param ticket_id Identificador del ticket * @return Total del ticket */ -- TODO: Una vez provado el nuevo método con esta instrucción es suficiente -- RETURN vn.ticketGetTotal (vTicketId); DECLARE v_total DOUBLE; DROP TEMPORARY TABLE IF EXISTS ticket_tmp; CREATE TEMPORARY TABLE ticket_tmp (INDEX (ticket_id)) ENGINE = MEMORY SELECT ticket_id; CALL ticket_total; SELECT total INTO v_total FROM ticket_total; DROP TEMPORARY TABLE ticket_total, ticket_tmp; RETURN v_total; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_volumen` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_volumen`(idT INT) RETURNS decimal(10,3) BEGIN DECLARE intWh INTEGER; DECLARE datFecha DATE; DECLARE dblVolume DECIMAL(10,3); SELECT warehouse_id, Fecha INTO intWh,datFecha FROM Tickets WHERE Id_Ticket = idT; SELECT IFNULL(SUM(m.Cantidad * cm3)/1000000,0) INTO dblVolume FROM Movimientos m JOIN bi.rotacion r on r.Id_Article = m.Id_Article AND r.warehouse_id = intWh WHERE m.Id_Ticket = idT; RETURN dblVolume; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_volumen_encajado` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_volumen_encajado`(idT INT) RETURNS decimal(10,1) BEGIN /* Devuelve el volumen estimado de un pedido, en cajas * * idT Numero de ticket * */ DECLARE vVolumenCajaM3 DOUBLE; DECLARE vTicketVolumenEnCajas DECIMAL(10,1); DECLARE CAJA VARCHAR(10) DEFAULT '94'; SELECT Volumen/1000000 INTO vVolumenCajaM3 FROM Cubos WHERE Id_Cubo = CAJA; SET vTicketVolumenEnCajas = ticket_volumen(idT) / vVolumenCajaM3; RETURN vTicketVolumenEnCajas; RETURN 1; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_volumen_en_cajas` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ticket_volumen_en_cajas`(idT INT) RETURNS decimal(10,1) BEGIN /* Devuelve el volumen estimado de un pedido, en cajas * * idT Numero de ticket * * DECLARE vVolumenCajaM3 DOUBLE; DECLARE vTicketVolumenEnCajas DECIMAL(10,1); DECLARE CAJA VARCHAR(10) DEFAULT '94'; SELECT Volumen/1000000 INTO vVolumenCajaM3 FROM Cubos WHERE Id_Cubo = CAJA; SET vTicketVolumenEnCajas = ticket_volumen(idT) / vVolumenCajaM3; RETURN vTicketVolumenEnCajas; */ RETURN 1; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `till_entry` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `till_entry`( v_customer INT ,v_bank INT ,v_amount DOUBLE ,v_concept VARCHAR(25) ,v_date DATE ,v_serial CHAR(1) ,v_batch TINYINT ,v_number INT ,v_company SMALLINT ,v_employee INT ) RETURNS int(11) BEGIN DECLARE v_account VARCHAR(12); DECLARE v_subaccount VARCHAR(12); DECLARE v_asiento INT DEFAULT NULL; -- Inserta el registro en cajas INSERT INTO Cajas SET Id_Trabajador = v_employee ,Id_Banco = v_bank ,Entrada = v_amount ,Concepto = v_concept ,Cajafecha = v_date ,Serie = v_serial ,Partida = v_batch ,Numero = v_number ,empresa_id = v_company; -- Inserta los asientos contables SELECT Cuenta INTO v_account FROM Bancos WHERE Id_Banco = v_bank; SELECT Cuenta INTO v_subaccount FROM Clientes WHERE Id_Cliente = v_customer; SET v_asiento = asiento ( v_asiento ,v_date ,v_account ,v_subaccount ,v_concept ,v_amount ,0 ,0 ,NULL -- Serie ,NULL -- Factura ,NULL -- IVA ,NULL -- Recargo ,FALSE -- Auxiliar ,v_company ); DO asiento ( v_asiento ,v_date ,v_subaccount ,v_account ,v_concept ,0 ,v_amount ,0 ,NULL -- Serie ,NULL -- Factura ,NULL -- IVA ,NULL -- Recargo ,FALSE -- Auxiliar ,v_company ); RETURN NULL; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `to_weeks` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `to_weeks`(v_date DATE) RETURNS int(11) DETERMINISTIC BEGIN RETURN FLOOR((TO_DAYS(v_date) - 366) / 7); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `ubicator_cabecaja` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `ubicator_cabecaja`(x SMALLINT,y SMALLINT,z SMALLINT,w SMALLINT,d SMALLINT,h SMALLINT) RETURNS tinyint(1) BEGIN IF ((y>d) OR (x>w) OR (z>h)) THEN -- si no cabe alguna de las medidas en la balda. RETURN FALSE; END IF; RETURN TRUE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `vnday` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `vnday`(datfec DATE) RETURNS int(11) DETERMINISTIC BEGIN DECLARE intper INT; SELECT day INTO intper FROM time WHERE date = datfec; RETURN intper; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `vndayname` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `vndayname`(datfec DATE) RETURNS varchar(10) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC BEGIN DECLARE vDayName VARCHAR(10); CASE weekday(datfec) WHEN 6 then SET vDayName = 'Domingo'; WHEN 0 then SET vDayName = 'Lunes'; WHEN 1 then SET vDayName = 'Martes'; WHEN 2 then SET vDayName = 'Miercoles'; WHEN 3 then SET vDayName = 'Jueves'; WHEN 4 then SET vDayName = 'Viernes'; WHEN 5 then SET vDayName = 'Sabado'; END CASE; RETURN vDayName; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `vnmonth` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `vnmonth`(datfec DATE) RETURNS int(11) DETERMINISTIC BEGIN DECLARE intper INT; SELECT month INTO intper FROM time WHERE date = datfec; RETURN intper; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `vnperiod` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `vnperiod`(datfec DATE) RETURNS int(6) DETERMINISTIC BEGIN DECLARE intper INT; SELECT period INTO intper FROM time WHERE date = datfec; RETURN intper; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `vntrimestre` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `vntrimestre`(datfec DATE) RETURNS int(11) DETERMINISTIC BEGIN CASE WHEN MONTH(datfec)<=3 THEN RETURN 1; WHEN MONTH(datfec)<=6 THEN RETURN 2; WHEN MONTH(datfec)<=9 THEN RETURN 3; ELSE return 4; END CASE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `vnweek` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `vnweek`(datfec DATE) RETURNS int(11) DETERMINISTIC BEGIN DECLARE intper INT; SELECT week INTO intper FROM time WHERE date = datfec; RETURN intper; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `vnyear` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `vnyear`(datfec DATE) RETURNS int(11) DETERMINISTIC BEGIN DECLARE intper INT; SELECT year INTO intper FROM time WHERE date = datfec; RETURN intper; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `abono` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `abono`(IN idT MEDIUMINT, IN idUSER SMALLINT) BEGIN -- OBSOLETO USAR vn.refund() DECLARE idC MEDIUMINT; DECLARE newFEC DATE; DECLARE idWH TINYINT; DECLARE idUSER SMALLINT; DECLARE idEMP MEDIUMINT; DECLARE idCON MEDIUMINT; DECLARE newTICKET MEDIUMINT; SELECT Id_Cliente, TIMESTAMPADD(DAY, 1,Fecha), warehouse_id, empresa_id, Id_Consigna INTO idC, newFEC, idWH, idEMP, idCON FROM Tickets WHERE Id_Ticket = idT; SELECT Id_Trabajador into idUSER from Trabajadores where user_id = account.userGetId(); IF idUSER IS NULL THEN SET idUSER = 20; END IF; CALL ticket_new_complet(idC, newFEC, idWH, idUSER, idEMP, idCON, 23,NULL,newTICKET); UPDATE Tickets SET Etiquetasemitidas = 1 WHERE Id_Ticket = newTICKET; INSERT INTO Movimientos(Id_Ticket, Id_Article, Cantidad, Concepte, Preu, Descuento, PrecioFijado) SELECT newTICKET, Id_Article, -1 * Cantidad, Concepte, Preu, Descuento, 1 FROM Movimientos WHERE Id_Ticket = idT; SELECT newTICKET; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `account_conciliacion_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `account_conciliacion_add`() BEGIN update account_conciliacion ac join ( select idaccount_conciliacion, @c:= if(@id = id_calculated, @c + 1, 1) contador , @id:= id_calculated as id_calculated, concat(id_calculated,'(',@c,')') as new_id from account_conciliacion join ( select id_calculated, count(*) rep, @c:= 0, @id:= concat('-',id_calculated) from account_conciliacion group by id_calculated having rep > 1 ) sub using(id_calculated) ) sub2 using(idaccount_conciliacion) set ac.id_calculated = sub2.new_id; insert into Cajas(Cajafecha, Partida, Serie, Concepto, Entrada, Salida, Id_Banco, Id_Trabajador, empresa_id, warehouse_id, Proveedores_account_id, id_calculated) select Fechaoperacion, TRUE, 'MB', ac.Concepto, IF(DebeHaber = 2, importe,null), IF(DebeHaber = 1, importe, null), pa.Id_Banco, 20 , pa.Id_Proveedor, 1, ac.Id_Proveedores_account,ac.id_calculated from account_conciliacion ac join Proveedores_account pa on pa.Id_Proveedores_account = ac.Id_Proveedores_account left join Cajas c on c.id_calculated = ac.id_calculated where c.Id_Caja is null; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `accumulatorsReadingDateUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `accumulatorsReadingDateUpdate`() BEGIN /* Actualiza los valores de la tabla en función de la cotización del EUR/USD * */ UPDATE accumulatorsReadingDate a JOIN ( SELECT d.id, CASE WHEN rr.rate between p.lowerBarrier and p.rate THEN p.strike WHEN rr.rate between p.rate and p.upperBarrier AND p.financialProductTypefk = 'AC' THEN p.strike WHEN rr.rate >= p.upperBarrier THEN p.strike * 2 ELSE 0 END AS Acumulado FROM vn2008.reference_rate rr JOIN accumulatorsReadingDate d ON d.readingDate = rr.date JOIN pago_sdc p ON p.pago_sdc_id = d.pagoSdcfk WHERE IFNULL(amount,0) = 0 AND rr.rate >= p.lowerBarrier) sub ON sub.id = a.id SET a.amount = sub.Acumulado WHERE a.amount IS NULL; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `add_awb_component` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `add_awb_component`(IN v_awb SMALLINT) BEGIN INSERT IGNORE INTO awb_component (awb_id,Id_Proveedor,awb_component_type_id,awb_role_id,awb_unit_id,value,Id_Moneda) SELECT id,Id_Proveedor,awb_component_type_id,awb_role_id,awb_unit_id,LEAST(GREATEST(value1,IFNULL(min_value,value1)),IFNULL(max_value,value1)),Id_Moneda FROM ( SELECT a.id,IFNULL(act.carguera_id,CASE awb_role_id WHEN 1 THEN a.carguera_id WHEN 2 THEN a.transitario_id WHEN 3 THEN f.airline_id END) Id_Proveedor, act.awb_component_type_id,act.awb_role_id,act.awb_unit_id, value * CASE awb_unit_id WHEN '1000Tj-20' THEN ((CAST(stems AS SIGNED) - 20000)/1000) + (min_value / value) WHEN '1000Tj-10' THEN ((CAST(stems AS SIGNED) - 10000)/1000) + (min_value / value) WHEN '100GW' THEN peso/100 WHEN 'AWB' THEN 1 -- No action WHEN 'FB' THEN hb/2 WHEN 'GW' THEN peso WHEN 'TW' THEN GREATEST(peso,volume_weight) END value1 , value, act.Id_Moneda, act.min_value, act.max_value FROM awb a JOIN flight f ON f.flight_id = a.flight_id LEFT JOIN awb_component_template act ON ((IFNULL(act.carguera_id, a.carguera_id) = a.carguera_id AND awb_role_id = 1) OR (IFNULL(act.carguera_id, a.transitario_id) = a.transitario_id AND awb_role_id = 2)) AND IFNULL(act.airport_out, f.airport_out) = f.airport_out AND IFNULL(act.airport_in, f.airport_in) = f.airport_in AND IFNULL(act.airline_id, f.airline_id) = f.airline_id WHERE a.id = v_awb AND Fecha <= CURDATE() ORDER BY Fecha DESC) t ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `adelantarTickets` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `adelantarTickets`(datCurrent DATE,datAttempted DATE) BEGIN DECLARE vWarehouse INTEGER; DECLARE vFechedTicket INTEGER; DECLARE done INT DEFAULT 0; DECLARE vFetchCounter INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT ticketId FROM tmpTicketList; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; OPEN cur1; SELECT warehouse_id INTO vWarehouse FROM tmpTicketList ttl JOIN Tickets t ON t.Id_Ticket = ttl.ticketId LIMIT 1; CALL item_stock(vWarehouse,CURDATE(),NULL); DROP TEMPORARY TABLE IF EXISTS tmpAdelantarTickets; CREATE TEMPORARY TABLE tmpAdelantarTickets( Id_Ticket INT, count INT, media DOUBLE) ENGINE = MEMORY; REPEAT FETCH cur1 INTO vFechedTicket; INSERT INTO tmpAdelantarTickets SELECT vFechedTicket, COUNT(Cantidad), AVG(Cantidad <= IFNULL(Saldo, 0)) AS `AVG` FROM Movimientos m LEFT JOIN (SELECT * FROM (SELECT Id_Article, Saldo FROM (SELECT Dia, Id_Article, SUM(Entradas - Salidas) AS Saldo FROM ( SELECT CURDATE() AS Dia, item_id Id_Article, stock AS Entradas, 0 AS Salidas FROM tmp_item ti JOIN Movimientos m ON m.Id_Article = ti.item_id AND m.Id_Ticket = vFechedTicket UNION ALL SELECT DATE(t.Fecha) AS Dia, mt.Id_Article, 0 AS Entradas, - m.Cantidad AS Salidas FROM Tickets t JOIN Movimientos m ON m.Id_Ticket = t.Id_Ticket AND t.warehouse_id = vWarehouse JOIN Movimientos mt ON mt.Id_Article = m.Id_Article WHERE mt.Id_Ticket = vFechedTicket AND t.Fecha BETWEEN curdate() AND datCurrent UNION ALL SELECT tr.landing, c.Id_Article, c.Cantidad, 0 FROM Compres c JOIN Movimientos mt ON mt.Id_Article = c.Id_Article JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = travel_id and tr.warehouse_id = vWarehouse WHERE mt.Id_Ticket = vFechedTicket AND tr.landing BETWEEN curdate() AND datCurrent UNION ALL SELECT tr.shipment, c.Id_Article, - c.Cantidad, 0 FROM Compres c JOIN Movimientos mt ON mt.Id_Article = c.Id_Article JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = travel_id and tr.warehouse_id_out = vWarehouse WHERE mt.Id_Ticket = vFechedTicket AND tr.shipment BETWEEN curdate() AND datCurrent ) sub GROUP BY Dia , Id_Article) sub2 ORDER BY Saldo) sub3 GROUP BY Id_Article) sub4 USING (Id_Article) WHERE m.Id_Ticket = vFechedTicket; UNTIL done END REPEAT; select * from tmpAdelantarTickets; CLOSE cur1; DROP TEMPORARY TABLE IF EXISTS tmpAdelantarTickets; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `agencia_descuadre` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencia_descuadre`(datSince DATE, datTo DATE, intAgency INT, intWarehouseAlias INT) BEGIN DECLARE isFile boolean; DECLARE datTo2359 DATETIME; SET datTo2359 = util.dayEnd(datTo); SELECT SUM(price) INTO isFile FROM agencia_descuadre; IF NOT IFNULL(isFile,0) THEN SELECT t.Id_Ticket,0 AS Total_Agencia,t.Id_Consigna,t.empresa_id,t.warehouse_id, v.suma_componente AS VN, v.suma_componente - shipping_charge AS Difer, e.shipping_charge AS teorico,t.Id_Agencia, t.Bultos,t.Id_Cliente, ap.zona FROM Tickets t LEFT JOIN (SELECT Id_Ticket, SUM(suma_componente) suma_componente,Fecha FROM v_descuadre_porte2 WHERE Fecha BETWEEN datSince AND datTo2359 GROUP BY Id_Ticket) v ON t.Id_Ticket = v.Id_Ticket LEFT JOIN (SELECT Id_Ticket, SUM(shipping_charge) shipping_charge, Fecha FROM v_expeditions_shipping_charge2 WHERE Fecha BETWEEN datSince AND datTo2359 GROUP BY Id_Ticket ) e ON t.Id_Ticket = e.Id_Ticket JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia JOIN Consignatarios c ON t.Id_Consigna = c.Id_Consigna JOIN Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = t.warehouse_id AND ap.province_id = c.province_id JOIN warehouse_group wg ON wg.warehouse_id =t.warehouse_id WHERE DATE(t.Fecha) BETWEEN datSince AND datTo2359 AND a.agency_id = intAgency and wg.warehouse_alias_id = intWarehouseAlias; ELSE SELECT t.Id_Ticket, Round(sum_price , 2) AS Total_Agencia,t.Id_Consigna,t.empresa_id,t.warehouse_id, v.suma_componente AS VN, IF(isFile,Round(sum_price, 2) - v.suma_componente,v.diferencia) AS Difer, v.teorico_agencia AS teorico,zd.Id_Agencia, t.Bultos,t.Id_Cliente FROM (SELECT *, SUM(price) sum_price FROM (select t.Id_Ticket, zd.price,t.Id_Consigna, zd.date,t.empresa_id,t.warehouse_id,c.Descuento,t.Id_Agencia from agencia_descuadre zd LEFT JOIN Tickets t ON t.Id_Ticket = zd.Id_Ticket LEFT JOIN Clientes c ON c.Id_Cliente = t.Id_Cliente ORDER BY t.Id_Cliente DESC) t GROUP BY Id_Ticket,`date`) zd LEFT JOIN Tickets t ON zd.date = DATE(t.Fecha) AND zd.Id_Consigna = t.Id_Consigna AND zd.warehouse_id = t.warehouse_id AND zd.Id_Agencia = t.Id_Agencia LEFT JOIN v_descuadre_porte v ON v.Id_Ticket = t.Id_Ticket WHERE t.Id_Cliente <> 4712 AND t.Id_Cliente <> 450 GROUP BY zd.date,Id_Consigna,warehouse_id,zd.Id_Agencia -- HAVING Difer > 0.5 OR Difer < -0.5 jgf 2015-08-18 ORDER BY v.diferencia; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `agencia_volume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencia_volume`() BEGIN DECLARE v_start DATETIME DEFAULT TIMESTAMP(CURDATE()); DECLARE v_end DATETIME DEFAULT TIMESTAMP(CURDATE(), '23:59:59'); SET v_start = IF(WEEKDAY(CURDATE()), CURDATE(),TIMESTAMPADD(DAY,-1,CURDATE())); SET v_start = IF(CURDATE() = '2014-05-02', '2014-05-01',v_start); DROP TEMPORARY TABLE IF EXISTS agenVOL; CREATE TEMPORARY TABLE agenVOL ( Id_Ticket INT PRIMARY KEY ,Id_Agencia INT ,Agencia VARCHAR(30) ,Bultos INT DEFAULT 0 ,Faltan INT DEFAULT 0 /*,Prioridad VARCHAR(15) DEFAULT ''*/ ) ENGINE=MEMORY; -- Insertamos los tickets que ya tienen la linea de portes INSERT INTO agenVOL(Id_Agencia, Agencia, Id_Ticket, Bultos) SELECT a.Id_Agencia, name , Id_Ticket, sum(Cantidad) Bultos FROM Tickets t JOIN Agencias a USING(Id_Agencia) JOIN Movimientos m USING(Id_Ticket) JOIN agency ag USING(agency_id) JOIN warehouse_joined wj ON wj.warehouse_id = t.warehouse_id WHERE Concepte LIKE '%porte%' AND wj.warehouse_alias_id = 1 -- El 1 equivale a Silla (SillaFV-SillaPCA) AND Fecha BETWEEN v_start AND v_end AND Vista = 1 GROUP BY Id_Ticket; -- Insertamos los tickets que ya tienen expediciones, que fallaran si se repite la clave primaria. INSERT INTO agenVOL(Id_Agencia, Agencia, Id_Ticket, Bultos) SELECT a.Id_Agencia, name, ticket_id, COUNT(ticket_id) FROM expeditions e JOIN Tickets t ON t.Id_Ticket = e.ticket_id JOIN Agencias a ON a.Id_Agencia = e.agency_id JOIN agency ag ON ag.agency_id = a.agency_id JOIN warehouse_joined wj ON wj.warehouse_id = t.warehouse_id WHERE t.Fecha BETWEEN v_start AND v_end AND wj.warehouse_alias_id = 1 -- El 1 equivale a Silla (SillaFV-SillaPCA) AND Vista = 1 GROUP BY ticket_id ON DUPLICATE KEY UPDATE Bultos = Bultos; -- Adivinamos el futuro INSERT INTO agenVOL(Id_Agencia, Agencia, Id_Ticket, Faltan) SELECT a.Id_Agencia, name, Id_Ticket, 1 as Faltan FROM Tickets t JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia JOIN agency ag ON ag.agency_id = a.agency_id LEFT JOIN expeditions e ON e.ticket_id = t.Id_Ticket JOIN warehouse_joined wj ON wj.warehouse_id = t.warehouse_id WHERE Fecha BETWEEN v_start AND v_end AND Bultos = 0 AND expeditions_id IS NULL AND EtiquetasEmitidas = 0 AND wj.warehouse_alias_id = 1 -- JGF 18/12/14 El 1 equivale a Silla (SillaFV-SillaPCA) AND Vista = 1 GROUP BY Id_Ticket ON DUPLICATE KEY UPDATE Faltan = Faltan + 1; -- Matizamos la urgencia para ZELERIS /* UPDATE agenVOL a JOIN Tickets t USING(Id_Ticket) JOIN Clientes c USING(Id_Cliente) JOIN Agencias agen ON agen.Id_Agencia = t.Id_Agencia JOIN agency ag ON ag.agency_id = agen.agency_id JOIN Agencias_province ap ON ag.agency_id = ap.province_id JOIN province p ON p.province_id = ap.province_id SET a.Prioridad = IF(p.name IN ('VALENCIA','MURCIA','MADRID','BARCELONA','GIRONA','ALICANTE','CASTELLON'), 'LENTA','RAPIDA') WHERE ag.name LIKE 'zeleris';*/ SELECT agen.agency_id, name Agencia, COUNT(Id_Ticket) expediciones, SUM(Bultos) Bultos, SUM(Faltan) Faltan/*, Prioridad*/ FROM agenVOL a JOIN Agencias agen USING(Id_Agencia) JOIN agency ag USING(agency_id) GROUP BY ag.agency_id/*, Prioridad*/; DROP TEMPORARY TABLE IF EXISTS agenVOL; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `alfa_invoices` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `alfa_invoices`(IN datFEC DATE) BEGIN DECLARE datSTART DATETIME; DECLARE vTotal DECIMAL(10,2) DEFAULT 0.00; SET @myId = -10000000; SET @myRef = 'factura'; SET @myTotal = vTotal; SET datSTART = TIMESTAMPADD(DAY, -1 * DAYOFMONTH(datFEC) + 1, datfec); IF datFEC < '2017-07-01' THEN SELECT Id_Factura `Invoice no`, date(Fecha) as `Invoice date`, Id_Cliente `Debtor no`, `IF` `Vat nr`, Razonsocial `Name`, BI7 `Amount excl Vat 6%`, BI16 `Amount excl Vat 19%`, IVA7 `Vat 6%`, IVA16 `Vat 19%`, Importe `Total inc Vat` from Facturas INNER JOIN Clientes USING(Id_Cliente) where empresa_id = 567 and Fecha BETWEEN datSTART AND datFEC order by `Invoice date`, factura_id; ELSE SELECT * FROM ( SELECT io.ref `Invoice no`, io.issued `Invoice date`, IF(@myId = io.id, '', clientFk) `Debtor no`, IF(@myId = io.id, '', c.fi) `Vat nr`, IF(@myId = io.id, '', c.socialName) `Name`, taxableBase `Taxable Amount excl VAT`, CONCAT(CAST(pgc.rate AS DECIMAL(2,0)) ,' %') `VAT Rate`, CAST(vat AS DECIMAL(10,2)) `VAT Quote`, CAST(@myTotal + taxableBase + vat AS DECIMAL(10,2)) `Total plus Vat`, IF(@myId := io.id, NULL, NULL) as ControlField FROM vn.invoiceOut io JOIN vn.client c ON c.id = io.clientFk JOIN vn.invoiceOutTax iot ON iot.invoiceOutFk = io.id JOIN vn.pgc ON pgc.code = iot.pgcFk WHERE io.companyFk = 567 AND io.issued BETWEEN datSTART AND datFEC ORDER BY io.id, iot.id ) t1 ORDER BY `Invoice date` DESC, `Invoice no`; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article`() BEGIN DROP TEMPORARY TABLE IF EXISTS `article_inventory`; CREATE TEMPORARY TABLE `article_inventory` ( `article_id` INT(11) NOT NULL PRIMARY KEY, `future` DATETIME ) ENGINE = MEMORY; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `articleTagUpdatePriority_kk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `articleTagUpdatePriority_kk`(IN vItem INT) BEGIN /* * DEPRECATED */ CALL vn.itemTagUpdatePriority(vItem); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_available_single` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article_available_single`(IN v_wh TINYINT, IN v_date DATETIME, IN id_single INT) BEGIN CALL bionic_available_single (v_wh, v_date,id_single,0); SELECT available AS minimo FROM tmp_item WHERE item_id = id_single; -- ixen totes les linies en lloc d'una sola DROP TEMPORARY TABLE IF EXISTS tmp_item; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_inventory_warehouses` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article_inventory_warehouses`(vDate DATE) proc: BEGIN /** * Recalcula los inventarios de todos los almacenes. * * @param vDate Fecha de los nuevos inventarios */ DECLARE vWh INT; DECLARE vDone BOOL; DECLARE vEntryId INT; DECLARE vTravelId INT; DECLARE vDateTime DATETIME DEFAULT TIMESTAMP(vDate, '00:00:00'); DECLARE vDeleteDate DATE DEFAULT TIMESTAMPADD(DAY, -2, vDate); DECLARE cWarehouses CURSOR FOR SELECT id FROM warehouse WHERE inventario; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; OPEN cWarehouses; l: LOOP SET vDone = FALSE; FETCH cWarehouses INTO vWh; IF vDone THEN LEAVE l; END IF; INSERT INTO travel SET warehouse_id_out = 13, warehouse_id = vWh, shipment = vDateTime, landing = vDateTime, agency_id = 53, ref = 'inventario', delivered = TRUE, received = TRUE; SELECT LAST_INSERT_ID() INTO vTravelId; INSERT INTO Entradas SET Id_Proveedor = 4, Fecha = vDateTime, Confirmada = TRUE, Pedida = TRUE, travel_id = vTravelId; SELECT LAST_INSERT_ID() INTO vEntryId; -- Inserta el visible CALL inventario_multiple_inventarios (vWh, vDateTime); -- Inserta Last_buy_id ALTER TABLE article_inventory ADD buy_id INT; UPDATE article_inventory ai JOIN ( SELECT * FROM ( SELECT Id_Article, Id_Compra,warehouse_id FROM Compres c JOIN Entradas e USING (Id_Entrada) JOIN travel tr ON tr.id = e.travel_id WHERE Novincular = FALSE AND costefijo > 0 AND tarifa2 > 0 AND NOT Redada AND landing BETWEEN date_inv() AND vDate ORDER BY (vWh = warehouse_id) DESC, landing DESC ) t1 GROUP BY Id_Article ) t ON ai.article_id = t.Id_Article SET ai.buy_id = t.Id_Compra; INSERT INTO Compres ( Id_Entrada ,Id_Article ,Cantidad ,Costefijo ,Packing ,Id_Cubo ,Tarifa2 ,Tarifa3 ,Productor ) SELECT vEntryId ,AI.article_id ,IF(AI.visible < 0,0,AI.visible) ,ifnull(C.Costefijo,0) + ifnull(C.Portefijo,0) + ifnull(C.Comisionfija,0) + ifnull(C.Embalajefijo,0) ,C.Packing ,C.Id_Cubo ,C.Tarifa2 ,C.Tarifa3 ,C.Productor FROM article_inventory AI LEFT JOIN Compres C ON C.Id_Compra = AI.buy_id; DROP TEMPORARY TABLE article_inventory; END LOOP; CLOSE cWarehouses; UPDATE tblContadores SET FechaInventario = vDate; DELETE e, t FROM travel t JOIN Entradas e ON e.travel_id = t.id WHERE Id_Proveedor = 4 AND shipment <= vDeleteDate AND (DAY(shipment) <> 1 OR shipment < TIMESTAMPADD(MONTH, -5, CURDATE())); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_minacum` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article_minacum`(IN v_wh TINYINT, IN v_date_ini DATETIME, IN v_range INT) BEGIN -- Cálculo del mÃnimo acumulado DECLARE v_date DATE DEFAULT v_date_ini; DECLARE v_date_end DATETIME; SET v_date_ini = TIMESTAMP(DATE(v_date_ini), '00:00:00'); SET v_date_end = TIMESTAMP(TIMESTAMPADD(DAY, v_range, v_date_ini),'23:59:59'); -- CALL item_travel (v_wh, v_date_ini); DROP TEMPORARY TABLE IF EXISTS article_minacum; CREATE TEMPORARY TABLE article_minacum ENGINE = MEMORY SELECT t.article_id, t.warehouse_id, minacum(dat, amount, v_date) AS amount FROM ( SELECT article_id, DATE(Fecha) AS dat, SUM(amount) AS amount, warehouse_id FROM ( SELECT Id_Article article_id, Fecha, -Cantidad AS amount, warehouse_id FROM Movimientos m INNER JOIN Tickets t USING (Id_Ticket) WHERE Fecha BETWEEN v_date_ini AND v_date_end AND Cantidad != 0 AND (@aid IS NULL OR Id_Article = @aid) AND (v_wh IS NULL OR t.warehouse_id = v_wh) UNION ALL SELECT Id_Article, t.landing, Cantidad, warehouse_id FROM Compres c INNER JOIN Entradas e USING (Id_Entrada) LEFT JOIN travel t ON e.travel_id = t.id WHERE t.landing BETWEEN v_date_ini AND v_date_end AND (v_wh IS NULL OR t.warehouse_id = v_wh) AND e.Inventario = FALSE AND Cantidad != 0 AND (@aid IS NULL OR Id_Article = @aid) UNION ALL SELECT Id_Article, t.shipment, -Cantidad, warehouse_id_out FROM Compres c INNER JOIN Entradas e USING (Id_Entrada) LEFT JOIN travel t ON e.travel_id = t.id WHERE t.shipment BETWEEN v_date_ini AND v_date_end AND (v_wh IS NULL OR t.warehouse_id_out = v_wh) AND e.Inventario = FALSE AND Cantidad != 0 AND (@aid IS NULL OR Id_Article = @aid) ) t1 GROUP BY t1.article_id, dat, warehouse_id ) t GROUP BY t.article_id, warehouse_id HAVING amount != 0; SET @aid = NULL; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_multiple_buy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article_multiple_buy`(v_date DATETIME, wh INT) BEGIN DECLARE v_date_aux DATETIME; SELECT TIMESTAMPADD(DAY, -90, CURDATE()) INTO v_date_aux; ALTER TABLE article_inventory ADD buy_id INT; DROP TEMPORARY TABLE IF EXISTS tmp; CREATE TEMPORARY TABLE tmp (KEY (Id_Article)) ENGINE = MEMORY SELECT * FROM ( SELECT Id_Article, Id_Compra FROM bi.Last_buy_id ORDER BY (wh = warehouse_id) DESC ) t GROUP BY Id_Article; UPDATE article_inventory ai JOIN tmp t ON ai.article_id = t.Id_Article SET ai.buy_id = t.Id_Compra; -- Los valores de hoy TRUNCATE TABLE tmp; INSERT INTO tmp SELECT Id_Article, Id_Compra FROM Compres c JOIN Entradas e USING (Id_Entrada) JOIN travel tr ON tr.id = e.travel_id WHERE Novincular = FALSE AND tarifa2 > 0 AND landing BETWEEN CURDATE() AND v_date ORDER BY (wh = warehouse_id) DESC; UPDATE article_inventory ai INNER JOIN tmp t ON ai.article_id = t.Id_Article SET ai.buy_id = t.Id_Compra; CREATE INDEX idx USING HASH ON article_inventory (buy_id); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_multiple_buy_date` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `article_multiple_buy_date`(IN date_ DATETIME, IN wh TINYINT(3)) BEGIN DECLARE datINV DATE; SELECT FechaInventario INTO datINV FROM tblContadores; ALTER TABLE `article_inventory` ADD `buy_date` datetime NOT NULL; UPDATE article_inventory INNER JOIN ( SELECT * FROM ( SELECT travel.landing AS bdate, Compres.Id_Article AS article_id FROM Compres JOIN Entradas USING(Id_Entrada) JOIN travel ON travel.id = Entradas.travel_id JOIN warehouse W ON W.id = travel.warehouse_id WHERE travel.landing BETWEEN datINV AND date_ AND IF(wh = 0, W.comisionantes, wh = travel.warehouse_id) /*AND Compres.Novincular = FALSE AND Entradas.Id_Proveedor <> 4 AND Entradas.Inventario = FALSE*/ -- jgf 2017/03/06 en la comparativa no trau el dia de caducitat AND Entradas.Redada = FALSE ORDER BY article_id, bdate DESC ) AS temp GROUP BY article_id ) AS buy ON article_inventory.article_id = buy.article_id SET article_inventory.buy_date = buy.bdate; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_multiple_buy_last` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = latin1 */ ; /*!50003 SET character_set_results = latin1 */ ; /*!50003 SET collation_connection = latin1_swedish_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article_multiple_buy_last`(IN wh TINYINT, IN date_end DATETIME) BEGIN DECLARE v_date DATETIME; DROP TEMPORARY TABLE IF EXISTS article_buy_last; CREATE TEMPORARY TABLE article_buy_last SELECT * FROM ( SELECT c.Id_Article AS article_id, c.Id_Compra AS id FROM Compres c INNER JOIN Entradas e USING(Id_Entrada) INNER JOIN travel t ON t.id = e.travel_id WHERE t.landing BETWEEN date_inv() AND date_end AND c.Novincular = FALSE AND c.tarifa2 > 0 ORDER BY t.landing DESC,(wh IN (0,t.warehouse_id)) DESC, (Id_Cubo IS NULL) ,article_id, (e.Id_proveedor = 4) ) t GROUP BY article_id; ALTER TABLE article_buy_last ADD INDEX (article_id); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_visible_single` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article_visible_single`(IN v_wh TINYINT,IN v_article INT) BEGIN DECLARE bisible FLOAT; CALL article_visible_single2(v_wh,v_article,@suma2); SET bisible = @suma2; SELECT bisible AS suma, A.Id_Article, A.Article, A.Medida, A.Tallos, A.Nicho, O.Abreviatura as origen, A.Color, A.Tipo, A.Nicho, A.Categoria FROM v_compres A INNER JOIN Origen O ON O.id = A.id_origen WHERE A.Id_Article =v_article AND A.warehouse_id = v_wh ORDER BY landing DESC LIMIT 1; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `article_visible_single2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `article_visible_single2`(IN v_wh TINYINT,IN v_article INT,OUT int_amount INT) BEGIN call item_stock(v_wh,CURDATE(),v_article); call article_visible(v_wh); SELECT SUM(stock) INTO int_amount FROM tmp_item WHERE item_id = v_article ; SELECT IFNULL(SUM(amount),0) + IFNULL(int_amount,0) INTO int_amount FROM article_visible WHERE article_id = v_article; DROP TEMPORARY TABLE tmp_item; DROP TEMPORARY TABLE article_visible; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `availableTraslate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `availableTraslate`(vWarehouseLanding INT, v_date DATE,vWarehouseShipment INT) proc: BEGIN DECLARE v_date_ini DATE; DECLARE v_date_end DATETIME; DECLARE v_reserve_date DATETIME; DECLARE v_date_inv DATE; IF v_date < CURDATE() THEN LEAVE proc; END IF; CALL vn2008.item_stock (vWarehouseLanding, v_date, NULL); -- Calcula algunos parámetros necesarios SET v_date_ini = TIMESTAMP(v_date, '00:00:00'); SET v_date_end = TIMESTAMP(TIMESTAMPADD(DAY, 4, v_date), '23:59:59'); SELECT FechaInventario INTO v_date_inv FROM vn2008.tblContadores; SELECT SUBTIME(NOW(), reserve_time) INTO v_reserve_date FROM hedera.order_config; -- Calcula el ultimo dia de vida para cada producto DROP TEMPORARY TABLE IF EXISTS item_range; CREATE TEMPORARY TABLE item_range (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT c.Id_Article item_id, MAX(landing) date_end FROM vn2008.Compres c JOIN vn2008.Entradas e ON c.Id_Entrada = e.Id_Entrada JOIN vn2008.travel t ON t.id = e.travel_id JOIN vn2008.warehouse w ON w.id = t.warehouse_id WHERE t.landing BETWEEN v_date_inv AND v_date_ini AND t.warehouse_id = vWarehouseLanding AND NOT e.Inventario AND NOT e.Redada GROUP BY Id_Article; -- Tabla con el ultimo dia de last_buy para cada producto que hace un replace de la anterior CALL item_last_buy_(vWarehouseShipment,curdate()); DROP TEMPORARY TABLE IF EXISTS item_range_copy; CREATE TEMPORARY TABLE item_range_copy LIKE item_range; INSERT INTO item_range_copy SELECT * FROM item_range; INSERT INTO item_range SELECT t.item_id, tr.landing FROM t_item_last_buy t JOIN Compres c ON c.Id_Compra = t.buy_id JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = e.travel_id LEFT JOIN item_range_copy i ON t.item_id = i.item_id WHERE t.warehouse_id = vWarehouseShipment ON DUPLICATE KEY UPDATE item_range.date_end = GREATEST(item_range.date_end,landing); DROP TEMPORARY TABLE item_range_copy; -- Replica la tabla item_range para poder usarla varias veces en la misma consulta DROP TEMPORARY TABLE IF EXISTS item_range_copy1; CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range; INSERT INTO item_range_copy1 SELECT c.item_id, TIMESTAMP(TIMESTAMPADD(DAY, t.life, c.date_end), '23:59:59') date_end FROM item_range c JOIN vn2008.Articles a ON a.Id_Article = c.item_id JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id HAVING date_end >= v_date_ini OR date_end IS NULL; DROP TEMPORARY TABLE IF EXISTS item_range_copy2; CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range_copy1; INSERT INTO item_range_copy2 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy3; CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range_copy1; INSERT INTO item_range_copy3 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy4; CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range_copy1; INSERT INTO item_range_copy4 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy5; CREATE TEMPORARY TABLE item_range_copy5 LIKE item_range_copy1; INSERT INTO item_range_copy5 SELECT * FROM item_range_copy1; -- Calcula el ATP DROP TEMPORARY TABLE IF EXISTS availableTraslate; CREATE TEMPORARY TABLE availableTraslate (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT t.item_id, SUM(stock) available FROM ( SELECT ti.item_id, stock FROM vn2008.tmp_item ti JOIN item_range ir ON ir.item_id = ti.item_id UNION ALL SELECT t.item_id, minacum(dt, amount, v_date) AS available FROM ( SELECT item_id, DATE(dat) dt, SUM(amount) amount FROM ( SELECT i.item_id, i.dat, i.amount FROM vn2008.item_out i JOIN item_range_copy1 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding UNION ALL SELECT m.Id_Article item_id, t.landing dat, m.Cantidad amount FROM Compres m JOIN Entradas e ON m.Id_Entrada = e.Id_Entrada JOIN travel t ON e.travel_id = t.id JOIN item_range_copy2 ir ON ir.item_id = m.Id_Article WHERE e.Inventario = 0 AND m.Cantidad <> 0 AND e.redada = 0 AND t.warehouse_id = vWarehouseLanding AND t.landing >= v_date_ini AND (ir.date_end IS NULL OR t.landing <= ir.date_end) UNION ALL SELECT i.item_id, i.dat, i.amount FROM vn2008.item_entry_out i JOIN item_range_copy3 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding UNION ALL SELECT r.item_id, r.shipment, -r.amount FROM hedera.order_row r JOIN hedera.`order` o ON o.id = r.order_id JOIN item_range_copy4 ir ON ir.item_id = r.item_id WHERE r.shipment >= v_date_ini AND (ir.date_end IS NULL OR r.shipment <= ir.date_end) AND r.warehouse_id = vWarehouseLanding AND r.created >= v_reserve_date AND NOT o.confirmed ) t GROUP BY item_id, dt ) t GROUP BY t.item_id ) t GROUP BY t.item_id HAVING available != 0; DROP TEMPORARY TABLE vn2008.tmp_item ,item_range ,item_range_copy1 ,item_range_copy2 ,item_range_copy3 ,item_range_copy4 ,item_range_copy5; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `availableTraslatekk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `availableTraslatekk`(vWarehouseLanding INT, v_date DATE,vWarehouseShipment INT) proc: BEGIN DECLARE v_date_ini DATE; DECLARE v_date_end DATETIME; DECLARE v_reserve_date DATETIME; DECLARE v_date_inv DATE; IF v_date < CURDATE() THEN LEAVE proc; END IF; CALL vn2008.item_stock (vWarehouseLanding, v_date, NULL); -- Calcula algunos parámetros necesarios SET v_date_ini = TIMESTAMP(v_date, '00:00:00'); SET v_date_end = TIMESTAMP(TIMESTAMPADD(DAY, 4, v_date), '23:59:59'); SELECT FechaInventario INTO v_date_inv FROM vn2008.tblContadores; SELECT SUBTIME(NOW(), reserve_time) INTO v_reserve_date FROM hedera.order_config; -- Calcula el ultimo dia de vida para cada producto DROP TEMPORARY TABLE IF EXISTS item_range; CREATE TEMPORARY TABLE item_range (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT c.Id_Article item_id, MAX(landing) date_end FROM vn2008.Compres c JOIN vn2008.Entradas e ON c.Id_Entrada = e.Id_Entrada JOIN vn2008.travel t ON t.id = e.travel_id JOIN vn2008.warehouse w ON w.id = t.warehouse_id WHERE t.landing BETWEEN v_date_inv AND v_date_ini AND t.warehouse_id = vWarehouseLanding AND NOT e.Inventario AND NOT e.Redada GROUP BY Id_Article; SELECT c.Id_Article item_id, MAX(landing) date_end FROM vn2008.Compres c JOIN vn2008.Entradas e ON c.Id_Entrada = e.Id_Entrada JOIN vn2008.travel t ON t.id = e.travel_id JOIN vn2008.warehouse w ON w.id = t.warehouse_id WHERE t.landing BETWEEN v_date_inv AND v_date_ini AND t.warehouse_id = vWarehouseLanding AND NOT e.Inventario AND NOT e.Redada GROUP BY Id_Article; -- Tabla con el ultimo dia de last_buy para cada producto que hace un replace de la anterior CALL item_last_buy_(vWarehouseShipment,curdate()); DROP TEMPORARY TABLE IF EXISTS item_range_copy; CREATE TEMPORARY TABLE item_range_copy LIKE item_range; INSERT INTO item_range_copy SELECT * FROM item_range; INSERT INTO item_range SELECT t.item_id, tr.landing FROM t_item_last_buy t JOIN Compres c ON c.Id_Compra = t.buy_id JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = e.travel_id LEFT JOIN item_range_copy i ON t.item_id = i.item_id WHERE t.warehouse_id = vWarehouseShipment ON DUPLICATE KEY UPDATE item_range.date_end = GREATEST(item_range.date_end,landing); SELECT t.item_id, tr.landing FROM t_item_last_buy t JOIN Compres c ON c.Id_Compra = t.buy_id JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = e.travel_id LEFT JOIN item_range_copy i ON t.item_id = i.item_id WHERE t.warehouse_id = vWarehouseShipment; DROP TEMPORARY TABLE item_range_copy; -- Replica la tabla item_range para poder usarla varias veces en la misma consulta DROP TEMPORARY TABLE IF EXISTS item_range_copy1; CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range; INSERT INTO item_range_copy1 SELECT c.item_id, TIMESTAMP(TIMESTAMPADD(DAY, t.life, c.date_end), '23:59:59') date_end FROM item_range c JOIN vn2008.Articles a ON a.Id_Article = c.item_id JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id HAVING date_end >= v_date_ini OR date_end IS NULL; DROP TEMPORARY TABLE IF EXISTS item_range_copy2; CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range_copy1; INSERT INTO item_range_copy2 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy3; CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range_copy1; INSERT INTO item_range_copy3 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy4; CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range_copy1; INSERT INTO item_range_copy4 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy5; CREATE TEMPORARY TABLE item_range_copy5 LIKE item_range_copy1; INSERT INTO item_range_copy5 SELECT * FROM item_range_copy1; -- Calcula el ATP SELECT item_id, stock,'tmp_item' FROM vn2008.tmp_item; DROP TEMPORARY TABLE IF EXISTS availableTraslate; CREATE TEMPORARY TABLE availableTraslate (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT t.item_id, SUM(stock) available FROM ( SELECT ti.item_id, stock FROM vn2008.tmp_item ti JOIN item_range ir ON ir.item_id = ti.item_id UNION ALL SELECT t.item_id, minacum(dt, amount, v_date) AS available FROM ( SELECT item_id, DATE(dat) dt, SUM(amount) amount FROM ( SELECT i.item_id, i.dat, i.amount FROM vn2008.item_out i JOIN item_range_copy1 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding UNION ALL SELECT i.item_id, i.dat, i.amount FROM vn2008.item_entry_in i JOIN item_range_copy2 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding UNION ALL SELECT i.item_id, i.dat, i.amount FROM vn2008.item_entry_out i JOIN item_range_copy3 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding UNION ALL SELECT r.item_id, r.shipment, -r.amount FROM hedera.order_row r JOIN hedera.`order` o ON o.id = r.order_id JOIN item_range_copy4 ir ON ir.item_id = r.item_id WHERE r.shipment >= v_date_ini AND (ir.date_end IS NULL OR r.shipment <= ir.date_end) AND r.warehouse_id = vWarehouseLanding AND r.created >= v_reserve_date AND NOT o.confirmed ) t GROUP BY item_id, dt ) t GROUP BY t.item_id ) t GROUP BY t.item_id HAVING available != 0; SELECT i.item_id, i.dat, i.amount,'item_out',vWarehouseLanding FROM vn2008.item_out i JOIN item_range_copy1 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding; select * from availableTraslate; DROP TEMPORARY TABLE vn2008.tmp_item ,item_range ,item_range_copy1 ,item_range_copy2 ,item_range_copy3 ,item_range_copy4 ,item_range_copy5; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `availableTraslateTesting` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `availableTraslateTesting`(vWarehouseLanding INT, v_date DATE,vWarehouseShipment INT) proc: BEGIN DECLARE v_date_ini DATE; DECLARE v_date_end DATETIME; DECLARE v_reserve_date DATETIME; DECLARE v_date_inv DATE; IF v_date < CURDATE() THEN LEAVE proc; END IF; CALL vn2008.item_stock (vWarehouseLanding, v_date, NULL); -- Calcula algunos parámetros necesarios SET v_date_ini = TIMESTAMP(v_date, '00:00:00'); SET v_date_end = TIMESTAMP(TIMESTAMPADD(DAY, 4, v_date), '23:59:59'); SELECT FechaInventario INTO v_date_inv FROM vn2008.tblContadores; SELECT SUBTIME(NOW(), reserve_time) INTO v_reserve_date FROM hedera.order_config; -- Calcula el ultimo dia de vida para cada producto DROP TEMPORARY TABLE IF EXISTS item_range; CREATE TEMPORARY TABLE item_range (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT c.Id_Article item_id, MAX(landing) date_end FROM vn2008.Compres c JOIN vn2008.Entradas e ON c.Id_Entrada = e.Id_Entrada JOIN vn2008.travel t ON t.id = e.travel_id JOIN vn2008.warehouse w ON w.id = t.warehouse_id WHERE t.landing BETWEEN v_date_inv AND v_date_ini AND t.warehouse_id = vWarehouseLanding AND NOT e.Inventario AND NOT e.Redada GROUP BY Id_Article; -- Tabla con el ultimo dia de last_buy para cada producto que hace un replace de la anterior SELECT vWarehouseShipment; CALL item_last_buy_(vWarehouseShipment,v_date); SELECT *,'last_buy' FROM t_item_last_buy t ; -- WHERE t.item_id = 41576; SELECT * FROM item_range t WHERE t.item_id = 41576; DROP TEMPORARY TABLE IF EXISTS item_range_copy; CREATE TEMPORARY TABLE item_range_copy LIKE item_range; INSERT INTO item_range_copy SELECT * FROM item_range; SELECT 'update' , t.item_id, tr.landing FROM t_item_last_buy t JOIN Compres c ON c.Id_Compra = t.buy_id JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = e.travel_id LEFT JOIN item_range_copy i ON t.item_id = i.item_id WHERE t.warehouse_id = vWarehouseShipment AND t.item_id = 41576; INSERT INTO item_range SELECT t.item_id, tr.landing FROM t_item_last_buy t JOIN Compres c ON c.Id_Compra = t.buy_id JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = e.travel_id LEFT JOIN item_range_copy i ON t.item_id = i.item_id WHERE t.warehouse_id = vWarehouseShipment ON DUPLICATE KEY UPDATE item_range.date_end = GREATEST(item_range.date_end,landing); DROP TEMPORARY TABLE item_range_copy; -- Replica la tabla item_range para poder usarla varias veces en la misma consulta DROP TEMPORARY TABLE IF EXISTS item_range_copy1; CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range; INSERT INTO item_range_copy1 SELECT c.item_id, TIMESTAMP(TIMESTAMPADD(DAY, t.life, c.date_end), '23:59:59') date_end FROM item_range c JOIN vn2008.Articles a ON a.Id_Article = c.item_id JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id HAVING date_end >= v_date_ini OR date_end IS NULL; select * from item_range_copy1 where item_id = 41576; DROP TEMPORARY TABLE IF EXISTS item_range_copy2; CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range_copy1; INSERT INTO item_range_copy2 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy3; CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range_copy1; INSERT INTO item_range_copy3 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy4; CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range_copy1; INSERT INTO item_range_copy4 SELECT * FROM item_range_copy1; DROP TEMPORARY TABLE IF EXISTS item_range_copy5; CREATE TEMPORARY TABLE item_range_copy5 LIKE item_range_copy1; INSERT INTO item_range_copy5 SELECT * FROM item_range_copy1; -- Calcula el ATP SELECT ti.item_id, stock FROM vn2008.tmp_item ti JOIN item_range ir ON ir.item_id = ti.item_id ; SELECT i.item_id, i.dat, i.amount FROM vn2008.item_out i JOIN item_range_copy1 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding; SELECT m.Id_Article item_id, t.landing dat, m.Cantidad amount FROM Compres m JOIN Entradas e ON m.Id_Entrada = e.Id_Entrada JOIN travel t ON e.travel_id = t.id JOIN item_range_copy2 ir ON ir.item_id = m.Id_Article WHERE e.Inventario = 0 AND m.Cantidad <> 0 AND e.redada = 0 AND t.warehouse_id = vWarehouseLanding AND t.landing >= v_date_ini AND (ir.date_end IS NULL OR t.landing <= ir.date_end); SELECT i.item_id, i.dat, i.amount FROM vn2008.item_entry_out i JOIN item_range_copy3 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding; SELECT r.item_id, r.shipment, -r.amount FROM hedera.order_row r JOIN hedera.`order` o ON o.id = r.order_id JOIN item_range_copy4 ir ON ir.item_id = r.item_id WHERE r.shipment >= v_date_ini AND (ir.date_end IS NULL OR r.shipment <= ir.date_end) AND r.warehouse_id = vWarehouseLanding AND r.created >= v_reserve_date AND NOT o.confirmed; DROP TEMPORARY TABLE IF EXISTS availableTraslate; CREATE TEMPORARY TABLE availableTraslate (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT t.item_id, SUM(stock) available FROM ( SELECT ti.item_id, stock FROM vn2008.tmp_item ti JOIN item_range ir ON ir.item_id = ti.item_id UNION ALL SELECT t.item_id, minacum(dt, amount, v_date) AS available FROM ( SELECT item_id, DATE(dat) dt, SUM(amount) amount FROM ( SELECT i.item_id, i.dat, i.amount FROM vn2008.item_out i JOIN item_range_copy1 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding UNION ALL SELECT m.Id_Article item_id, t.landing dat, m.Cantidad amount FROM Compres m JOIN Entradas e ON m.Id_Entrada = e.Id_Entrada JOIN travel t ON e.travel_id = t.id JOIN item_range_copy2 ir ON ir.item_id = m.Id_Article WHERE e.Inventario = 0 AND m.Cantidad <> 0 AND e.redada = 0 AND t.warehouse_id = vWarehouseLanding AND t.landing >= v_date_ini AND (ir.date_end IS NULL OR t.landing <= ir.date_end) UNION ALL SELECT i.item_id, i.dat, i.amount FROM vn2008.item_entry_out i JOIN item_range_copy3 ir ON ir.item_id = i.item_id WHERE i.dat >= v_date_ini AND (ir.date_end IS NULL OR i.dat <= ir.date_end) AND i.warehouse_id = vWarehouseLanding UNION ALL SELECT r.item_id, r.shipment, -r.amount FROM hedera.order_row r JOIN hedera.`order` o ON o.id = r.order_id JOIN item_range_copy4 ir ON ir.item_id = r.item_id WHERE r.shipment >= v_date_ini AND (ir.date_end IS NULL OR r.shipment <= ir.date_end) AND r.warehouse_id = vWarehouseLanding AND r.created >= v_reserve_date AND NOT o.confirmed ) t GROUP BY item_id, dt ) t GROUP BY t.item_id ) t GROUP BY t.item_id HAVING available != 0; select * from availableTraslate where item_id = 41576; DROP TEMPORARY TABLE vn2008.tmp_item ,item_range ,item_range_copy1 ,item_range_copy2 ,item_range_copy3 ,item_range_copy4 ,item_range_copy5; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `balance_create` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `balance_create`(IN vStartingMonth INT , IN vEndingMonth INT , IN vCompany INT , IN vConsolidate BOOLEAN , IN vInterGroupSalesIncluded BOOLEAN) BEGIN DECLARE v_sql TEXT; DECLARE strTABLE VARCHAR(20) DEFAULT "balance_nest_tree"; DECLARE intGAP INTEGER DEFAULT 7; DECLARE intYEARS INTEGER DEFAULT 3; DECLARE vConsolidatedGroup INTEGER; DECLARE vStartingDate DATE DEFAULT '2015-01-01'; DECLARE vStartingYear INT DEFAULT 2015; -- Solicitamos la tabla tmp.nest, como base para el balance CALL nest_tree(strTABLE,intGAP, FALSE); DROP TEMPORARY TABLE IF EXISTS tmp.balance; CREATE TEMPORARY TABLE tmp.balance SELECT * FROM tmp.nest; DROP TEMPORARY TABLE IF EXISTS tmp.empresas_receptoras; DROP TEMPORARY TABLE IF EXISTS tmp.empresas_emisoras; IF vConsolidate THEN SELECT empresa_grupo INTO vConsolidatedGroup FROM empresa WHERE id = vCompany; END IF; CREATE TEMPORARY TABLE tmp.empresas_receptoras SELECT id as empresa_id FROM vn2008.empresa WHERE id = vCompany OR empresa_grupo = vConsolidatedGroup; CREATE TEMPORARY TABLE tmp.empresas_emisoras SELECT Id_Proveedor as empresa_id FROM vn2008.Proveedores p; IF NOT vInterGroupSalesIncluded THEN DELETE ee.* FROM tmp.empresas_emisoras ee JOIN vn2008.empresa e on e.id = ee.empresa_id WHERE e.empresa_grupo = vConsolidatedGroup; END IF; -- Se calculan las facturas que intervienen, para luego poder servir el desglose desde aqui DROP TEMPORARY TABLE IF EXISTS tmp.balance_desglose; CREATE TEMPORARY TABLE tmp.balance_desglose SELECT er.empresa_id as receptora_id , ee.empresa_id as emisora_id /* , year(IFNULL(IFNULL(r.dateBooking,tr.dateBooking),IFNULL(tr.Fecha,r.Fecha))) as `year` , month(IFNULL(IFNULL(r.dateBooking,tr.dateBooking),IFNULL(tr.Fecha,r.Fecha))) as `month` */ , year(IFNULL(r.dateBooking,r.Fecha)) as `year` , month(IFNULL(r.dateBooking,r.Fecha)) as `month` , gastos_id as Id_Gasto , sum(bi) as importe FROM recibida r JOIN recibida_iva ri on ri.recibida_id = r.id JOIN tmp.empresas_receptoras er on er.empresa_id = r.empresa_id JOIN tmp.empresas_emisoras ee ON ee.empresa_id = r.proveedor_id /* LEFT JOIN vn2008.recibida_entrada re ON re.recibida_id = r.id LEFT JOIN vn2008.recibida tr ON tr.id = re.awb_recibida */ WHERE IFNULL(r.dateBooking,r.Fecha) between vStartingDate and CURDATE() GROUP BY Id_Gasto, year, month, emisora_id, receptora_id; INSERT INTO tmp.balance_desglose(receptora_id , emisora_id , year , month , Id_Gasto , importe) SELECT gr.empresa_id , gr.empresa_id , year , month , Id_Gasto , sum(importe) FROM gastos_resumen gr JOIN tmp.empresas_receptoras er on gr.empresa_id = er.empresa_id WHERE year >= vStartingYear AND month BETWEEN vStartingMonth AND vEndingMonth GROUP BY Id_Gasto, year, month, gr.empresa_id; DELETE FROM tmp.balance_desglose WHERE month < vStartingMonth OR month > vEndingMonth; -- Ahora el balance SET v_sql = sql_printf ( ' ALTER TABLE tmp.balance ADD COLUMN %t INT(10) NULL , ADD COLUMN %t INT(10) NULL , ADD COLUMN %t INT(10) NULL , ADD COLUMN Id_Gasto VARCHAR(10) NULL, ADD COLUMN Gasto VARCHAR(45) NULL; ', YEAR(CURDATE())-2, YEAR(CURDATE())-1, YEAR(CURDATE()) ); CALL util.exec (v_sql); -- Añadimos los gastos, para facilitar el formulario UPDATE tmp.balance b JOIN vn2008.balance_nest_tree bnt on bnt.id = b.id JOIN (SELECT Id_Gasto, Gasto FROM vn2008.Gastos GROUP BY Id_Gasto) g ON g.Id_Gasto = bnt.Id_Gasto SET b.Id_Gasto = g.Id_Gasto , b.Gasto = g.Gasto; -- Rellenamos los valores de primer nivel, los que corresponden a los gastos simples WHILE intYEARS > 0 DO SET intYEARS = intYEARS - 1; SET v_sql = sql_printf ( ' UPDATE tmp.balance b JOIN ( SELECT Id_Gasto, sum(Importe) as Importe FROM tmp.balance_desglose WHERE year = %v GROUP BY Id_Gasto ) sub on sub.Id_Gasto = b.Id_Gasto SET %t = - Importe; ', YEAR(CURDATE()) - intYEARS, YEAR(CURDATE()) - intYEARS ); CALL util.exec (v_sql); END WHILE; -- Añadimos las ventas SET v_sql = sql_printf ( ' UPDATE tmp.balance b JOIN ( SELECT sum(IF(year = %v, venta, 0)) as y2 , sum(IF(year = %v, venta, 0)) as y1 , sum(IF(year = %v, venta, 0)) as y0 , c.Gasto FROM bs.ventas_contables c join tmp.empresas_receptoras er on er.empresa_id = c.empresa_id WHERE month BETWEEN %v AND %v GROUP BY c.Gasto ) sub ON sub.Gasto = b.Id_Gasto SET %t = IFNULL(%t,0) + sub.y2 , %t = IFNULL(%t,0) + sub.y1 , %t = IFNULL(%t,0) + sub.y0 ; ', YEAR(CURDATE()) - 2, YEAR(CURDATE()) - 1, YEAR(CURDATE()), vStartingMonth, vEndingMonth, YEAR(CURDATE()) - 2, YEAR(CURDATE()) - 2, YEAR(CURDATE()) - 1, YEAR(CURDATE()) - 1, YEAR(CURDATE()), YEAR(CURDATE()) ); CALL util.exec (v_sql); -- Ventas intra grupo IF NOT vInterGroupSalesIncluded THEN SELECT lft, rgt INTO @grupoLft, @grupoRgt FROM tmp.balance b WHERE TRIM(b.`name`) = 'Grupo'; DELETE FROM tmp.balance WHERE lft BETWEEN @grupoLft AND @grupoRgt; END IF; -- Rellenamos el valor de los padres con la suma de los hijos DROP TEMPORARY TABLE IF EXISTS tmp.balance_aux; CREATE TEMPORARY TABLE tmp.balance_aux SELECT * FROM tmp.balance; UPDATE tmp.balance b JOIN ( select b1.id, b1.name, sum(b2.`2015`) as `2015`, sum(b2.`2016`) as `2016`, sum(b2.`2017`) as `2017` from tmp.nest b1 join tmp.balance_aux b2 on b2.lft between b1.lft and b1.rgt group by b1.id) sub on sub.id = b.id SET b.`2015` = sub.`2015`, b.`2016` = sub.`2016`, b.`2017` = sub.`2017` ; SELECT *, concat('',ifnull(Id_Gasto,'')) as newgasto FROM tmp.balance; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `base_ticket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `base_ticket`(IN Id_Ticket INT) BEGIN SELECT red(SUM(Cantidad * Preu * (100 - Descuento) / 100)) AS base FROm Movimientos m INNER JOIN Tickets t USING (Id_Ticket) WHERE t.Id_Ticket = Id_Ticket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_available_` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_`( vDate DATE, vAddress INT, vAgency INT) BEGIN /** * Calcula el disponible para un conjunto de almacenes y fechas * devueltos por el procedimiento travel_tree() * * @table t_bionic_available Tabla con los ids de cache **/ DECLARE vAvailableCalc INT; DECLARE vShipment DATE; DECLARE vAgencyId INT; DECLARE vWh INT; DECLARE vDone BOOL; DECLARE cTravelTree CURSOR FOR SELECT warehouse_id, Fecha_envio FROM travel_tree; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; -- Establecemos los almacenes y las fechas que van a entrar al disponible SELECT agency_id INTO vAgencyId FROM Agencias WHERE Id_Agencia = vAgency; CALL travel_tree (vDate, vAddress, vAgencyId); DROP TEMPORARY TABLE IF EXISTS t_bionic_available; CREATE TEMPORARY TABLE t_bionic_available( calc_id INT UNSIGNED, PRIMARY KEY (calc_id) ) ENGINE = MEMORY; OPEN cTravelTree; l: LOOP SET vDone = FALSE; FETCH cTravelTree INTO vWh, vShipment; IF vDone THEN LEAVE l; END IF; CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWh, vShipment); INSERT IGNORE INTO t_bionic_available SET calc_id = vAvailableCalc; END LOOP; CLOSE cTravelTree; DROP TEMPORARY TABLE travel_tree; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_available_articlelist` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_articlelist`(IN strART VARCHAR(50) , IN minMED DOUBLE , IN maxMED DOUBLE , IN minPVP DOUBLE , IN maxPVP DOUBLE) BEGIN DECLARE intSPACE_POS INT; DECLARE strSUBTR VARCHAR(50); DECLARE strFILTER VARCHAR(500); DECLARE v_sql TEXT; DROP TEMPORARY TABLE IF EXISTS articlelist; CREATE TEMPORARY table articlelist (Id_Article INT(11) PRIMARY KEY) ENGINE = INNODB; -- Arreglos SET minMED = IFNULL(minMED,0); SET minMED = IF(minMED = 0,0.01, minMED); SET maxMED = IFNULL(maxMED,9990); SET maxMED = IF(maxMED = 0,9990, maxMED); SET minPVP = IFNULL(minPVP,0); SET minPVP = IF(minPVP = 0, 0.01, minPVP); SET maxPVP = IFNULL(maxPVP,9990); SET maxPVP = IF(maxPVP = 0, 9990, maxPVP); -- ARTICLE SET strART = TRIM(strART); IF ASCII(strART) BETWEEN 48 AND 57 THEN INSERT INTO articlelist(Id_Article) VALUES(CAST(strART AS UNSIGNED)); ELSE SET strFILTER = 'TRUE '; WHILE LENGTH(strART) > 0 DO SET intSPACE_POS = POSITION(' ' IN strART) ; IF intSPACE_POS = 0 THEN SET strFILTER = CONCAT(strFILTER, ' AND CONCAT(a.Id_Article,Article,t.Tipo) LIKE "%',strART,'%"'); SET strART = ''; ELSE SET strFILTER = CONCAT(strFILTER, ' AND CONCAT(a.Id_Article,Article,t.Tipo) LIKE "%',LEFT(strART,intSPACE_POS - 1),'%"'); SET strART = TRIM(SUBSTRING(strART, intSPACE_POS)); END IF; END WHILE; if minpvp = 0.01 and maxpvp = 9990 then SET v_sql = sql_printf ( ' REPLACE vn2008.articlelist SELECT a.Id_Article FROM vn2008.Articles a LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id WHERE %s AND Medida BETWEEN %v AND %v; ' ,strFILTER ,minMED ,maxMED); else SET v_sql = sql_printf ( ' REPLACE vn2008.articlelist SELECT a.Id_Article FROM vn2008.Articles a LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id JOIN ( SELECT DISTINCT Id_Article FROM vn2008.Movimientos m JOIN vn2008.Tickets t using(Id_Ticket) JOIN vn2008.Clientes c using(Id_Cliente) WHERE Fecha > CURDATE() - INTERVAL 4 DAY AND Preu BETWEEN %v AND %v AND c.invoice <> 0 ) v on v.Id_Article = a.Id_Article WHERE %s AND Medida BETWEEN %v AND %v; ' ,minPVP ,maxPVP ,strFILTER ,minMED ,maxMED); end if; CALL util.exec (v_sql); END IF; -- SELECT Id_Article, Article, Medida FROM Articles join articlelist using(Id_Article); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_available_items_` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_items_`(v_date DATE, -- fecha de recepcion de mercancia v_consigna INT, v_agencia INT) BEGIN /** * Crea una tabla con los identificadores de los articulos disponibles. * * @table t_bionic_available_items **/ CALL bionic_available_ (v_date, v_consigna, v_agencia); DROP TEMPORARY TABLE IF EXISTS t_bionic_available_items; CREATE TEMPORARY TABLE t_bionic_available_items (INDEX (Id_Article)) ENGINE = MEMORY SELECT a.Id_Article, a.Article FROM `cache`.available c JOIN Articles a ON c.item_id = a.Id_Article JOIN t_bionic_available ba ON c.calc_id = ba.calc_id WHERE c.available GROUP BY a.Article; DROP TEMPORARY TABLE t_bionic_available; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_available_single` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_single`(IN v_wh TINYINT, IN v_date DATETIME, IN id_single INT, IN refresh TINYINT) BEGIN DECLARE intcalc_id INT; call cache.available_refresh(intcalc_id,refresh, v_wh,v_date); SELECT available AS minimo FROM cache.available WHERE calc_id = intcalc_id AND item_id = id_single ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_available_types_` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_types_`( v_date DATE, -- fecha de recepcion de mercancia v_consigna INT, v_agencia INT) BEGIN /** * Calcula los tipos disponibles para un conjunto de almacenes * y fechas devueltos por el procedimiento travel_tree() * * @table t_bionic_available_types Tabla con los tipos disponibles **/ CALL bionic_available_(v_date, v_consigna, v_agencia); DROP TEMPORARY TABLE IF EXISTS t_bionic_available_types; CREATE TEMPORARY TABLE t_bionic_available_types (INDEX (tipo_id)) ENGINE = MEMORY SELECT a.tipo_id, t.Tipo FROM `cache`.available c JOIN Articles a ON c.item_id = a.Id_Article JOIN Tipos t ON t.tipo_id = a.tipo_id JOIN t_bionic_available ba ON c.calc_id = ba.calc_id WHERE c.available > 0 -- JGF 2016-03-23 en el bionic no apareixen negatius, els tipos que no continguen disponible, tampoc els volem mostrar AND t.Orden != 0 GROUP BY t.tipo_id; DROP TEMPORARY TABLE t_bionic_available; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_available_types_filter` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_types_filter`( v_date DATE, v_consigna INT, v_agencia INT, v_filter TEXT) BEGIN /** * Este procedimiento devuelve una tabla t_bionic_available_types * que debe de ser borrar por quien la llame, y se conecta con la tabla articlelist * que tambien hay que eliminar. * * @param vDatefecha de recepcion de mercancia * @table t_bionic_available_types */ DECLARE v_sql TEXT; DECLARE v_list TEXT; SET v_list = ''; SET v_filter = IFNULL(v_filter,' TRUE'); CALL bionic_available_(v_date, v_consigna, v_agencia); -- Inroducimos los valores en una tabla temporal DROP TEMPORARY TABLE IF EXISTS t_bionic_available_types; CALL check_table_existence('articlelist'); IF @table_exists THEN SET v_list = 'JOIN vn2008.articlelist AL ON AL.Id_Article = a.Id_Article '; END IF; SET v_sql = sql_printf ( ' CREATE TEMPORARY TABLE t_bionic_available_types SELECT a.tipo_id, Tipo, reino, count(*) as item_count FROM `cache`.available c JOIN vn2008.Articles a ON c.item_id = a.Id_Article JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id JOIN vn2008.reinos r ON r.id = t.reino_id JOIN vn2008.t_bionic_available ba ON c.calc_id = ba.calc_id %s WHERE c.available > 0 AND %s GROUP BY a.tipo_id; ' , v_list , v_filter); CALL sql_query (v_sql); DROP TEMPORARY TABLE t_bionic_available; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc`( vDate DATE, -- Fecha de recepcion de mercancia vAddress INT, vAgency INT) proc: BEGIN DECLARE vAvailableCalc INT; DECLARE vShipment DATE; DECLARE vAgencyId INT; DECLARE vCustomer INT; DECLARE vWh SMALLINT; DECLARE vDone BOOL; DECLARE cTravelTree CURSOR FOR SELECT warehouse_id, Fecha_envio FROM travel_tree; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DROP TEMPORARY TABLE IF EXISTS tmp.bionic_item, tmp.bionic_component, tmp.bionic_lot, tmp.bionic_price; -- Establece los almacenes y las fechas que van a entrar al disponible SELECT agency_id INTO vAgencyId FROM Agencias WHERE Id_Agencia = vAgency; SELECT Id_Cliente INTO vCustomer FROM Consignatarios WHERE Id_Consigna = vAddress; CALL travel_tree(vDate, vAddress, vAgencyId); -- Crea la tabla temporal que almacenará los lotes CREATE TEMPORARY TABLE tmp.bionic_lot LIKE template_bionic_lot; OPEN cTravelTree; l: LOOP SET vDone = FALSE; FETCH cTravelTree INTO vWh, vShipment; IF vDone THEN LEAVE l; END IF; CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWh, vShipment); CALL item_last_buy_ (vWh, vShipment); INSERT INTO tmp.bionic_lot (warehouse_id, item_id, available, buy_id) SELECT vWh, i.item_id, IFNULL(i.available, 0), ilb.buy_id FROM `cache`.available i JOIN tmp.bionic_calc br ON br.item_id = i.item_id LEFT JOIN Articles a ON a.Id_Article = i.item_id LEFT JOIN t_item_last_buy ilb ON ilb.item_id = i.item_id WHERE i.calc_id = vAvailableCalc AND a.Id_Article != 100 AND i.available > 0; DROP TEMPORARY TABLE t_item_last_buy; END LOOP; CLOSE cTravelTree; CALL bionic_calc_component(vAddress, vAgency); CREATE TEMPORARY TABLE tmp.bionic_item ENGINE = MEMORY SELECT b.item_id, SUM(b.available) available, p.name producer, a.Article item, a.Medida size, a.Tallos stems, a.Categoria category, a.Color, a.Foto image, o.Abreviatura origin, bl.min_price price FROM tmp.bionic_lot b JOIN Articles a ON b.item_id = a.Id_Article LEFT JOIN producer p ON p.producer_id = a.producer_id AND p.visible JOIN Origen o ON o.id = a.id_origen JOIN ( SELECT MIN(price) min_price, item_id FROM tmp.bionic_price GROUP BY item_id ) bl ON bl.item_id = b.item_id GROUP BY b.item_id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_clon` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_clon`(IN v_ticket BIGINT) BEGIN /* Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo */ DECLARE v_shipment DATE; DECLARE v_customer INT; DECLARE v_wh SMALLINT; DECLARE v_agencia INT; DECLARE v_consigna INT; DECLARE v_landing DATE; DECLARE v_agency INT; REPLACE order_Tickets(order_id,Id_Ticket) VALUES(48, v_ticket); SELECT t.Id_Cliente , t.warehouse_id, date(t.Fecha), t.Id_Consigna, t.Id_Agencia, t.landing, a.agency_id INTO v_customer, v_wh, v_shipment, v_consigna, v_agencia, v_landing, v_agency FROM vn2008.Agencias a JOIN vn2008.Tickets t ON t.Id_Agencia = a.Id_Agencia WHERE t.Id_Ticket = v_ticket; DROP TEMPORARY TABLE IF EXISTS travel_tree; CREATE TEMPORARY TABLE travel_tree ENGINE = MEMORY SELECT v_wh warehouse_id, v_shipment Fecha_envio, v_landing Fecha_recepcion; CALL item_last_buy_ (v_wh, v_shipment); -- rellena la tabla t_item_last_buy con la ultima compra DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; CREATE TEMPORARY TABLE tmp.bionic_lot SELECT v_wh warehouse_id,NULL available, m.Id_Article item_id,ilb.buy_id FROM Movimientos m LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article WHERE m.Id_Ticket = v_ticket GROUP BY m.Id_Article; CALL bionic_calc_component(v_consigna,v_agencia); -- Bionizamos lineas con Preu = 0 DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m JOIN Tickets t on t.Id_Ticket = m.Id_Ticket WHERE m.Id_Ticket = v_ticket AND Preu = 0; CALL bionic_movement_update(1); -- Bionizamos lineas con Preu > 0 DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m JOIN Tickets t on t.Id_Ticket = m.Id_Ticket WHERE m.Id_Ticket = v_ticket AND Preu > 0; CALL bionic_movement_update(6); IF v_landing IS NULL THEN CALL travel_tree_shipment(v_shipment, v_consigna, v_agency,v_wh); UPDATE Tickets t JOIN travel_tree_shipment tts ON t.warehouse_id = tts.warehouse_id SET t.landing = tts.landing WHERE Id_Ticket = v_ticket; END IF; -- Log call Ditacio(v_ticket ,'Bioniza Ticket' ,'T' , 20 , 'proc bionic_calc_clon' , NULL); -- Limpieza DROP TEMPORARY TABLE t_item_last_buy; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_clonkk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_clonkk`(IN v_ticket BIGINT) BEGIN /* Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo */ DECLARE v_shipment DATE; DECLARE v_customer INT; DECLARE v_wh SMALLINT; DECLARE v_agencia INT; DECLARE v_consigna INT; DECLARE v_landing DATE; REPLACE order_Tickets(order_id,Id_Ticket) VALUES(48, v_ticket); SELECT Id_Cliente , t.warehouse_id, date(t.Fecha), Id_Consigna , Id_Agencia INTO v_customer ,v_wh, v_shipment , v_consigna , v_agencia FROM vn2008.Agencias a JOIN vn2008.Tickets t using(Id_Agencia) WHERE Id_Ticket = v_ticket; DROP TEMPORARY TABLE IF EXISTS travel_tree; CREATE TEMPORARY TABLE travel_tree ENGINE = MEMORY SELECT v_wh warehouse_id, v_shipment Fecha_envio, v_landing Fecha_recepcion; CALL item_last_buy_ (v_wh, v_shipment); -- rellena la tabla t_item_last_buy con la ultima compra DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; CREATE TEMPORARY TABLE tmp.bionic_lot SELECT v_wh warehouse_id,NULL available, m.Id_Article item_id,ilb.buy_id FROM Movimientos m LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article WHERE m.Id_Ticket = v_ticket GROUP BY m.Id_Article; CALL bionic_calc_component(v_consigna,v_agencia); -- Bionizamos lineas con Preu = 0 DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m JOIN Tickets t on t.Id_Ticket = m.Id_Ticket WHERE m.Id_Ticket = v_ticket AND Preu = 0; CALL bionic_movement_update(1); -- Bionizamos lineas con Preu > 0 DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m JOIN Tickets t on t.Id_Ticket = m.Id_Ticket WHERE m.Id_Ticket = v_ticket AND Preu > 0; CALL bionic_movement_update(6); -- Log call Ditacio(v_ticket ,'Bioniza Ticket' ,'T' , 20 , 'proc bionic_calc_clon' , NULL); -- Limpieza DROP TEMPORARY TABLE t_item_last_buy; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_component` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_component`( -- v_date DATE, -- fecha de recepcion de mercancia v_consigna INT, v_agencia INT) proc: BEGIN DECLARE v_customer INT; DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.3; DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT DEFAULT 138000; -- DECLARE vValorEmbolsado DOUBLE DEFAULT 0.04; SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna; SET @rate2 := 0; SET @rate3 := 0; DROP TEMPORARY TABLE IF EXISTS t_bionic_temp; CREATE TEMPORARY TABLE t_bionic_temp (PRIMARY KEY (item_id,warehouse_id)) ENGINE = MEMORY SELECT b.item_id, b.warehouse_id,available, IF((@rate2 := IFNULL(pf.rate_2,c.Tarifa2)) < a.PVP AND a.`Min`, a.PVP, @rate2) * 1.0 rate_2, IF((@rate3 := IFNULL(pf.rate_3,c.Tarifa3)) < a.PVP AND a.`Min`, a.PVP, @rate3) * 1.0 rate_3, ifnull(pf.rate_3,0) AS min_price, IFNULL(pf.Packing,c.Packing) packing, IFNULL(pf.grouping,c.grouping) grouping, ABS(IFNULL(pf.caja,c.caja)) box, b.buy_id, a.tipo_id FROM tmp.bionic_lot b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra JOIN vn2008.Articles a ON b.item_id = a.Id_Article JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id LEFT JOIN vn2008.reinos r ON r.id = t.reino_id LEFT JOIN vn2008.PreciosEspeciales p ON a.Id_Article = p.Id_Article AND p.Id_Cliente = v_customer LEFT JOIN ( SELECT * FROM ( SELECT p.item_id, p.grouping, p.Packing,p.caja, p.rate_2, p.rate_3, t.warehouse_id FROM vn2008.price_fixed p JOIN vn2008.travel_tree t ON t.warehouse_id = p.warehouse_id OR p.warehouse_id = 0 WHERE t.Fecha_envio BETWEEN p.date_start AND p.date_end ORDER BY p.item_id, p.warehouse_id DESC ) t GROUP BY item_id, warehouse_id ) pf ON pf.item_id = b.item_id AND pf.warehouse_id = b.warehouse_id -- descartamos articulos con coste menor de 0.01 WHERE Costefijo + Portefijo + Embalajefijo + Comisionfija > 0.01 AND r.display <> 0; -- Creamos la tabla tmp.bionic_component DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component; CREATE TEMPORARY TABLE tmp.bionic_component LIKE template_bionic_component; -- Componentes del precio, valores absolutos INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) SELECT b.warehouse_id, b.item_id, 29, rate_3 - Costefijo - Portefijo - Embalajefijo - Comisionfija FROM t_bionic_temp b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) SELECT b.warehouse_id, b.item_id, 28, Costefijo + Portefijo + Embalajefijo + Comisionfija FROM t_bionic_temp b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; -- Ahora los valores en funcion de la base DROP TEMPORARY TABLE IF EXISTS t_components_base; CREATE TEMPORARY TABLE t_components_base SELECT bc.item_id, ROUND(SUM(cost), 4) AS base, bc.warehouse_id FROM tmp.bionic_component bc GROUP BY bc.item_id,warehouse_id; -- La ratio se calcula teniendo en cuenta el valor de las reclamaciones y el saldo de greuge INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, item_id, 17, ROUND(base * LEAST(recobro,0.25), 3) FROM t_components_base cb JOIN bi.claims_ratio ON Id_Cliente = v_customer WHERE recobro > 0.009; -- PAK 2016-08-31 Componente de maná automático, en función del maná acumulado por el comercial. INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, item_id, 39, ROUND(base * prices_modifier_rate, 3) as manaAuto FROM t_components_base cb JOIN Clientes c on c.Id_Cliente = v_customer JOIN bs.mana_spellers ms ON c.Id_Trabajador = ms.Id_Trabajador WHERE ms.prices_modifier_activated HAVING manaAuto <> 0 ; /* -- Vendedor variable INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, item_id, Id_Componente, IFNULL(ROUND(base * tax,4), 0) FROM t_components_base cb JOIN bi.tarifa_componentes WHERE tarifa_componentes_series_id = 2 and IFNULL(tax, 0) > 0; */ -- ******* Inicio Bloque para componentes con tarifa_class diferente de NULL -- Descuento por ultimas unidades INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, b.item_id, Id_Componente, GREATEST(IFNULL(ROUND(base * tax,4), 0), b.min_price - b.rate_3) FROM t_components_base cb JOIN bi.tarifa_componentes JOIN t_bionic_temp b ON b.item_id = cb.item_id LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id WHERE Id_Componente = 32 AND tax <> 0 AND b.min_price < b.rate_3 AND PrecioEspecial IS NULL; -- Incremento por paquete suelto INSERT INTO tmp.bionic_component SELECT b.warehouse_id, b.item_id, 22, rate_2 - rate_3 FROM t_bionic_temp b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id WHERE PrecioEspecial IS NULL; -- ******* Fin Bloque para componentes con tarifa_class diferente de NULL -- Reparto INSERT INTO tmp.bionic_component SELECT b.warehouse_id , b.item_id , 15 , COEFICIENTE_DE_INFLACION_GENERAL * ROUND( r.cm3 * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) * IFNULL(az.price * az.inflacion ,50) / VOLUMEN_CAJA_VERDNATURA, 4 ) cost FROM t_bionic_temp b JOIN vn2008.Articles art ON art.Id_Article = b.item_id JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id HAVING cost <> 0; -- Reparto bonificado INSERT INTO tmp.bionic_component SELECT b.warehouse_id , b.item_id , 41 , COEFICIENTE_DE_INFLACION_GENERAL * ROUND( r.cm3 * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) * awb.bonus * az.inflacion / VOLUMEN_CAJA_VERDNATURA, 4 ) cost FROM t_bionic_temp b JOIN vn2008.Articles art ON art.Id_Article = b.item_id JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id JOIN vn2008.agency_weekday_bonus awb ON awb.warehouse_id = az.warehouse_id AND awb.zona = az.zona AND a.agency_id = awb.agency_id LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id JOIN vn2008.travel_tree t ON t.warehouse_id = awb.warehouse_id AND weekday(t.Fecha_recepcion) = awb.weekDay HAVING cost <> 0; -- PAK 12-05-2015 -- EMBOLSADO IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = v_consigna) THEN -- IF v_consigna IN (13690, 3402, 5661, 4233) THEN INSERT INTO tmp.bionic_component SELECT b.warehouse_id, b.item_id, 38, ap.packagingValue cost FROM t_bionic_temp b JOIN vn.addressForPackaging ap WHERE ap.addressFk = v_consigna; END IF; -- JGF 14-08-2015 -- Modificacion de precio por dia de preparacion del pedido INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, cb.item_id, 14, cb.base * (IFNULL(pe.percentage,pp.percentage)/100) FROM t_components_base cb JOIN vn2008.travel_tree tt ON tt.warehouse_id = cb.warehouse_id LEFT JOIN vn2008.preparation_percentage pp ON pp.week_day = weekday(tt.Fecha_envio) AND cb.warehouse_id = IFNULL(pp.warehouse_id,cb.warehouse_id) LEFT JOIN vn2008.preparation_exception pe ON pe.exception_day = tt.Fecha_envio AND cb.warehouse_id = IFNULL(pe.warehouse_id,cb.warehouse_id) WHERE IFNULL(pe.percentage,pp.percentage); -- Creamos la tabla tmp.bionic_component_copy por que mysql no puede reabrir una tabla temporal DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component_copy; CREATE TEMPORARY TABLE tmp.bionic_component_copy SELECT * FROM tmp.bionic_component; -- JGF 19-01-2016 -- Precios especiales INSERT INTO tmp.bionic_component SELECT b.warehouse_id, b.item_id, 10, pe.PrecioEspecial - SUM(cost) sum_cost FROM tmp.bionic_component_copy b JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id WHERE t.tarifa_class IS NULL GROUP BY b.item_id, b.warehouse_id HAVING ABS(sum_cost) > 0.001; -- Lotes DROP TEMPORARY TABLE IF EXISTS t_component_sum; CREATE TEMPORARY TABLE t_component_sum (INDEX (item_id, warehouse_id)) ENGINE = MEMORY SELECT SUM(cost) sum_cost, b.item_id, b.warehouse_id, t.tarifa_class FROM tmp.bionic_component b JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente GROUP BY b.item_id, b.warehouse_id, t.tarifa_class; -- ***** Inicia Modifica t_bionic_rate las diferentes tarifas -- Tarifa por unidad minima DROP TEMPORARY TABLE IF EXISTS t_bionic_rate; CREATE TEMPORARY TABLE t_bionic_rate ENGINE = MEMORY SELECT b.warehouse_id, item_id, 1 rate, IF(box = 1, grouping, 1) grouping, SUM(sum_cost) price FROM t_bionic_temp b JOIN t_component_sum cs USING(item_id, warehouse_id) WHERE IFNULL(cs.tarifa_class,1) = 1 AND box < 2 AND (packing > grouping or box = 0) GROUP BY warehouse_id, item_id; -- Tarifa por caja INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, grouping, price) SELECT b.warehouse_id, item_id, 2 rate, packing grouping, SUM(sum_cost) price FROM t_bionic_temp b JOIN t_component_sum cs USING(item_id, warehouse_id) WHERE available IS NULL OR (IFNULL(cs.tarifa_class,2) = 2 AND packing > 0 AND available >= packing) GROUP BY warehouse_id, item_id; -- Tarifa para toda la cantidad disponible INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, grouping, price) SELECT b.warehouse_id, item_id, 3 rate, available grouping, SUM(sum_cost) price FROM t_bionic_temp b JOIN t_component_sum cs USING(item_id, warehouse_id) WHERE IFNULL(cs.tarifa_class,3) = 3 GROUP BY warehouse_id, item_id; -- ***** Fin Modifica t_bionic_rate las diferentes tarifas DROP TEMPORARY TABLE IF EXISTS tmp.bionic_price; CREATE TEMPORARY TABLE tmp.bionic_price LIKE template_bionic_price; INSERT INTO tmp.bionic_price (warehouse_id, item_id, rate, grouping, price) SELECT * FROM ( SELECT * FROM t_bionic_rate ORDER BY price ) t GROUP BY item_id, warehouse_id, grouping; DROP TEMPORARY TABLE IF EXISTS tmp.travel_tree; CREATE TEMPORARY TABLE tmp.travel_tree ENGINE = MEMORY SELECT * FROM travel_tree; -- Limpieza DROP TEMPORARY TABLE travel_tree; DROP TEMPORARY TABLE t_bionic_temp; DROP TEMPORARY TABLE t_component_sum; DROP TEMPORARY TABLE t_components_base; DROP TEMPORARY TABLE t_bionic_rate; DROP TEMPORARY TABLE tmp.bionic_component_copy; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_component_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_component_beta`( -- v_date DATE, -- fecha de recepcion de mercancia v_consigna INT, v_agencia INT) proc: BEGIN DECLARE v_customer INT; DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.3; DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT DEFAULT 138000; -- DECLARE vValorEmbolsado DOUBLE DEFAULT 0.04; SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna; SET @rate2 := 0; SET @rate3 := 0; DROP TEMPORARY TABLE IF EXISTS t_bionic_temp; CREATE TEMPORARY TABLE t_bionic_temp (PRIMARY KEY (item_id,warehouse_id)) ENGINE = MEMORY SELECT b.item_id, b.warehouse_id,available, IF((@rate2 := IFNULL(pf.rate_2,c.Tarifa2)) < a.PVP AND a.`Min`, a.PVP, @rate2) * 1.0 rate_2, IF((@rate3 := IFNULL(pf.rate_3,c.Tarifa3)) < a.PVP AND a.`Min`, a.PVP, @rate3) * 1.0 rate_3, ifnull(pf.rate_3,0) AS min_price, IFNULL(pf.Packing,c.Packing) packing, IFNULL(pf.grouping,c.grouping) grouping, ABS(IFNULL(pf.caja,c.caja)) box, b.buy_id, a.tipo_id FROM tmp.bionic_lot b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra JOIN vn2008.Articles a ON b.item_id = a.Id_Article JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id LEFT JOIN vn2008.reinos r ON r.id = t.reino_id LEFT JOIN vn2008.PreciosEspeciales p ON a.Id_Article = p.Id_Article AND p.Id_Cliente = v_customer LEFT JOIN ( SELECT * FROM ( SELECT p.item_id, p.grouping, p.Packing,p.caja, p.rate_2, p.rate_3, t.warehouse_id FROM vn2008.price_fixed p JOIN vn2008.travel_tree t ON t.warehouse_id = p.warehouse_id OR p.warehouse_id = 0 WHERE t.Fecha_envio BETWEEN p.date_start AND p.date_end ORDER BY p.item_id, p.warehouse_id DESC ) t GROUP BY item_id, warehouse_id ) pf ON pf.item_id = b.item_id AND pf.warehouse_id = b.warehouse_id -- descartamos articulos con coste menor de 0.01 WHERE Costefijo + Portefijo + Embalajefijo + Comisionfija > 0.01 AND r.display <> 0; -- Creamos la tabla tmp.bionic_component DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component; CREATE TEMPORARY TABLE tmp.bionic_component LIKE template_bionic_component; -- Componentes del precio, valores absolutos INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) SELECT b.warehouse_id, b.item_id, 29, rate_3 - Costefijo - Portefijo - Embalajefijo - Comisionfija FROM t_bionic_temp b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) SELECT b.warehouse_id, b.item_id, 28, Costefijo + Portefijo + Embalajefijo + Comisionfija FROM t_bionic_temp b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; -- Ahora los valores en funcion de la base DROP TEMPORARY TABLE IF EXISTS t_components_base; CREATE TEMPORARY TABLE t_components_base SELECT bc.item_id, ROUND(SUM(cost), 4) AS base, bc.warehouse_id FROM tmp.bionic_component bc GROUP BY bc.item_id,warehouse_id; -- La ratio se calcula teniendo en cuenta el valor de las reclamaciones y el saldo de greuge INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, item_id, 17, ROUND(base * LEAST(recobro,0.25), 3) FROM t_components_base cb JOIN bi.claims_ratio ON Id_Cliente = v_customer WHERE recobro > 0.009; -- PAK 2016-08-31 Componente de maná automático, en función del maná acumulado por el comercial. INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, item_id, 39, ROUND(base * prices_modifier_rate, 3) as manaAuto FROM t_components_base cb JOIN Clientes c on c.Id_Cliente = v_customer JOIN bs.mana_spellers ms ON c.Id_Trabajador = ms.Id_Trabajador WHERE ms.prices_modifier_activated HAVING manaAuto <> 0 ; /* -- Vendedor variable INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, item_id, Id_Componente, IFNULL(ROUND(base * tax,4), 0) FROM t_components_base cb JOIN bi.tarifa_componentes WHERE tarifa_componentes_series_id = 2 and IFNULL(tax, 0) > 0; */ -- ******* Inicio Bloque para componentes con tarifa_class diferente de NULL -- Descuento por ultimas unidades INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, b.item_id, Id_Componente, GREATEST(IFNULL(ROUND(base * tax,4), 0), b.min_price - b.rate_3) FROM t_components_base cb JOIN bi.tarifa_componentes JOIN t_bionic_temp b ON b.item_id = cb.item_id LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id WHERE Id_Componente = 32 AND tax <> 0 AND b.min_price < b.rate_3 AND PrecioEspecial IS NULL; -- Incremento por paquete suelto INSERT INTO tmp.bionic_component SELECT b.warehouse_id, b.item_id, 22, rate_2 - rate_3 FROM t_bionic_temp b JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id WHERE PrecioEspecial IS NULL; -- ******* Fin Bloque para componentes con tarifa_class diferente de NULL -- Reparto INSERT INTO tmp.bionic_component SELECT b.warehouse_id , b.item_id , 15 , COEFICIENTE_DE_INFLACION_GENERAL * ROUND( r.cm3 * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) * az.price * az.inflacion / VOLUMEN_CAJA_VERDNATURA, 4 ) cost FROM t_bionic_temp b JOIN vn2008.Articles art ON art.Id_Article = b.item_id JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id HAVING cost <> 0; -- Reparto bonificado INSERT INTO tmp.bionic_component SELECT b.warehouse_id , b.item_id , 41 , COEFICIENTE_DE_INFLACION_GENERAL * ROUND( r.cm3 * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) * awb.bonus * az.inflacion / VOLUMEN_CAJA_VERDNATURA, 4 ) cost FROM t_bionic_temp b JOIN vn2008.Articles art ON art.Id_Article = b.item_id JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id JOIN vn2008.agency_weekday_bonus awb ON awb.warehouse_id = az.warehouse_id AND awb.zona = az.zona AND a.agency_id = awb.agency_id LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id JOIN vn2008.travel_tree t ON t.warehouse_id = awb.warehouse_id AND weekday(t.Fecha_recepcion) = awb.weekDay HAVING cost <> 0; -- PAK 12-05-2015 -- EMBOLSADO IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = v_consigna) THEN -- IF v_consigna IN (13690, 3402, 5661, 4233) THEN INSERT INTO tmp.bionic_component SELECT b.warehouse_id, b.item_id, 38, ap.packagingValue cost FROM t_bionic_temp b JOIN vn.addressForPackaging ap WHERE ap.addressFk = v_consigna; END IF; -- JGF 14-08-2015 -- Modificacion de precio por dia de preparacion del pedido INSERT INTO tmp.bionic_component SELECT cb.warehouse_id, cb.item_id, 14, cb.base * (IFNULL(pe.percentage,pp.percentage)/100) FROM t_components_base cb JOIN vn2008.travel_tree tt ON tt.warehouse_id = cb.warehouse_id LEFT JOIN vn2008.preparation_percentage pp ON pp.week_day = weekday(tt.Fecha_envio) AND cb.warehouse_id = IFNULL(pp.warehouse_id,cb.warehouse_id) LEFT JOIN vn2008.preparation_exception pe ON pe.exception_day = tt.Fecha_envio AND cb.warehouse_id = IFNULL(pe.warehouse_id,cb.warehouse_id) WHERE IFNULL(pe.percentage,pp.percentage); -- Creamos la tabla tmp.bionic_component_copy por que mysql no puede reabrir una tabla temporal DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component_copy; CREATE TEMPORARY TABLE tmp.bionic_component_copy SELECT * FROM tmp.bionic_component; -- JGF 19-01-2016 -- Precios especiales INSERT INTO tmp.bionic_component SELECT b.warehouse_id, b.item_id, 10, pe.PrecioEspecial - SUM(cost) sum_cost FROM tmp.bionic_component_copy b JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id WHERE t.tarifa_class IS NULL GROUP BY b.item_id, b.warehouse_id HAVING ABS(sum_cost) > 0.001; -- Lotes DROP TEMPORARY TABLE IF EXISTS t_component_sum; CREATE TEMPORARY TABLE t_component_sum (INDEX (item_id, warehouse_id)) ENGINE = MEMORY SELECT SUM(cost) sum_cost, b.item_id, b.warehouse_id, t.tarifa_class FROM tmp.bionic_component b JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente GROUP BY b.item_id, b.warehouse_id, t.tarifa_class; -- ***** Inicia Modifica t_bionic_rate las diferentes tarifas -- Tarifa por unidad minima DROP TEMPORARY TABLE IF EXISTS t_bionic_rate; CREATE TEMPORARY TABLE t_bionic_rate ENGINE = MEMORY SELECT b.warehouse_id, item_id, 1 rate, IF(box = 1, grouping, 1) grouping, SUM(sum_cost) price FROM t_bionic_temp b JOIN t_component_sum cs USING(item_id, warehouse_id) WHERE IFNULL(cs.tarifa_class,1) = 1 AND box < 2 AND (packing > grouping or box = 0) GROUP BY warehouse_id, item_id; -- Tarifa por caja INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, grouping, price) SELECT b.warehouse_id, item_id, 2 rate, packing grouping, SUM(sum_cost) price FROM t_bionic_temp b JOIN t_component_sum cs USING(item_id, warehouse_id) WHERE available IS NULL OR (IFNULL(cs.tarifa_class,2) = 2 AND packing > 0 AND available >= packing) GROUP BY warehouse_id, item_id; -- Tarifa para toda la cantidad disponible INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, grouping, price) SELECT b.warehouse_id, item_id, 3 rate, available grouping, SUM(sum_cost) price FROM t_bionic_temp b JOIN t_component_sum cs USING(item_id, warehouse_id) WHERE IFNULL(cs.tarifa_class,3) = 3 GROUP BY warehouse_id, item_id; -- ***** Fin Modifica t_bionic_rate las diferentes tarifas DROP TEMPORARY TABLE IF EXISTS tmp.bionic_price; CREATE TEMPORARY TABLE tmp.bionic_price LIKE template_bionic_price; INSERT INTO tmp.bionic_price (warehouse_id, item_id, rate, grouping, price) SELECT * FROM ( SELECT * FROM t_bionic_rate ORDER BY price ) t GROUP BY item_id, warehouse_id, grouping; DROP TEMPORARY TABLE IF EXISTS tmp.travel_tree; CREATE TEMPORARY TABLE tmp.travel_tree ENGINE = MEMORY SELECT * FROM travel_tree; -- Limpieza DROP TEMPORARY TABLE travel_tree; DROP TEMPORARY TABLE t_bionic_temp; DROP TEMPORARY TABLE t_component_sum; DROP TEMPORARY TABLE t_components_base; DROP TEMPORARY TABLE t_bionic_rate; DROP TEMPORARY TABLE tmp.bionic_component_copy; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_date` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_date`(v_ticket INT) proc: BEGIN /** * Este procedimiento asigna la fecha de llegada correcta a un ticket. * * @param v_ticket Id del ticket **/ DECLARE v_shipment DATE; DECLARE v_agency_id INT; DECLARE v_wh SMALLINT; DECLARE v_province INT; DECLARE v_landing DATE; SELECT agency_id, DATE(Fecha), t.warehouse_id, province_id INTO v_agency_id, v_shipment, v_wh, v_province FROM Tickets t JOIN Consignatarios c ON c.Id_Consigna = t.Id_Consigna JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia WHERE Id_Ticket = v_ticket; SELECT landing INTO v_landing FROM ( SELECT @d := TIMESTAMPADD(DAY, subtract_day, v_shipment), @w := WEEKDAY(@d), IF(week_day IS NOT NULL, TIMESTAMPADD(DAY, (week_day - @w) + IF(@w > week_day, 7, 0), @d), @d) landing /* TIMESTAMPADD(DAY, IFNULL(IF(WEEKDAY(@vdate) > week_day, 7, 0) + week_day - WEEKDAY(@vdate), subtract_day) - CAST(subtract_day AS DECIMAL), @vdate) landing */ FROM agency_hour WHERE warehouse_id = v_wh AND (province_id = v_province OR province_id IS NULL) AND agency_id = v_agency_id ORDER BY (province_id IS NOT NULL) * 3 + (week_day IS NOT NULL) DESC, landing LIMIT 1 ) t; IF v_landing IS NULL THEN SET v_landing = v_shipment; END IF; UPDATE Tickets SET landing = v_landing WHERE Id_Ticket = v_ticket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_movement` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_movement`(IN v_id_mov BIGINT ) proc: BEGIN /* Este procedimiento bioniza una linea de movimiento */ DECLARE v_shipment DATE; DECLARE v_customer INT; DECLARE v_wh SMALLINT; DECLARE v_agencia INT; DECLARE v_consigna INT; DECLARE v_ticket BIGINT; DECLARE v_id_article BIGINT; DECLARE v_landing DATE; DECLARE v_ticket_free BOOLEAN DEFAULT TRUE; SELECT FALSE INTO v_ticket_free FROM Tickets t JOIN Movimientos m ON m.Id_Ticket = t.Id_Ticket LEFT JOIN vn.ticketState ts on ts.ticket = t.Id_Ticket WHERE Id_Movimiento = v_id_mov AND (t.Factura != "" or ( ts.alertLevel > 0 AND m.Preu != 0 ) ) LIMIT 1; SELECT Id_Ticket, Id_Article INTO v_ticket, v_id_article FROM Movimientos WHERE Id_Movimiento = v_id_mov; REPLACE order_Tickets(order_id,Id_Ticket) VALUES(48, v_ticket); SELECT Id_Cliente , t.warehouse_id, date(t.Fecha), Id_Consigna , Id_Agencia INTO v_customer ,v_wh, v_shipment , v_consigna , v_agencia FROM vn2008.Agencias a JOIN vn2008.Tickets t using(Id_Agencia) WHERE Id_Ticket = v_ticket; DROP TEMPORARY TABLE IF EXISTS travel_tree; CREATE TEMPORARY TABLE travel_tree ENGINE = MEMORY SELECT v_wh warehouse_id, v_shipment Fecha_envio, v_landing Fecha_recepcion; CALL item_last_buy_ (v_wh, v_shipment); -- rellena la tabla t_item_last_buy con la ultima compra DELETE FROM t_item_last_buy WHERE item_id != v_id_article; DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; CREATE TEMPORARY TABLE tmp.bionic_lot SELECT v_wh warehouse_id,NULL available, m.Id_Article item_id,ilb.buy_id FROM Movimientos m LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article WHERE m.Id_Movimiento = v_id_mov; CALL bionic_calc_component(v_consigna,v_agencia); DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento,v_wh warehouse_id FROM Movimientos m WHERE m.Id_Movimiento = v_id_mov; CALL bionic_movement_update(IF(v_ticket_free,1,6)); -- si el ticket esta facturado, respeta los precios -- Log call Ditacio(v_ticket ,'Bioniza Linea' ,'T' , 20 , 'proc bionic_calc_movement ' , v_id_mov); -- Limpieza DROP TEMPORARY TABLE t_item_last_buy; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_movement_ok` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_movement_ok`(IN v_ticket BIGINT) BEGIN /* Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo */ DECLARE v_shipment DATE; DECLARE v_customer INT; DECLARE v_wh SMALLINT; DECLARE v_agencia INT; DECLARE v_consigna INT; DECLARE v_landing DATE; REPLACE order_Tickets(order_id,Id_Ticket) VALUES(48, v_ticket); SELECT Id_Cliente , t.warehouse_id, date(t.Fecha), Id_Consigna , Id_Agencia INTO v_customer ,v_wh, v_shipment , v_consigna , v_agencia FROM vn2008.Agencias a JOIN vn2008.Tickets t using(Id_Agencia) WHERE Id_Ticket = v_ticket; DROP TEMPORARY TABLE IF EXISTS travel_tree; CREATE TEMPORARY TABLE travel_tree ENGINE = MEMORY SELECT v_wh warehouse_id, v_shipment Fecha_envio, v_landing Fecha_recepcion; CALL item_last_buy_ (v_wh, v_shipment); -- rellena la tabla t_item_last_buy con la ultima compra DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; CREATE TEMPORARY TABLE tmp.bionic_lot SELECT v_wh warehouse_id,NULL available, m.Id_Article item_id,ilb.buy_id FROM Movimientos m LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article WHERE m.Id_Ticket = v_ticket GROUP BY m.Id_Article; CALL bionic_calc_component(v_consigna,v_agencia); DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m WHERE m.Id_Ticket = v_ticket; CALL bionic_movement_update(1); -- Log call Ditacio(v_ticket ,'Bioniza Lineas OK' ,'T' , 20 , 'proc bionic_calc_movement_ok ' , NULL); -- Limpieza DROP TEMPORARY TABLE t_item_last_buy; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_reverse` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_reverse`( vWarehouse INT, vMargin DECIMAL(10,3), vRetailedPrice DECIMAL(10,3), vM3 DECIMAL(10,3), vConsigna INT, vAgencia INT) proc: BEGIN DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.3; DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT DEFAULT 138000; DECLARE vCost DECIMAL(10,4) DEFAULT 0; DECLARE vCustomer INT; DECLARE vRecovery DECIMAL(10,4) DEFAULT 0; DECLARE vMana DECIMAL(10,4) DEFAULT 0; DECLARE vPort DECIMAL(10,4) DEFAULT 0; SELECT Id_Cliente INTO vCustomer FROM Consignatarios WHERE Id_Consigna = vConsigna; -- Recobro SELECT ROUND(LEAST(recobro,0.25), 3) INTO vRecovery FROM bi.claims_ratio WHERE Id_Cliente = vCustomer AND recobro > 0.009; -- Componente de maná automático, en función del maná acumulado por el comercial. SELECT ROUND(prices_modifier_rate, 3) INTO vMana FROM Clientes c JOIN bs.mana_spellers ms ON c.Id_Trabajador = ms.Id_Trabajador WHERE ms.prices_modifier_activated AND c.Id_Cliente = vCustomer; -- Reparto SELECT COEFICIENTE_DE_INFLACION_GENERAL * ROUND( vM3 * az.price * az.inflacion / VOLUMEN_CAJA_VERDNATURA, 4 ) INTO vPort FROM vn2008.Agencias a JOIN vn2008.Consignatarios c ON c.Id_Consigna = vConsigna AND a.Id_Agencia = vAgencia JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = vWarehouse AND ap.province_id = c.province_id JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = vAgencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = vWarehouse; -- Modificacion de precio por dia de preparacion del pedido -- No aplicada SET vCost = ((vRetailedPrice - vPort) / ( 1 + (vRecovery + vMana))) - vMargin; SELECT vCost,vRetailedPrice,vPort,vRecovery,vMana,vMargin,vCustomer; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_ticket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_ticket`(IN v_ticket BIGINT ) proc: BEGIN /* Este procedimiento trata de "rebionizar" un ticket, eliminando los componentes existentes e insertandolos de nuevo */ DECLARE v_shipment DATE; DECLARE v_customer INT; DECLARE v_wh SMALLINT; DECLARE v_agencia INT; DECLARE v_consigna INT; DECLARE v_landing DATE; DECLARE v_ticket_free BOOLEAN; DECLARE v_agency INT; CALL bionic_free(); SELECT (IFNULL(ts.alertLevel,0) >0 or IFNULL(Factura,"") != "") = FALSE INTO v_ticket_free FROM Tickets t LEFT JOIN vn.ticketState ts ON t.Id_Ticket = ts.ticket WHERE t.Id_Ticket = v_ticket; /*SELECT (EtiquetasEmitidas or PedidoImpreso or Firmado or nz(Factura)) = FALSE INTO v_ticket_free FROM Tickets WHERE Id_Ticket = v_ticket;*/ REPLACE order_Tickets(order_id, Id_Ticket) VALUES(48, v_ticket); SELECT Id_Cliente, t.warehouse_id, date(t.Fecha), Id_Consigna, t.Id_Agencia, landing, a.agency_id INTO v_customer, v_wh, v_shipment, v_consigna, v_agencia, v_landing, v_agency FROM vn2008.Tickets t LEFT JOIN vn2008.Agencias a ON t.Id_Agencia = a.Id_Agencia WHERE Id_Ticket = v_ticket; DROP TEMPORARY TABLE IF EXISTS travel_tree; CREATE TEMPORARY TABLE travel_tree ENGINE = MEMORY SELECT v_wh warehouse_id, v_shipment Fecha_envio, v_landing Fecha_recepcion; CALL item_last_buy_ (v_wh, v_shipment); -- rellena la tabla t_item_last_buy con la ultima compra DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; CREATE TEMPORARY TABLE tmp.bionic_lot SELECT v_wh warehouse_id,NULL available, m.Id_Article item_id,ilb.buy_id FROM Movimientos m LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article WHERE m.Id_Ticket = v_ticket GROUP BY m.Id_Article; CALL bionic_calc_component(v_consigna,v_agencia); DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m where m.Id_Ticket = v_ticket; CALL bionic_movement_update(IF(v_ticket_free,1,6)); -- si el ticket esta facturado, respeta los precios IF v_landing IS NULL THEN CALL travel_tree_shipment(v_shipment, v_consigna, v_agency,v_wh); UPDATE Tickets t JOIN travel_tree_shipment tts ON t.warehouse_id = tts.warehouse_id SET t.landing = tts.landing WHERE Id_Ticket = v_ticket; END IF; -- Limpieza -- DROP TEMPORARY TABLE t_item_last_buy; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_free` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_free`() BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; DROP TEMPORARY TABLE IF EXISTS tmp.bionic_item; DROP TEMPORARY TABLE IF EXISTS tmp.bionic_price; DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component; DROP TEMPORARY TABLE IF EXISTS tmp.travel_tree; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_from_item` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_item`( v_date DATE, v_consigna INT, v_agencia INT, v_item INT) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.bionic_calc; CREATE TEMPORARY TABLE tmp.bionic_calc (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT v_item item_id; CALL bionic_calc (v_date, v_consigna, v_agencia); DROP TEMPORARY TABLE tmp.bionic_calc; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_from_order` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_order`( v_date DATE, -- fecha de recepcion de mercancia v_consigna INT, v_agencia INT, v_order INT) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.bionic_calc; CREATE TEMPORARY TABLE tmp.bionic_calc (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT item_id FROM order_row WHERE order_id = v_order GROUP BY item_id; CALL bionic_calc (v_date, v_consigna, v_agencia); DROP TEMPORARY TABLE tmp.bionic_calc; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_from_ticket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_ticket`( v_date DATE, -- fecha de recepcion de mercancia v_consigna INT, v_agencia INT, v_ticket INT) BEGIN DECLARE int_warehouse SMALLINT; DECLARE v_agency_id INT; DECLARE v_shipment DATE; SELECT warehouse_id INTO int_warehouse FROM Tickets WHERE Id_Ticket = v_ticket; SELECT agency_id INTO v_agency_id FROM Agencias WHERE Id_Agencia = v_agencia; CALL bionic_free(); CALL travel_tree(v_date,v_consigna, v_agency_id); SELECT Fecha_envio INTO v_shipment FROM travel_tree WHERE warehouse_id = int_warehouse; CALL item_last_buy_ (int_warehouse, v_shipment); DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; CREATE TEMPORARY TABLE tmp.bionic_lot SELECT int_warehouse warehouse_id,NULL available, m.Id_Article item_id,ilb.buy_id FROM Movimientos m LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article WHERE m.Id_Ticket = v_ticket AND m.Id_Article != 100 GROUP BY warehouse_id, item_id; DROP TEMPORARY TABLE t_item_last_buy; CALL bionic_calc_component ( v_consigna, v_agencia); -- para recuperar el shipment en caso de que se necesite SET @shipment = v_shipment; DROP TEMPORARY TABLE tmp.bionic_lot; IF IFNULL(v_shipment,CURDATE() - 1) < CURDATE() THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'No se puede realizar el cambio'; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_from_type` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_type`( v_date DATE, -- fecha de recepcion de mercancia v_consigna INT, v_agencia INT, v_type INT) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.bionic_calc; CREATE TEMPORARY TABLE tmp.bionic_calc (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT Id_Article AS item_id FROM Articles WHERE tipo_id = v_type; CALL bionic_calc (v_date, v_consigna, v_agencia); DROP TEMPORARY TABLE tmp.bionic_calc; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_make_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_make_update`( i_ticket INT ,i_agencia INT ,i_consigna INT ,i_warehouse INT ,d_shipment DATE ,d_landing DATE ,i_option INT) BEGIN /** * Ejecuta los cambios en el ticket, en los movimientos y en los componentes. */ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; -- Cambios en el ticket START TRANSACTION; UPDATE Tickets t SET t.Id_Agencia = i_agencia, t.Id_Consigna = i_consigna, t.warehouse_id = i_warehouse, t.landing = d_landing, t.Fecha = d_shipment WHERE t.Id_Ticket = i_ticket; -- La opcion 8 es No realizar modificaciones en los precios IF i_option <> 8 THEN DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, i_warehouse warehouse_id FROM Movimientos m WHERE m.Id_Ticket = i_ticket; CALL bionic_movement_update (i_option); DROP TEMPORARY TABLE tmp.movement; END IF; COMMIT; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_movement_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_movement_update`(i_option INT) BEGIN /** * A partir de la tabla tmp.movement, crea los Movimientos_componentes * y modifica el campo Preu de la tabla Movimientos * * @param i_option integer tipo de actualizacion * @param table tmp.movement tabla memory con el campo Id_Movimiento, warehouse_id **/ DECLARE intComponent INT; DECLARE bolRENUEVA_COMPONENTES BOOLEAN; DECLARE bolRESPETA_PRECIOS BOOLEAN; CASE i_option WHEN 1 THEN -- caso normal SET bolRENUEVA_COMPONENTES = TRUE; SET bolRESPETA_PRECIOS = FALSE; WHEN 2 THEN SET intComponent = 17; -- greuge al client SET bolRENUEVA_COMPONENTES = TRUE; SET bolRESPETA_PRECIOS = TRUE; WHEN 3 THEN SET intComponent = 37; -- convertir en maná SET bolRENUEVA_COMPONENTES = TRUE; SET bolRESPETA_PRECIOS = TRUE; WHEN 4 THEN SET intComponent = 34; -- greuge contra la cartera del producto SET bolRENUEVA_COMPONENTES = TRUE; SET bolRESPETA_PRECIOS = TRUE; WHEN 5 THEN SET intComponent = 35; -- greuge contra la cartera del comprador SET bolRENUEVA_COMPONENTES = TRUE; SET bolRESPETA_PRECIOS = TRUE; WHEN 6 THEN SET intComponent = 36; -- descuadre para la empresa SET bolRENUEVA_COMPONENTES = TRUE; SET bolRESPETA_PRECIOS = TRUE; WHEN 7 THEN -- Insertamos el 80% para el coste REPLACE INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento,28, round(((m.Preu * (100 - m.Descuento) /100 ) - SUM(IFNULL(mc.Valor,0))) * 0.8 ,3) FROM Movimientos m JOIN tmp.movement mo ON m.Id_Movimiento = mo.Id_Movimiento LEFT JOIN Movimientos_componentes mc ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente NOT IN (28,29) GROUP BY m.Id_Movimiento; -- Insertamos el 20% para el margen REPLACE INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento,29, round(((m.Preu * (100 - m.Descuento) /100 ) - SUM(IFNULL(mc.Valor,0))) * 0.2 ,3) FROM Movimientos m JOIN tmp.movement mo ON m.Id_Movimiento = mo.Id_Movimiento LEFT JOIN Movimientos_componentes mc ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente NOT IN (28,29) GROUP BY m.Id_Movimiento; SET bolRENUEVA_COMPONENTES = FALSE; SET bolRESPETA_PRECIOS = FALSE; WHEN 8 THEN -- Eliminamos todos los componentes exceptos los propios de la tarifa para no perderla DELETE mc.* FROM tmp.movement mo JOIN Movimientos_componentes mc ON mo.Id_Movimiento = mc.Id_Movimiento; -- Insertamos el 100% para el coste Tipo 78 (Genérico) REPLACE INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento,28, round(((m.Preu * (100 - m.Descuento) /100 )) ,3) FROM Movimientos m JOIN tmp.movement mo ON m.Id_Movimiento = mo.Id_Movimiento; SET bolRENUEVA_COMPONENTES = FALSE; SET bolRESPETA_PRECIOS = FALSE; WHEN 9 THEN -- PAK 2017-02-06 caso especial de artículos cuyo precio se pone a mano, como los portes SET bolRENUEVA_COMPONENTES = TRUE; SET bolRESPETA_PRECIOS = TRUE; END CASE; IF bolRENUEVA_COMPONENTES THEN -- Eliminamos todos los componentes exceptos los propios de la tarifa para no perderla DELETE mc.* FROM tmp.movement mo JOIN Movimientos_componentes mc ON mo.Id_Movimiento = mc.Id_Movimiento JOIN tarifa_componentes tc ON tc.Id_Componente = mc.Id_Componente WHERE tc.is_renewable = TRUE; -- Insertamos los componentes actuales REPLACE INTO Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento, bc.component_id, bc.cost FROM Movimientos m JOIN tmp.movement mo ON m.Id_Movimiento = mo.Id_Movimiento JOIN tmp.bionic_component bc ON bc.item_id = m.Id_Article AND bc.warehouse_id = mo.warehouse_id LEFT JOIN Movimientos_componentes mc ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = bc.component_id LEFT JOIN tarifa_componentes tc ON tc.Id_Componente = bc.component_id WHERE IF(mc.Id_Componente IS NULL AND tc.is_renewable = FALSE,FALSE,TRUE); END IF; IF bolRESPETA_PRECIOS THEN REPLACE INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento,intComponent, round((m.Preu * (100 - m.Descuento) /100 ) - SUM(mc.Valor) ,3) dif FROM Movimientos m JOIN tmp.movement mo ON m.Id_Movimiento = mo.Id_Movimiento LEFT JOIN Movimientos_componentes mc ON mc.Id_Movimiento = m.Id_Movimiento WHERE mc.Id_Componente <> intComponent GROUP BY m.Id_Movimiento HAVING dif <> 0; ELSE -- Cambios en movimientos. UPDATE Movimientos m JOIN Articles a on a.Id_Article = m.Id_Article JOIN Tipos tp on tp.tipo_id = a.tipo_id JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento FROM Movimientos_componentes mc JOIN tmp.movement m ON m.Id_Movimiento = mc.Id_Movimiento GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento SET m.Preu = sum_valor WHERE Tipo != 'Portes'; -- PAK 2017-02-06 -- Insertamos descuento, si lo hay REPLACE INTO Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento, 21, m.Preu * (100 -m.Descuento) / 100 - sum(Valor) v_valor FROM Movimientos m JOIN tmp.movement mo ON m.Id_Movimiento = mo.Id_Movimiento JOIN Movimientos_componentes mc ON mc.Id_Movimiento = m.Id_Movimiento WHERE mc.Id_Componente != 21 GROUP BY m.Id_Movimiento having round(v_valor,4) <> 0; END IF; -- Fija el Costfixat UPDATE Movimientos m JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento FROM Movimientos_componentes mc JOIN tmp.movement m ON m.Id_Movimiento = mc.Id_Movimiento join bi.tarifa_componentes tc using(Id_Componente) join bi.tarifa_componentes_series tcs on tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id AND tcs.base GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento SET m.CostFixat = sum_valor, PrecioFijado = 1; -- PAK 2017-02-06 -- Familia PORTES, un unico componente de porte DELETE mc.* FROM Movimientos_componentes mc JOIN tmp.movement mo ON mo.Id_Movimiento = mc.Id_Movimiento JOIN Movimientos m on m.Id_Movimiento = mc.Id_Movimiento JOIN Articles a ON a.Id_Article = m.Id_Article JOIN Tipos tp ON tp.tipo_id = a.tipo_id WHERE Tipo = 'Portes'; INSERT INTO Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento, 15, preu -- Reparto FROM Movimientos m JOIN tmp.movement mo ON mo.Id_Movimiento = m.Id_Movimiento JOIN Articles a ON a.Id_Article = m.Id_Article JOIN Tipos tp ON tp.tipo_id = a.tipo_id WHERE Tipo = 'Portes' AND preu > 0; -- PAK 2017-09-27 -- Tipos con un unico componente de coste /* DELETE mc.* FROM Movimientos_componentes mc JOIN tmp.movement mo ON mo.Id_Movimiento = mc.Id_Movimiento JOIN Movimientos m on m.Id_Movimiento = mc.Id_Movimiento JOIN Articles a ON a.Id_Article = m.Id_Article JOIN Tipos tp ON tp.tipo_id = a.tipo_id WHERE tp.hasComponents = FALSE; INSERT INTO Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) SELECT m.Id_Movimiento, 28, preu -- Coste FROM Movimientos m JOIN tmp.movement mo ON mo.Id_Movimiento = m.Id_Movimiento JOIN Articles a ON a.Id_Article = m.Id_Article JOIN Tipos tp ON tp.tipo_id = a.tipo_id WHERE tp.hasComponents = FALSE; */ END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_movement_update_mode` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_movement_update_mode`(IN idMOV BIGINT, IN i_MODE INT) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.movement; CREATE TEMPORARY TABLE tmp.movement (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY SELECT Id_Movimiento, warehouse_id FROM Movimientos m JOIN Tickets t using(Id_Ticket) WHERE m.Id_Movimiento = idMOV; CALL bionic_movement_update(i_MODE); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_movimiento_precio_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_movimiento_precio_update`(IN i_mov INT) BEGIN DECLARE d_compo_precio DOUBLE; DECLARE d_mov_precio DOUBLE; SELECT SUM(Valor) INTO d_compo_precio FROM bi.movimientos_componentes WHERE Id_Movimiento = i_mov; SELECT Preu INTO d_mov_precio FROM Movimientos WHERE Id_Movimiento = i_mov; IF d_mov_precio <> d_compo_precio AND d_compo_precio IS NOT NULL AND d_mov_precio IS NOT NULL THEN INSERT INTO bi.movimientos_componentes(Id_Movimiento, Id_Componente, Valor) VALUES (i_mov, 21, d_mov_precio - d_compo_precio) ON DUPLICATE KEY UPDATE Valor = Valor + d_mov_precio - d_compo_precio ; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bionic_tickets_range_bionizar` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bionic_tickets_range_bionizar`(IN datSTART DATE, IN datEND DATE) BEGIN DECLARE done BIT DEFAULT 0; DECLARE datEND_Midnight DATETIME DEFAULT vn2008.dayend(datEND); DECLARE v_ticket BIGINT; DECLARE rs CURSOR FOR SELECT DISTINCT t.Id_Ticket FROM ( -- Movimientos que no coincide la suma de los componentes con el precio select t.Id_Ticket, IFNULL(sum(Valor),0) - (Preu * (100 - m.Descuento)/100) as Diferencia, NULL as Nothing from vn2008.Tickets t join vn2008.Movimientos m on t.Id_Ticket = m.Id_Ticket join vn2008.Articles a using(Id_Article) left join vn2008.Movimientos_componentes mc using(Id_Movimiento) join vn2008.Tipos tp on a.tipo_id = tp.tipo_id where t.Fecha between datSTART and datEND_Midnight and not tp.confeccion and m.Cantidad > 0 and tp.reino_id != 6 group by Id_Movimiento having ABS(Diferencia) > 1 OR (Diferencia IS NULL) UNION ALL -- Movimientos sin componente de coste SELECT t.Id_Ticket, NULL, NULL FROM Tickets t LEFT JOIN ( SELECT DISTINCT t.Id_Ticket, 0 FROM Tickets t JOIN Movimientos m on m.Id_Ticket = t.Id_Ticket JOIN Articles a on a.Id_Article = m.Id_Article JOIN Tipos tp on a.tipo_id = tp.tipo_id JOIN Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento JOIN tarifa_componentes tc on tc.Id_Componente = mc.Id_Componente WHERE (tarifa_componentes_series_id = 1 OR tp.reino_id = 6) AND t.Fecha between datSTART and datEND_Midnight ) sub on sub.Id_Ticket = t.Id_Ticket WHERE sub.Id_Ticket IS NULL AND t.Fecha between datSTART and datEND_Midnight UNION ALL -- Movimientos sin porte en tickets con agencia que SI que deberia de llevar SELECT m.Id_Ticket, count(Id_Movimiento) as Lineas_totales, Lineas_conPorte FROM Movimientos m JOIN Articles a on a.Id_Article = m.Id_Article JOIN Tipos tp on tp.tipo_id = a.tipo_id JOIN Tickets t on m.Id_Ticket = t.Id_Ticket JOIN v_expeditions_shipping_charge v on v.Id_ticket = t.Id_Ticket LEFT JOIN ( SELECT m.Id_Ticket, count(Id_Componente) Lineas_conPorte FROM Movimientos_componentes mc JOIN Movimientos m using(Id_Movimiento) JOIN Tickets t using(Id_Ticket) WHERE Id_Componente = 15 AND Fecha between datSTART and datEND_Midnight GROUP BY m.Id_Ticket ) sub on sub.Id_Ticket = t.Id_Ticket WHERE t.Fecha between datSTART and datEND_Midnight AND Preu != 0 AND tp.reino_id != 6 AND shipping_charge > 1 GROUP BY m.Id_Ticket HAVING Lineas_totales > IFNULL(Lineas_conPorte,0) ) sub JOIN Tickets t ON t.Id_Ticket = sub.Id_Ticket JOIN warehouse w ON w.id = t.warehouse_id WHERE w.inventario; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN rs; FETCH rs INTO v_ticket ; WHILE NOT done DO CALL bionic_calc_ticket(v_ticket); call Ditacio(v_ticket ,'Bioniza Ticket' ,'T' , 20 , 'proc bionic_tickets_range_bionizar' , NULL); FETCH rs INTO v_ticket ; END WHILE; CLOSE rs; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bonus_comparados` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `bonus_comparados`() BEGIN SELECT CodigoTrabajador as Comercial , T.Fecha , bs.Id_Ticket , T.Alias , bs.Id_Article , A.Article , A.Medida ,A.Categoria , O.Abreviatura , bs.amount , bs.bonus , amount * bonus * IF(bonus_buenos.bonus_sales_id IS NULL,0,1) as saldo FROM bonus_sales bs JOIN Articles A USING(Id_Article) JOIN Trabajadores USING(Id_Trabajador) JOIN Tickets T USING(Id_Ticket) JOIN Clientes C USING(Id_Cliente) JOIN Origen O ON O.id = A.id_origen JOIN Permisos P ON bs.Id_Trabajador = P.Id_Trabajador LEFT JOIN ( select b.bonus_sales_id from bonus_sales b left join Movimientos M using(Id_Ticket, Id_Article) join Tickets T on T.Id_Ticket = b.Id_Ticket where Fecha >= '2012-12-01' and Cantidad > amount / 2 ) bonus_buenos USING(bonus_sales_id) WHERE T.Fecha > '2012-12-01' AND invoice AND Id_Grupo = 6; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_label` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_label`(IN entry_id_ INT, IN groupby TINYINT(1)) BEGIN DECLARE done INT DEFAULT 0; DECLARE label INT; DECLARE id INT; DECLARE recordset CURSOR FOR SELECT Compres.Etiquetas, Compres.Id_Compra FROM Compres INNER JOIN (SELECT e.Id_entrada FROM Entradas e INNER JOIN ( SELECT Id_Entrada,Inventario,Id_proveedor,travel_id,Id_Agencia FROM Entradas e1 INNER JOIN travel t ON e1.travel_id = t.id WHERE Id_Entrada = entry_id_) y ON y.Inventario = e.Inventario AND e.travel_id = y.travel_id AND e.Id_proveedor = y.Id_proveedor AND y.Id_Agencia = e.Id_Agencia WHERE (0 OR e.Id_Entrada = entry_id_)) entry_label ON Compres.Id_Entrada = entry_label.Id_entrada INNER JOIN Articles ON Compres.Id_Article = Articles.Id_Article WHERE Articles.Imprimir <> FALSE; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; DROP TEMPORARY TABLE IF EXISTS `buy_label_source`; CREATE TEMPORARY TABLE `buy_label_source` ( `buy_id` INT(11) NOT NULL ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; OPEN recordset; REPEAT FETCH recordset INTO label, id; WHILE label > 0 DO SET label = label - 1; INSERT INTO buy_label_source (buy_id) VALUES (id); END WHILE; UNTIL done END REPEAT; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_label_bunch` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_label_bunch`(IN entry_id_ INT, IN groupby TINYINT(1),IN single TINYINT(1), IN idCOM BIGINT) BEGIN DECLARE done INT DEFAULT 0; DECLARE date_ DATE; DECLARE provider_id INT; DECLARE agency_id INT; DECLARE i_wh INT; DECLARE label INT; DECLARE id INT; DECLARE recordset CURSOR FOR SELECT ROUND(C.Cantidad / IF(C.caja = FALSE, 1,C.Grouping) + 0.49), C.Id_Compra FROM Compres C INNER JOIN entry_label ON C.Id_Entrada = entry_label.entry_id INNER JOIN Articles A ON C.Id_Article = A.Id_Article WHERE (A.Imprimir <> FALSE AND idCOM = 0 AND C.Novincular = FALSE) OR idCOM = C.Id_Compra; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET idCOM = IFNULL(idCOM, 0); DROP TEMPORARY TABLE IF EXISTS `entry_label`; CREATE TEMPORARY TABLE `entry_label` (`entry_id` INT(11) NOT NULL) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; IF groupby <> FALSE THEN SELECT Id_Proveedor, DATE(landing), travel.agency_id, warehouse_id INTO provider_id, date_, agency_id, i_wh FROM Entradas INNER JOIN travel ON travel.id = Entradas.travel_id WHERE Id_Entrada = entry_id_; INSERT INTO entry_label (entry_id) SELECT Entradas.Id_Entrada FROM Entradas INNER JOIN travel ON travel.id = Entradas.travel_id WHERE Entradas.Inventario = FALSE AND Entradas.Id_Proveedor = provider_id AND warehouse_id = i_wh AND DATE(landing) = date_ AND travel.agency_id= agency_id; ELSE INSERT INTO entry_label (entry_id) VALUES (entry_id_); SELECT landing INTO date_ FROM Entradas e JOIN travel t ON t.id = e.travel_id JOIN Compres c ON c.Id_Entrada = e.Id_Entrada WHERE (entry_id_ = e.Id_Entrada OR c.Id_Compra = idCOM) LIMIT 1; END IF; DROP TEMPORARY TABLE IF EXISTS `buy_label_source`; CREATE TEMPORARY TABLE `buy_label_source` (`buy_id` INT(11) NOT NULL) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; OPEN recordset; FETCH recordset INTO label, id; REPEAT REPEAT SET label = label - 1; INSERT INTO buy_label_source (buy_id) VALUES (id); UNTIL label <= 0 OR single END REPEAT; INSERT INTO buy_label_source (buy_id) VALUES (0); FETCH recordset INTO label, id; UNTIL done END REPEAT; SELECT C.Id_Article, @a:=IF(A.min AND IFNULL(rate_3, C.Tarifa3) < A.PVP, A.PVP, IFNULL(rate_3, C.Tarifa3)) Tarifa2, ROUND(IF(C.caja = FALSE, @a, @a * C.Grouping), 2) AS Bunch, ROUND(@a / A.Tallos, 2) AS PPT, A.Article, A.Medida, A.Color, A.Categoria, Abreviatura AS Origen, p.name Productor, A.Tallos, C.grouping, E.Notas_Eva, P.Proveedor, C.Packing FROM buy_label_source bls LEFT JOIN Compres C ON C.Id_Compra = bls.buy_id LEFT JOIN Entradas E ON E.Id_Entrada = C.Id_Entrada LEFT JOIN Articles A ON A.Id_Article = C.Id_Article LEFT JOIN Proveedores P ON P.Id_Proveedor = E.Id_Proveedor LEFT JOIN Origen o ON A.id_origen = o.id LEFT JOIN producer p ON p.producer_id = A.producer_id LEFT JOIN (SELECT item_id, rate_3 FROM price_fixed WHERE IFNULL(date_, CURDATE()) BETWEEN date_start AND date_end AND rate_3 AND warehouse_id IN (0 , i_wh) GROUP BY item_id) pf ON pf.item_id = A.Id_Article; DROP TEMPORARY TABLE `entry_label`; DROP TEMPORARY TABLE `buy_label_source`; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_label_bunchkk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_label_bunchkk`(IN entry_id_ INT, IN groupby TINYINT(1),IN single TINYINT(1), IN idCOM BIGINT) BEGIN DECLARE done INT DEFAULT 0; DECLARE date_ DATE; DECLARE provider_id INT; DECLARE agency_id INT; DECLARE i_wh INT; DECLARE label INT; DECLARE id INT; DECLARE recordset CURSOR FOR SELECT ROUND(C.Cantidad / IF(C.caja = FALSE, 1,C.Grouping) + 0.49), C.Id_Compra FROM Compres C INNER JOIN entry_label ON C.Id_Entrada = entry_label.entry_id INNER JOIN Articles A ON C.Id_Article = A.Id_Article WHERE (A.Imprimir <> FALSE AND idCOM = 0 AND C.Novincular = FALSE) OR idCOM = C.Id_Compra; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET idCOM = IFNULL(idCOM, 0); DROP TEMPORARY TABLE IF EXISTS `entry_label`; CREATE TEMPORARY TABLE `entry_label` ( `entry_id` INT(11) NOT NULL ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; IF groupby <> FALSE THEN SELECT Id_Proveedor, DATE(landing), travel.agency_id, warehouse_id INTO provider_id, date_, agency_id, i_wh FROM Entradas INNER JOIN travel ON travel.id = Entradas.travel_id WHERE Id_Entrada = entry_id_; INSERT INTO entry_label (entry_id) SELECT Entradas.Id_Entrada FROM Entradas INNER JOIN travel ON travel.id = Entradas.travel_id WHERE Entradas.Inventario = FALSE AND Entradas.Id_Proveedor = provider_id AND warehouse_id = i_wh AND DATE(landing) = date_ AND travel.agency_id= agency_id; ELSE INSERT INTO entry_label (entry_id) VALUES (entry_id_); SELECT landing INTO date_ FROM Entradas e JOIN travel t ON t.id = e.travel_id JOIN Compres c ON c.Id_Entrada = e.Id_Entrada WHERE (entry_id_ = e.Id_Entrada OR c.Id_Compra = idCOM) LIMIT 1; END IF; DROP TEMPORARY TABLE IF EXISTS `buy_label_source`; CREATE TEMPORARY TABLE `buy_label_source` ( `buy_id` INT(11) NOT NULL ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; OPEN recordset; FETCH recordset INTO label, id; REPEAT REPEAT SET label = label - 1; INSERT INTO buy_label_source (buy_id) VALUES (id); UNTIL label <= 0 OR single END REPEAT; INSERT INTO buy_label_source (buy_id) VALUES (0); FETCH recordset INTO label, id; UNTIL done END REPEAT; SELECT C.Id_Article,@a := IF(A.min AND IFNULL(rate_3,C.Tarifa3) < A.PVP, A.PVP, IFNULL(rate_3,C.Tarifa3)) Tarifa2, ROUND(IF(C.caja = FALSE, @a,@a * C.Grouping),2) AS Bunch, ROUND(@a / A.Tallos,2) AS PPT, A.Article, A.Medida, A.Color, A.Categoria, Abreviatura as Origen, C.Productor, A.Tallos, C.grouping, E.Notas_Eva,P.Proveedor,C.Packing FROM buy_label_source bls LEFT JOIN Compres C ON C.Id_Compra = bls.buy_id LEFT JOIN Entradas E ON E.Id_Entrada = C.Id_Entrada LEFT JOIN Articles A ON A.Id_Article = C.Id_Article LEFT JOIN Proveedores P ON P.Id_Proveedor = E.Id_Proveedor LEFT JOIN Origen o ON A.id_origen = o.id LEFT JOIN ( SELECT item_id, rate_3 FROM price_fixed WHERE IFNULL(date_,CURDATE()) BETWEEN date_start AND date_end AND rate_3 AND warehouse_id IN (0,i_wh) GROUP BY item_id ) pf ON pf.item_id = A.Id_Article; -- JGF 02/02/15 canvie CURDATE() per IFNULL(date_,CURDATE()) DROP TEMPORARY TABLE `entry_label`; DROP TEMPORARY TABLE `buy_label_source`; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_scan` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_scan`(v_barcode VARCHAR(255), v_labels INT) BEGIN /** * Marca una compra de subasta como escaneada. * * @param v_barcode Código de compra de una etiqueta de subasta * @param v_labels Cantidad escaneada **/ DECLARE v_edi INT; DECLARE v_buy INT; DECLARE v_item INT; DECLARE v_do_photo BOOL; -- Aun no se sabe como obtener el número de serie de transacción de -- las compras realizadas a través de un reloj, por lo que se establece -- siempre a '01' IF SUBSTR(v_barcode, 3, 2) != '99' THEN SET v_barcode = CONCAT(LEFT(v_barcode, 12), '010'); END IF; SELECT e.id, c.Id_Compra, c.Id_Article, a.do_photo INTO v_edi, v_buy, v_item, v_do_photo FROM buy_edi e JOIN Compres c ON c.buy_edi_id = e.id JOIN Articles a ON a.Id_Article = c.Id_Article WHERE e.barcode = v_barcode AND e.entry_year = YEAR(CURDATE()) ORDER BY c.Id_Compra LIMIT 1; UPDATE buy_edi SET scanned = TRUE WHERE id = v_edi; UPDATE Compres SET Vida = Vida + IF(v_labels != -1, v_labels, Etiquetas) WHERE Id_Compra = v_buy; IF v_do_photo THEN UPDATE Articles SET do_photo = FALSE WHERE Id_Article = v_item; END IF; SELECT v_buy buy, v_do_photo do_photo; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_split` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_split`(v_buy INT, v_fv_entry INT, v_pca_entry INT) BEGIN DECLARE v_item INT; DECLARE v_packing INT; DECLARE v_remaining INT; DECLARE v_labels INT; DECLARE v_remainder INT; DECLARE v_is_buy INT; DECLARE v_id INT; DECLARE v_amount INT; DECLARE v_done BOOL DEFAULT FALSE; DECLARE cur CURSOR FOR SELECT TRUE, c.Id_Compra, c.Cantidad - IFNULL((c.Vida * c.Packing), 0) FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE c.Id_Article = v_item AND t.shipment = CURDATE() AND t.warehouse_id_out IN (7, 40) AND t.warehouse_id NOT IN (44, 1) AND NOT e.redada AND NOT e.Inventario AND IFNULL(c.Vida, 0) < c.Etiquetas LOCK IN SHARE MODE UNION ALL SELECT FALSE, m.Id_Movimiento, m.Cantidad - IFNULL(l.stem, 0) FROM Movimientos m JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket LEFT JOIN movement_label l ON l.Id_Movimiento = m.Id_Movimiento WHERE m.Id_Article = v_item AND t.Fecha = CURDATE() AND t.warehouse_id IN (7, 40) AND NOT t.Etiquetasemitidas AND IFNULL(l.stem, 0) < m.Cantidad LOCK IN SHARE MODE; DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; START TRANSACTION; -- Obtiene los datos de la compra SELECT Id_Article, Packing, Cantidad INTO v_item, v_packing, v_remaining FROM Compres WHERE Id_Compra = v_buy; -- Crea splits de los tickets DROP TEMPORARY TABLE IF EXISTS tmp.split; CREATE TEMPORARY TABLE tmp.split ( is_buy BOOL, id INT, labels INT, remainder INT ) ENGINE = MEMORY; OPEN cur; l: LOOP SET v_done = FALSE; FETCH cur INTO v_is_buy, v_id, v_amount; IF v_done OR v_remaining = 0 THEN LEAVE l; END IF; SET v_amount = LEAST(v_amount, v_remaining); SET v_remaining = v_remaining - v_amount; SET v_labels = v_amount DIV v_packing; INSERT INTO tmp.split VALUES (v_is_buy, v_id, v_labels, v_amount % v_packing); IF v_is_buy THEN UPDATE Compres SET Vida = Vida + v_labels WHERE Id_Compra = v_id; ELSE INSERT INTO movement_label SET Id_Movimiento = v_id, stem = v_amount, label = v_labels ON DUPLICATE KEY UPDATE stem = stem + VALUES(stem), label = label + VALUES(label); END IF; END LOOP; CLOSE cur; -- Crea los movimientos de almacén a silla CALL buy_transfer (v_buy, v_fv_entry, v_pca_entry); UPDATE Compres SET dispatched = Vida * Packing WHERE Id_Compra = v_buy; -- Devuelve los splits creados DROP TEMPORARY TABLE IF EXISTS tmp.aux; CREATE TEMPORARY TABLE tmp.aux ENGINE = MEMORY SELECT s.labels, s.remainder, w.`name` destination, a.Id_Article, a.Article, a.Medida FROM tmp.split s JOIN Compres c ON c.Id_Compra = s.id JOIN Articles a ON a.Id_Article = c.Id_Article JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id JOIN warehouse w ON t.warehouse_id = w.id WHERE s.is_buy; INSERT INTO tmp.aux SELECT s.labels, s.remainder, o.Consignatario, a.Id_Article, a.Article, a.Medida FROM tmp.split s JOIN Movimientos m ON m.Id_Movimiento = s.id JOIN Articles a ON a.Id_Article = m.Id_Article JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket JOIN Consignatarios o ON o.Id_Consigna = t.Id_Consigna WHERE NOT s.is_buy; SELECT * FROM tmp.aux; -- Limpia y confirma cambios DROP TEMPORARY TABLE tmp.split, tmp.aux; COMMIT; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas`(v_buy INT) BEGIN DECLARE v_entry INT; DECLARE v_wh INT; SELECT Id_Entrada, warehouse_id INTO v_entry, v_wh FROM Compres JOIN Entradas USING(Id_Entrada) JOIN travel ON travel.id = travel_id WHERE v_buy = Id_Compra; CALL buy_tarifas_table (v_entry); UPDATE Compres C LEFT JOIN Cubos CB USING(Id_Cubo) JOIN Articles A USING(Id_Article) JOIN Tipos TP USING(tipo_id) JOIN Entradas E USING(Id_Entrada) JOIN travel TR ON TR.id = E.travel_id JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia LEFT JOIN recibida_entrada re ON E.Id_Entrada = re.Id_Entrada LEFT JOIN awb_recibida ar ON re.awb_recibida = ar.recibida_id LEFT JOIN v_awb_volumen va ON va.awb_id = ar.awb_id JOIN tblTARIFAS TC SET C.Portefijo = @PF:= IF (va.importe, ROUND((va.importe * A.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3), ROUND(IFNULL(((AG.m3 * cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) / C.Packing,0),3) ), C.Comisionfija = @CF:= ROUND(IFNULL(E.comision * C.Costefijo / 100,0),3), C.Embalajefijo = @EF:= IF(CB.Retornable != 0, 0, ROUND(IFNULL( CB.Valor / C.Packing ,0),3)), C.Tarifa3 = @t3:= IF(TC.t3 = 0, C.Costefijo,ROUND((C.Costefijo + @CF + @EF + @PF) / ((100 - TC.t3 - TP.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 C.Tarifa2 = @t2:= ROUND(@t3 * (1 + ( (TC.t2 - TC.t3)/100) ),2), C.Tarifa2 = IF(@t2 <= @t3, @t3 , @t2) WHERE C.Id_Compra = v_buy; IF v_wh = 42 -- Canarias THEN UPDATE Compres SET Tarifa2 = Tarifa3 WHERE Id_Compra = v_buy; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_awb` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_awb`(IN strAWB varchar(18)) BEGIN DECLARE datINV DATE; DECLARE wh_id INT; DECLARE idENTRADA INT; SELECT warehouse_id, E.Id_Entrada INTO wh_id, idENTRADA FROM Entradas E JOIN travel ON travel.id = travel_id JOIN recibida_entrada re on E.Id_Entrada = re.Id_Entrada JOIN awb_recibida ar ON re.awb_recibida = ar.recibida_id JOIN awb ON awb.id = ar.awb_id WHERE awb.codigo = strAWB LIMIT 1; CALL buy_tarifas_table(idENTRADA); UPDATE Compres C LEFT JOIN Cubos CB USING(Id_Cubo) JOIN Articles A USING(Id_Article) JOIN Entradas E USING(Id_Entrada) JOIN recibida_entrada re on E.Id_Entrada = re.Id_Entrada JOIN awb_recibida ar ON re.awb_recibida = ar.recibida_id JOIN v_awb_volumen va ON va.awb_id = ar.awb_id JOIN Tipos TP USING(tipo_id) JOIN travel TR ON TR.id = E.travel_id JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia JOIN tblTARIFAS TC SET C.Portefijo = @PF:= round((va.importe * A.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3), C.Comisionfija = @CF:= ROUND(IFNULL(E.comision * C.Costefijo / 100,0),3), C.Embalajefijo = @EF:= IF(CB.Retornable != 0, 0, ROUND(IFNULL( CB.Valor / C.Packing ,0),3)), C.Tarifa3 = @t3:= IF(TC.t3 = 0, C.Costefijo,ROUND((C.Costefijo + @CF + @EF + @PF) / ((100 - TC.t3 - TP.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 C.Tarifa2 = @t2:= round(@t3 * (1 + ( (TC.t2 - TC.t3)/100) ),2), C.Tarifa2 = @t2:= IF(@t2 <= @t3, @t3 , @t2) WHERE va.codigo = strAWB ; CASE wh_id WHEN 41 THEN -- Canarias UPDATE Compres SET Tarifa2 = Tarifa3 WHERE Id_Entrada = idENTRADA; ELSE BEGIN END; END CASE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_awb_bucle` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_awb_bucle`() BEGIN DECLARE strAWB VARCHAR(25); DECLARE done INT DEFAULT FALSE; DECLARE rs CURSOR FOR SELECT codigo FROM awb WHERE MYSQL_TIME > '2015-06-30' AND importe > 0 ; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN rs; FETCH rs INTO strAWB; -- drop temporary table if exists killme; -- create temporary table killme select strAWB, now() as fecha, 0; WHILE NOT done DO insert into killme select strAWB, MYSQL_TIME, importe from awb where codigo = strAWB; call buy_tarifas_awb(strAWB); FETCH rs INTO strAWB; select * from killme order by fecha desc; END WHILE; drop temporary table killme; CLOSE rs; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_entry` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_entry`(IN idENTRADA INT(11)) BEGIN DECLARE datINV DATE; DECLARE wh_id INT; DECLARE m3i INTEGER; SELECT warehouse_id INTO wh_id FROM Entradas JOIN travel ON travel.id = travel_id WHERE Id_Entrada = idENTRADA; CALL buy_tarifas_table(idENTRADA); SELECT AG.m3 * sum( etiquetas * IFNULL(((AG.m3 * cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) ,0) ) / sum(etiquetas * IFNULL(((AG.m3 * ( A.density / 167 ) * cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) ,0)) INTO m3i FROM Compres C JOIN Articles A USING(Id_Article) JOIN Entradas E USING(Id_Entrada) JOIN Tipos TP USING(tipo_id) JOIN travel TR ON TR.id = E.travel_id JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia WHERE E.Id_Entrada = idENTRADA; UPDATE Compres C LEFT JOIN Cubos CB USING(Id_Cubo) JOIN Articles A USING(Id_Article) JOIN Entradas E USING(Id_Entrada) LEFT JOIN recibida_entrada re on E.Id_Entrada = re.Id_Entrada LEFT JOIN awb_recibida ar ON re.awb_recibida = ar.recibida_id LEFT JOIN v_awb_volumen va ON va.awb_id = ar.awb_id JOIN Tipos TP USING(tipo_id) JOIN travel TR ON TR.id = E.travel_id JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia JOIN tblTARIFAS TC SET C.Portefijo = @PF:= IF (va.importe, round((va.importe * A.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3), ROUND(IFNULL(((AG.m3 * @cm3:= cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) / C.Packing,0),3) ), C.Comisionfija = @CF:= ROUND(IFNULL(E.comision * C.Costefijo / 100,0),3), C.Embalajefijo = @EF:= IF(CB.Retornable != 0, 0, ROUND(IFNULL( CB.Valor / C.Packing ,0),3)), C.Tarifa3 = @t3:= IF(TC.t3 = 0, C.Costefijo,ROUND((C.Costefijo + @CF + @EF + @PF) / ((100 - TC.t3 - TP.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 C.Tarifa2 = @t2:= round(@t3 * (1 + ( (TC.t2 - TC.t3)/100)),2), C.Tarifa2 = @t2:= IF(@t2 <= @t3, @t3 , @t2) WHERE C.Id_Entrada = idENTRADA ; CASE wh_id WHEN 41 THEN -- Canarias UPDATE Compres SET Tarifa2 = Tarifa3 WHERE Id_Entrada = idENTRADA; ELSE BEGIN END; END CASE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_lot` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_tarifas_lot`(IN idCOMPRA INT(11)) BEGIN DECLARE intWHIN INTEGER(3); DECLARE intDAYS INTEGER(3); DECLARE dbM3 DOUBLE; DECLARE done INT DEFAULT 0; DECLARE datFEC DATE; DECLARE wh INTEGER(3); DECLARE idART INTEGER(11); DECLARE dbCOST DOUBLE; DECLARE m3value DOUBLE; DECLARE intLIFE INTEGER; DECLARE intPACK INTEGER; DECLARE intPromo DOUBLE; DECLARE whlc CURSOR FOR SELECT whin, days, m3 FROM warehouse_lc WHERE whout = @wh:= wh UNION ALL SELECT @wh, 0, 0 ; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; SELECT Id_Article, warehouse_id, landing, nz(Costefijo) + nz(Embalajefijo) + nz(Portefijo) + nz(Comisionfija), life, C.Packing, (cm3_2(C.Id_Cubo, C.Id_Article) / 1000000) / C.Packing, promo INTO idART , wh , datFEC , dbCOST , intLIFE, intPACK, m3value, intPromo FROM Compres C JOIN Articles A USING (Id_Article) JOIN Tipos TP USING (tipo_id) JOIN Entradas E USING (Id_Entrada) JOIN travel tr ON tr.id = E.travel_id WHERE Id_Compra = idCOMPRA; OPEN whlc; FETCH whlc INTO intWHIN, intDAYS, dbM3; WHILE NOT done DO SELECT idART , wh , datFEC , dbCOST , intLIFE, intPACK, m3value, intWHIN, intDAYS, dbM3, done, dbCOST + (m3value * dbM3); INSERT INTO price_fixed(item_id, rate_3, rate_2, date_start, date_end, warehouse_id) SELECT idART, round( (dbCOST + (m3value * dbM3)) / ((100 - t3 - intPromo )/100) , 2), @tf2 := round((dbCOST + (m3value * dbM3)) / ((100 - t2 - intPromo)/100) ,2), TIMESTAMPADD(DAY, intDAYS, datFEC), TIMESTAMPADD(DAY, intLIFE, datFEC), intWHIN FROM tarifas WHERE warehouse_id = intWHIN AND fecha <= TIMESTAMPADD(DAY, intDAYS, datFEC) ORDER BY fecha DESC LIMIT 1; FETCH whlc INTO intWHIN, intDAYS, dbM3; END WHILE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_recalcular_almacen` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_tarifas_recalcular_almacen`(IN wh_id INT, IN datFEC DATE) BEGIN DECLARE done INT DEFAULT 0; DECLARE idE INT; DECLARE cur1 CURSOR FOR SELECT Id_Entrada FROM Entradas JOIN travel ON travel.id = travel_id WHERE landing >= datFEC AND wh_id IN (0,warehouse_id); DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; OPEN cur1; REPEAT FETCH cur1 INTO idE; IF NOT done THEN Call buy_tarifas_entry(idE); END IF; UNTIL done END REPEAT; CLOSE cur1; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_T3` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_T3`(IN idCOMPRA INT(11)) BEGIN DECLARE idENTRADA BIGINT; DECLARE wh_id INT; SELECT Id_Entrada, warehouse_id INTO idENTRADA, wh_id FROM Compres JOIN Entradas using(Id_Entrada) JOIN travel ON travel.id = travel_id WHERE idCOMPRA = Id_Compra; CALL buy_tarifas_table(idENTRADA); UPDATE Compres C JOIN tblTARIFAS TC SET C.Tarifa3 = @t3:= C.Tarifa3, C.Tarifa2 = @t2:= round(@t3 * (1 + ( (TC.t2 - TC.t3)/100) ),2), C.Tarifa2 = @t2:= IF(@t2 <= @t3, @t3 + 0.01, @t2) WHERE C.Id_Compra = idCOMPRA; IF wh_id = 41 THEN -- Canarias UPDATE Compres SET Tarifa2 = Tarifa3 WHERE Id_Compra = idCOMPRA; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_T3_pf` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_T3_pf`(IN idPRICE INT, IN t3 DOUBLE) BEGIN DECLARE idENTRADA BIGINT; DECLARE idCOMPRA BIGINT; DECLARE datFEC DATE; DECLARE wh INT; DECLARE idART BIGINT; SELECT date_start, warehouse_id, item_id INTO datFEC, wh, idART FROM price_fixed WHERE price_fixed_id = idPRICE; SELECT C.Id_Entrada, Id_Compra INTO idENTRADA, idCOMPRA FROM Compres C JOIN Entradas E using(Id_Entrada) JOIN travel TR on TR.id = E.travel_id WHERE Id_Article = idART AND wh IN (0, warehouse_id) AND Novincular = FALSE AND NOT Redada AND landing <= datFEC ORDER BY landing DESC LIMIT 1; CALL buy_tarifas_table(idENTRADA); SELECT @t2:= round(t3 * (1 + ( (TC.t2 - TC.t3)/100) ),2) as rate_2b, @t2:= IF(@t2 <= t3, t3 + 0.01, @t2) as rate_2 FROM price_fixed PF JOIN Compres C ON C.Id_Compra = idCOMPRA AND price_fixed_id = idPRICE JOIN tblTARIFAS TC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_table` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_tarifas_table`(v_entry INT) BEGIN DECLARE v_date DATE; DECLARE v_wh INT; -- Obtiene fecha de llegada y almacén entrante SELECT landing, warehouse_id INTO v_date , v_wh FROM travel TR JOIN Entradas E ON TR.id = E.travel_id WHERE Id_Entrada = v_entry; -- Prepara una tabla con las tarifas aplicables en funcion de la fecha y el almacén DROP TEMPORARY TABLE IF EXISTS tblTARIFAS; CREATE TEMPORARY TABLE tblTARIFAS ENGINE = MEMORY SELECT * FROM ( SELECT * FROM ( SELECT t0, t1, t2, t3 FROM tarifas WHERE fecha <= v_date AND warehouse_id = v_wh ORDER BY fecha DESC ) sub UNION ALL SELECT t0, t1, t2, t3 FROM tblContadores ) sub2 LIMIT 1; -- pak 22/09/2015 UPDATE bi.rotacion r JOIN Compres c ON c.Id_Article = r.Id_Article SET cm3 = vn2008.cm3_unidad(c.Id_Compra) WHERE Id_Entrada = v_entry AND r.warehouse_id = v_wh; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_transfer` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `buy_transfer`(v_buy INT, v_fv_entry INT, v_pca_entry INT) proc: BEGIN /** * Traslada la cantidad restante de una compra de Holanda * al almacén de Silla. **/ DECLARE v_wh INT; DECLARE v_entry INT; DECLARE v_fv INT; DECLARE v_amount INT; DECLARE v_item INT; DECLARE v_holland_wh INT DEFAULT 7; -- Comprueba que es mercancía que llega al almacén de Holanda SELECT t.warehouse_id, tp.FV INTO v_wh, v_fv FROM Compres c JOIN Entradas e ON c.Id_Entrada = e.Id_Entrada JOIN travel t ON t.id = e.travel_id JOIN Articles a ON a.Id_Article = c.Id_Article JOIN Tipos tp ON tp.tipo_id = a.tipo_id WHERE c.Id_Compra = v_buy; IF v_wh != v_holland_wh THEN LEAVE proc; END IF; -- Calcula a que almacén de Silla debe transladar la mercancía SET v_entry = IF(v_fv, v_fv_entry, v_pca_entry); SET v_entry = IFNULL(v_entry, IFNULL(v_pca_entry, v_fv_entry)); IF v_entry IS NULL THEN LEAVE proc; END IF; -- Calcula la cantidad a trasladar SELECT Id_Article INTO v_item FROM Compres WHERE Id_Compra = v_buy; SELECT IFNULL(SUM(amount), 0) INTO v_amount FROM ( SELECT SUM(c.Cantidad) amount FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE c.Id_Article = v_item AND t.landing = CURDATE() AND t.warehouse_id = v_holland_wh UNION ALL SELECT -SUM(c.Cantidad) FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE c.Id_Article = v_item AND t.shipment = CURDATE() AND t.warehouse_id_out = v_holland_wh UNION ALL SELECT -SUM(Cantidad) FROM Movimientos m JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket WHERE m.Id_Article = v_item AND t.Fecha = CURDATE() AND t.warehouse_id = v_holland_wh ) t; IF v_amount <= 0 THEN LEAVE proc; END IF; -- Crea la nueva línea de compra con el translado INSERT INTO Compres ( Id_Article, Etiquetas, Cantidad, Id_Entrada, Id_Cubo, Packing, grouping, caja, Costefijo, Portefijo, Embalajefijo, Comisionfija, novincular, buy_edi_id) SELECT c.Id_Article, v_amount DIV c.Packing, v_amount, v_entry, c.Id_Cubo, c.Packing, c.grouping, c.caja, @cost := IFNULL(c.Costefijo, 0) + IFNULL(c.Comisionfija, 0) + IFNULL(c.Portefijo, 0), @porte := ROUND((@cm3:= cm3_2(c.Id_Cubo, c.Id_Article)) * a.m3 / 1000000 / c.Packing, 3), c.EmbalajeFijo, @comision := ROUND(c.Costefijo * e.comision / 100, 3), c.novincular, c.buy_edi_id FROM Compres c JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo JOIN Entradas e ON e.Id_Entrada = v_entry JOIN travel t ON t.id = e.travel_id JOIN Agencias a ON t.agency_id = a.Id_Agencia WHERE c.Id_Compra = v_buy; CALL buy_tarifas (LAST_INSERT_ID()); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cacheReset` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cacheReset`(vCacheName VARCHAR(10), vParams VARCHAR(15)) BEGIN UPDATE cache.cache_calc SET expires = NOW() WHERE cacheName = vCacheName collate utf8_unicode_ci AND params = vParams collate utf8_unicode_ci; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `Cajas_Saldo_Detalle` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Cajas_Saldo_Detalle`() BEGIN Select Proveedores.Id_Proveedor, Proveedor, Fecha, round(Importe) as Importe from Proveedores join ( select Fecha, sub.Id_Proveedor, sum(Importe) as Importe from ( select round(sum(Importe),2) as Importe, TIMESTAMPADD(DAY,-1,CURDATE()) as Fecha, Id_Proveedor from pago join Proveedores using(Id_Proveedor) where Fecha >= '2011-01-01' and Id_Proveedor NOT IN (select id from empresa) group by Id_Proveedor union all select IFNULL(-1 * round(sum(rv.Cantidad / if(Id_Moneda = 2,rate,1)),2),0) AS Vto, TIMESTAMPADD(DAY,-1,CURDATE()), proveedor_id from recibida_vencimiento rv join recibida r on r.id = rv.recibida_id join reference_rate rr on rr.`date` = rv.fecha join Proveedores P on P.Id_Proveedor = r.proveedor_id join Paises PS on PS.Id = P.pais_id where rv.fecha between '2011-01-01' and CURDATE()-1 and Id_Proveedor NOT IN (select id from empresa) group by proveedor_id union all select -1 * round(rv.Cantidad / if(Id_Moneda = 2,currate(),1),2) AS Vto, rv.fecha, proveedor_id from recibida_vencimiento rv join recibida r on r.id = rv.recibida_id join Proveedores P on P.Id_Proveedor = r.proveedor_id join Paises PS on PS.Id = P.pais_id where rv.fecha >= CURDATE() and Id_Proveedor NOT IN (select id from empresa) union all select @remesas:= @pago:= @saldo:= 0.0000, curdate(), @prov:= 0) sub group by Fecha,Id_Proveedor ) sub2 using(Id_Proveedor) having Importe < -100 ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `CalculoRemesas` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `CalculoRemesas`(IN vFechaRemesa DATE) BEGIN DROP TEMPORARY TABLE IF EXISTS TMP_REMESAS; CREATE TEMPORARY TABLE TMP_REMESAS SELECT CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1, cli.Id_Cliente, cli.Cliente, cli.`IF` as NIF, c.PaymentDate as Vencimiento, 0 ImporteFac, cast(c.Recibo as decimal(10,2)) as ImporteRec, 0 as ImporteActual, c.company_id empresa_id, cli.RazonSocial, cast(c.Recibo as decimal(10,2)) as ImporteTotal, cast(c.Recibo as decimal(10,2)) as Saldo, p.Proveedor as Empresa, e.abbreviation as EMP, cli.cuenta, iban AS Iban, CONVERT(SUBSTRING(iban,5,4),UNSIGNED INT) AS nrbe , sepavnl as SEPA, corevnl as RecibidoCORE FROM Clientes cli JOIN (SELECT risk.company_id, c.Id_Cliente, sum(risk.amount) as Recibo, IF((c.Vencimiento + graceDays) mod 30.001 <= day(vFechaRemesa) ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-1,vFechaRemesa))) ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-2,vFechaRemesa))) ) as PaymentDate FROM Clientes c JOIN pay_met pm on pm.id = pay_met_id JOIN ( SELECT company_id, customer_id, amount FROM Clientes c JOIN bi.customer_risk cr ON cr.customer_id = c.Id_Cliente WHERE pay_met_id = 4 UNION ALL SELECT empresa_id, Id_Cliente, - Importe FROM Facturas f JOIN Clientes c using(Id_Cliente) JOIN pay_met pm on pm.id = pay_met_id WHERE f.Vencimiento > vFechaRemesa AND pay_met_id = 4 AND deudaviva AND Importe > 0 ) risk ON c.Id_Cliente = risk.customer_id GROUP BY risk.company_id, Id_Cliente HAVING Recibo > 10 ) c on c.Id_Cliente = cli.Id_Cliente JOIN Proveedores p on p.Id_Proveedor = c.company_id JOIN empresa e on e.id = c.company_id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `CalculoRemesaskk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `CalculoRemesaskk`(IN vFechaRemesa DATE) BEGIN DROP TEMPORARY TABLE IF EXISTS TMP_REMESAS; CREATE TEMPORARY TABLE TMP_REMESAS SELECT CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1, cli.Id_Cliente, cli.Cliente, cli.`IF` as NIF , cli.CC, c.PaymentDate as Vencimiento, 0 ImporteFac, cast(c.Recibo as decimal(10,2)) as ImporteRec, 0 as ImporteActual, c.empresa_id, cli.RazonSocial, cast(c.Recibo as decimal(10,2)) as ImporteTotal, cast(c.Recibo as decimal(10,2)) as Saldo, p.Proveedor as Empresa, e.abbreviation as EMP, cli.cuenta, CONCAT(cc_to_iban(CC),CC) AS Iban, CONVERT(left(CC,4),UNSIGNED INT) AS nrbe , IF(c.empresa_id=442,sepavnl,sepafth) as SEPA, IF(c.empresa_id=442,corevnl,corefth) as RecibidoCORE FROM Clientes cli JOIN (SELECT empresa_id, c.Id_Cliente, sum(Importe) as Recibo, IF((c.Vencimiento + graceDays) mod 30.001 <= day(vFechaRemesa) ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-1,vFechaRemesa))) ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-2,vFechaRemesa))) ) as PaymentDate FROM Clientes c JOIN pay_met pm on pm.id = pay_met_id JOIN ( SELECT empresa_id, Id_Cliente, Importe FROM Facturas f JOIN Clientes c using(Id_Cliente) JOIN pay_met pm on pm.id = pay_met_id WHERE IF(Importe > 0,paymentday(Fecha,c.Vencimiento + graceDays), Fecha) <= vFechaRemesa AND pay_met_id = 4 AND deudaviva UNION ALL SELECT empresa_id, Id_Cliente, - Entregado FROM Recibos r JOIN Clientes c using(Id_Cliente) JOIN pay_met pm on pm.id = pay_met_id WHERE pay_met_id = 4 AND deudaviva ) sub using(Id_Cliente) GROUP BY empresa_id, Id_Cliente HAVING Recibo > 10 ) c on c.Id_Cliente = cli.Id_Cliente JOIN Proveedores p on p.Id_Proveedor = c.empresa_id JOIN empresa e on e.id = c.empresa_id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `calling` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `calling`() BEGIN DROP TEMPORARY TABLE IF EXISTS Agenda, Agenda2; CREATE TEMPORARY TABLE IF NOT EXISTS Agenda (Telefono varchar(15) PRIMARY KEY, Cliente VARCHAR(45)); CREATE TEMPORARY TABLE IF NOT EXISTS Agenda2 LIKE Agenda; REPLACE Agenda(Telefono, Cliente) SELECT Telefono, Nombre from v_Agenda2; REPLACE Agenda(Telefono, Cliente) SELECT DISTINCT src, clid FROM cdr WHERE src < 6000 AND clid NOT LIKE '%device%' AND calldate > TIMESTAMPADD(DAY, -7,CURDATE()) ; INSERT INTO Agenda2(Telefono, Cliente) SELECT Telefono, Cliente FROM Agenda; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `camiones` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `camiones`(vWarehouse INT, vDate DATE) BEGIN SELECT Temperatura ,ROUND(SUM(Etiquetas * volume)) AS cm3 ,ROUND(SUM(IF(scanned, Etiquetas, 0) * volume)) AS cm3s ,ROUND(SUM(Vida * volume)) AS cm3e FROM ( SELECT t.Temperatura, c.Etiquetas, b.scanned, c.Vida, IF(cu.Volumen > 0, cu.Volumen, cu.x * cu.y * IF(cu.z > 0, cu.z, a.Medida + 10)) volume FROM Compres c LEFT JOIN buy_edi b ON b.id = c.buy_edi_id JOIN Articles a ON a.Id_Article = c.Id_Article JOIN Tipos t ON t.tipo_id = a.tipo_id JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel tr ON tr.id = e.travel_id JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo WHERE tr.warehouse_id = vWarehouse AND tr.landing = vDate ) sub GROUP BY Temperatura; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `Campaigns_Generator` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Campaigns_Generator`(IN datFEC DATE, IN intDAYS INT, IN intIMP INT) BEGIN DELETE FROM Campaigns; INSERT INTO Campaigns(Id_Cliente, Notas) SELECT T.Id_Cliente, CONCAT('Consumo año anterior: ',FORMAT(SUM(M.Cantidad * M.Preu * (100 - M.Descuento) / 100), 0), ' € ') as Total FROM Movimientos M INNER JOIN Tickets T ON T.Id_Ticket = M.Id_Ticket WHERE Date(T.Fecha) BETWEEN ADDDATE(datFEC,-1 * intDAYS) AND datFEC GROUP BY T.Id_Cliente; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `Campaigns_GeneratorKK` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Campaigns_GeneratorKK`(IN datFEC DATE, IN intDAYS INT, IN intIMP INT) BEGIN DELETE FROM Campaigns; INSERT INTO Campaigns(Id_Cliente, Notas) SELECT T.Id_Cliente, CONCAT('Consumo año anterior: ',FORMAT(SUM(M.Cantidad * M.Preu * (100 - M.Descuento) / 100), 0), ' € ') as Total FROM Movimientos M INNER JOIN Tickets T ON T.Id_Ticket = M.Id_Ticket WHERE Date(T.Fecha) BETWEEN ADDDATE(datFEC,-1 * intDAYS) AND datFEC GROUP BY T.Id_Cliente; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `Canariaskk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Canariaskk`(IN datFEC DATE, IN idWH INT , IN idEMP INT) BEGIN DECLARE idTICKET DOUBLE; CALL ticket_new_complet(4712, datFEC, idWH , 20, idEMP, NULL, NULL,NULL, idTICKET); INSERT INTO Movimientos (Id_Ticket, Id_Article, Concepte, Cantidad, Preu, PrecioFijado) SELECT idTICKET, 95, CONCAT(Codintrastat, ' : ', IF(Abreviatura = 'XYZ', 'NAC', Abreviatura), ' : ' , Nombotanic), sum(Cantidad), Preu, TRUE FROM Articles INNER JOIN Movimientos ON Articles.Id_Article = Movimientos.Id_Article INNER JOIN Tickets ON Movimientos.Id_Ticket = Tickets.Id_Ticket INNER JOIN Consignatarios ON Tickets.Id_Consigna = Consignatarios.Id_Consigna INNER JOIN province ON Consignatarios.province_id = province.province_id INNER JOIN Origen ON Articles.id_origen = Origen.id WHERE date(Tickets.Fecha) = datFEC AND province.name IN ('SANTA CRUZ DE TENERIFE','LAS PALMAS DE GRAN CANARIA') GROUP BY Nombotanic, Preu; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `check_table_existence` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `check_table_existence`(IN table_name CHAR(64)) BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE '42S02' SET @err = 1; SET @err = 0; SET @table_name = table_name; SET @sqlString = CONCAT('SELECT NULL FROM ',@table_name); PREPARE stmt1 FROM @sqlString; IF (@err = 1) THEN SET @table_exists = 0; ELSE SET @table_exists = 1; DEALLOCATE PREPARE stmt1; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clean`(IN v_full TINYINT(1)) BEGIN DECLARE v_date DATETIME; DECLARE v_date_fut DATE; DECLARE v_date18 DATETIME; DECLARE v_date8 DATE; DECLARE v_date6 DATE; DECLARE v_date3Month DATE; DECLARE strtable varchar(15) DEFAULT NULL; DECLARE done BIT DEFAULT 0; SET v_date = TIMESTAMPADD(MONTH, -2, CURDATE()); SET v_date18 = TIMESTAMPADD(MONTH, -18,CURDATE()); SET v_date3Month = TIMESTAMPADD(MONTH, -3, CURDATE()); SET v_date8 = TIMESTAMPADD(DAY, -8,CURDATE()); SET v_date6 = TIMESTAMPADD(DAY, -6,CURDATE()); INSERT INTO vn2008.daily_task_log(consulta) VALUES('clean START'); DELETE FROM cdr WHERE calldate < v_date; DELETE FROM Monitoring WHERE ODBC_TIME < v_date; DELETE FROM Conteo WHERE Fecha < v_date; DELETE FROM XDiario WHERE FECHA < v_date3Month OR FECHA IS NULL; DELETE FROM mail WHERE DATE_ODBC < v_date; -- DELETE FROM Cajas WHERE CajaFecha < v_date18; DELETE rr FROM Recibos_recorded rr JOIN Recibos r ON rr.Id_Recibos = r.Id WHERE r.Fechacobro < v_date; SELECT MAX(idTickets_dits) INTO @id FROM Tickets_dits WHERE ODBC_DATE < v_date; DELETE FROM Tickets_dits WHERE idTickets_dits <= @id; -- DELETE FROM Tickets_dits WHERE ODBC_DATE < v_date; DELETE FROM expeditions WHERE odbc_date < v_date18; DELETE FROM expeditions_deleted WHERE odbc_date < v_date18; DELETE FROM Entradas_dits WHERE ODBC_DATE < v_date18; DELETE FROM log_articles WHERE ODBC_DATE < v_date; DELETE FROM sms WHERE DATE_ODBC < v_date18; DELETE FROM Movimientos_mark WHERE odbc_date < v_date; DELETE FROM Splits WHERE Fecha < v_date18; DELETE ts FROM Tickets_stack ts JOIN Tickets t ON ts.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date; DELETE tobs FROM ticket_observation tobs JOIN Tickets t ON tobs.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date; DELETE tobs FROM movement_label tobs JOIN Movimientos m ON tobs.Id_Movimiento = m.Id_Movimiento JOIN Tickets t ON m.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date; DELETE FROM chat WHERE odbc_date < v_date; DELETE FROM Extractos WHERE Fecha < v_date; DELETE FROM Remesas WHERE `Fecha Remesa` < v_date18; DELETE FROM sharingcart where datEND < v_date; DELETE FROM sharingclient where datEND < v_date; DELETE FROM Stockcontrol WHERE Datestart < v_date18; DELETE FROM bi.comparativa_clientes WHERE Fecha < v_date18; DELETE FROM reference_rate WHERE date < v_date18; SELECT MAX(inter_id) INTO @id FROM vncontrol.inter WHERE odbc_date < v_date18; DELETE FROM vncontrol.inter WHERE inter_id <= @id; -- DELETE FROM vncontrol.inter WHERE odbc_date < v_date18; DELETE FROM Entradas_dits WHERE ODBC_DATE < v_date; DELETE FROM Ordenes WHERE datTICKET < v_date18 AND datTICKET <> '2000-01-01'; DELETE FROM cyc_declaration WHERE Fecha < v_date18; DELETE FROM vn.message WHERE sendDate < v_date; DELETE FROM travel_reserve WHERE odbc_date < v_date; -- DELETE FROM syslog.systemevents WHERE odbc_date < v_date8; DELETE FROM daily_task_log WHERE odbc_date < v_date; -- DELETE FROM bi.Greuge_Evolution WHERE Fecha < v_date AND weekday(Fecha) != 1; DELETE mc FROM Movimientos_checked mc JOIN Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento WHERE m.odbc_date < v_date; DELETE FROM cache.departure_limit WHERE Fecha < TIMESTAMPADD(MONTH,-1,CURDATE()); DELETE cm FROM Compres_mark cm JOIN Compres c ON c.Id_Compra = cm.Id_Compra JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE t.landing <= v_date; DELETE co FROM Compres_ok co JOIN Compres c ON c.Id_Compra = co.Id_Compra JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE t.landing <= v_date; -- DELETE FROM vn2008.scan WHERE odbc_date < v_date6 AND id <> 1; SET v_date = TIMESTAMPADD(YEAR, 2000 - YEAR(v_date), v_date); SET v_date_fut = TIMESTAMPADD(MONTH, 3, v_date); IF v_date_fut > '2000-12-31' THEN SET v_date_fut = '2000-12-30'; END IF; IF v_full THEN DELETE FROM Tickets WHERE (Fecha <= v_date AND Fecha NOT IN ('2000-01-01','2000-01-02')) OR (Fecha BETWEEN v_date_fut AND '2000-12-31'); DELETE e.* FROM Entradas e LEFT JOIN recibida_entrada re ON e.Id_Entrada = re.Id_Entrada WHERE travel_id IS NULL AND re.Id_Entrada IS NULL; END IF; -- Tickets vacios PAK 17/05/2016 UPDATE Tickets t JOIN ( SELECT DISTINCT t.Id_Ticket FROM Tickets t LEFT JOIN Movimientos m using(Id_Ticket) WHERE Id_Movimiento IS NULL AND t.Fecha between '2016-01-01' and util.yesterday()) sub using(Id_Ticket) SET t.Fecha = TIMESTAMPADD(YEAR, 2000 - year(CURDATE()), t.Fecha ); -- Tickets Nulos PAK 11/10/2016 UPDATE vn2008.Tickets SET empresa_id = 965 WHERE Id_Cliente = 31 AND empresa_id != 965; -- Equipos duplicados DELETE w.* FROM vn2008.workerTeam w JOIN (SELECT id, team, user, COUNT(*) - 1 as duplicated FROM vn.workerTeam GROUP BY team,user HAVING duplicated ) d ON d.team = w.team AND d.user = w.user AND d.id != w.id; INSERT INTO vn2008.daily_task_log(consulta) VALUES('clean END'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `clean_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clean_launcher`() BEGIN call vn2008.clean(TRUE); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `Clientes_Calidad` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Clientes_Calidad`() BEGIN DECLARE intMONTH INTEGER; DECLARE intYEAR INTEGER; SET intYEAR = YEAR(Curdate()); SET intMONTH = MONTH(curdate())-1; IF intMONTH = 0 THEN SET intYEAR = intYEAR -1; SET intMONTH = 12; END IF; UPDATE Clientes SET Calidad = 0; TRUNCATE bi.calidad_detalle; INSERT INTO bi.calidad_detalle(Id_Cliente,calidad_parametros_id,valor) SELECT Id_Cliente, calidad_parametros_id, 0 FROM bi.calidad_parametros JOIN Clientes; -- Valoramos del 0 al 5 su consumo REPLACE INTO bi.calidad_detalle(Id_Cliente,calidad_parametros_id,valor) SELECT Id_Cliente, 1, IF(Consumo > 5, 5, Consumo) FROM ( SELECT Id_Cliente, round(sum(importe)/1000) as Consumo from bs.ventas v join vn2008.time t on t.date = v.fecha where year =intYEAR and month = intMONTH group by Id_Cliente) sub; -- Incrementamos dos puntos a los de giro bancario, y restamos uno a los de pago contado/contrareembolso REPLACE INTO bi.calidad_detalle(Id_Cliente,calidad_parametros_id,valor) SELECT Id_Cliente, 3, CASE pay_met_id WHEN 4 -- giro THEN 2 WHEN 1 -- contado THEN -1 WHEN 5 -- tarjeta THEN 1 WHEN 7 -- tarjeta THEN 1 WHEN 6 -- contrareembolso THEN -1 ELSE 0 END FROM Clientes; /* Incrementamos a los que tengan reclamaciones 0%, 2 puntos 1%, 1 punto 2% 0 puntos 3% -3 puntos 4% - 6 puntos 5% - 9 puntos */ REPLACE INTO bi.calidad_detalle(Id_Cliente,calidad_parametros_id,valor) SELECT Id_Cliente, 2, CASE nz(Ratio) WHEN 0 THEN 2 WHEN 0.01 THEN 1 WHEN 0.02 THEN 0 WHEN 0.03 THEN -3 WHEN 0.04 THEN -6 ELSE -9 END FROM bi.claims_ratio ; -- Ahora les ponemos un punto a los que compran por la web mas del 50% de sus pedidos REPLACE INTO bi.calidad_detalle(Id_Cliente,calidad_parametros_id,valor) SELECT Id_Cliente, 4, Webs FROM ( SELECT Id_Cliente, sum(sub.Id_Trabajador = 4) / count(sub.Id_Trabajador) as Webs FROM Tickets JOIN (SELECT Id_Ticket, Id_Trabajador FROM Tickets_dits WHERE idaccion_dits = 84 AND ODBC_DATE >= TIMESTAMPADD(DAY,-30,CURDATE())) sub USING(Id_Ticket) WHERE Fecha > '2001-01-01' AND Id_Agencia <> 23 -- ni tickets borrados, ni abonos cuentan GROUP BY Id_Cliente HAVING Webs > 0.5) sub2; -- Marcamos con un 11 a los clientes recien nacidos, para protegerlos REPLACE INTO bi.calidad_detalle(Id_Cliente,calidad_parametros_id,valor) SELECT Id_Cliente, 5, 11 FROM (SELECT Id_Cliente, MIN(Fecha) as Inicio FROM Tickets WHERE Fecha > '2001-01-01' GROUP BY Id_Cliente HAVING Inicio >= TIMESTAMPADD(DAY,-30,CURDATE())) sub ; -- Ahora actualizamos la tabla Clientes UPDATE Clientes JOIN (SELECT Id_Cliente, SUM(valor) AS valoracion FROM bi.calidad_detalle GROUP BY Id_Cliente) sub USING (Id_Cliente) SET calidad = IF(valoracion > 11, 11, valoracion); IF DAY(CURDATE()) = 1 THEN -- Y de paso, desactivamos a los que hace tiempo que no compran.alter -- JGF Sólo desctivamos a los clientes que no han comprado en los dos ultimos meses UPDATE account.user u SET active = 0 WHERE u.role = 2 AND id NOT IN (SELECT DISTINCT c.Id_Cliente FROM Clientes c LEFT JOIN Tickets t ON t.Id_Cliente = c.Id_Cliente WHERE Created > TIMESTAMPADD(MONTH, - 2, CURDATE()) OR Fecha > TIMESTAMPADD(MONTH, - 2, CURDATE())); END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `Clientes_Calidad_detalle` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Clientes_Calidad_detalle`(IN IdC INT) BEGIN SELECT descripcion Concepto, valor Puntos FROM bi.calidad_parametros JOIN bi.calidad_detalle using(calidad_parametros_id) WHERE Id_Cliente = idC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientes_saldos` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clientes_saldos`() BEGIN DROP TEMPORARY TABLE IF EXISTS clientes_pendientes; CREATE TEMPORARY TABLE clientes_pendientes ( Id_Cliente INT NOT NULL , empresa_id INT NOT NULL , saldo double NOT NULL , PRIMARY KEY(Id_Cliente, empresa_id)); INSERT INTO clientes_pendientes SELECT Id_Cliente, empresa_id, sum(importe) as saldo FROM ( SELECT Id_Cliente, empresa_id, - Entregado as importe FROM Recibos JOIN Clientes USING(Id_Cliente) JOIN pay_met p on p.id = pay_met_id WHERE deudaviva UNION ALL SELECT Id_Cliente, empresa_id, Importe FROM Facturas JOIN Clientes USING(Id_Cliente) JOIN pay_met p on p.id = pay_met_id WHERE deudaviva ) sub GROUP BY empresa_id, Id_Cliente having saldo > 0; DROP TEMPORARY TABLE IF EXISTS cobros_pendientes; CREATE TEMPORARY TABLE cobros_pendientes (Id_Cliente INT ,fecha DATE ,empresa_id INT NOT NULL ,saldo DOUBLE ,PRIMARY KEY(Id_Cliente, empresa_id)); INSERT INTO cobros_pendientes(Id_Cliente , fecha , empresa_id , saldo) SELECT cp.Id_Cliente, CASE (vencimiento > 30) WHEN TRUE THEN timestampadd(DAY,vencimiento,maxFecha) ELSE timestampadd( DAY ,vencimiento - day(maxFecha) ,timestampadd(MONTH,1,maxFecha) ) END as fecha, cp.empresa_id, cp.saldo FROM clientes_pendientes cp JOIN Clientes USING(Id_Cliente) JOIN ( SELECT max(Fecha) as maxFecha, Id_Cliente, empresa_id FROM Facturas GROUP BY Id_Cliente, empresa_id ) mf on mf.Id_Cliente = cp.Id_Cliente AND mf.empresa_id = cp.empresa_id; SELECT * FROM cobros_pendientes; DROP TEMPORARY TABLE cobros_pendientes; DROP TEMPORARY TABLE clientes_pendientes; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientManaGrouped` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clientManaGrouped`(vClient INT) BEGIN SELECT 'Tickets' as Grupo, CAST(sum(s.quantity * Valor) AS DECIMAL(10,2)) as Mana FROM vn.ticket t JOIN vn.address a ON a.id = t.addressFk JOIN vn.sale s on s.ticketFk = t.id JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = s.id WHERE Id_Componente IN (37, 39) AND t.shipped >= '2016-01-01' AND t.clientFk = vClient UNION ALL SELECT 'Recibos' as Grupo, - sum(Entregado) as Mana FROM vn2008.Recibos r JOIN vn2008.Clientes c using(Id_Cliente) WHERE r.Id_Banco = 66 AND r.Fechacobro >= '2016-01-01' AND c.Id_Cliente = vClient UNION ALL SELECT 'Greuges' as Grupo, sum(g.Importe) as Mana FROM vn2008.Greuges g JOIN vn2008.Clientes c using(Id_Cliente) WHERE g.Greuges_type_id = 3 -- Maná AND g.Fecha > '2016-01-01' AND c.Id_Cliente = vClient; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `clonWeeklyTickets` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clonWeeklyTickets`(IN vWeek INT) BEGIN DECLARE done BIT DEFAULT 0; DECLARE vLanding DATE; DECLARE vShipment DATE; DECLARE vWarehouse INT; DECLARE vTicket INT; DECLARE vWeekDay INT; DECLARE vClient INT; DECLARE vEmpresa INT; DECLARE vConsignatario INT; DECLARE vAgencia INT; DECLARE vNewTicket INT; DECLARE vYear INT; DECLARE rsTicket CURSOR FOR SELECT tt.Id_Ticket, weekDay, Id_Cliente, warehouse_id, empresa_id, Id_Consigna, Id_Agencia FROM Tickets_turno tt JOIN Tickets t ON tt.Id_Ticket = t.Id_Ticket; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET done = 0; SET vYear = YEAR(CURDATE()) + IF(vWeek < WEEK(CURDATE()),1, 0); OPEN rsTicket; FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vConsignatario, vAgencia; WHILE NOT done DO SELECT date INTO vShipment FROM time WHERE year = vYear AND week = vWeek AND WEEKDAY(date) = vWeekDay; -- busca si el ticket ya ha sido clonado IF (select count(*) FROM Tickets t JOIN ticket_observation tob ON t.Id_Ticket = tob.Id_Ticket WHERE Id_Consigna = vConsignatario AND Fecha = vShipment AND tob.text LIKE CONCAT('%',vTicket,'%')) = 0 THEN IF (SELECT COUNT(*) FROM Agencias WHERE Id_Agencia = vAgencia AND Agencia LIKE '%turno%') THEN SET vAgencia = NULL; END IF; CALL vn.ticketCreate(vClient, vShipment, vWarehouse, vEmpresa, vConsignatario, vAgencia, NULL, vLanding, vNewTicket); INSERT INTO Movimientos (Id_Ticket, Id_Article, Concepte, Cantidad, Preu, Descuento, CostFixat, PrecioFijado) SELECT vNewTicket, Id_Article, Concepte, Cantidad, Preu, Descuento, CostFixat, PrecioFijado FROM Movimientos WHERE Id_Ticket = vTicket; INSERT INTO Ordenes (orden,datorden,datticket,codvendedor,codcomprador,cantidad,preciomax,preu,id_article,id_cliente,comentario, ok, total,datcompra,ko,id_movimiento) SELECT o.orden,o.datorden,vShipment,o.codvendedor,o.codcomprador,o.cantidad,o.preciomax,o.preu,o.id_article,o.id_cliente,o.comentario, o.ok, o.total,o.datcompra,o.ko,m2.Id_Movimiento FROM Movimientos m JOIN Ordenes o ON o.Id_Movimiento = m.Id_Movimiento JOIN Movimientos m2 ON m.Concepte = m2.Concepte AND m.Cantidad = m2.Cantidad AND m.Id_Article = m2.Id_Article WHERE m.Id_Ticket = vTicket AND m2.Id_Ticket = vNewTicket; INSERT INTO ticket_observation(Id_Ticket,observation_type_id,text) VALUES(vNewTicket,4,CONCAT('turno desde ticket: ',vTicket)) ON DUPLICATE KEY UPDATE text = CONCAT(ticket_observation.text,VALUES(text),' '); CALL bionic_calc_clon(vNewTicket); END IF; FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vConsignatario, vAgencia; END WHILE; CLOSE rsTicket; DROP TEMPORARY TABLE IF EXISTS travel_tree_shipment; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cobro` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cobro`(IN datFEC DATE , IN idCLI INT , IN dblIMPORTE DOUBLE , IN idCAJA INT , IN idPAYMET INT , IN strCONCEPTO VARCHAR(40) , IN idEMP INT , IN idWH INT , IN idTRABAJADOR INT) BEGIN DECLARE bolCASH BOOLEAN; DECLARE cuenta_banco BIGINT; DECLARE cuenta_cliente BIGINT; DECLARE max_asien INT; -- XDIARIO -- No se asientan los cobros directamente, salvo en el caso de las cajas de CASH SELECT (cash = 1) INTO bolCASH FROM Bancos WHERE Bancos.Id_Banco = idCAJA; IF bolCASH THEN SELECT Cuenta INTO cuenta_banco FROM Bancos WHERE Id_Banco = idCAJA; SELECT Cuenta INTO cuenta_cliente FROM Clientes WHERE Id_Cliente = idCLI; SELECT MAX(asien)+1 INTO max_asien FROM XDiario; INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id) SELECT max_asien,datFEC,SUBCTA,CONTRA,strCONCEPTO,EURODEBE,EUROHABER,idEMP FROM ( SELECT cuenta_banco SUBCTA, cuenta_cliente CONTRA, 0 EURODEBE, dblIMPORTE EUROHABER UNION ALL SELECT cuenta_cliente SUBCTA, cuenta_banco CONTRA, dblIMPORTE EURODEBE, 0 EUROHABER ) gf; END IF; -- CAJERA INSERT INTO Cajas(Id_Trabajador , Id_Banco , Entrada , Concepto , Cajafecha , Serie , Partida , Numero ,empresa_id ,warehouse_id) VALUES ( idTRABAJADOR , idCAJA , dblIMPORTE , strCONCEPTO , datFEC , 'A' , TRUE , idCLI , idEMP , idWH ); -- RECIBO INSERT INTO Recibos(Entregado ,Fechacobro ,Id_Trabajador ,Id_Banco ,Id_Cliente ,Id_Factura ,empresa_id) VALUES ( dblIMPORTE , datFEC , idTRABAJADOR , idCAJA , idCLI , strCONCEPTO , idEMP); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `colas_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `colas_launcher`() BEGIN INSERT INTO vn2008.Colas(Id_Informe,Id_Trabajador) VALUES (11,57); INSERT INTO vn2008.Colas(Id_Informe) VALUES (16); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comercial_caducado` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comercial_caducado`() BEGIN -- Este procedimiento le pasa los clientes al jefe de ventas cuando llevan dos meses inactivos IF day(CURDATE()) = 5 then -- solo se ejecuta los dias 5 de cada mes Update Clientes join ( Select c.Id_Cliente from Clientes c join jerarquia j on j.worker_id = c.Id_Trabajador -- este filtro es para que solo toque los de los comerciales join ( select Id_Cliente, sum(Importe) as Saldo from ( select Id_Cliente, Importe from Facturas union all select Id_Cliente, - Entregado from Recibos ) sub group by Id_Cliente ) sindeuda on sindeuda.Id_Cliente = c.Id_Cliente left join ( select distinct Id_Cliente from Facturas where Fecha BETWEEN CURDATE() - INTERVAL 12 MONTH AND CURDATE() ) f on f.Id_Cliente = c.Id_Cliente left join ( select distinct Id_Cliente from Tickets where Fecha between CURDATE() - INTERVAL 2 DAY AND CURDATE() + INTERVAL 200 DAY ) tic_vivos on tic_vivos.Id_Cliente = c.Id_Cliente where c.Created < CURDATE() - INTERVAL 2 MONTH -- este filtro respeta a los recien nacidos.... and j.boss_id = 87 -- sólo afecta a los comerciales de Alfredo and f.Id_Cliente is null -- comprueba que no tenga facturas en los dos ultimos meses and sindeuda.Saldo < 10 -- sólo cambia a los clientes con deuda escasa o nula and tic_vivos.Id_Cliente is null -- si tiene tickets vivos, lo respeta ) sub using(Id_Cliente) set Id_Trabajador = 87 ;-- Alfredo Giner; end if; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comparativa_clientes` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comparativa_clientes`(IN v_date DATE,IN i_vendedor INT, IN i_comprador INT, IN i_tipo INT, IN i_wh INT, IN days INT) BEGIN DECLARE date_cyear_ini DATETIME; DECLARE date_cyear_end DATETIME; DECLARE date_lyear_ini DATETIME; DECLARE date_lyear_end DATETIME; DECLARE week_count TINYINT DEFAULT 7; SET date_cyear_ini = TIMESTAMP(DATE(TIMESTAMPADD(DAY, -22 - WEEKDAY(v_date), v_date)), '00:00:00'); SET date_cyear_end = TIMESTAMP(DATE(TIMESTAMPADD(DAY, (7 * week_count) -1, date_cyear_ini)), '23:59:59'); SET date_lyear_ini = TIMESTAMPADD(DAY,-364,date_cyear_ini); SET date_lyear_end = TIMESTAMPADD(DAY,-364,date_cyear_end); CALL article (); INSERT INTO article_inventory (article_id) SELECT Id_Article FROM Articles a JOIN Tipos t ON t.tipo_id = a.tipo_id LEFT JOIN reinos r ON r.id = t.reino_id WHERE (i_tipo = 0 OR a.tipo_id = i_tipo) AND r.display <> 0; IF v_date < CURDATE() THEN ALTER TABLE `article_inventory` ADD `buy_id` INT NOT NULL DEFAULT 0, ADD `buy_date` DATE DEFAULT '2000-01-01', ADD `life` INT DEFAULT 0, ADD `sd` INT DEFAULT 0, ADD `avalaible` INT DEFAULT 0, ADD `visible` INT DEFAULT 0; ELSE CALL inventario_multiple_2 (v_date, i_wh, days); CALL article_multiple_buy (v_date, i_wh); CALL article_multiple_buy_date (v_date, i_wh); END IF; DROP TEMPORARY TABLE IF EXISTS clientcom; CREATE TEMPORARY TABLE clientcom SELECT vnperiod(Fecha) as period ,Id_Article , Cantidad , Preu , CS.Id_Cliente FROM vn2008.Movimientos M JOIN vn2008.Tickets T USING (Id_Ticket) JOIN vn2008.Consignatarios CS USING(Id_Consigna) JOIN vn2008.Clientes C ON C.Id_Cliente = CS.Id_Cliente JOIN vn2008.Articles a USING (Id_Article) LEFT JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id WHERE (T.Fecha BETWEEN date_cyear_ini AND date_cyear_end or T.Fecha BETWEEN date_lyear_ini AND date_lyear_end) AND T.Id_Cliente NOT IN(400,200) AND i_vendedor IN (0, C.Id_Trabajador ) AND i_comprador IN (0, tp.Id_Trabajador) AND i_tipo IN (0,tp.tipo_id) AND r.display <> 0 AND T.warehouse_id NOT IN (0,13) ORDER BY period; DROP TEMPORARY TABLE IF EXISTS clientcom_periods; CREATE TEMPORARY TABLE clientcom_periods SELECT period, @order:= @order + 1 as period_order FROM ( SELECT DISTINCT period, @order:=0 FROM clientcom ORDER BY period) sub; SELECT cc.Id_Article , cc.Id_Cliente ,CAST(SUM(IF(period_order = 1, cc.Cantidad, 0)) AS SIGNED) AS lweek1 ,CAST(SUM(IF(period_order = 2, cc.Cantidad, 0)) AS SIGNED) AS lweek2 ,CAST(SUM(IF(period_order = 3, cc.Cantidad, 0)) AS SIGNED) AS lweek3 ,CAST(SUM(IF(period_order = 4, cc.Cantidad, 0)) AS SIGNED) AS lweek4 ,CAST(SUM(IF(period_order = 5, cc.Cantidad, 0)) AS SIGNED) AS lweek5 ,CAST(SUM(IF(period_order = 6, cc.Cantidad, 0)) AS SIGNED) AS lweek6 ,CAST(SUM(IF(period_order = 7, cc.Cantidad, 0)) AS SIGNED) AS lweek7 ,CAST(SUM(IF(period_order = 7+1, cc.Cantidad, 0)) AS SIGNED) AS cweek1 ,CAST(SUM(IF(period_order = 7+2, cc.Cantidad, 0)) AS SIGNED) AS cweek2 ,CAST(SUM(IF(period_order = 7+3, cc.Cantidad, 0)) AS SIGNED) AS cweek3 ,CAST(SUM(IF(period_order = 7+4, cc.Cantidad, 0)) AS SIGNED) AS cweek4 ,CAST(SUM(IF(period_order = 7+5, cc.Cantidad, 0)) AS SIGNED) AS cweek5 ,CAST(SUM(IF(period_order = 7+6, cc.Cantidad, 0)) AS SIGNED) AS cweek6 ,CAST(SUM(IF(period_order = 7+7, cc.Cantidad, 0)) AS SIGNED) AS cweek7 ,CAST(SUM(IF(period_order = 1, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice1 ,CAST(SUM(IF(period_order = 2, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice2 ,CAST(SUM(IF(period_order = 3, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice3 ,CAST(SUM(IF(period_order = 4, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice4 ,CAST(SUM(IF(period_order = 5, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice5 ,CAST(SUM(IF(period_order = 6, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice6 ,CAST(SUM(IF(period_order = 7, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice7 ,CAST(SUM(IF(period_order = 7+1, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice1 ,CAST(SUM(IF(period_order = 7+2, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice2 ,CAST(SUM(IF(period_order = 7+3, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice3 ,CAST(SUM(IF(period_order = 7+4, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice4 ,CAST(SUM(IF(period_order = 7+5, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice5 ,CAST(SUM(IF(period_order = 7+6, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice6 ,CAST(SUM(IF(period_order = 7+7, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice7 ,A.Article ,A.Medida ,A.Color ,A.tipo_id ,C.Cliente ,T1.CodigoTrabajador as Comercial ,O.Abreviatura as Origen ,TT.ball as Tinta ,r.reino as Reino ,TP.Id_Tipo ,JF.CodigoTrabajador as Equipo ,T2.CodigoTrabajador as Comprador ,TT.orden as Orden_Color ,i.buy_id , i.life , CAST(IFNULL(i.sd,0) AS SIGNED) as sd ,CAST(i.avalaible AS SIGNED) avalaible , CAST(i.visible AS SIGNED) visible , i.buy_date ,P.Proveedor FROM clientcom cc JOIN clientcom_periods ccp using(period) -- La parte del inventario LEFT JOIN article_inventory i ON i.article_id = cc.Id_Article LEFT JOIN Compres CM ON i.buy_id = CM.Id_Compra LEFT JOIN Entradas E USING(Id_Entrada) LEFT JOIN Proveedores P ON P.Id_Proveedor = E.Id_Proveedor -- Ahora la parte de los vendedores JOIN Clientes C ON C.Id_Cliente = cc.Id_Cliente JOIN Trabajadores T1 ON C.Id_Trabajador = T1.Id_Trabajador LEFT JOIN jerarquia J ON J.worker_id = T1.Id_Trabajador JOIN Trabajadores JF ON JF.Id_Trabajador = J.boss_id -- JOIN Trabajadores JF ON T1.Id_Trabajador = JF.boss JGF propuesta para sustituir por las dos lineas superiores -- Ahora la parte de los compradores JOIN Articles A ON A.Id_Article = cc.Id_Article JOIN Origen O ON O.id = A.id_origen JOIN Tintas TT ON TT.Id_Tinta = A.Color JOIN Tipos TP ON TP.tipo_id = A.tipo_id JOIN reinos r ON r.id = TP.reino_id JOIN Trabajadores T2 ON T2.Id_Trabajador = TP.Id_Trabajador GROUP BY Id_Article,Id_Cliente; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comparativa_clienteskk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comparativa_clienteskk`(IN v_date DATE,IN i_vendedor INT, IN i_comprador INT, IN i_tipo INT, IN i_wh INT, IN days INT) BEGIN DECLARE date_cyear_ini DATETIME; DECLARE date_cyear_end DATETIME; DECLARE date_lyear_ini DATETIME; DECLARE date_lyear_end DATETIME; DECLARE week_count TINYINT DEFAULT 7; SET date_cyear_ini = TIMESTAMP(DATE(TIMESTAMPADD(DAY, -22 - WEEKDAY(v_date), v_date)), '00:00:00'); SET date_cyear_end = TIMESTAMP(DATE(TIMESTAMPADD(DAY, (7 * week_count) -1, date_cyear_ini)), '23:59:59'); SET date_lyear_ini = TIMESTAMPADD(DAY,-364,date_cyear_ini); SET date_lyear_end = TIMESTAMPADD(DAY,-364,date_cyear_end); CALL article (); INSERT INTO article_inventory (article_id) SELECT Id_Article FROM Articles a JOIN Tipos t using(tipo_id) WHERE i_tipo = 0 OR a.tipo_id = i_tipo AND reino_id <> 6; IF v_date < CURDATE() THEN ALTER TABLE `article_inventory` ADD `buy_id` INT NOT NULL DEFAULT 0, ADD `buy_date` DATE DEFAULT '2000-01-01', ADD `life` INT DEFAULT 0, ADD `sd` INT DEFAULT 0, ADD `avalaible` INT DEFAULT 0, ADD `visible` INT DEFAULT 0; ELSE CALL inventario_multiple_2 (v_date, i_wh, days); CALL article_multiple_buy (v_date, i_wh); CALL article_multiple_buy_date (v_date, i_wh); END IF; DROP TEMPORARY TABLE IF EXISTS clientcom; CREATE TEMPORARY TABLE clientcom SELECT vnperiod(Fecha) as period ,Id_Article , Cantidad , Preu , CS.Id_Cliente FROM vn2008.Movimientos M JOIN vn2008.Tickets T USING (Id_Ticket) JOIN vn2008.Consignatarios CS USING(Id_Consigna) JOIN vn2008.Clientes C ON C.Id_Cliente = CS.Id_Cliente JOIN vn2008.Articles A USING (Id_Article) LEFT JOIN vn2008.Tipos USING(tipo_id) WHERE (T.Fecha BETWEEN date_cyear_ini AND date_cyear_end or T.Fecha BETWEEN date_lyear_ini AND date_lyear_end) AND T.Id_Cliente NOT IN(400,200) AND i_vendedor IN (0, C.Id_Trabajador ) AND i_comprador IN (0, Tipos.Id_Trabajador) AND i_tipo IN (0,Tipos.tipo_id) AND reino_id <> 6 AND T.warehouse_id NOT IN (0,13) ORDER BY period; DROP TEMPORARY TABLE IF EXISTS clientcom_periods; CREATE TEMPORARY TABLE clientcom_periods SELECT period, @order:= @order + 1 as period_order FROM ( SELECT DISTINCT period, @order:=0 FROM clientcom ORDER BY period) sub; SELECT cc.Id_Article , cc.Id_Cliente ,CAST(SUM(IF(period_order = 1, cc.Cantidad, 0)) AS SIGNED) AS lweek1 ,CAST(SUM(IF(period_order = 2, cc.Cantidad, 0)) AS SIGNED) AS lweek2 ,CAST(SUM(IF(period_order = 3, cc.Cantidad, 0)) AS SIGNED) AS lweek3 ,CAST(SUM(IF(period_order = 4, cc.Cantidad, 0)) AS SIGNED) AS lweek4 ,CAST(SUM(IF(period_order = 5, cc.Cantidad, 0)) AS SIGNED) AS lweek5 ,CAST(SUM(IF(period_order = 6, cc.Cantidad, 0)) AS SIGNED) AS lweek6 ,CAST(SUM(IF(period_order = 7, cc.Cantidad, 0)) AS SIGNED) AS lweek7 ,CAST(SUM(IF(period_order = 7+1, cc.Cantidad, 0)) AS SIGNED) AS cweek1 ,CAST(SUM(IF(period_order = 7+2, cc.Cantidad, 0)) AS SIGNED) AS cweek2 ,CAST(SUM(IF(period_order = 7+3, cc.Cantidad, 0)) AS SIGNED) AS cweek3 ,CAST(SUM(IF(period_order = 7+4, cc.Cantidad, 0)) AS SIGNED) AS cweek4 ,CAST(SUM(IF(period_order = 7+5, cc.Cantidad, 0)) AS SIGNED) AS cweek5 ,CAST(SUM(IF(period_order = 7+6, cc.Cantidad, 0)) AS SIGNED) AS cweek6 ,CAST(SUM(IF(period_order = 7+7, cc.Cantidad, 0)) AS SIGNED) AS cweek7 ,CAST(SUM(IF(period_order = 1, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice1 ,CAST(SUM(IF(period_order = 2, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice2 ,CAST(SUM(IF(period_order = 3, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice3 ,CAST(SUM(IF(period_order = 4, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice4 ,CAST(SUM(IF(period_order = 5, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice5 ,CAST(SUM(IF(period_order = 6, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice6 ,CAST(SUM(IF(period_order = 7, cc.Cantidad* Preu, 0)) AS SIGNED) AS lprice7 ,CAST(SUM(IF(period_order = 7+1, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice1 ,CAST(SUM(IF(period_order = 7+2, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice2 ,CAST(SUM(IF(period_order = 7+3, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice3 ,CAST(SUM(IF(period_order = 7+4, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice4 ,CAST(SUM(IF(period_order = 7+5, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice5 ,CAST(SUM(IF(period_order = 7+6, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice6 ,CAST(SUM(IF(period_order = 7+7, cc.Cantidad* Preu, 0)) AS SIGNED) AS cprice7 ,A.Article ,A.Medida ,A.Color ,A.tipo_id ,C.Cliente ,T1.CodigoTrabajador as Comercial ,O.Abreviatura as Origen ,TT.ball as Tinta ,r.reino as Reino ,TP.Id_Tipo ,JF.CodigoTrabajador as Equipo ,T2.CodigoTrabajador as Comprador ,TT.orden as Orden_Color ,i.buy_id , i.life , CAST(IFNULL(i.sd,0) AS SIGNED) as sd ,CAST(i.avalaible AS SIGNED) avalaible , CAST(i.visible AS SIGNED) visible , i.buy_date ,P.Proveedor FROM clientcom cc JOIN clientcom_periods ccp using(period) -- La parte del inventario LEFT JOIN article_inventory i ON i.article_id = cc.Id_Article LEFT JOIN Compres CM ON i.buy_id = CM.Id_Compra LEFT JOIN Entradas E USING(Id_Entrada) LEFT JOIN Proveedores P ON P.Id_Proveedor = E.Id_Proveedor -- Ahora la parte de los vendedores JOIN Clientes C ON C.Id_Cliente = cc.Id_Cliente JOIN Trabajadores T1 ON C.Id_Trabajador = T1.Id_Trabajador LEFT JOIN jerarquia J ON J.worker_id = T1.Id_Trabajador JOIN Trabajadores JF ON JF.Id_Trabajador = J.boss_id -- JOIN Trabajadores JF ON T1.Id_Trabajador = JF.boss JGF propuesta para sustituir por las dos lineas superiores -- Ahora la parte de los compradores JOIN Articles A ON A.Id_Article = cc.Id_Article JOIN Origen O ON O.id = A.id_origen JOIN Tintas TT ON TT.Id_Tinta = A.Color JOIN Tipos TP ON TP.tipo_id = A.tipo_id JOIN reinos r ON r.id = TP.reino_id JOIN Trabajadores T2 ON T2.Id_Trabajador = TP.Id_Trabajador GROUP BY Id_Article,Id_Cliente; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comparativa_clientes_tickets` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comparativa_clientes_tickets`(IN i_week INT , IN i_year INT , IN i_vendedor INT , IN i_comprador INT , IN i_article INT , IN i_cliente INT , IN i_tipo INT , IN i_reino INT , IN i_equipo INT , IN v_color varchar(3)) BEGIN DECLARE datSTART DATETIME; DECLARE datEND DATETIME; SELECT min(date), TIMESTAMP(max(date),'23:59:59') INTO datSTART, datEND FROM time WHERE i_week = week AND i_year = year; SELECT T.Id_Ticket, Fecha, Alias, Id_Article, Concepte, Cantidad, Preu, M.Descuento, Cantidad * Preu * (100-M.Descuento)/100 as Importe, w.name as almacen FROM Movimientos M JOIN Tickets T using(Id_Ticket) JOIN warehouse w on w.id = T.warehouse_id JOIN Consignatarios CS using(Id_Consigna) JOIN Clientes C ON C.Id_Cliente = CS.Id_Cliente JOIN Trabajadores TR ON TR.Id_Trabajador = C.Id_Trabajador JOIN jerarquia J ON J.worker_id = TR.Id_Trabajador JOIN Articles A using(Id_Article) JOIN Tipos TP using(tipo_id) WHERE T.Fecha BETWEEN datSTART AND datEND AND i_vendedor IN (0, C.Id_Trabajador) AND i_comprador IN (0, TP.Id_Trabajador) AND i_cliente IN (0, CS.Id_Cliente) AND i_tipo IN (0, A.tipo_id) AND i_article IN (0,A.Id_Article) AND i_reino IN (0,TP.reino_id) AND i_equipo IN(0,J.boss_id) AND v_color IN ("",A.color); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comparative` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comparative`( v_date DATETIME ,days TINYINT ,i_wh TINYINT ,i_tipo INT ,i_filtro INT ) BEGIN DECLARE wstart INT; DECLARE wend INT; DECLARE cyear INT; DECLARE date_cyear_ini DATETIME; DECLARE date_cyear_end DATETIME; DECLARE week_count TINYINT DEFAULT 7; DECLARE date_lyear_ini DATETIME; DECLARE date_lyear_end DATETIME; DECLARE corrector INT; DECLARE w1, w2, w3, w4, w5, w6, w7 INT; DECLARE y1, y2, y3, y4, y5, y6, y7 INT; DECLARE wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016 DECLARE i INT DEFAULT 0; DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE'; IF i_filtro THEN SELECT `sql` INTO strFILTRO FROM filtros WHERE id = i_filtro; END IF; SET corrector = 1; IF days < 0 OR days > 30 THEN SET days = 15; END IF; IF i_wh = NULL THEN SET i_wh = 0; END IF; -- JGF 2015-04-16 cambio -21 por -22 para que la semana cuente de domingo a sabado SET date_cyear_ini = TIMESTAMP(DATE(TIMESTAMPADD(DAY, -22 - WEEKDAY(v_date), v_date)), '00:00:00'); SET date_cyear_end = TIMESTAMP(DATE(TIMESTAMPADD(DAY, (7 * week_count) -1, date_cyear_ini)), '23:59:59'); -- Eliminamos el calculo del inventario para fechas en el pasado CALL article (); INSERT INTO article_inventory (article_id) SELECT Id_Article FROM Articles a JOIN Tipos t ON a.tipo_id = t.tipo_id LEFT JOIN reinos r ON r.id = t.reino_id WHERE (i_tipo = 0 OR a.tipo_id = i_tipo) AND r.display <> 0; IF v_date < CURDATE() THEN ALTER TABLE `article_inventory` ADD `buy_id` INT NOT NULL DEFAULT 0, ADD `buy_date` DATE DEFAULT '2000-01-01', ADD `life` INT DEFAULT 0, ADD `sd` INT DEFAULT 0, ADD `avalaible` INT DEFAULT 0, ADD `visible` INT DEFAULT 0; ELSE CALL inventario_multiple_2 (v_date, i_wh, days); CALL article_multiple_buy (v_date, i_wh); CALL article_multiple_buy_date (v_date, i_wh); END IF; DROP TEMPORARY TABLE IF EXISTS wtable; CREATE TEMPORARY TABLE wtable ( cy INT(6), ly INT(6) ); REPEAT SET i = i + 1; SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini)); -- PAK 11/01/2016 INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100); -- VALUES( ys * 100 + ws, (ys -1) * 100 + ws); -- PAK 11/01/2016 UNTIL i = 7 END REPEAT; SELECT cy, ly INTO w1, y1 FROM wtable limit 1; SELECT cy, ly INTO w2, y2 FROM wtable WHERE cy > w1 limit 1; SELECT cy, ly INTO w3, y3 FROM wtable WHERE cy > w2 limit 1; SELECT cy, ly INTO w4, y4 FROM wtable WHERE cy > w3 limit 1; SELECT cy, ly INTO w5, y5 FROM wtable WHERE cy > w4 limit 1; SELECT cy, ly INTO w6, y6 FROM wtable WHERE cy > w5 limit 1; SELECT cy, ly INTO w7, y7 FROM wtable WHERE cy > w6 limit 1; DROP TEMPORARY TABLE wtable; SET cyear = YEAR(date_cyear_ini); -- Genera una tabla con los datos del año pasado. DROP TEMPORARY TABLE IF EXISTS last_year; CREATE TEMPORARY TABLE last_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(Periodo = y1, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek1 ,CAST(SUM(IF(Periodo = y2, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek2 ,CAST(SUM(IF(Periodo = y3, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek3 ,CAST(SUM(IF(Periodo = y4, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek4 ,CAST(SUM(IF(Periodo = y5, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek5 ,CAST(SUM(IF(Periodo = y6, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek6 ,CAST(SUM(IF(Periodo = y7, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek7 ,CAST(SUM(IF(Periodo = y1, price, 0)) AS DECIMAL(10,0)) AS lprice1 ,CAST(SUM(IF(Periodo = y2, price, 0)) AS DECIMAL(10,0)) AS lprice2 ,CAST(SUM(IF(Periodo = y3, price, 0)) AS DECIMAL(10,0)) AS lprice3 ,CAST(SUM(IF(Periodo = y4, price, 0)) AS DECIMAL(10,0)) AS lprice4 ,CAST(SUM(IF(Periodo = y5, price, 0)) AS DECIMAL(10,0)) AS lprice5 ,CAST(SUM(IF(Periodo = y6, price, 0)) AS DECIMAL(10,0)) AS lprice6 ,CAST(SUM(IF(Periodo = y7, price, 0)) AS DECIMAL(10,0)) AS lprice7 FROM Comparativa JOIN warehouse W on W.id = warehouse_id WHERE (Periodo BETWEEN y1 and y7) AND IF(i_wh = 0, W.is_comparative, i_wh = warehouse_id) GROUP BY Id_Article; -- Genera una tabla con los datos de este año. DROP TEMPORARY TABLE IF EXISTS cur_year; CREATE TEMPORARY TABLE cur_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(week = w1, Total, 0)) AS DECIMAL(10,0)) AS cweek1 ,CAST(SUM(IF(week = w2, Total, 0)) AS DECIMAL(10,0)) AS cweek2 ,CAST(SUM(IF(week = w3, Total, 0)) AS DECIMAL(10,0)) AS cweek3 ,CAST(SUM(IF(week = w4, Total, 0)) AS DECIMAL(10,0)) AS cweek4 ,CAST(SUM(IF(week = w5, Total, 0)) AS DECIMAL(10,0)) AS cweek5 ,CAST(SUM(IF(week = w6, Total, 0)) AS DECIMAL(10,0)) AS cweek6 ,CAST(SUM(IF(week = w7, Total, 0)) AS DECIMAL(10,0)) AS cweek7 ,CAST(SUM(IF(week = w1, price, 0)) AS DECIMAL(10,0)) AS cprice1 ,CAST(SUM(IF(week = w2, price, 0)) AS DECIMAL(10,0)) AS cprice2 ,CAST(SUM(IF(week = w3, price, 0)) AS DECIMAL(10,0)) AS cprice3 ,CAST(SUM(IF(week = w4, price, 0)) AS DECIMAL(10,0)) AS cprice4 ,CAST(SUM(IF(week = w5, price, 0)) AS DECIMAL(10,0)) AS cprice5 ,CAST(SUM(IF(week = w6, price, 0)) AS DECIMAL(10,0)) AS cprice6 ,CAST(SUM(IF(week = w7, price, 0)) AS DECIMAL(10,0)) AS cprice7 FROM ( SELECT A.Id_Article ,CTS.period week ,SUM(Cantidad) AS Total ,TRUNCATE(SUM(Cantidad * IF(T.Fecha >= '2015-10-01',M.CostFixat,Preu * (100 - Descuento) / 100)),0) AS price FROM Movimientos M LEFT JOIN Tickets T ON T.Id_Ticket = M.Id_Ticket INNER JOIN `time` CTS ON CTS.`date` = DATE(T.Fecha) INNER JOIN Articles A USING (Id_Article) INNER JOIN Tipos tp ON tp.tipo_id = A.tipo_id LEFT JOIN reinos r ON r.id = tp.reino_id JOIN warehouse W ON W.id = T.warehouse_id WHERE Fecha BETWEEN date_cyear_ini AND date_cyear_end AND T.Id_Cliente NOT IN(400,200) AND IF(i_wh = 0, W.is_comparative, i_wh = T.warehouse_id) AND r.display <> 0 GROUP BY A.Id_Article, week ) t GROUP BY Id_Article; -- Genera la tabla con la comparativa. DROP TEMPORARY TABLE IF EXISTS remcom; SET strFILTRO = REPLACE(strFILTRO, 'Id_Article','A.Id_Article'); SET strFILTRO = REPLACE(strFILTRO, 'tipo_id','tp.tipo_id'); -- select * from article_inventory; CALL util.exec (sql_printf ( 'CREATE TEMPORARY TABLE vn2008.remcom SELECT an.nicho, p.name Productor, C.Packing, C.Costefijo ,A.Color, Id_Tipo as Tipo,A.tipo_id, o.Abreviatura as Origen, A.Categoria ,A.Tallos, A.Medida, A.Article, TR.CodigoTrabajador ,cweek1, cweek2, cweek3, cweek4, cweek5, cweek6, cweek7 ,lweek1, lweek2, lweek3, lweek4, lweek5, lweek6, lweek7 ,cprice1, cprice2, cprice3, cprice4, cprice5, cprice6, cprice7 ,lprice1, lprice2, lprice3, lprice4, lprice5, lprice6, lprice7 ,A.Id_Article, i.buy_id , tp.life , CAST(IFNULL(i.sd,0) AS SIGNED) as sd ,CAST(i.avalaible AS SIGNED) avalaible, CAST(i.visible AS SIGNED) visible, i.buy_date ,E.Id_Proveedor AS provider_id, t.Orden, t.Tinta ,A.offer, A.bargain, A.comments, A.relevancy ,IF(cy.Id_Article IS NULL AND i.visible = 0 AND i.avalaible = 0 AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) AS filtret FROM vn2008.article_inventory i JOIN vn2008.Articles A ON A.Id_Article = i.article_id LEFT JOIN vn2008.Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s LEFT JOIN vn2008.producer p ON p.producer_id = A.producer_id LEFT JOIN vn2008.Tipos tp ON A.tipo_id = tp.tipo_id LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id LEFT JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador LEFT JOIN vn2008.Tintas t ON t.Id_Tinta = A.color LEFT JOIN vn2008.Compres C ON i.buy_id = C.Id_Compra LEFT JOIN vn2008.Entradas E USING(Id_Entrada) LEFT JOIN vn2008.Origen o ON o.id = A.id_origen LEFT JOIN vn2008.last_year ly ON ly.Id_Article = A.Id_Article LEFT JOIN vn2008.cur_year cy ON cy.Id_Article = A.Id_Article AND (i.avalaible <> 0 OR i.visible <> 0 OR cweek1 OR cweek2 OR cweek3 OR cweek4 OR cweek5 OR cweek6 OR cweek7 OR lweek1 OR lweek2 OR lweek3 OR lweek4 OR lweek5 OR lweek6 OR lweek7) WHERE r.display <> 0 AND %s ' ,i_wh,strFILTRO )); ALTER TABLE remcom CHANGE COLUMN `cweek1` `cweek1` INT NOT NULL, CHANGE COLUMN `cweek2` `cweek2` INT NOT NULL, CHANGE COLUMN `cweek3` `cweek3` INT NOT NULL, CHANGE COLUMN `cweek4` `cweek4` INT NOT NULL, CHANGE COLUMN `cweek5` `cweek5` INT NOT NULL, CHANGE COLUMN `cweek6` `cweek6` INT NOT NULL, CHANGE COLUMN `cweek7` `cweek7` INT NOT NULL, CHANGE COLUMN `lweek1` `lweek1` INT NOT NULL, CHANGE COLUMN `lweek2` `lweek2` INT NOT NULL, CHANGE COLUMN `lweek3` `lweek3` INT NOT NULL, CHANGE COLUMN `lweek4` `lweek4` INT NOT NULL, CHANGE COLUMN `lweek5` `lweek5` INT NOT NULL, CHANGE COLUMN `lweek6` `lweek6` INT NOT NULL, CHANGE COLUMN `lweek7` `lweek7` INT NOT NULL; SELECT * FROM remcom; -- Destruye las tablas temporales creadas. DROP TEMPORARY TABLE last_year; DROP TEMPORARY TABLE cur_year; DROP TEMPORARY TABLE article_inventory; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comparativekk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comparativekk`( v_date DATETIME ,days TINYINT ,i_wh TINYINT ,i_tipo INT ,i_filtro INT ) BEGIN DECLARE wstart INT; DECLARE wend INT; DECLARE cyear INT; DECLARE date_cyear_ini DATETIME; DECLARE date_cyear_end DATETIME; DECLARE week_count TINYINT DEFAULT 7; DECLARE date_lyear_ini DATETIME; DECLARE date_lyear_end DATETIME; DECLARE corrector INT; DECLARE w1, w2, w3, w4, w5, w6, w7 INT; DECLARE y1, y2, y3, y4, y5, y6, y7 INT; DECLARE wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016 DECLARE i INT DEFAULT 0; DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE'; IF i_filtro THEN SELECT `sql` INTO strFILTRO FROM filtros WHERE id = i_filtro; END IF; SET corrector = 1; IF days < 0 OR days > 30 THEN SET days = 15; END IF; IF i_wh = NULL THEN SET i_wh = 0; END IF; -- JGF 2015-04-16 cambio -21 por -22 para que la semana cuente de domingo a sabado SET date_cyear_ini = TIMESTAMP(DATE(TIMESTAMPADD(DAY, -22 - WEEKDAY(v_date), v_date)), '00:00:00'); SET date_cyear_end = TIMESTAMP(DATE(TIMESTAMPADD(DAY, (7 * week_count) -1, date_cyear_ini)), '23:59:59'); -- Eliminamos el calculo del inventario para fechas en el pasado CALL article (); INSERT INTO article_inventory (article_id) SELECT Id_Article FROM Articles a JOIN Tipos t ON a.tipo_id = t.tipo_id LEFT JOIN vn2008.reinos r ON r.id = t.reino_id WHERE (i_tipo = 0 OR a.tipo_id = i_tipo) AND r.display <> 0; IF v_date < CURDATE() THEN ALTER TABLE `article_inventory` ADD `buy_id` INT NOT NULL DEFAULT 0, ADD `buy_date` DATE DEFAULT '2000-01-01', ADD `life` INT DEFAULT 0, ADD `sd` INT DEFAULT 0, ADD `avalaible` INT DEFAULT 0, ADD `visible` INT DEFAULT 0; ELSE CALL inventario_multiple_2 (v_date, i_wh, days); CALL article_multiple_buy (v_date, i_wh); CALL article_multiple_buy_date (v_date, i_wh); END IF; DROP TEMPORARY TABLE IF EXISTS wtable; CREATE TEMPORARY TABLE wtable ( cy INT(6), ly INT(6) ); REPEAT SET i = i + 1; SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini)); -- PAK 11/01/2016 INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100); -- VALUES( ys * 100 + ws, (ys -1) * 100 + ws); -- PAK 11/01/2016 UNTIL i = 7 END REPEAT; SELECT cy, ly INTO w1, y1 FROM wtable limit 1; SELECT cy, ly INTO w2, y2 FROM wtable WHERE cy > w1 limit 1; SELECT cy, ly INTO w3, y3 FROM wtable WHERE cy > w2 limit 1; SELECT cy, ly INTO w4, y4 FROM wtable WHERE cy > w3 limit 1; SELECT cy, ly INTO w5, y5 FROM wtable WHERE cy > w4 limit 1; SELECT cy, ly INTO w6, y6 FROM wtable WHERE cy > w5 limit 1; SELECT cy, ly INTO w7, y7 FROM wtable WHERE cy > w6 limit 1; DROP TEMPORARY TABLE wtable; SET cyear = YEAR(date_cyear_ini); -- Genera una tabla con los datos del año pasado. DROP TEMPORARY TABLE IF EXISTS last_year; CREATE TEMPORARY TABLE last_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(Periodo = y1, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek1 ,CAST(SUM(IF(Periodo = y2, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek2 ,CAST(SUM(IF(Periodo = y3, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek3 ,CAST(SUM(IF(Periodo = y4, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek4 ,CAST(SUM(IF(Periodo = y5, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek5 ,CAST(SUM(IF(Periodo = y6, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek6 ,CAST(SUM(IF(Periodo = y7, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek7 ,CAST(SUM(IF(Periodo = y1, price, 0)) AS DECIMAL(10,0)) AS lprice1 ,CAST(SUM(IF(Periodo = y2, price, 0)) AS DECIMAL(10,0)) AS lprice2 ,CAST(SUM(IF(Periodo = y3, price, 0)) AS DECIMAL(10,0)) AS lprice3 ,CAST(SUM(IF(Periodo = y4, price, 0)) AS DECIMAL(10,0)) AS lprice4 ,CAST(SUM(IF(Periodo = y5, price, 0)) AS DECIMAL(10,0)) AS lprice5 ,CAST(SUM(IF(Periodo = y6, price, 0)) AS DECIMAL(10,0)) AS lprice6 ,CAST(SUM(IF(Periodo = y7, price, 0)) AS DECIMAL(10,0)) AS lprice7 FROM Comparativa JOIN warehouse W on W.id = warehouse_id WHERE (Periodo BETWEEN y1 and y7) AND IF(i_wh = 0, W.is_comparative, i_wh = warehouse_id) GROUP BY Id_Article; -- Genera una tabla con los datos de este año. DROP TEMPORARY TABLE IF EXISTS cur_year; CREATE TEMPORARY TABLE cur_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(week = w1, Total, 0)) AS DECIMAL(10,0)) AS cweek1 ,CAST(SUM(IF(week = w2, Total, 0)) AS DECIMAL(10,0)) AS cweek2 ,CAST(SUM(IF(week = w3, Total, 0)) AS DECIMAL(10,0)) AS cweek3 ,CAST(SUM(IF(week = w4, Total, 0)) AS DECIMAL(10,0)) AS cweek4 ,CAST(SUM(IF(week = w5, Total, 0)) AS DECIMAL(10,0)) AS cweek5 ,CAST(SUM(IF(week = w6, Total, 0)) AS DECIMAL(10,0)) AS cweek6 ,CAST(SUM(IF(week = w7, Total, 0)) AS DECIMAL(10,0)) AS cweek7 ,CAST(SUM(IF(week = w1, price, 0)) AS DECIMAL(10,0)) AS cprice1 ,CAST(SUM(IF(week = w2, price, 0)) AS DECIMAL(10,0)) AS cprice2 ,CAST(SUM(IF(week = w3, price, 0)) AS DECIMAL(10,0)) AS cprice3 ,CAST(SUM(IF(week = w4, price, 0)) AS DECIMAL(10,0)) AS cprice4 ,CAST(SUM(IF(week = w5, price, 0)) AS DECIMAL(10,0)) AS cprice5 ,CAST(SUM(IF(week = w6, price, 0)) AS DECIMAL(10,0)) AS cprice6 ,CAST(SUM(IF(week = w7, price, 0)) AS DECIMAL(10,0)) AS cprice7 FROM ( SELECT A.Id_Article ,CTS.period week ,SUM(Cantidad) AS Total ,TRUNCATE(SUM(Cantidad * IF(T.Fecha >= '2015-10-01',M.CostFixat,Preu * (100 - Descuento) / 100)),0) AS price FROM Movimientos M LEFT JOIN Tickets T ON T.Id_Ticket = M.Id_Ticket INNER JOIN `time` CTS ON CTS.`date` = DATE(T.Fecha) INNER JOIN Articles A USING (Id_Article) INNER JOIN Tipos tp ON tp.tipo_id = A.tipo_id LEFT JOIN reinos r ON r.id = tp.reino_id JOIN warehouse W ON W.id = T.warehouse_id WHERE Fecha BETWEEN date_cyear_ini AND date_cyear_end AND T.Id_Cliente NOT IN(400,200) AND IF(i_wh = 0, W.is_comparative, i_wh = T.warehouse_id) AND r.display <> 0 GROUP BY A.Id_Article, week ) t GROUP BY Id_Article; -- Genera la tabla con la comparativa. DROP TEMPORARY TABLE IF EXISTS remcom; SET strFILTRO = REPLACE(strFILTRO, 'Id_Article','A.Id_Article'); SET strFILTRO = REPLACE(strFILTRO, 'tipo_id','tp.tipo_id'); -- select * from article_inventory; CALL util.exec (sql_printf ( 'CREATE TEMPORARY TABLE vn2008.remcom SELECT an.nicho, p.name Productor, C.Packing, C.Costefijo ,A.Color, Id_Tipo as Tipo,A.tipo_id, o.Abreviatura as Origen, A.Categoria ,A.Tallos, A.Medida, A.Article, TR.CodigoTrabajador ,cweek1, cweek2, cweek3, cweek4, cweek5, cweek6, cweek7 ,lweek1, lweek2, lweek3, lweek4, lweek5, lweek6, lweek7 ,cprice1, cprice2, cprice3, cprice4, cprice5, cprice6, cprice7 ,lprice1, lprice2, lprice3, lprice4, lprice5, lprice6, lprice7 ,A.Id_Article, i.buy_id , i.life , CAST(IFNULL(i.sd,0) AS SIGNED) as sd ,CAST(i.avalaible AS SIGNED) avalaible, CAST(i.visible AS SIGNED) visible, i.buy_date ,E.Id_Proveedor AS provider_id, t.Orden, t.Tinta ,A.offer, A.bargain, A.comments ,IF(cy.Id_Article IS NULL AND i.visible = 0 AND i.avalaible = 0 AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) AS filtret FROM vn2008.article_inventory i JOIN vn2008.Articles A ON A.Id_Article = i.article_id LEFT JOIN vn2008.Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s LEFT JOIN vn2008.producer p ON p.producer_id = A.producer_id LEFT JOIN vn2008.Tipos tp ON A.tipo_id = tp.tipo_id LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id LEFT JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador LEFT JOIN vn2008.Tintas t ON t.Id_Tinta = A.color LEFT JOIN vn2008.Compres C ON i.buy_id = C.Id_Compra LEFT JOIN vn2008.Entradas E USING(Id_Entrada) LEFT JOIN vn2008.Origen o ON o.id = A.id_origen LEFT JOIN vn2008.last_year ly ON ly.Id_Article = A.Id_Article LEFT JOIN vn2008.cur_year cy ON cy.Id_Article = A.Id_Article WHERE r.display <> 0 AND (i.avalaible <> 0 OR i.visible <> 0 OR cweek1 OR cweek2 OR cweek3 OR cweek4 OR cweek5 OR cweek6 OR cweek7 OR lweek1 OR lweek2 OR lweek3 OR lweek4 OR lweek5 OR lweek6 OR lweek7) AND %s LIMIT 20000' ,i_wh,strFILTRO )); ALTER TABLE remcom CHANGE COLUMN `cweek1` `cweek1` INT NOT NULL, CHANGE COLUMN `cweek2` `cweek2` INT NOT NULL, CHANGE COLUMN `cweek3` `cweek3` INT NOT NULL, CHANGE COLUMN `cweek4` `cweek4` INT NOT NULL, CHANGE COLUMN `cweek5` `cweek5` INT NOT NULL, CHANGE COLUMN `cweek6` `cweek6` INT NOT NULL, CHANGE COLUMN `cweek7` `cweek7` INT NOT NULL, CHANGE COLUMN `lweek1` `lweek1` INT NOT NULL, CHANGE COLUMN `lweek2` `lweek2` INT NOT NULL, CHANGE COLUMN `lweek3` `lweek3` INT NOT NULL, CHANGE COLUMN `lweek4` `lweek4` INT NOT NULL, CHANGE COLUMN `lweek5` `lweek5` INT NOT NULL, CHANGE COLUMN `lweek6` `lweek6` INT NOT NULL, CHANGE COLUMN `lweek7` `lweek7` INT NOT NULL; SELECT * FROM remcom; -- Destruye las tablas temporales creadas. DROP TEMPORARY TABLE last_year; DROP TEMPORARY TABLE cur_year; DROP TEMPORARY TABLE article_inventory; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comparativekk2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comparativekk2`( v_date DATETIME ,days TINYINT ,i_wh TINYINT ,i_tipo INT ,i_filtro INT ) BEGIN DECLARE wstart INT; DECLARE wend INT; DECLARE cyear INT; DECLARE date_cyear_ini DATETIME; DECLARE date_cyear_end DATETIME; DECLARE week_count TINYINT DEFAULT 7; DECLARE date_lyear_ini DATETIME; DECLARE date_lyear_end DATETIME; DECLARE corrector INT; DECLARE w1, w2, w3, w4, w5, w6, w7 INT; DECLARE y1, y2, y3, y4, y5, y6, y7 INT; DECLARE wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016 DECLARE i INT DEFAULT 0; DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE'; IF i_filtro THEN SELECT `sql` INTO strFILTRO FROM filtros WHERE id = i_filtro; END IF; SET corrector = 1; IF days < 0 OR days > 30 THEN SET days = 15; END IF; IF i_wh = NULL THEN SET i_wh = 0; END IF; -- JGF 2015-04-16 cambio -21 por -22 para que la semana cuente de domingo a sabado SET date_cyear_ini = TIMESTAMP(DATE(TIMESTAMPADD(DAY, -22 - WEEKDAY(v_date), v_date)), '00:00:00'); SET date_cyear_end = TIMESTAMP(DATE(TIMESTAMPADD(DAY, (7 * week_count) -1, date_cyear_ini)), '23:59:59'); -- Eliminamos el calculo del inventario para fechas en el pasado CALL article (); INSERT INTO article_inventory (article_id) SELECT Id_Article FROM Articles a JOIN Tipos t ON a.tipo_id = t.tipo_id LEFT JOIN vn2008.reinos r ON r.id = t.reino_id WHERE (i_tipo = 0 OR a.tipo_id = i_tipo) AND r.display <> 0; IF v_date < CURDATE() THEN ALTER TABLE `article_inventory` ADD `buy_id` INT NOT NULL DEFAULT 0, ADD `buy_date` DATE DEFAULT '2000-01-01', ADD `life` INT DEFAULT 0, ADD `sd` INT DEFAULT 0, ADD `avalaible` INT DEFAULT 0, ADD `visible` INT DEFAULT 0; ELSE CALL inventario_multiple_2 (v_date, i_wh, days); CALL article_multiple_buy (v_date, i_wh); CALL article_multiple_buy_date (v_date, i_wh); END IF; DROP TEMPORARY TABLE IF EXISTS wtable; CREATE TEMPORARY TABLE wtable ( cy INT(6), ly INT(6) ); REPEAT SET i = i + 1; SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini)); -- PAK 11/01/2016 INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100); -- VALUES( ys * 100 + ws, (ys -1) * 100 + ws); -- PAK 11/01/2016 UNTIL i = 7 END REPEAT; SELECT cy, ly INTO w1, y1 FROM wtable limit 1; SELECT cy, ly INTO w2, y2 FROM wtable WHERE cy > w1 limit 1; SELECT cy, ly INTO w3, y3 FROM wtable WHERE cy > w2 limit 1; SELECT cy, ly INTO w4, y4 FROM wtable WHERE cy > w3 limit 1; SELECT cy, ly INTO w5, y5 FROM wtable WHERE cy > w4 limit 1; SELECT cy, ly INTO w6, y6 FROM wtable WHERE cy > w5 limit 1; SELECT cy, ly INTO w7, y7 FROM wtable WHERE cy > w6 limit 1; DROP TEMPORARY TABLE wtable; SET cyear = YEAR(date_cyear_ini); -- Genera una tabla con los datos del año pasado. DROP TEMPORARY TABLE IF EXISTS last_year; CREATE TEMPORARY TABLE last_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(Periodo = y1, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek1 ,CAST(SUM(IF(Periodo = y2, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek2 ,CAST(SUM(IF(Periodo = y3, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek3 ,CAST(SUM(IF(Periodo = y4, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek4 ,CAST(SUM(IF(Periodo = y5, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek5 ,CAST(SUM(IF(Periodo = y6, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek6 ,CAST(SUM(IF(Periodo = y7, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek7 ,CAST(SUM(IF(Periodo = y1, price, 0)) AS DECIMAL(10,0)) AS lprice1 ,CAST(SUM(IF(Periodo = y2, price, 0)) AS DECIMAL(10,0)) AS lprice2 ,CAST(SUM(IF(Periodo = y3, price, 0)) AS DECIMAL(10,0)) AS lprice3 ,CAST(SUM(IF(Periodo = y4, price, 0)) AS DECIMAL(10,0)) AS lprice4 ,CAST(SUM(IF(Periodo = y5, price, 0)) AS DECIMAL(10,0)) AS lprice5 ,CAST(SUM(IF(Periodo = y6, price, 0)) AS DECIMAL(10,0)) AS lprice6 ,CAST(SUM(IF(Periodo = y7, price, 0)) AS DECIMAL(10,0)) AS lprice7 FROM Comparativa JOIN warehouse W on W.id = warehouse_id WHERE (Periodo BETWEEN y1 and y7) AND IF(i_wh = 0, W.is_comparative, i_wh = warehouse_id) GROUP BY Id_Article; -- Genera una tabla con los datos de este año. DROP TEMPORARY TABLE IF EXISTS cur_year; CREATE TEMPORARY TABLE cur_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(week = w1, Total, 0)) AS DECIMAL(10,0)) AS cweek1 ,CAST(SUM(IF(week = w2, Total, 0)) AS DECIMAL(10,0)) AS cweek2 ,CAST(SUM(IF(week = w3, Total, 0)) AS DECIMAL(10,0)) AS cweek3 ,CAST(SUM(IF(week = w4, Total, 0)) AS DECIMAL(10,0)) AS cweek4 ,CAST(SUM(IF(week = w5, Total, 0)) AS DECIMAL(10,0)) AS cweek5 ,CAST(SUM(IF(week = w6, Total, 0)) AS DECIMAL(10,0)) AS cweek6 ,CAST(SUM(IF(week = w7, Total, 0)) AS DECIMAL(10,0)) AS cweek7 ,CAST(SUM(IF(week = w1, price, 0)) AS DECIMAL(10,0)) AS cprice1 ,CAST(SUM(IF(week = w2, price, 0)) AS DECIMAL(10,0)) AS cprice2 ,CAST(SUM(IF(week = w3, price, 0)) AS DECIMAL(10,0)) AS cprice3 ,CAST(SUM(IF(week = w4, price, 0)) AS DECIMAL(10,0)) AS cprice4 ,CAST(SUM(IF(week = w5, price, 0)) AS DECIMAL(10,0)) AS cprice5 ,CAST(SUM(IF(week = w6, price, 0)) AS DECIMAL(10,0)) AS cprice6 ,CAST(SUM(IF(week = w7, price, 0)) AS DECIMAL(10,0)) AS cprice7 FROM ( SELECT A.Id_Article ,CTS.period week ,SUM(Cantidad) AS Total ,TRUNCATE(SUM(Cantidad * IF(T.Fecha >= '2015-10-01',M.CostFixat,Preu * (100 - Descuento) / 100)),0) AS price FROM Movimientos M LEFT JOIN Tickets T ON T.Id_Ticket = M.Id_Ticket INNER JOIN `time` CTS ON CTS.`date` = DATE(T.Fecha) INNER JOIN Articles A USING (Id_Article) INNER JOIN Tipos tp ON tp.tipo_id = A.tipo_id LEFT JOIN reinos r ON r.id = tp.reino_id JOIN warehouse W ON W.id = T.warehouse_id WHERE Fecha BETWEEN date_cyear_ini AND date_cyear_end AND T.Id_Cliente NOT IN(400,200) AND IF(i_wh = 0, W.is_comparative, i_wh = T.warehouse_id) AND r.display <> 0 GROUP BY A.Id_Article, week ) t GROUP BY Id_Article; -- Genera la tabla con la comparativa. DROP TEMPORARY TABLE IF EXISTS remcom; SET strFILTRO = REPLACE(strFILTRO, 'Id_Article','A.Id_Article'); SET strFILTRO = REPLACE(strFILTRO, 'tipo_id','tp.tipo_id'); -- select * from article_inventory; CALL util.exec (sql_printf ( 'CREATE TEMPORARY TABLE vn2008.remcom SELECT an.nicho, p.name Productor, C.Packing, C.Costefijo ,A.Color, Id_Tipo as Tipo,A.tipo_id, o.Abreviatura as Origen, A.Categoria ,A.Tallos, A.Medida, A.Article, TR.CodigoTrabajador ,cweek1, cweek2, cweek3, cweek4, cweek5, cweek6, cweek7 ,lweek1, lweek2, lweek3, lweek4, lweek5, lweek6, lweek7 ,cprice1, cprice2, cprice3, cprice4, cprice5, cprice6, cprice7 ,lprice1, lprice2, lprice3, lprice4, lprice5, lprice6, lprice7 ,A.Id_Article, i.buy_id , tp.life , CAST(IFNULL(i.sd,0) AS SIGNED) as sd ,CAST(i.avalaible AS SIGNED) avalaible, CAST(i.visible AS SIGNED) visible, i.buy_date ,E.Id_Proveedor AS provider_id, t.Orden, t.Tinta ,A.offer, A.bargain, A.comments, A.relevancy ,IF(cy.Id_Article IS NULL AND i.visible = 0 AND i.avalaible = 0 AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) AS filtret FROM vn2008.article_inventory i JOIN vn2008.Articles A ON A.Id_Article = i.article_id LEFT JOIN vn2008.Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s LEFT JOIN vn2008.producer p ON p.producer_id = A.producer_id LEFT JOIN vn2008.Tipos tp ON A.tipo_id = tp.tipo_id LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id LEFT JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador LEFT JOIN vn2008.Tintas t ON t.Id_Tinta = A.color LEFT JOIN vn2008.Compres C ON i.buy_id = C.Id_Compra LEFT JOIN vn2008.Entradas E USING(Id_Entrada) LEFT JOIN vn2008.Origen o ON o.id = A.id_origen LEFT JOIN vn2008.last_year ly ON ly.Id_Article = A.Id_Article LEFT JOIN vn2008.cur_year cy ON cy.Id_Article = A.Id_Article AND (i.avalaible <> 0 OR i.visible <> 0 OR cweek1 OR cweek2 OR cweek3 OR cweek4 OR cweek5 OR cweek6 OR cweek7 OR lweek1 OR lweek2 OR lweek3 OR lweek4 OR lweek5 OR lweek6 OR lweek7) WHERE r.display <> 0 AND %s ' ,i_wh,strFILTRO )); ALTER TABLE remcom CHANGE COLUMN `cweek1` `cweek1` INT NOT NULL, CHANGE COLUMN `cweek2` `cweek2` INT NOT NULL, CHANGE COLUMN `cweek3` `cweek3` INT NOT NULL, CHANGE COLUMN `cweek4` `cweek4` INT NOT NULL, CHANGE COLUMN `cweek5` `cweek5` INT NOT NULL, CHANGE COLUMN `cweek6` `cweek6` INT NOT NULL, CHANGE COLUMN `cweek7` `cweek7` INT NOT NULL, CHANGE COLUMN `lweek1` `lweek1` INT NOT NULL, CHANGE COLUMN `lweek2` `lweek2` INT NOT NULL, CHANGE COLUMN `lweek3` `lweek3` INT NOT NULL, CHANGE COLUMN `lweek4` `lweek4` INT NOT NULL, CHANGE COLUMN `lweek5` `lweek5` INT NOT NULL, CHANGE COLUMN `lweek6` `lweek6` INT NOT NULL, CHANGE COLUMN `lweek7` `lweek7` INT NOT NULL; SELECT * FROM remcom; -- Destruye las tablas temporales creadas. DROP TEMPORARY TABLE last_year; DROP TEMPORARY TABLE cur_year; DROP TEMPORARY TABLE article_inventory; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comparativeTest` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comparativeTest`( v_date DATETIME ,days TINYINT ,i_wh TINYINT ,i_tipo INT ,i_filtro INT ) BEGIN DECLARE wstart INT; DECLARE wend INT; DECLARE cyear INT; DECLARE date_cyear_ini DATETIME; DECLARE date_cyear_end DATETIME; DECLARE week_count TINYINT DEFAULT 7; DECLARE date_lyear_ini DATETIME; DECLARE date_lyear_end DATETIME; DECLARE corrector INT; DECLARE w1, w2, w3, w4, w5, w6, w7 INT; DECLARE y1, y2, y3, y4, y5, y6, y7 INT; DECLARE wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016 DECLARE i INT DEFAULT 0; DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE'; IF i_filtro THEN SELECT `sql` INTO strFILTRO FROM filtros WHERE id = i_filtro; END IF; SET corrector = 1; IF days < 0 OR days > 30 THEN SET days = 15; END IF; IF i_wh = NULL THEN SET i_wh = 0; END IF; -- JGF 2015-04-16 cambio -21 por -22 para que la semana cuente de domingo a sabado SET date_cyear_ini = TIMESTAMP(DATE(TIMESTAMPADD(DAY, -22 - WEEKDAY(v_date), v_date)), '00:00:00'); SET date_cyear_end = TIMESTAMP(DATE(TIMESTAMPADD(DAY, (7 * week_count) -1, date_cyear_ini)), '23:59:59'); -- Eliminamos el calculo del inventario para fechas en el pasado CALL article (); INSERT INTO article_inventory (article_id) SELECT Id_Article FROM Articles a JOIN Tipos t ON a.tipo_id = t.tipo_id LEFT JOIN vn2008.reinos r ON r.id = t.reino_id WHERE (i_tipo = 0 OR a.tipo_id = i_tipo) AND r.display <> 0; IF v_date < CURDATE() THEN ALTER TABLE `article_inventory` ADD `buy_id` INT NOT NULL DEFAULT 0, ADD `buy_date` DATE DEFAULT '2000-01-01', ADD `life` INT DEFAULT 0, ADD `sd` INT DEFAULT 0, ADD `avalaible` INT DEFAULT 0, ADD `visible` INT DEFAULT 0; ELSE CALL inventario_multiple_2 (v_date, i_wh, days); CALL article_multiple_buy (v_date, i_wh); CALL article_multiple_buy_date (v_date, i_wh); END IF; DROP TEMPORARY TABLE IF EXISTS wtable; CREATE TEMPORARY TABLE wtable ( cy INT(6), ly INT(6) ); REPEAT SET i = i + 1; SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini)); -- PAK 11/01/2016 INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100); -- VALUES( ys * 100 + ws, (ys -1) * 100 + ws); -- PAK 11/01/2016 UNTIL i = 7 END REPEAT; SELECT cy, ly INTO w1, y1 FROM wtable limit 1; SELECT cy, ly INTO w2, y2 FROM wtable WHERE cy > w1 limit 1; SELECT cy, ly INTO w3, y3 FROM wtable WHERE cy > w2 limit 1; SELECT cy, ly INTO w4, y4 FROM wtable WHERE cy > w3 limit 1; SELECT cy, ly INTO w5, y5 FROM wtable WHERE cy > w4 limit 1; SELECT cy, ly INTO w6, y6 FROM wtable WHERE cy > w5 limit 1; SELECT cy, ly INTO w7, y7 FROM wtable WHERE cy > w6 limit 1; DROP TEMPORARY TABLE wtable; SET cyear = YEAR(date_cyear_ini); -- Genera una tabla con los datos del año pasado. DROP TEMPORARY TABLE IF EXISTS last_year; CREATE TEMPORARY TABLE last_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(Periodo = y1, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek1 ,CAST(SUM(IF(Periodo = y2, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek2 ,CAST(SUM(IF(Periodo = y3, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek3 ,CAST(SUM(IF(Periodo = y4, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek4 ,CAST(SUM(IF(Periodo = y5, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek5 ,CAST(SUM(IF(Periodo = y6, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek6 ,CAST(SUM(IF(Periodo = y7, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek7 ,CAST(SUM(IF(Periodo = y1, price, 0)) AS DECIMAL(10,0)) AS lprice1 ,CAST(SUM(IF(Periodo = y2, price, 0)) AS DECIMAL(10,0)) AS lprice2 ,CAST(SUM(IF(Periodo = y3, price, 0)) AS DECIMAL(10,0)) AS lprice3 ,CAST(SUM(IF(Periodo = y4, price, 0)) AS DECIMAL(10,0)) AS lprice4 ,CAST(SUM(IF(Periodo = y5, price, 0)) AS DECIMAL(10,0)) AS lprice5 ,CAST(SUM(IF(Periodo = y6, price, 0)) AS DECIMAL(10,0)) AS lprice6 ,CAST(SUM(IF(Periodo = y7, price, 0)) AS DECIMAL(10,0)) AS lprice7 FROM Comparativa JOIN warehouse W on W.id = warehouse_id WHERE (Periodo BETWEEN y1 and y7) AND IF(i_wh = 0, W.is_comparative, i_wh = warehouse_id) GROUP BY Id_Article; -- Genera una tabla con los datos de este año. DROP TEMPORARY TABLE IF EXISTS cur_year; CREATE TEMPORARY TABLE cur_year (KEY (Id_Article)) ENGINE = MEMORY SELECT Id_Article ,CAST(SUM(IF(week = w1, Total, 0)) AS DECIMAL(10,0)) AS cweek1 ,CAST(SUM(IF(week = w2, Total, 0)) AS DECIMAL(10,0)) AS cweek2 ,CAST(SUM(IF(week = w3, Total, 0)) AS DECIMAL(10,0)) AS cweek3 ,CAST(SUM(IF(week = w4, Total, 0)) AS DECIMAL(10,0)) AS cweek4 ,CAST(SUM(IF(week = w5, Total, 0)) AS DECIMAL(10,0)) AS cweek5 ,CAST(SUM(IF(week = w6, Total, 0)) AS DECIMAL(10,0)) AS cweek6 ,CAST(SUM(IF(week = w7, Total, 0)) AS DECIMAL(10,0)) AS cweek7 ,CAST(SUM(IF(week = w1, price, 0)) AS DECIMAL(10,0)) AS cprice1 ,CAST(SUM(IF(week = w2, price, 0)) AS DECIMAL(10,0)) AS cprice2 ,CAST(SUM(IF(week = w3, price, 0)) AS DECIMAL(10,0)) AS cprice3 ,CAST(SUM(IF(week = w4, price, 0)) AS DECIMAL(10,0)) AS cprice4 ,CAST(SUM(IF(week = w5, price, 0)) AS DECIMAL(10,0)) AS cprice5 ,CAST(SUM(IF(week = w6, price, 0)) AS DECIMAL(10,0)) AS cprice6 ,CAST(SUM(IF(week = w7, price, 0)) AS DECIMAL(10,0)) AS cprice7 FROM ( SELECT A.Id_Article ,CTS.period week ,SUM(Cantidad) AS Total ,TRUNCATE(SUM(Cantidad * IF(T.Fecha >= '2015-10-01',M.CostFixat,Preu * (100 - Descuento) / 100)),0) AS price FROM Movimientos M LEFT JOIN Tickets T ON T.Id_Ticket = M.Id_Ticket INNER JOIN `time` CTS ON CTS.`date` = DATE(T.Fecha) INNER JOIN Articles A USING (Id_Article) INNER JOIN Tipos tp ON tp.tipo_id = A.tipo_id LEFT JOIN reinos r ON r.id = tp.reino_id JOIN warehouse W ON W.id = T.warehouse_id WHERE Fecha BETWEEN date_cyear_ini AND date_cyear_end AND T.Id_Cliente NOT IN(400,200) AND IF(i_wh = 0, W.is_comparative, i_wh = T.warehouse_id) AND r.display <> 0 GROUP BY A.Id_Article, week ) t GROUP BY Id_Article; -- Genera la tabla con la comparativa. DROP TEMPORARY TABLE IF EXISTS remcom; SET strFILTRO = REPLACE(strFILTRO, 'Id_Article','A.Id_Article'); SET strFILTRO = REPLACE(strFILTRO, 'tipo_id','tp.tipo_id'); -- select * from article_inventory; CALL util.exec (sql_printf ( 'SELECT an.nicho, p.name Productor, C.Packing, C.Costefijo ,A.Color, Id_Tipo as Tipo,A.tipo_id, o.Abreviatura as Origen, A.Categoria ,A.Tallos, A.Medida, A.Article, TR.CodigoTrabajador ,cweek1, cweek2, cweek3, cweek4, cweek5, cweek6, cweek7 ,lweek1, lweek2, lweek3, lweek4, lweek5, lweek6, lweek7 ,cprice1, cprice2, cprice3, cprice4, cprice5, cprice6, cprice7 ,lprice1, lprice2, lprice3, lprice4, lprice5, lprice6, lprice7 ,A.Id_Article, i.buy_id , tp.life , CAST(IFNULL(i.sd,0) AS SIGNED) as sd ,CAST(i.avalaible AS SIGNED) avalaible, CAST(i.visible AS SIGNED) visible, i.buy_date ,E.Id_Proveedor AS provider_id, t.Orden, t.Tinta ,A.offer, A.bargain, A.comments, A.relevancy ,IF(cy.Id_Article IS NULL AND i.visible = 0 AND i.avalaible = 0 AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) AS filtret FROM vn2008.article_inventory i JOIN vn2008.Articles A ON A.Id_Article = i.article_id LEFT JOIN vn2008.Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s LEFT JOIN vn2008.producer p ON p.producer_id = A.producer_id LEFT JOIN vn2008.Tipos tp ON A.tipo_id = tp.tipo_id LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id LEFT JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador LEFT JOIN vn2008.Tintas t ON t.Id_Tinta = A.color LEFT JOIN vn2008.Compres C ON i.buy_id = C.Id_Compra LEFT JOIN vn2008.Entradas E USING(Id_Entrada) LEFT JOIN vn2008.Origen o ON o.id = A.id_origen LEFT JOIN vn2008.last_year ly ON ly.Id_Article = A.Id_Article LEFT JOIN vn2008.cur_year cy ON cy.Id_Article = A.Id_Article AND (i.avalaible <> 0 OR i.visible <> 0 OR cweek1 OR cweek2 OR cweek3 OR cweek4 OR cweek5 OR cweek6 OR cweek7 OR lweek1 OR lweek2 OR lweek3 OR lweek4 OR lweek5 OR lweek6 OR lweek7) WHERE r.display <> 0 AND %s ' ,i_wh,strFILTRO )); -- Destruye las tablas temporales creadas. DROP TEMPORARY TABLE last_year; DROP TEMPORARY TABLE cur_year; DROP TEMPORARY TABLE article_inventory; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `compresFromTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `compresFromTicket`(IN vTicketId BIGINT, IN vEntryId BIGINT) BEGIN DECLARE vShipmentWarehouse INT; DECLARE vShipmentDate INT; SELECT warehouse_id_out, shipment INTO vShipmentWarehouse, vShipmentDate FROM travel tr JOIN Entradas e ON e.travel_id = tr.id WHERE Id_Entrada = vEntryId; CALL item_last_buy_(vShipmentWarehouse,vShipmentDate); INSERT INTO Compres(Id_Article,Cantidad, Id_Entrada, Id_Cubo, Packing, grouping, caja, Costefijo, Etiquetas) SELECT m.Id_Article, m.Cantidad, vEntryId, c.Id_Cubo, c.Packing, IF(c.grouping,c.grouping,1), c.caja, buyingAbsoluteCost(c.Id_Compra) Costefijo, ifnull(floor(m.Cantidad / c.Packing),1) Etiquetas FROM Movimientos m JOIN Articles a ON m.Id_Article = a.Id_Article LEFT JOIN t_item_last_buy b ON m.Id_Article = b.item_id AND b.warehouse_id = vShipmentWarehouse LEFT JOIN Compres c ON c.Id_Compra = b.buy_id WHERE m.Id_Ticket = vTicketId; CALL buy_tarifas_entry(vEntryId); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `CompresTriggerBeforeDelete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `CompresTriggerBeforeDelete`(oldId INT, oldEntrada INT) BEGIN DECLARE hasToRecalculate BOOLEAN; DECLARE newWarehouse INT; SELECT Id_Compra INTO hasToRecalculate FROM vn.lastBuy lb WHERE lb.id = oldId LIMIT 1; IF hasToRecalculate THEN SELECT warehouse_id INTO newWarehouse FROM travel t JOIN Entradas e ON t.id = e.travel_id WHERE e.Id_Entrada = oldEntrada; CALL vn.lastBuyRefresh(newWarehouse); END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `compresTriggerBeforeInsert` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `compresTriggerBeforeInsert`(newNoVincular INT, newEntrada INT, newCompra INT, newItem INT) BEGIN DECLARE newWarehouse INTEGER; IF newNoVincular = FALSE THEN UPDATE travel t JOIN vn.lastBuy lb ON newItem = lb.item AND t.warehouse_id = lb.warehouse JOIN Entradas e ON e.travel_id = t.id SET lb.id = newCompra WHERE e.Id_Entrada = newEntrada AND t.landing > lb.landing AND t.landing <= CURDATE(); END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `compresTriggerBeforeUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `compresTriggerBeforeUpdate`(vOldEntrada INT, vNewEntrada INT, oldItem INT, newItem INT, newNoVincular BOOLEAN, newCompra INT) BEGIN DECLARE newWarehouse INTEGER; DECLARE hasToRecalculate BOOLEAN; IF newNoVincular = FALSE THEN IF oldItem <> newItem OR vOldEntrada <> vNewEntrada THEN SELECT Id_Compra INTO hasToRecalculate FROM travel t JOIN Entradas e ON e.travel_id = t.id JOIN vn.lastBuy lb ON lb.id = newCompra WHERE e.Id_Entrada = vOldEntrada LIMIT 1; IF hasToRecalculate THEN SELECT warehouse_id INTO newWarehouse FROM travel t JOIN Entradas e ON t.id = e.travel_id WHERE e.Id_Entrada = vOldEntrada; CALL vn.lastBuyRefresh(newWarehouse); END IF; END IF; IF vOldEntrada <> vNewEntrada THEN UPDATE Entradas oldEntrada JOIN travel oldTravel ON oldEntrada.travel_id = oldtravel.id JOIN Entradas newEntrada ON newEntrada.Id_Entrada = vNewEntrada JOIN travel newTravel ON newTravel.id = newEntrada.travel_id JOIN vn.lastBuy lb ON newItem = lb.item AND newTravel.warehouse_id = lb.warehouse SET lb.id = newCompra WHERE oldEntrada.Id_Entrada = vOldEntrada AND oldTravel.warehouse_id <> newTravel.warehouse_id AND newTravel.landing > lb.landing AND newTravel.landing <= CURDATE(); END IF; END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `confection_control_source` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `confection_control_source`(vScopeDays TINYINT) BEGIN DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(CURDATE(),'23:59:59'); DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight); DECLARE maxAlertLevel INT DEFAULT 2; DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer; CREATE TEMPORARY TABLE tmp.production_buffer ENGINE = MEMORY SELECT date(t.Fecha) as Fecha, hour(t.Fecha) as Hora, hour(t.Fecha) as Departure, t.Id_Ticket, m.Id_Movimiento, m.Cantidad, m.Concepte, ABS(m.Reservado) Reservado, i.Categoria, t.Alias as Cliente, wh.name as Almacen, t.warehouse_id, cs.province_id, a.agency_id, ct.description as Taller, stock.visible, stock.available FROM vn2008.Tickets t JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia JOIN vn2008.warehouse wh ON wh.id = t.warehouse_id JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket JOIN vn2008.Articles i ON i.Id_Article = m.Id_Article JOIN vn2008.Tipos tp ON tp.tipo_id = i.tipo_id JOIN vn.confectionType ct ON ct.id = tp.confeccion JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket LEFT JOIN ( SELECT item_id, sum(visible) visible, sum(available) available FROM ( SELECT a.item_id, 0 as visible, a.available FROM cache.cache_calc cc LEFT JOIN cache.available a ON a.calc_id = cc.id WHERE cc.cache_id IN (2,8) AND cc.params IN (concat("1/", CURDATE()),concat("44/", CURDATE())) UNION ALL SELECT v.item_id, v.visible, 0 as available FROM cache.cache_calc cc LEFT JOIN cache.visible v ON v.calc_id = cc.id where cc.cache_id IN (2,8) and cc.params IN ("1","44") ) sub GROUP BY item_id ) stock ON stock.item_id = m.Id_Article WHERE tp.confeccion AND tls.alertLevel < maxAlertLevel AND wh.hasConfectionTeam AND t.Fecha BETWEEN CURDATE() AND vEndingDate AND m.Cantidad > 0; -- Hora limite de preparación CALL production_buffer_set_priority; -- Entradas INSERT INTO tmp.production_buffer( Fecha, Id_Ticket, Cantidad, Concepte, Categoria, Cliente, Almacen, Taller ) SELECT tr.shipment AS Fecha, e.Id_Entrada AS Id_Ticket, c.Cantidad, a.Article, a.Categoria, whi.name as Cliente, who.name as Almacen, ct.description as Taller FROM vn2008.Compres c JOIN vn2008.Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN vn2008.travel tr ON tr.id = e.travel_id JOIN vn2008.warehouse whi ON whi.id = tr.warehouse_id JOIN vn2008.warehouse who ON who.id = tr.warehouse_id_out JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id JOIN vn.confectionType ct ON ct.id = tp.confeccion WHERE who.hasConfectionTeam AND tp.confeccion AND tr.shipment BETWEEN CURDATE() AND vEndingDate; SELECT * FROM tmp.production_buffer; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `createBouquet` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `createBouquet`( vName VARCHAR(50), vType int, vSize int, vColour VARCHAR(5), OUT vItem INT(11) ) BEGIN DECLARE vDate DATE; DECLARE vCodintrastat INT(11); -- COMPROBAMOS SI EXISTE UN ARTÍCULO IGUAL. SELECT Id_Article INTO vItem FROM Articles WHERE (Id_Article BETWEEN 161000 AND 169000) AND Article LIKE CONCAT('%', vName) AND tipo_id = vType AND Medida = vSize AND Color = vColour LIMIT 1; -- SI NO EXISTE CREAMOS UNO NUEVO IF vItem IS NULL THEN -- OBTENER EL ID ENTRE 161000 Y 169000 DEL SIGUIENTE ARTÍCULO SELECT (IF(MAX(Id_Article) IS NULL, 161000, (MAX(Id_Article) + 1))) INTO vItem FROM Articles WHERE Id_Article BETWEEN 161000 AND 169000; -- INSERTAR EL ARTÍCULO INSERT INTO Articles(Id_Article, Article, tipo_id, Medida, color, id_origen) VALUES ( vItem, vName, vType, vSize, vColour, 1 ); END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `createWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `createWorker`( vName VARCHAR(50), vCognames VARCHAR(50), vDNI VARCHAR(9), vAddress TEXT, vPostalCode VARCHAR(5), vTown VARCHAR(25), vProvince SMALLINT(5), vCompany SMALLINT(5), vPhone VARCHAR(11), vMail VARCHAR(80) CHARSET utf8, vDniExpiration DATETIME, vEmployeeBoss INT ) BEGIN DECLARE vClient INT; DECLARE vUser INT; DECLARE vWorker INT; DECLARE vWorkerCode VARCHAR(8); DECLARE vPassword VARCHAR(50); DECLARE vUsername VARCHAR(50) CHARSET utf8; DECLARE vOficial INT DEFAULT 1; DECLARE vDiscount INT DEFAULT 3; DECLARE vPayMethodFk INT DEFAULT 4; DECLARE vDueDay INT DEFAULT 5; DECLARE vDefaultCredit INT DEFAULT 300; DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1; ############################################################################## #### GENERAR CLIENTE ############################################################################## -- Comprobar si existe un cliente con el mismo DNI. SELECT Id_cliente INTO vClient FROM vn2008.Clientes WHERE `if` = vDNI; -- Si no existe el cliente creamos uno nuevo. IF vClient IS NULL THEN SELECT (MAX(Id_Cliente) + 1) INTO vClient FROM Clientes WHERE Id_Cliente < 999999; INSERT INTO Clientes ( Id_Cliente, Cliente, Domicilio, `IF`, Telefono, province_id, Poblacion, CodPostal, RazonSocial, Contacto, Oficial, Descuento, Codpos, pay_met_id, Vencimiento, Credito, contabilizado) SELECT vClient, Concat('TR ', vName, ' ', vCognames), vAddress, vDNI, vPhone, vProvince, vTown, vPostalCode, CONCAT(vCognames, ' ', vName), vName, vOficial, vDiscount, vPostalCode, vPayMethodFk, vDueDay, vDefaultCredit, vIsTaxDataChecked; END IF; ############################################################################## #### GENERAR USUARIO ############################################################################## SET vUsername = LCASE(CONCAT(REPLACE(vName, ' ', ''), LEFT(vCognames, 1), MID(vCognames, (LOCATE(' ', vCognames) + 1), 1))); -- Generar nombre de usuario hasta que haya uno disponible. WHILE (SELECT COUNT(*) FROM account.user WHERE `name`= vUsername) DO SET vUsername = CONCAT(vUsername, (FLOOR(RAND() * 100))); END WHILE; SET vPassword = CONCAT(IF(INSTR(vCognames,' ') = 0, vCognames, LEFT(vCognames, INSTR(vCognames,' ') - 1)), '.' , vClient); -- Comprobamos si existe un usuario con el mismo ID de cliente. IF NOT (SELECT COUNT(*) FROM account.user where id = vClient) THEN -- Alta del usuario. INSERT INTO account.user (id, role, `name`, `password`, active) VALUES (vClient, 1, LCASE(vUsername), MD5(LCASE(vPassword)), 1); SET vUser = vClient; INSERT INTO account.account SET id = vClient; ELSE -- Alta del usuario. INSERT INTO account.user (role, `name`, `password`, active) VALUES (1, LCASE(vUsername), MD5(LCASE(vPassword)), 1); SET vUser = LAST_INSERT_ID(); INSERT INTO account.account SET id = vUser; END IF; ############################################################################## #### GENERAR TRABAJADOR ############################################################################## SET vWorkerCode = CONCAT(LEFT(vName, 1), LEFT(vCognames, 1), MID(vCognames, (LOCATE(' ', vCognames) + 1), 1)); -- Generar código de trabajador hasta que haya uno disponible. IF (SELECT COUNT(*) FROM Trabajadores WHERE CodigoTrabajador = vWorkerCode) THEN SET vWorkerCode = "001"; END IF; -- Comprobamos si ya existe un trabajador con el mismo DNI. IF NOT (SELECT COUNT(*) FROM Trabajadores WHERE dni = vDNI) THEN -- Alta en la tabla trabajadores. INSERT INTO Trabajadores (CodigoTrabajador, Nombre, Apellidos, `Password`, dni, empresa_id, user_id, boss, DniExpiration) VALUES (vWorkerCode, vName, vCognames, LCASE(vPassword), vDNI, vCompany, vUser, vEmployeeBoss, VDniExpiration); SET vWorker = LAST_INSERT_ID(); ELSE UPDATE Trabajadores SET user_id = vUser WHERE dni = vDNI; END IF; ############################################################################## #### REENVIO EMAIL ############################################################################## IF vMail IS NOT NULL AND NOT (SELECT COUNT(*) FROM account.mailForward WHERE forwardTo = vMail) THEN INSERT INTO account.mailForward (account, forwardTo) VALUES (vUser, vMail); UPDATE Trabajadores SET email = CONCAT(vUsername, '@verdnatura.es') WHERE user_id = vUser; END IF; -- Devolver información generada SELECT vUser, vWorker, vPassword, vUsername; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `credit_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `credit_update`() BEGIN DECLARE dblDiferencia DOUBLE DEFAULT 10.0; DECLARE dblImporteRec,auxdblImporteRec DOUBLE DEFAULT 0.0; DECLARE dblImporteFac,auxdblImporteFac DOUBLE DEFAULT 0.0; DECLARE intIdRecibo,auxintIdRecibo INT (11) DEFAULT 0; DECLARE intId_Cliente,auxintId_Cliente,intId_ClienteRec,auxintId_ClienteRec INT DEFAULT 0; DECLARE bitFin,bitFinRecord,bitFinRecord1 BIT DEFAULT 0; DECLARE datFechaVencimiento DATE DEFAULT CURDATE(); DECLARE intEmpresa_id INT DEFAULT 0; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `customerDebtEvolution` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `customerDebtEvolution`(IN vCustomer INT) BEGIN SELECT * FROM ( SELECT day, date, @s:= round(IFNULL(Euros,0) + @s,2) as Saldo, Euros, Credito, 0 as Cero FROM ( SELECT day, date, IFNULL(Euros,0) as Euros, Credito FROM time JOIN (SELECT @s:= 0, - Credito as Credito FROM Clientes WHERE Id_Cliente = vCustomer) c LEFT JOIN (SELECT Euros, date(Fecha) as Fecha FROM ( SELECT Fechacobro as Fecha, Entregado as Euros FROM Recibos WHERE Id_Cliente = vCustomer AND Fechacobro >= '2017-01-01' UNION ALL SELECT paymentday(f.Fecha,c.Vencimiento), - Importe FROM Facturas f JOIN Clientes c ON f.Id_Cliente = c.Id_Cliente WHERE f.Id_Cliente = vCustomer AND Fecha >= '2017-01-01' UNION ALL SELECT '2016-12-31', Debt FROM bi.customerDebtInventory WHERE Id_Cliente = vCustomer UNION ALL SELECT Fecha, - SUM(Cantidad * Preu * (100 - Descuento ) * 1.10 / 100) FROM Tickets t JOIN Movimientos m on m.Id_Ticket = t.Id_Ticket WHERE Id_Cliente = vCustomer AND Factura IS NULL AND Fecha >= '2017-01-01' GROUP BY Fecha ) sub2 ORDER BY Fecha )sub ON time.date = sub.Fecha WHERE time.date BETWEEN '2016-12-31' AND CURDATE() ORDER BY date ) sub3 )sub4 ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cycDueDateClassification` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cycDueDateClassification`(vCompany INT,vDate DATE) BEGIN SELECT Fecha, Clasificacion, CAST(SUM(Importe) AS DECIMAL(10,2)) as Importe, empresa_id FROM ( SELECT CASE WHEN C.Vencimiento <= 30 THEN '0-30 dias' WHEN C.Vencimiento BETWEEN 31 AND 60 THEN '31-60 dias' WHEN C.Vencimiento BETWEEN 61 AND 90 THEN '61-90 dias' ELSE '> 90 dias' END AS Clasificacion, F.Importe, C.Fecha, F.empresa_id FROM cyc_declaration C JOIN Facturas F USING(factura_id) WHERE C.Riesgo > 0 AND C.Fecha = vDate AND F.empresa_id = vCompany ) cyc GROUP BY Fecha, Clasificacion, empresa_id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cycGeneralClassification` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cycGeneralClassification`(vCompany INT,vDate DATE) BEGIN SELECT Fecha, Clasificacion, CAST(SUM(Importe) AS DECIMAL(10,2)) as Importe, empresa_id FROM ( SELECT CASE IFNULL(C.Riesgo,-1) WHEN 0 THEN 'No aseguradas' WHEN -1 THEN 'Clasificacion nada' ELSE 'Asegurados' END AS Clasificacion, F.Importe, C.Fecha, F.empresa_id FROM cyc_declaration C JOIN Facturas F ON F.factura_id = C.factura_id WHERE C.Fecha = vDate AND F.empresa_id = vCompany ) cyc GROUP BY Fecha, Clasificacion, empresa_id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cycNoInsurancedClassification` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cycNoInsurancedClassification`(vCompany INT,vDate DATE) BEGIN SELECT 'ORG. PUBLICOS' AS Tipo, C.Fecha, CAST(SUM(F.Importe) AS DECIMAL(10,2)) as Importe, F.empresa_id FROM cyc_declaration C INNER JOIN Facturas F USING(factura_id) JOIN Clientes CL USING(Id_Cliente) WHERE C.Riesgo IS NULL AND LEFT(CL.`IF`,1) = 'G' AND C.Fecha = vDate AND F.empresa_id = vCompany GROUP BY Fecha, F.empresa_id UNION ALL SELECT 'VINCULADAS' , C.Fecha, CAST(SUM(F.Importe) AS DECIMAL(10,2)) as Importe, F.empresa_id FROM cyc_declaration C INNER JOIN Facturas F USING(factura_id) WHERE C.Riesgo IS NULL AND F.Id_Cliente IN(2066, 2067) AND C.Fecha = vDate AND F.empresa_id = vCompany GROUP BY Fecha, F.empresa_id UNION ALL SELECT 'CONTADO', C.Fecha, CAST(SUM(F.Importe) AS DECIMAL(10,2)) as Importe, F.empresa_id FROM cyc_declaration C INNER JOIN Facturas F USING(factura_id) JOIN Clientes CL USING(Id_Cliente) WHERE C.Riesgo IS NULL AND pay_met_id = 1 AND LEFT(CL.`IF`,1) <> 'G' AND F.Id_Cliente NOT IN(2066, 2067) AND C.Fecha = vDate AND F.empresa_id = vCompany GROUP BY Fecha, F.empresa_id UNION ALL SELECT 'OTROS', C.Fecha, CAST(SUM(F.Importe) AS DECIMAL(10,2)) as Importe, F.empresa_id FROM cyc_declaration C INNER JOIN Facturas F USING(factura_id) JOIN Clientes CL USING(Id_Cliente) WHERE C.Riesgo IS NULL AND pay_met_id <> 1 AND LEFT(CL.`IF`,1) <> 'G' AND F.Id_Cliente NOT IN(2066, 2067) AND C.Fecha = vDate AND F.empresa_id = vCompany GROUP BY Fecha, F.empresa_id ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cyc_mensual` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = '' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cyc_mensual`(IN datFEC DATE) BEGIN REPLACE cyc_declaration(factura_id, Riesgo, Fecha, Vencimiento) SELECT F.factura_id, R.Riesgo, @fecha, IFNULL(C.Vencimiento,0) FROM Facturas F INNER JOIN Clientes C ON F.Id_Cliente = C.Id_Cliente INNER JOIN empresa E ON E.id = F.empresa_id LEFT JOIN ( SELECT * FROM ( SELECT Id_Cliente, Riesgo FROM cyc WHERE Fecha <= @fecha:= TIMESTAMPADD(DAY, -1 * DAY(datFEC), datFEC) ORDER BY Fecha DESC ) sub GROUP BY Id_Cliente ) R ON F.Id_Cliente = R.Id_Cliente WHERE E.cyc AND periodo(Fecha) = periodo(@fecha) ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cyc_report2kk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cyc_report2kk`() BEGIN SELECT Fecha, Clasificacion, CAST(SUM(Importe) AS DECIMAL(10,2)) as Importe, empresa_id FROM ( SELECT CASE WHEN C.Vencimiento <= 30 THEN '0-30 dias' WHEN C.Vencimiento BETWEEN 31 AND 60 THEN '31-60 dias' WHEN C.Vencimiento BETWEEN 61 AND 90 THEN '61-90 dias' ELSE '> 90 dias' END AS Clasificacion, F.Importe, C.Fecha, F.empresa_id FROM cyc_declaration C INNER JOIN Facturas F USING(factura_id) WHERE C.Riesgo > 0 ) cyc GROUP BY Fecha, Clasificacion, empresa_id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cyc_reportkk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `cyc_reportkk`() BEGIN SELECT Fecha, Clasificacion, CAST(SUM(Importe) AS DECIMAL(10,2)) as Importe, empresa_id FROM ( SELECT CASE IFNULL(C.Riesgo,-1) WHEN 0 THEN 'No aseguradas' WHEN -1 THEN 'Sin clasificar' ELSE 'Asegurados' END AS Clasificacion, F.Importe, C.Fecha, F.empresa_id FROM cyc_declaration C INNER JOIN Facturas F USING(factura_id) ) cyc GROUP BY Fecha, Clasificacion, empresa_id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `defaulterRanking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `defaulterRanking`() BEGIN SELECT c.Id_Cliente, hasChanged, Cliente, amount as Deuda, CodigoTrabajador, CyC, Apuntador, Fecha_obs, last_obs, defaulterSince from bi.defaulters d join ( SELECT customer_id Id_Cliente,SUM(amount) AS Saldo FROM bi.customerRiskOverdue GROUP BY customer_id ) saldos ON saldos.Id_Cliente = d.client join Clientes c on c.Id_Cliente = d.client join Trabajadores t USING (Id_Trabajador) left join ( SELECT Id_Cliente, last_obs, CodigoTrabajador as Apuntador, Fecha as Fecha_obs FROM ( SELECT Id_Cliente, `text` as last_obs, CodigoTrabajador, client_observation.odbc_date as Fecha FROM client_observation JOIN Trabajadores using(Id_Trabajador) order by client_observation.odbc_date desc ) sub GROUP BY Id_Cliente ) obs on obs.Id_Cliente = d.client WHERE date = CURDATE() and amount > 0 and not (Saldo > amount AND amount < 0) and CodigoTrabajador not in ('CYC','BUD','EJE') ORDER BY amount DESC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `desglose_volume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `desglose_volume`(IN agency_id INT) BEGIN DECLARE v_start DATETIME DEFAULT TIMESTAMP(CURDATE()); DECLARE v_end DATETIME DEFAULT TIMESTAMP(CURDATE(), '23:59:59'); SET v_start = IF(WEEKDAY(CURDATE()), CURDATE(),TIMESTAMPADD(DAY,-1,CURDATE())); SET v_start = IF(CURDATE() = '2014-05-02', '2014-05-01',v_start); DROP TEMPORARY TABLE IF EXISTS zeleVOL; CREATE TEMPORARY TABLE zeleVOL ( Id_Ticket INT PRIMARY KEY ,Provincia VARCHAR(30) ,Bultos INT DEFAULT 0 ,Faltan INT DEFAULT 0 ); -- Insertamos los tickets que ya tienen la linea de portes INSERT INTO zeleVOL(Provincia, Id_Ticket, Bultos) SELECT p.name, t.Id_Ticket, sum(m.Cantidad) FROM Tickets t JOIN Consignatarios c USING(Id_Consigna) JOIN province p ON c.province_id = p.province_id JOIN Movimientos m USING(Id_Ticket) JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia JOIN warehouse_joined wj ON wj.warehouse_id = t.warehouse_id WHERE m.Id_Article = 71 AND wj.warehouse_alias_id = 1 -- El 1 equivale a Silla (SillaFV-SillaPCA) AND t.Fecha BETWEEN v_start AND v_end AND a.agency_id = agency_id GROUP BY p.name, Id_Ticket; -- Insertamos los tickets que ya tienen expediciones, que fallaran si se repite la clave primaria. INSERT INTO zeleVOL(Provincia, Id_Ticket, Bultos) SELECT p.name, e.ticket_id, COUNT(e.ticket_id) FROM expeditions e JOIN Tickets t ON ticket_id = Id_Ticket JOIN Consignatarios c USING(Id_Consigna) JOIN province p ON c.province_id = p.province_id JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia JOIN warehouse_joined wj ON wj.warehouse_id = t.warehouse_id WHERE e.odbc_date BETWEEN v_start AND v_end AND wj.warehouse_alias_id = 1 -- El 1 equivale a Silla (SillaFV-SillaPCA) AND a.agency_id = agency_id GROUP BY p.name, ticket_id ON DUPLICATE KEY UPDATE Bultos = Bultos; -- Por encajar INSERT INTO zeleVOL(Provincia, Id_Ticket, Faltan) SELECT province, Id_Ticket, COUNT(Id_Ticket) as Faltan FROM ( SELECT p.name AS province, Id_Ticket, COUNT(Id_Movimiento) l, SUM(Cantidad) c FROM Movimientos m JOIN Tickets t USING(Id_Ticket) JOIN Consignatarios c USING(Id_Consigna) JOIN province p ON c.province_id = p.province_id JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia LEFT JOIN expeditions e ON t.Id_Ticket = e.ticket_id JOIN warehouse_joined wj ON wj.warehouse_id = t.warehouse_id WHERE Fecha BETWEEN v_start AND v_end AND wj.warehouse_alias_id = 1 -- El 1 equivale a Silla (SillaFV-SillaPCA) AND a.agency_id = agency_id AND (Bultos = 0 AND expeditions_id IS NULL AND EtiquetasEmitidas = 0) GROUP BY p.name, Id_Ticket ) sub GROUP BY province ON DUPLICATE KEY UPDATE Faltan = Faltan; -- Mostramos el resultado SELECT Provincia, COUNT(Id_Ticket) expediciones, SUM(Bultos) Bultos, SUM(Faltan) Prevision FROM zeleVOL GROUP BY Provincia; DROP TEMPORARY TABLE IF EXISTS zeleVOL; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `dif_porte` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `dif_porte`(IN datFEC DATE) BEGIN /* Calcula los greuges de porte que no coinciden con lo esperado / / / */ drop temporary table if exists tmp.bionic_porte; create temporary table tmp.bionic_porte select Id_Ticket, sum(Valor * Cantidad) as bionic from vn2008.Movimientos m join vn2008.Movimientos_componentes mc using(Id_Movimiento) where Id_Componente = 15 group by Id_Ticket; ALTER TABLE tmp.bionic_porte ADD KEY bp_Id_Ticket_ix (Id_Ticket); drop temporary table if exists tmp.shipping_porte; create temporary table tmp.shipping_porte select Id_Ticket, shipping_charge from vn2008.v_expeditions_shipping_charge where Fecha >= datFEC; ALTER TABLE tmp.shipping_porte ADD KEY sp_Id_Ticket_ix (Id_Ticket); drop temporary table if exists tmp.greuge_porte; create temporary table tmp.greuge_porte select Id as Id_Greuge, cast(right(Comentario,7) as decimal(10,0)) Id_Ticket, Importe FROM vn2008.Greuges where Comentario like 'dif_porte%'; ALTER TABLE tmp.greuge_porte ADD KEY Id_Ticket_ix (Id_Ticket); select * from tmp.greuge_porte; SELECT Id_Ticket,shipping_charge as Teorico, bionic as Practico, Importe as Greuge, shipping_charge - bionic - Importe as dif FROM tmp.shipping_porte join tmp.greuge_porte using(Id_Ticket) join tmp.bionic_porte using(Id_Ticket) ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `Ditacio` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Ditacio`(IN intId INT,IN straccion varchar(100),IN strtabla CHAR(1),IN intIdTrabajador INT, IN straccion_old VARCHAR(100),IN straccion_new VARCHAR(100)) proc_label:BEGIN DECLARE intlengthaccion TINYINT; DECLARE strtabla_dits VARCHAR(35); SELECT CASE WHEN strtabla='A' THEN 'Articles_dits' WHEN strtabla='I' THEN 'Inventario_dits' WHEN strtabla='E' THEN 'Entradas_dits' WHEN strtabla='T' THEN 'Tickets_dits' WHEN strtabla='C' THEN 'Clientes_dits' WHEN strtabla='V' THEN 'travel_dits' WHEN strtabla='R' THEN 'Rutas_dits' WHEN strtabla='G' THEN 'Agencias_dits' WHEN strtabla='S' THEN 'salarioDits' ELSE NULL END INTO strtabla_dits; IF (strtabla_dits IS NULL) THEN LEAVE proc_label; END IF; SET @intIdTrabajador = intIdTrabajador; SET @intId = intId; SET @strvalue_old = straccion_old; SET @strvalue_new = straccion_new; SET @intidaccion = NULL; SELECT idaccion_dits INTO @intidaccion FROM accion_dits WHERE accion=left(straccion,CHAR_LENGTH(accion)) ORDER BY CHAR_LENGTH(accion) DESC LIMIT 1; IF @intidaccion IS null THEN -- idaccion genèric per a evitar errors en cas de no existir SET @intidaccion = 103; END IF; SET @SQL=CONCAT('INSERT INTO ',strtabla_dits,' (idaccion_dits,Id_Trabajador,Id_Ticket,value_old,value_new) VALUES (?,?,?,?,?)'); PREPARE stmt1 FROM @SQL; EXECUTE stmt1 USING @intidaccion,@intIdTrabajador,@intId,@strvalue_old,@strvalue_new; DEALLOCATE PREPARE stmt1; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `emailYesterdayPurchasesByConsigna` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `emailYesterdayPurchasesByConsigna`(IN v_Date DATE, IN v_Client_Id INT) BEGIN DECLARE MyIdTicket BIGINT; DECLARE MyAlias VARCHAR(50); DECLARE MyDomicilio VARCHAR(255); DECLARE MyPoblacion VARCHAR(25); DECLARE MyImporte DOUBLE; DECLARE MyMailTo VARCHAR(250); DECLARE MyMailReplyTo VARCHAR(250); DECLARE done INT DEFAULT FALSE; DECLARE emptyList INT DEFAULT 0; DECLARE txt TEXT; DECLARE rs CURSOR FOR SELECT t.Id_Ticket, Alias, cast(amount as decimal(10,2)) Importe, Domicilio, POBLACION FROM Tickets t JOIN Consignatarios cs on t.Id_Consigna = cs.Id_Consigna JOIN v_ticket_amount v on v.Id_Ticket = t.Id_Ticket WHERE t.Fecha BETWEEN v_Date AND dayend(v_Date) AND t.Id_Cliente = v_Client_Id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET v_Date = IFNULL(v_Date, util.yesterday()); OPEN rs; FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion; SET emptyList = done; SET txt = CONCAT('
',
' Relación de envíos.
',
'Dia: ', v_Date, '
');
WHILE NOT done DO
SET txt = CONCAT(txt, '
',
'
'
, ' ', MyAlias, '
Ticket ', MyIdTicket,'
', MyImporte, ' €
'
, ' ', MyDomicilio, '(', MyPoblacion, ')');
FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion;
END WHILE;
SET txt = CONCAT(txt,
'',
'
',
' ',
'
Puede acceder al detalle de los albaranes haciendo click sobre el número de Ticket',
' Muchas gracias por su confianza
',
'